1. Code refactoring for copy node info

This commit is contained in:
vadym 2021-06-19 17:54:10 +03:00
parent b8a11fb40d
commit 68328859ad
9 changed files with 44 additions and 33 deletions

View File

@ -7,8 +7,9 @@ android {
applicationId "io.github.chronosx88.yggdrasil"
minSdkVersion 15
targetSdkVersion 29
versionCode 23
versionName "2.0.3"
versionCode 30
versionName "2.0.12"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
setProperty("archivesBaseName", project.getParent().name+"-"+versionName)
}

View File

@ -14,6 +14,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".AboutActivity"

View File

@ -1,11 +1,12 @@
package io.github.chronosx88.yggdrasil
import android.os.Bundle
import android.view.MenuItem
import android.widget.ListView
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import io.github.chronosx88.yggdrasil.models.NodeInfo
import io.github.chronosx88.yggdrasil.models.config.NodeInfoListAdapter
class CopyLocalNodeInfoActivity: AppCompatActivity() {
@ -18,8 +19,8 @@ class CopyLocalNodeInfoActivity: AppCompatActivity() {
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
val ipv6Address = intent.extras!!.getString(MainActivity.IPv6, "")
val publicKey = preferences.getString(MainActivity.publicKey, "")
var nodeInfoListView = findViewById<ListView>(R.id.nodeInfoList)
val nodeInfoList = listOf<NodeInfo>(NodeInfo("IP address", ipv6Address!!), NodeInfo("Public Key", publicKey!!));
var nodeInfoListView = findViewById<RecyclerView>(R.id.node_info_list)
val nodeInfoList = listOf(NodeInfo("IP address", ipv6Address!!), NodeInfo("Public Key", publicKey!!));
val adapter =
NodeInfoListAdapter(
this,

View File

@ -43,7 +43,7 @@ class PeerListActivity : AppCompatActivity() {
companion object {
const val PEER_LIST = "PEER_LIST"
const val PEER_LIST_URL = "https://publicpeers.neilalexander.dev/publicnodes.json"
const val PEER_LIST_URL = "xxx"
const val CACHE_NAME = "PEER_LIST_CACHE"
const val ONLINE_PEERINFO_LIST = "online_peer_info_list"
const val OFFLINE_PEERINFO_LIST = "offline_peer_info_list"

View File

@ -9,6 +9,11 @@ import org.acra.ktx.initAcra
import org.acra.sender.HttpSender
class YggApplication : Application() {
companion object {
const val ACRA_BACKEND_URL = "xxx"
}
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
@ -18,9 +23,9 @@ class YggApplication : Application() {
reportFormat = StringFormat.JSON
//each plugin you chose above can be configured in a block like this:
httpSender {
uri = "http://<host>/report"
basicAuthLogin="***"
basicAuthPassword = "***"
uri = ACRA_BACKEND_URL
basicAuthLogin="KOF7CEnt5tfTqIhj"
basicAuthPassword = "F4cCIqo9EjpihcPt"
httpMethod = HttpSender.Method.POST
}
dialog {

View File

@ -23,6 +23,7 @@ import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeS
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2PeerInfoSet
import mobile.Mobile
import mobile.Yggdrasil
import org.acra.ACRA
import java.io.*
import java.net.Inet6Address
import kotlin.concurrent.thread
@ -139,6 +140,7 @@ class YggdrasilTunService : VpnService() {
private fun sendMeshPeerStatus(pi: PendingIntent?){
class Token : TypeToken<List<Peer>>()
ygg.addressString
ACRA.errorReporter.putCustomData("Peers JSON", ygg.peersJSON)
var meshPeers: List<Peer> = gson.fromJson(ygg.peersJSON, Token().type)
val intent: Intent = Intent().putStringArrayListExtra(
MainActivity.MESH_PEERS,
@ -202,6 +204,8 @@ class YggdrasilTunService : VpnService() {
ygg.send(buffer.sliceArray(IntRange(0, length - 1)))
} catch (e: IOException) {
e.printStackTrace()
} catch (e: Exception){
e.printStackTrace();
}
}
@ -212,6 +216,8 @@ class YggdrasilTunService : VpnService() {
tunOutputStream.write(buffer)
} catch (e: IOException) {
e.printStackTrace()
} catch (e: Exception){
e.printStackTrace();
}
}
}

View File

@ -10,8 +10,9 @@ import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import io.github.chronosx88.yggdrasil.R
import io.github.chronosx88.yggdrasil.models.NodeInfo
class NodeInfoListAdapter(private val context: Context, private val infoSet: Array<Pair<String, String>>) :
class NodeInfoListAdapter(private val context: Context, private val infoSet: Array<NodeInfo>) :
RecyclerView.Adapter<NodeInfoListAdapter.ViewHolder>() {
class ViewHolder(private val context: Context, view: View) : RecyclerView.ViewHolder(view) {
@ -50,8 +51,8 @@ class NodeInfoListAdapter(private val context: Context, private val infoSet: Arr
// Get element from your dataset at this position and replace the
// contents of the view with that element
viewHolder.key.text = infoSet[position].first
viewHolder.value.text = infoSet[position].second
viewHolder.key.text = infoSet[position].key
viewHolder.value.text = infoSet[position].value
}
// Return the size of your dataset (invoked by the layout manager)

View File

@ -3,11 +3,11 @@ package io.github.chronosx88.yggdrasil.models.config
import com.google.gson.annotations.SerializedName
data class Peer (
//Example [{"PublicKey":[154,201,118,156,19,74,134,115,94,159,76,86,36,192,221,105,220,254,226,161,108,226,17,192,75,243,225,15,42,195,155,2],"Endpoint":"(self)","BytesSent":0,"BytesRecvd":0,"Protocol":"self","Port":0,"Uptime":209900460}]
@SerializedName("Endpoint") var endpoint : String,
//Example [{"Key":"JQZIX3KIamcp/6S9rycKiAGyg9MK7U6h8UUY5ej36fY=","Root":"AAABERGfllXfKNJshDs/8uzKEIFkFEccE16dmZV/cAo=","Coords":[2,4],"Port":1,"Remote":"tcp://[fe80::5207:4518:4378:7f1%wlan0]:57541","IP":"202:d7cd:bd04:6bbc:acc6:b002:da12:86c7"},{"Key":"DCNBiKAV1xr72JAFUgNrOYfY6Qm/f0Nq6ESZTSLn1eo=","Root":"AAABERGfllXfKNJshDs/8uzKEIFkFEccE16dmZV/cAo=","Coords":[2,4,1],"Port":2,"Remote":"tcp://[fe80::1c39:839:90a5:6ef%wlan0]:1108","IP":"204:7b97:ceeb:fd45:1ca0:84ed:ff55:bf92"}]
@SerializedName("Key") var key : String,
@SerializedName("Root") var root : String,
//@SerializedName("Coords") var uptime : Long,
@SerializedName("Port") var port : Int,
@SerializedName("Uptime") var uptime : Long,
@SerializedName("Protocol") var protocol : String,
@SerializedName("BytesSent") var bytesSent : Long,
@SerializedName("BytesRecvd") var bytesReceived : Long
@SerializedName("Remote") var remote : String,
@SerializedName("IP") var ip : String
)

View File

@ -119,11 +119,8 @@ class Utils {
if (list != null) {
for(s in list) {
var p = gson.fromJson(s, Peer::class.java)
if(p.endpoint == "(self)"){
out.add(PeerInfo(p.protocol, InetAddress.getByName("localhost"), p.port, null, true))
} else {
var fixWlanPart = p.endpoint.substring(p.endpoint.indexOf('%'), p.endpoint.indexOf(']'))
var fixedUrlString = p.endpoint.replace(fixWlanPart, "")
var fixWlanPart = p.remote.substring(p.remote.indexOf('%'), p.remote.indexOf(']'))
var fixedUrlString = p.remote.replace(fixWlanPart, "")
var url = URI(fixedUrlString)
out.add(
PeerInfo(
@ -136,7 +133,6 @@ class Utils {
)
}
}
}
return out
}
}