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" applicationId "io.github.chronosx88.yggdrasil"
minSdkVersion 15 minSdkVersion 15
targetSdkVersion 29 targetSdkVersion 29
versionCode 23
versionName "2.0.3" versionCode 30
versionName "2.0.12"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
setProperty("archivesBaseName", project.getParent().name+"-"+versionName) setProperty("archivesBaseName", project.getParent().name+"-"+versionName)
} }

View File

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

View File

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

View File

@ -43,7 +43,7 @@ class PeerListActivity : AppCompatActivity() {
companion object { companion object {
const val PEER_LIST = "PEER_LIST" 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 CACHE_NAME = "PEER_LIST_CACHE"
const val ONLINE_PEERINFO_LIST = "online_peer_info_list" const val ONLINE_PEERINFO_LIST = "online_peer_info_list"
const val OFFLINE_PEERINFO_LIST = "offline_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 import org.acra.sender.HttpSender
class YggApplication : Application() { class YggApplication : Application() {
companion object {
const val ACRA_BACKEND_URL = "xxx"
}
override fun attachBaseContext(base: Context) { override fun attachBaseContext(base: Context) {
super.attachBaseContext(base) super.attachBaseContext(base)
@ -18,9 +23,9 @@ class YggApplication : Application() {
reportFormat = StringFormat.JSON reportFormat = StringFormat.JSON
//each plugin you chose above can be configured in a block like this: //each plugin you chose above can be configured in a block like this:
httpSender { httpSender {
uri = "http://<host>/report" uri = ACRA_BACKEND_URL
basicAuthLogin="***" basicAuthLogin="KOF7CEnt5tfTqIhj"
basicAuthPassword = "***" basicAuthPassword = "F4cCIqo9EjpihcPt"
httpMethod = HttpSender.Method.POST httpMethod = HttpSender.Method.POST
} }
dialog { 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 io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2PeerInfoSet
import mobile.Mobile import mobile.Mobile
import mobile.Yggdrasil import mobile.Yggdrasil
import org.acra.ACRA
import java.io.* import java.io.*
import java.net.Inet6Address import java.net.Inet6Address
import kotlin.concurrent.thread import kotlin.concurrent.thread
@ -139,6 +140,7 @@ class YggdrasilTunService : VpnService() {
private fun sendMeshPeerStatus(pi: PendingIntent?){ private fun sendMeshPeerStatus(pi: PendingIntent?){
class Token : TypeToken<List<Peer>>() class Token : TypeToken<List<Peer>>()
ygg.addressString ygg.addressString
ACRA.errorReporter.putCustomData("Peers JSON", ygg.peersJSON)
var meshPeers: List<Peer> = gson.fromJson(ygg.peersJSON, Token().type) var meshPeers: List<Peer> = gson.fromJson(ygg.peersJSON, Token().type)
val intent: Intent = Intent().putStringArrayListExtra( val intent: Intent = Intent().putStringArrayListExtra(
MainActivity.MESH_PEERS, MainActivity.MESH_PEERS,
@ -202,6 +204,8 @@ class YggdrasilTunService : VpnService() {
ygg.send(buffer.sliceArray(IntRange(0, length - 1))) ygg.send(buffer.sliceArray(IntRange(0, length - 1)))
} catch (e: IOException) { } catch (e: IOException) {
e.printStackTrace() e.printStackTrace()
} catch (e: Exception){
e.printStackTrace();
} }
} }
@ -212,6 +216,8 @@ class YggdrasilTunService : VpnService() {
tunOutputStream.write(buffer) tunOutputStream.write(buffer)
} catch (e: IOException) { } catch (e: IOException) {
e.printStackTrace() e.printStackTrace()
} catch (e: Exception){
e.printStackTrace();
} }
} }
} }

View File

@ -10,8 +10,9 @@ import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.github.chronosx88.yggdrasil.R 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>() { RecyclerView.Adapter<NodeInfoListAdapter.ViewHolder>() {
class ViewHolder(private val context: Context, view: View) : RecyclerView.ViewHolder(view) { 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 // Get element from your dataset at this position and replace the
// contents of the view with that element // contents of the view with that element
viewHolder.key.text = infoSet[position].first viewHolder.key.text = infoSet[position].key
viewHolder.value.text = infoSet[position].second viewHolder.value.text = infoSet[position].value
} }
// Return the size of your dataset (invoked by the layout manager) // 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 import com.google.gson.annotations.SerializedName
data class Peer ( 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}] //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("Endpoint") var endpoint : String, @SerializedName("Key") var key : String,
@SerializedName("Root") var root : String,
//@SerializedName("Coords") var uptime : Long,
@SerializedName("Port") var port : Int, @SerializedName("Port") var port : Int,
@SerializedName("Uptime") var uptime : Long, @SerializedName("Remote") var remote : String,
@SerializedName("Protocol") var protocol : String, @SerializedName("IP") var ip : String
@SerializedName("BytesSent") var bytesSent : Long,
@SerializedName("BytesRecvd") var bytesReceived : Long
) )

View File

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