Merge remote-tracking branch 'origin/master'

# Conflicts:
#	build.gradle
This commit is contained in:
Vadym 2021-04-19 10:57:24 +03:00
commit 0825fb814c
35 changed files with 545 additions and 123 deletions

View File

@ -9,3 +9,6 @@ The application for connecting to Yggdrasil network on Android.
Once connected, you can access yggdrasil public services, as the application has peered automatically to default peers within the application. Once connected, you can access yggdrasil public services, as the application has peered automatically to default peers within the application.
<img src="https://user-images.githubusercontent.com/8705683/87849784-62048a80-c8fc-11ea-8eb0-908e69d7595e.png" alt="" height="500" width=""> <img src="https://user-images.githubusercontent.com/8705683/87849784-62048a80-c8fc-11ea-8eb0-908e69d7595e.png" alt="" height="500" width="">
New builds and updates here:
https://t.me/yggdrasil_android

View File

@ -3,13 +3,13 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android-extensions'
android { android {
compileSdkVersion 30 compileSdkVersion 29
defaultConfig { defaultConfig {
applicationId "io.github.chronosx88.yggdrasil" applicationId "io.github.chronosx88.yggdrasil"
minSdkVersion 15 minSdkVersion 15
targetSdkVersion 30 targetSdkVersion 29
versionCode 6 versionCode 18
versionName "1.6" versionName "1.7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
setProperty("archivesBaseName", project.getParent().name+"-"+versionName) setProperty("archivesBaseName", project.getParent().name+"-"+versionName)
} }

View File

@ -32,6 +32,12 @@
android:label="@string/title_activity_dns_list" android:label="@string/title_activity_dns_list"
android:theme="@style/AppTheme.NoActionBar" android:theme="@style/AppTheme.NoActionBar"
android:screenOrientation="portrait"/> android:screenOrientation="portrait"/>
<activity
android:name=".CopyLocalNodeInfoActivity"
android:parentActivityName=".MainActivity"
android:label="@string/title_activity_copy_local_node_info"
android:theme="@style/AppTheme.NoActionBar"
android:screenOrientation="portrait"/>
<service <service
android:name=".YggdrasilTunService" android:name=".YggdrasilTunService"
android:enabled="true" android:enabled="true"

View File

@ -0,0 +1,28 @@
package io.github.chronosx88.yggdrasil
import android.os.Bundle
import android.widget.ListView
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager
import io.github.chronosx88.yggdrasil.models.NodeInfo
import io.github.chronosx88.yggdrasil.models.config.CopyInfoAdapter
import io.github.chronosx88.yggdrasil.models.config.SelectDNSInfoListAdapter
class CopyLocalNodeInfoActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_copy_local_node_info)
setSupportActionBar(findViewById(R.id.toolbar))
val preferences =
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
val ipv6Address = intent.extras!!.getString(MainActivity.IPv6, "")
val signingPublicKey = preferences.getString(MainActivity.signingPublicKey, "")
val encryptionPublicKey = preferences.getString(MainActivity.encryptionPublicKey, "")
var nodeInfoListView = findViewById<ListView>(R.id.nodeInfoList)
val nodeInfoList = listOf<NodeInfo>(NodeInfo("IP address", ipv6Address!!), NodeInfo("Encryption Public Key", encryptionPublicKey!!), NodeInfo("Signing Public Key", signingPublicKey!!));
var adapter = CopyInfoAdapter(this, nodeInfoList)
nodeInfoListView.adapter = adapter
}
}

View File

@ -59,11 +59,11 @@ class DNSListActivity : AppCompatActivity() {
try { try {
for (d in cd) { for (d in cd) {
var ping = ping(d.address, 53) var ping = ping(d.address.hostAddress, 53)
d.ping = ping d.ping = ping
} }
for (dns in allDNS) { for (dns in allDNS) {
var ping = ping(dns.address, 53) var ping = ping(dns.address.hostAddress, 53)
dns.ping = ping dns.ping = ping
runOnUiThread( runOnUiThread(
Runnable Runnable
@ -110,7 +110,7 @@ class DNSListActivity : AppCompatActivity() {
thread(start = true) { thread(start = true) {
var di = DNSInfo(InetAddress.getByName("["+ip+"]"), ccp, "User DNS") var di = DNSInfo(InetAddress.getByName("["+ip+"]"), ccp, "User DNS")
try { try {
var ping = ping(di.address, 53) var ping = ping(di.address.hostAddress, 53)
di.ping = ping di.ping = ping
} catch(e: Throwable){ } catch(e: Throwable){
di.ping = Int.MAX_VALUE di.ping = Int.MAX_VALUE
@ -127,7 +127,7 @@ class DNSListActivity : AppCompatActivity() {
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present. // Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.save, menu) menuInflater.inflate(R.menu.save_dns, menu)
val item = menu.findItem(R.id.saveItem) as MenuItem val item = menu.findItem(R.id.saveItem) as MenuItem
item.setActionView(R.layout.menu_save) item.setActionView(R.layout.menu_save)
val saveButton = item val saveButton = item

View File

@ -107,19 +107,21 @@ class MainActivity : AppCompatActivity() {
) )
val adapter = PeerInfoListAdapter(this, currentPeers.sortedWith(compareBy { it.ping })) val adapter = PeerInfoListAdapter(this, currentPeers.sortedWith(compareBy { it.ping }))
peersListView.adapter = adapter peersListView.adapter = adapter
if (adapter.count > 10) {
val item = adapter.getView(0, null, peersListView)
item.measure(0, 0)
val params = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
(10 * item.measuredHeight).toInt()
)
peersListView.layoutParams = params
}
if(isStarted && this.currentPeers.isEmpty()) { if(isStarted && this.currentPeers.isEmpty()) {
updatePeers() updatePeers()
} }
val copyAddressButton = findViewById<Button>(R.id.copyIp)
copyAddressButton.setOnClickListener {
val ip = findViewById<TextView>(R.id.ip)
val clipboard: ClipboardManager =
getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip =
ClipData.newPlainText("IP address", ip.text.toString())
clipboard.setPrimaryClip(clip)
showToast(getString(R.string.address_copied))
}
val editPeersButton = findViewById<Button>(R.id.edit) val editPeersButton = findViewById<Button>(R.id.edit)
editPeersButton.setOnClickListener { editPeersButton.setOnClickListener {
if(isStarted){ if(isStarted){
@ -150,6 +152,14 @@ class MainActivity : AppCompatActivity() {
intent.putStringArrayListExtra(DNS_LIST, serializeDNSInfoSet2StringList(currentDNS)) intent.putStringArrayListExtra(DNS_LIST, serializeDNSInfoSet2StringList(currentDNS))
startActivityForResult(intent, DNS_LIST_CODE) startActivityForResult(intent, DNS_LIST_CODE)
} }
val nodeInfoButton = findViewById<Button>(R.id.nodeInfo)
nodeInfoButton.setOnClickListener {
if(isStarted) {
val intent = Intent(this@MainActivity, CopyLocalNodeInfoActivity::class.java)
intent.putExtra(IPv6, findViewById<TextView>(R.id.ip).text.toString())
startActivity(intent)
}
}
if(isStarted){ if(isStarted){
val ipLayout = findViewById<LinearLayout>(R.id.ipLayout) val ipLayout = findViewById<LinearLayout>(R.id.ipLayout)
ipLayout.visibility = View.VISIBLE ipLayout.visibility = View.VISIBLE
@ -404,7 +414,7 @@ class MainActivity : AppCompatActivity() {
super.onRestoreInstanceState(savedInstanceState) super.onRestoreInstanceState(savedInstanceState)
val preferences = val preferences =
PreferenceManager.getDefaultSharedPreferences(this.baseContext) PreferenceManager.getDefaultSharedPreferences(this.baseContext)
findViewById<Switch>(R.id.staticIP).isChecked = findViewById<SwitchCompat>(R.id.staticIP).isChecked =
preferences.getString(STATIC_IP, null) != null preferences.getString(STATIC_IP, null) != null
} }

View File

@ -5,15 +5,18 @@ import android.content.Intent
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.* import android.view.*
import android.webkit.URLUtil
import android.widget.Button import android.widget.Button
import android.widget.ListView import android.widget.ListView
import android.widget.PopupWindow import android.widget.PopupWindow
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager
import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.hbb20.BuildConfig
import com.hbb20.CCPCountry import com.hbb20.CCPCountry
import com.vincentbrison.openlibraries.android.dualcache.Builder import com.vincentbrison.openlibraries.android.dualcache.Builder
import com.vincentbrison.openlibraries.android.dualcache.SizeOf import com.vincentbrison.openlibraries.android.dualcache.SizeOf
@ -21,32 +24,30 @@ import com.vincentbrison.openlibraries.android.dualcache.JsonSerializer
import io.github.chronosx88.yggdrasil.models.PeerInfo import io.github.chronosx88.yggdrasil.models.PeerInfo
import io.github.chronosx88.yggdrasil.models.Status import io.github.chronosx88.yggdrasil.models.Status
import io.github.chronosx88.yggdrasil.models.config.DropDownAdapter import io.github.chronosx88.yggdrasil.models.config.DropDownAdapter
import io.github.chronosx88.yggdrasil.models.config.Peer
import io.github.chronosx88.yggdrasil.models.config.SelectPeerInfoListAdapter import io.github.chronosx88.yggdrasil.models.config.SelectPeerInfoListAdapter
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2PeerInfoSet import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2PeerInfoSet
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.ping import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.ping
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.serializePeerInfoSet2StringList import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.serializePeerInfoSet2StringList
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.*
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import java.io.FileNotFoundException import java.io.FileNotFoundException
import java.lang.reflect.Type import java.lang.reflect.Type
import java.net.InetAddress import java.net.InetAddress
import java.net.URI import java.net.URI
import java.net.URL import java.net.URL
import java.net.UnknownHostException
import java.nio.charset.Charset import java.nio.charset.Charset
class PeerListActivity : AppCompatActivity() { class PeerListActivity : AppCompatActivity() {
companion object { companion object {
const val PEER_LIST = "PEER_LIST"
const val PEER_LIST_URL = "https://publicpeers.neilalexander.dev/publicnodes.json" const val PEER_LIST_URL = "https://publicpeers.neilalexander.dev/publicnodes.json"
const val CACHE_NAME = "PEER_LIST_CACHE" const val CACHE_NAME = "PEER_LIST_CACHE"
const val ONLINE_PEERINFO_LIST = "ONLINE_PEERINFO_LIST" const val ONLINE_PEERINFO_LIST = "online_peer_info_list"
const val OFFLINE_PEERINFO_LIST = "OFFLINE_PEERINFO_LIST" const val OFFLINE_PEERINFO_LIST = "offline_peer_info_list"
const val TEST_APP_VERSION = BuildConfig.VERSION_CODE; const val TEST_APP_VERSION = BuildConfig.VERSION_CODE
const val RAM_MAX_SIZE = 100000 const val RAM_MAX_SIZE = 100000
const val DISK_MAX_SIZE = 100000 const val DISK_MAX_SIZE = 100000
} }
@ -61,6 +62,8 @@ class PeerListActivity : AppCompatActivity() {
} }
} }
private var peerListUrl = PEER_LIST_URL
private var peerListPing = true
var popup: PopupWindow? = null var popup: PopupWindow? = null
var adapter: DropDownAdapter? = null var adapter: DropDownAdapter? = null
@ -71,6 +74,13 @@ class PeerListActivity : AppCompatActivity() {
findViewById<FloatingActionButton>(R.id.fab).setOnClickListener { _ -> findViewById<FloatingActionButton>(R.id.fab).setOnClickListener { _ ->
addNewPeer() addNewPeer()
} }
val preferences =
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
var peerListUrl: String =
preferences.getString(PEER_LIST, "")!!
if(!peerListUrl.isNullOrBlank()){
this@PeerListActivity.peerListUrl = peerListUrl
}
var extras = intent.extras var extras = intent.extras
var peerList = findViewById<ListView>(R.id.peerList) var peerList = findViewById<ListView>(R.id.peerList)
var adapter = SelectPeerInfoListAdapter(this, arrayListOf(), mutableSetOf()) var adapter = SelectPeerInfoListAdapter(this, arrayListOf(), mutableSetOf())
@ -83,73 +93,20 @@ class PeerListActivity : AppCompatActivity() {
JsonSerializer(ArrayList<PeerInfo>().javaClass), baseContext JsonSerializer(ArrayList<PeerInfo>().javaClass), baseContext
).build(); ).build();
GlobalScope.launch { GlobalScope.launch() {
try { try {
var cp = deserializeStringList2PeerInfoSet( var cp = deserializeStringList2PeerInfoSet(
extras!!.getStringArrayList(MainActivity.PEER_LIST)!! extras!!.getStringArrayList(MainActivity.PEER_LIST)!!
) )
for(pi in cp){ for (pi in cp) {
var ping = ping(pi.address, pi.port) var ping = ping(pi.hostName, pi.port)
pi.ping = ping pi.ping = ping
} }
try { try {
var json = downloadJson(PEER_LIST_URL) var peerInfoCache = peerInfoListCache.get(ONLINE_PEERINFO_LIST)
var countries = CCPCountry.getLibraryMasterCountriesEnglish() if (peerInfoCache != null && peerInfoCache.isNotEmpty()) {
val mapType: Type = object : for (peerInfo in peerInfoCache) {
TypeToken<Map<String?, Map<String, Status>>>() {}.type var ping = ping(peerInfo.hostName, peerInfo.port)
val peersMap: Map<String, Map<String, Status>> = Gson().fromJson(json, mapType)
for ((country, peers) in peersMap.entries) {
for ((peer, status) in peers) {
if (status.up) {
for (ccp in countries) {
if (ccp.name.toLowerCase()
.contains(country.replace(".md", "").replace("-", " "))
) {
var url = URI(peer)
try {
var address = InetAddress.getByName(url.host)
var peerInfo =
PeerInfo(
url.scheme,
address,
url.port,
ccp.nameCode
)
var ping = ping(address, url.port)
peerInfo.ping = ping
if(cp.contains(peerInfo)){
continue
}
withContext(Dispatchers.Main) {
adapter.addItem(peerInfo)
if(adapter.count % 5 == 0) {
adapter.sort()
}
}
} catch (e: Throwable){
e.printStackTrace()
}
}
}
}
}
}
var allPeersList = adapter.getAllPeers()
var cachePeerInfoList = mutableListOf<PeerInfo>()
for(p in allPeersList){
if(p.ping<Int.MAX_VALUE){
cachePeerInfoList.add(p)
}
}
if(cachePeerInfoList.size>0){
peerInfoListCache.put(ONLINE_PEERINFO_LIST, cachePeerInfoList.toList())
}
} catch (e: FileNotFoundException){
e.printStackTrace()
var onlinePeerInfoList = peerInfoListCache.get(ONLINE_PEERINFO_LIST)
if(onlinePeerInfoList!=null) {
for (peerInfo in onlinePeerInfoList) {
var ping = ping(peerInfo.address, peerInfo.port)
peerInfo.ping = ping peerInfo.ping = ping
if (cp.contains(peerInfo)) { if (cp.contains(peerInfo)) {
continue continue
@ -162,17 +119,117 @@ class PeerListActivity : AppCompatActivity() {
} }
} }
} }
var json = downloadJson(this@PeerListActivity.peerListUrl)
var countries = CCPCountry.getLibraryMasterCountriesEnglish()
val mapType: Type = object :
TypeToken<Map<String?, Map<String, Status>>>() {}.type
val peersMap: Map<String, Map<String, Status>> = Gson().fromJson(json, mapType)
var cachePeerInfoList = mutableListOf<PeerInfo>()
for ((country, peers) in peersMap.entries) {
for ((peer, status) in peers) {
if (status.up) {
for (ccp in countries) {
if (ccp.name.toLowerCase()
.contains(country.replace(".md", "").replace("-", " "))
) {
if(!peerListPing){
return@launch
}
var url = URI(peer)
try {
var address = InetAddress.getByName(url.host)
var peerInfo =
PeerInfo(
url.scheme,
address,
url.port,
ccp.nameCode
)
var ping = ping(url.host, url.port)
peerInfo.ping = ping
if (cp.contains(peerInfo)) {
continue
}
if (peerInfo.ping < Int.MAX_VALUE) {
cachePeerInfoList.add(peerInfo)
}
withContext(Dispatchers.Main) {
adapter.addItem(peerInfo)
if (adapter.count % 5 == 0) {
adapter.sort()
if (cachePeerInfoList.size > 0) {
peerInfoListCache.put(
ONLINE_PEERINFO_LIST,
cachePeerInfoList.toList()
)
}
}
}
} catch (e: Throwable) {
e.printStackTrace()
}
}
}
}
}
}
} catch (e: Exception) {
when (e) {
is FileNotFoundException, is UnknownHostException -> {
var onlinePeerInfoList = peerInfoListCache.get(ONLINE_PEERINFO_LIST)
if (onlinePeerInfoList != null) {
for (peerInfo in onlinePeerInfoList) {
var ping = ping(peerInfo.hostName, peerInfo.port)
peerInfo.ping = ping
if (cp.contains(peerInfo)) {
continue
}
withContext(Dispatchers.Main) {
adapter.addItem(peerInfo)
if (adapter.count % 5 == 0) {
adapter.sort()
}
}
}
}
e.printStackTrace()
}
else -> e.printStackTrace()
}
} }
var currentPeers = ArrayList(cp.sortedWith(compareBy { it.ping })) var currentPeers = ArrayList(cp.sortedWith(compareBy { it.ping }))
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
adapter.addAll(0, currentPeers) adapter.addAll(0, currentPeers)
} }
} catch (e: Throwable){ } catch (e: Throwable) {
e.printStackTrace() e.printStackTrace()
} }
} }
} }
private fun editPeerListUrl() {
val view: View = LayoutInflater.from(this).inflate(R.layout.edit_peer_list_url_dialog, null)
val ab: AlertDialog.Builder = AlertDialog.Builder(this)
ab.setCancelable(true).setView(view)
var ad = ab.show()
var saveButton = view.findViewById<Button>(R.id.save)
var urlInput = view.findViewById<TextView>(R.id.urlInput)
urlInput.text = peerListUrl
saveButton.setOnClickListener{
var url = urlInput.text.toString()
if(!URLUtil.isValidUrl(url)){
urlInput.error = "The URL is invalid!"
return@setOnClickListener;
}
peerListUrl = url
val preferences =
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
preferences.edit().putString(PEER_LIST, peerListUrl).apply()
ad.dismiss()
}
}
private fun addNewPeer() { private fun addNewPeer() {
val view: View = LayoutInflater.from(this).inflate(R.layout.new_peer_dialog, null) val view: View = LayoutInflater.from(this).inflate(R.layout.new_peer_dialog, null)
val countryCode: String = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { val countryCode: String = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
@ -226,7 +283,7 @@ class PeerListActivity : AppCompatActivity() {
GlobalScope.launch { GlobalScope.launch {
var pi = PeerInfo(schema, InetAddress.getByName(ip), port, ccp) var pi = PeerInfo(schema, InetAddress.getByName(ip), port, ccp)
try { try {
var ping = ping(pi.address, pi.port) var ping = ping(pi.hostName, pi.port)
pi.ping = ping pi.ping = ping
} catch (e: Throwable){ } catch (e: Throwable){
pi.ping = Int.MAX_VALUE pi.ping = Int.MAX_VALUE
@ -277,12 +334,14 @@ class PeerListActivity : AppCompatActivity() {
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present. // Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.save, menu) menuInflater.inflate(R.menu.save_peers, menu)
val item = menu.findItem(R.id.saveItem) as MenuItem val item = menu.findItem(R.id.saveItem) as MenuItem
item.setActionView(R.layout.menu_save) item.setActionView(R.layout.menu_save)
val saveButton = item val saveButton = item
.actionView.findViewById<Button>(R.id.saveButton) .actionView.findViewById<Button>(R.id.saveButton)
saveButton.setOnClickListener { saveButton.setOnClickListener {
saveButton.isClickable = false
cancelPeerListPing()
val result = Intent(this, MainActivity::class.java) val result = Intent(this, MainActivity::class.java)
var adapter = findViewById<ListView>(R.id.peerList).adapter as SelectPeerInfoListAdapter var adapter = findViewById<ListView>(R.id.peerList).adapter as SelectPeerInfoListAdapter
val selectedPeers = adapter.getSelectedPeers() val selectedPeers = adapter.getSelectedPeers()
@ -290,8 +349,25 @@ class PeerListActivity : AppCompatActivity() {
setResult(Activity.RESULT_OK, result) setResult(Activity.RESULT_OK, result)
finish() finish()
} }
val editUrl = menu.findItem(R.id.editUrlItem) as MenuItem
editUrl.setActionView(R.layout.menu_edit_url)
val editUrlButton = editUrl
.actionView.findViewById<Button>(R.id.editUrlButton)
editUrlButton.setOnClickListener {
editPeerListUrl()
}
return true return true
} }
private fun cancelPeerListPing() {
peerListPing = false
}
override fun onStop() {
super.onStop()
cancelPeerListPing()
}
} }
class SizeOfPeerList: SizeOf<List<PeerInfo>> { class SizeOfPeerList: SizeOf<List<PeerInfo>> {
@ -299,9 +375,6 @@ class SizeOfPeerList: SizeOf<List<PeerInfo>> {
override fun sizeOf(obj: List<PeerInfo>): Int{ override fun sizeOf(obj: List<PeerInfo>): Int{
var size = 0 var size = 0
for (o in obj) { for (o in obj) {
if (o.address != null) {
size += o.address.toString().length * 2
}
if (o.hostName != null) { if (o.hostName != null) {
size += o.hostName.length * 2 size += o.hostName.length * 2
} }
@ -317,5 +390,4 @@ class SizeOfPeerList: SizeOf<List<PeerInfo>> {
} }
return size return size
} }
} }

View File

@ -161,7 +161,7 @@ class YggdrasilTunService : VpnService() {
val blackList = arrayListOf<String>() val blackList = arrayListOf<String>()
blackList.add("") blackList.add("")
config["Peers"] = convertPeerInfoSet2PeerIdSet(peers) config["Peers"] = convertPeerInfoSet2PeerIdSet(peers)
config["Listen"] = "" config["Listen"] = arrayListOf<String>()
config["AdminListen"] = "tcp://localhost:9001" config["AdminListen"] = "tcp://localhost:9001"
config["IfName"] = "tun0" config["IfName"] = "tun0"
if(staticIP) { if(staticIP) {
@ -177,7 +177,7 @@ class YggdrasilTunService : VpnService() {
.putString(MainActivity.signingPublicKey, signingPublicKey) .putString(MainActivity.signingPublicKey, signingPublicKey)
.putString(MainActivity.encryptionPrivateKey, encryptionPrivateKey) .putString(MainActivity.encryptionPrivateKey, encryptionPrivateKey)
.putString(MainActivity.encryptionPublicKey, encryptionPublicKey) .putString(MainActivity.encryptionPublicKey, encryptionPublicKey)
.putString(MainActivity.STATIC_IP,MainActivity.STATIC_IP).apply() .putString(MainActivity.STATIC_IP, MainActivity.STATIC_IP).apply()
} else { } else {
val signingPrivateKey = preferences.getString(MainActivity.signingPrivateKey, null) val signingPrivateKey = preferences.getString(MainActivity.signingPrivateKey, null)
val signingPublicKey = preferences.getString(MainActivity.signingPublicKey, null) val signingPublicKey = preferences.getString(MainActivity.signingPublicKey, null)

View File

@ -0,0 +1,13 @@
package io.github.chronosx88.yggdrasil.models
class NodeInfo {
constructor(key: String, value: String){
this.key = key
this.value = value
}
var key: String
var value: String
}

View File

@ -7,9 +7,13 @@ import java.net.InetAddress
class PeerInfo { class PeerInfo {
constructor(){
}
constructor(schema: String, address: InetAddress, port: Int, countryCode: String){ constructor(schema: String, address: InetAddress, port: Int, countryCode: String){
this.schema = schema this.schema = schema
this.address = address
var a = address.toString(); var a = address.toString();
if(a.lastIndexOf('/')>0){ if(a.lastIndexOf('/')>0){
this.hostName = a.split("/")[0] this.hostName = a.split("/")[0]
@ -22,7 +26,6 @@ class PeerInfo {
constructor(schema: String, address: InetAddress, port: Int, countryCode: String?, isMeshPeer: Boolean){ constructor(schema: String, address: InetAddress, port: Int, countryCode: String?, isMeshPeer: Boolean){
this.schema = schema this.schema = schema
this.address = address
var a = address.toString(); var a = address.toString();
if(a.lastIndexOf('/')>0){ if(a.lastIndexOf('/')>0){
this.hostName = a.split("/")[0] this.hostName = a.split("/")[0]
@ -34,9 +37,8 @@ class PeerInfo {
this.isMeshPeer = isMeshPeer this.isMeshPeer = isMeshPeer
} }
var schema: String lateinit var schema: String
var address: InetAddress lateinit var hostName: String
var hostName: String
var port = 0 var port = 0
var countryCode: String?=null var countryCode: String?=null
var ping: Int = Int.MAX_VALUE var ping: Int = Int.MAX_VALUE

View File

@ -0,0 +1,67 @@
package io.github.chronosx88.yggdrasil.models.config
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import io.github.chronosx88.yggdrasil.R
import io.github.chronosx88.yggdrasil.models.NodeInfo
class CopyInfoAdapter(
context: Context,
nodeInfoList: List<NodeInfo>,
) : ArrayAdapter<NodeInfo?> (context, 0, nodeInfoList) {
private val mContext: Context = context
private var nodeInfoList: MutableList<NodeInfo> = nodeInfoList as MutableList<NodeInfo>
override fun getItem(position: Int): NodeInfo? {
return nodeInfoList[position]
}
override fun getCount(): Int {
return nodeInfoList.size
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
var copyNodeInfoHolder = CopyInfoHolder()
var listItem: View? = convertView
if (listItem == null) {
listItem = LayoutInflater.from(mContext).inflate(R.layout.copy_node_info_list_item, parent, false)
copyNodeInfoHolder.copyButton = listItem.findViewById(R.id.nodeInfoButton) as Button
copyNodeInfoHolder.nodeInfoText = listItem.findViewById(R.id.nodeInfoText) as TextView
copyNodeInfoHolder.nodeInfoKey = listItem.findViewById(R.id.nodeInfoKey) as TextView
listItem.tag = copyNodeInfoHolder
} else {
copyNodeInfoHolder = listItem.tag as CopyInfoHolder
}
copyNodeInfoHolder.nodeInfoKey.text = nodeInfoList[position].key
copyNodeInfoHolder.nodeInfoText.text = nodeInfoList[position].value
copyNodeInfoHolder.copyButton.setOnClickListener{ _ ->
val clipboard: ClipboardManager =
context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip =
ClipData.newPlainText(nodeInfoList[position].key, nodeInfoList[position].value)
clipboard.setPrimaryClip(clip)
showToast(nodeInfoList[position].key + " " + context.getString(R.string.node_info_copied))
}
return listItem!!
}
private fun showToast(text: String){
val duration = Toast.LENGTH_SHORT
val toast = Toast.makeText(context, text, duration)
toast.setGravity(Gravity.CENTER, 0, 0)
toast.show()
}
class CopyInfoHolder {
lateinit var nodeInfoKey: TextView
lateinit var nodeInfoText: TextView
lateinit var copyButton: Button
}
}

View File

@ -1,14 +1,14 @@
package io.github.chronosx88.yggdrasil.models.config package io.github.chronosx88.yggdrasil.models.config
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import android.view.Gravity
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ArrayAdapter import android.widget.*
import android.widget.CheckBox
import android.widget.ImageView
import android.widget.TextView
import io.github.chronosx88.yggdrasil.R import io.github.chronosx88.yggdrasil.R
import io.github.chronosx88.yggdrasil.models.DNSInfo import io.github.chronosx88.yggdrasil.models.DNSInfo
@ -66,6 +66,14 @@ class SelectDNSInfoListAdapter(
} }
} }
} }
dnsInfoHolder.dnsInfoText.setOnClickListener {
val clipboard: ClipboardManager =
context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip =
ClipData.newPlainText("DNS info", dnsId)
clipboard.setPrimaryClip(clip)
showToast(dnsId + " " + context.getString(R.string.node_info_copied))
}
dnsInfoHolder.checkbox.isChecked = this.currentDNS.contains(currentDNS) dnsInfoHolder.checkbox.isChecked = this.currentDNS.contains(currentDNS)
return listItem!! return listItem!!
} }
@ -100,4 +108,11 @@ class SelectDNSInfoListAdapter(
lateinit var dnsInfoText: TextView lateinit var dnsInfoText: TextView
lateinit var ping: TextView lateinit var ping: TextView
} }
private fun showToast(text: String){
val duration = Toast.LENGTH_SHORT
val toast = Toast.makeText(context, text, duration)
toast.setGravity(Gravity.CENTER, 0, 0)
toast.show()
}
} }

View File

@ -1,14 +1,14 @@
package io.github.chronosx88.yggdrasil.models.config package io.github.chronosx88.yggdrasil.models.config
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import android.view.Gravity
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ArrayAdapter import android.widget.*
import android.widget.CheckBox
import android.widget.ImageView
import android.widget.TextView
import io.github.chronosx88.yggdrasil.R import io.github.chronosx88.yggdrasil.R
import io.github.chronosx88.yggdrasil.models.PeerInfo import io.github.chronosx88.yggdrasil.models.PeerInfo
@ -46,12 +46,11 @@ class SelectPeerInfoListAdapter(
val currentPeer = allPeers[position] val currentPeer = allPeers[position]
peerInfoHolder.countryFlag.setImageResource(currentPeer.getCountry(mContext)!!.flagID) peerInfoHolder.countryFlag.setImageResource(currentPeer.getCountry(mContext)!!.flagID)
val peerId = currentPeer.toString() val peerId = currentPeer.toString()
peerInfoHolder.peerInfoText.text = peerId
if(currentPeer.ping == Int.MAX_VALUE){ if(currentPeer.ping == Int.MAX_VALUE){
peerInfoHolder.peerInfoText.text = peerId
peerInfoHolder.ping.text="" peerInfoHolder.ping.text=""
peerInfoHolder.peerInfoText.setTextColor(Color.GRAY) peerInfoHolder.peerInfoText.setTextColor(Color.GRAY)
} else { } else {
peerInfoHolder.peerInfoText.text = peerId
peerInfoHolder.ping.text = currentPeer.ping.toString() + " ms" peerInfoHolder.ping.text = currentPeer.ping.toString() + " ms"
peerInfoHolder.peerInfoText.setTextColor(Color.WHITE) peerInfoHolder.peerInfoText.setTextColor(Color.WHITE)
} }
@ -66,6 +65,14 @@ class SelectPeerInfoListAdapter(
} }
} }
} }
peerInfoHolder.peerInfoText.setOnClickListener {
val clipboard: ClipboardManager =
context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip =
ClipData.newPlainText("Peer info", peerId)
clipboard.setPrimaryClip(clip)
showToast(peerId + " " + context.getString(R.string.node_info_copied))
}
peerInfoHolder.checkbox.isChecked = this.currentPeers.contains(currentPeer) peerInfoHolder.checkbox.isChecked = this.currentPeers.contains(currentPeer)
return listItem!! return listItem!!
} }
@ -79,7 +86,9 @@ class SelectPeerInfoListAdapter(
} }
fun addItem(peerInfo: PeerInfo){ fun addItem(peerInfo: PeerInfo){
allPeers.add(peerInfo) if(!allPeers.contains(peerInfo)){
allPeers.add(peerInfo)
}
} }
fun addItem(index: Int, peerInfo: PeerInfo){ fun addItem(index: Int, peerInfo: PeerInfo){
@ -105,4 +114,10 @@ class SelectPeerInfoListAdapter(
lateinit var ping: TextView lateinit var ping: TextView
} }
private fun showToast(text: String){
val duration = Toast.LENGTH_SHORT
val toast = Toast.makeText(context, text, duration)
toast.setGravity(Gravity.CENTER, 0, 0)
toast.show()
}
} }

View File

@ -77,15 +77,15 @@ class Utils {
} }
@JvmStatic @JvmStatic
fun ping(address: InetAddress, port:Int): Int { fun ping(hostname: String, port:Int): Int {
val start = System.currentTimeMillis() val start = System.currentTimeMillis()
val socket = Socket() val socket = Socket()
try { try {
socket.connect(InetSocketAddress(address, port), 5000) socket.connect(InetSocketAddress(hostname, port), 5000)
socket.close() socket.close()
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
print(address) print(hostname)
return Int.MAX_VALUE return Int.MAX_VALUE
} }
return (System.currentTimeMillis() - start).toInt() return (System.currentTimeMillis() - start).toInt()

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".CopyLocalNodeInfoActivity"
android:background="@color/grey">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_node_info" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -35,10 +35,10 @@
android:textColor="@color/dark_30" android:textColor="@color/dark_30"
/> />
<Button <Button
android:id="@+id/copyIp" android:id="@+id/nodeInfo"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:text="COPY" android:text="INFO"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
android:background="@android:color/transparent"/> android:background="@android:color/transparent"/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
@ -53,7 +53,7 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@+id/copyIp" app:layout_constraintEnd_toStartOf="@+id/nodeInfo"
android:text="" android:text=""
android:textColor="@color/white"/> android:textColor="@color/white"/>
</LinearLayout> </LinearLayout>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<ListView
android:id="@+id/nodeInfoList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@color/dark_20"
android:dividerHeight="2px"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,52 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_toLeftOf="@+id/nodeInfoButton"
android:id="@+id/data">
<TextView
android:id="@+id/nodeInfoKey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textSize="10sp"
android:text = "nodeInfoKey"
android:textColor="@color/white"
android:layout_marginStart="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@+id/nodeInfoText"
android:layout_marginLeft="10dp"
android:paddingBottom="5dp"/>
<TextView
android:id="@+id/nodeInfoText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:gravity="center_vertical"
android:minHeight="35dp"
android:text="nodeInfoText"
android:textColor="@color/white"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="@+id/nodeInfoKey"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/nodeInfoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="COPY"
android:textColor="@color/white"
android:layout_alignParentRight="true"
android:background="@android:color/transparent"/>
</RelativeLayout>

View File

@ -0,0 +1,43 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:background="@color/grey">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_margin="10dp"
app:boxBackgroundMode="none"
android:background="@drawable/edit_text_rounded_corner"
android:textColorHint="@color/white"
style="@style/EditText.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/urlInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="URL"
android:textColor="@color/white"
android:textCursorDrawable="@null"/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/save"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:layout_constraintTop_toBottomOf="@+id/url"
android:background="@drawable/button_selector"
app:backgroundTint="@null"
android:text="SAVE"
android:textColor="@color/white"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/editUrlButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="EDIT URL"
android:background="@android:color/transparent"/>
</RelativeLayout>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/editUrlItem"
android:title=""
app:actionLayout="@layout/menu_edit_url"
app:showAsAction="always"/>
<item android:id="@+id/saveItem"
android:title=""
app:actionLayout="@layout/menu_save"
app:showAsAction="always"/>
</menu>

View File

@ -5,7 +5,8 @@
<string name="switch_button_title">SwitchOn</string> <string name="switch_button_title">SwitchOn</string>
<string name="title_activity_peer_list">Edit peers</string> <string name="title_activity_peer_list">Edit peers</string>
<string name="title_activity_dns_list">Edit DNS</string> <string name="title_activity_dns_list">Edit DNS</string>
<string name="address_copied">Address copied</string> <string name="node_info_copied">copied</string>
<string name="schema">Schema</string> <string name="schema">Schema</string>
<string name="title_activity_about">Yggdrasil</string> <string name="title_activity_about">Yggdrasil</string>
<string name="title_activity_copy_local_node_info">Node info</string>
</resources> </resources>

View File

@ -1,13 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = '1.4.32' ext.kotlin_version = '1.4.10'
repositories { repositories {
google() google()
mavenCentral() mavenCentral()
jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.2.0-rc01' classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
@ -17,6 +18,7 @@ buildscript {
allprojects { allprojects {
repositories { repositories {
google() google()
jcenter()
} }
} }

View File

@ -0,0 +1,4 @@
v1.0
1. Implemented VPN network interface for Yggdrasil tunneling
2. Optimized memory buffer
3. Added IPv6 info

View File

@ -0,0 +1,13 @@
v1.2
* New DNS and new Peer form
* fix adding Peers when json url unavailable
* DNS dynamic list selection fixes
* ping selected Peers and DNS fixes
* fixed when app crashed sometimes after ygg switch off
* fixed high CPU consumption after switch-off.
* prevent NPE fix
v1.1
1. Added dynamic peer list loading and edit functionality
2. Layout minor changes
3. Peers ping test and sorting by response time

View File

@ -0,0 +1,3 @@
v1.3
1. open MainActivity after Notification click, task (#12)
2. new DNS only number issue

View File

@ -0,0 +1,3 @@
v1.4
* F-Droid support
* Android 4.0.3 support (API 15)

View File

@ -0,0 +1,4 @@
The application for connecting to Yggdrasil network on Android
Once connected, you can access yggdrasil public services,
as the application has peered automatically to default peers within the application

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -0,0 +1 @@
The application for connecting to Yggdrasil network on Android

View File

@ -0,0 +1 @@
Yggdrasil

View File

@ -4,7 +4,7 @@ all:
-go get -u github.com/yggdrasil-network/yggdrasil-go; -go get -u github.com/yggdrasil-network/yggdrasil-go;
-cd $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go; \ -cd $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go; \
go get -v -d ./...; \ go get -v -d ./...; \
go get -u github.com/vikulin/yggdrasil-extras@268b006; \ go get -u github.com/yggdrasil-network/yggdrasil-extras@005d79c; \
ANDROID=true ./build; ANDROID=true ./build;
mv -f $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go/yggdrasil.aar yggdrasil.aar; mv -f $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go/yggdrasil.aar yggdrasil.aar;
mv -f $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go/yggdrasil-sources.jar yggdrasil-sources.jar; mv -f $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go/yggdrasil-sources.jar yggdrasil-sources.jar;