From fd8742f513977c0772e7c8be8d77e2379d1e0ae7 Mon Sep 17 00:00:00 2001 From: vadym Date: Sun, 23 Aug 2020 11:22:16 +0300 Subject: [PATCH 01/11] 1. pure threading in packets read/write --- .idea/codeStyles/Project.xml | 16 ++++++++++++++++ .../chronosx88/yggdrasil/PeerListActivity.kt | 12 ------------ .../chronosx88/yggdrasil/YggdrasilTunService.kt | 10 +++------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index ce889bd..ce1fc4f 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,6 +1,22 @@ + + diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt index 786cddc..37f3fac 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt @@ -241,18 +241,6 @@ class PeerListActivity : AppCompatActivity() { val result = Intent(this, MainActivity::class.java) var adapter = findViewById(R.id.peerList).adapter as SelectPeerInfoListAdapter val selectedPeers = adapter.getSelectedPeers() - /* WiFi Direct test - no peers is needed - if(selectedPeers.size>0) { - result.putExtra(MainActivity.PEER_LIST, serializePeerInfoSet2StringList(selectedPeers)) - setResult(Activity.RESULT_OK, result) - finish() - } else { - val text = "Select at least one peer" - val duration = Toast.LENGTH_SHORT - val toast = Toast.makeText(applicationContext, text, duration) - toast.setGravity(Gravity.CENTER, 0, 0) - toast.show() - }*/ result.putExtra(MainActivity.PEER_LIST, serializePeerInfoSet2StringList(selectedPeers)) setResult(Activity.RESULT_OK, result) finish() diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt index 7fac9e5..52a0892 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt @@ -27,6 +27,7 @@ import mobile.Mobile import mobile.Yggdrasil import java.io.* import java.net.Inet6Address +import kotlin.concurrent.thread class YggdrasilTunService : VpnService() { @@ -44,8 +45,6 @@ class YggdrasilTunService : VpnService() { private const val TAG = "Yggdrasil-service" } - private var scope: CoroutineScope? = null - private val FOREGROUND_ID = 1338 override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { @@ -124,15 +123,13 @@ class YggdrasilTunService : VpnService() { setupIOStreams(dns) - val job = SupervisorJob() - scope = CoroutineScope(Dispatchers.Default + job) - scope!!.launch { + thread(start = true) { val buffer = ByteArray(MAX_PACKET_SIZE) while (!isClosed) { readPacketsFromTun(yggConduitEndpoint, buffer) } } - scope!!.launch { + thread(start = true) { while (!isClosed) { writePacketsToTun(yggConduitEndpoint) } @@ -234,7 +231,6 @@ class YggdrasilTunService : VpnService() { private fun stopVpn(pi: PendingIntent?) { isClosed = true; - scope!!.coroutineContext.cancelChildren() tunInputStream.close() tunOutputStream.close() tunInterface!!.close() From 0c5a3b0f82191574087de05247ddb8ec5dc660ce Mon Sep 17 00:00:00 2001 From: vadym Date: Sun, 23 Aug 2020 21:38:43 +0300 Subject: [PATCH 02/11] 1. remove checkmarks fix --- .../models/config/SelectPeerInfoListAdapter.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/models/config/SelectPeerInfoListAdapter.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/models/config/SelectPeerInfoListAdapter.kt index 5bb0914..addb6d5 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/models/config/SelectPeerInfoListAdapter.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/models/config/SelectPeerInfoListAdapter.kt @@ -57,15 +57,13 @@ class SelectPeerInfoListAdapter( peerInfoHolder.peerInfoText.setTextColor(Color.WHITE) } peerInfoHolder.checkbox.setOnCheckedChangeListener { _, isChecked -> - if(!isLoading) { - if (isChecked) { - if (!currentPeers.contains(currentPeer)) { - currentPeers.add(currentPeer) - } - } else { - if (currentPeers.contains(currentPeer)) { - currentPeers.remove(currentPeer) - } + if (isChecked) { + if (!currentPeers.contains(currentPeer)) { + currentPeers.add(currentPeer) + } + } else { + if (currentPeers.contains(currentPeer)) { + currentPeers.remove(currentPeer) } } } From 63dcc3802b775c02281412561e9f6a22c948d5d1 Mon Sep 17 00:00:00 2001 From: vadym Date: Wed, 26 Aug 2020 12:34:14 +0300 Subject: [PATCH 03/11] 1. fix for bug #19 --- .../chronosx88/yggdrasil/MainActivity.kt | 28 ++++--------------- .../chronosx88/yggdrasil/PeerListActivity.kt | 3 +- .../yggdrasil/YggdrasilTunService.kt | 7 +++-- 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt index 6209ae0..9507f18 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt @@ -143,24 +143,16 @@ class MainActivity : AppCompatActivity() { ipLayout.visibility = View.VISIBLE findViewById(R.id.ip).text = address } - /* + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { val connectivityManager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager connectivityManager?.let { it.registerDefaultNetworkCallback(object : ConnectivityManager.NetworkCallback() { override fun onAvailable(network: Network) { - if(isStarted) { - stopVpn() - Thread.sleep(1000) - startVpn() - } + startVpn() } override fun onLost(network: Network?) { - if(isStarted) { - stopVpn() - Thread.sleep(1000) - startVpn() - } + stopVpn() } }) } @@ -171,22 +163,14 @@ class MainActivity : AppCompatActivity() { Log.i(TAG, "Network state has been changed") if ("android.net.conn.CONNECTIVITY_CHANGE" == intent.action) { if (status == NetworkUtils.NETWORK_STATUS_NOT_CONNECTED) { - if(isStarted) { - stopVpn() - Thread.sleep(1000) - startVpn() - } + stopVpn() } else { - if(isStarted) { - stopVpn() - Thread.sleep(1000) - startVpn() - } + startVpn() } } } } - }*/ + } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { val sourceDir: String = this.applicationInfo.sourceDir val dexFile = DexFile(sourceDir) diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt index 37f3fac..e516138 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt @@ -34,14 +34,13 @@ import java.net.URI import java.net.URL import java.nio.charset.Charset - class PeerListActivity : AppCompatActivity() { companion object { const val PEER_LIST_URL = "https://publicpeers.neilalexander.dev/publicnodes.json" } - fun downloadJson(link: String): String { + private fun downloadJson(link: String): String { URL(link).openStream().use { input -> var outStream = ByteArrayOutputStream() outStream.use { output -> diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt index 52a0892..3d1a797 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt @@ -31,7 +31,7 @@ import kotlin.concurrent.thread class YggdrasilTunService : VpnService() { - private lateinit var ygg: Yggdrasil + //private lateinit var ygg: Yggdrasil private lateinit var tunInputStream: InputStream private lateinit var tunOutputStream: OutputStream private lateinit var address: String @@ -43,6 +43,7 @@ class YggdrasilTunService : VpnService() { companion object { private const val TAG = "Yggdrasil-service" + private val ygg = Yggdrasil() } private val FOREGROUND_ID = 1338 @@ -58,7 +59,7 @@ class YggdrasilTunService : VpnService() { val peers = deserializeStringList2PeerInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_PEERS)) val dns = deserializeStringList2DNSInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_DNS)) val staticIP: Boolean = intent.getBooleanExtra(MainActivity.STATIC_IP, false) - ygg = Yggdrasil() + setupTunInterface(pi, peers, dns, staticIP) foregroundNotification(FOREGROUND_ID, "Yggdrasil service started") } @@ -235,7 +236,7 @@ class YggdrasilTunService : VpnService() { tunOutputStream.close() tunInterface!!.close() Log.d(TAG,"Stop is running from service") - ygg.stop() + //ygg.stop() val intent: Intent = Intent() pi!!.send(this, MainActivity.STATUS_STOP, intent) stopForeground(true) From ebe7485120e05390a93a17b22a42e93dafd2663e Mon Sep 17 00:00:00 2001 From: vadym Date: Wed, 26 Aug 2020 13:00:38 +0300 Subject: [PATCH 04/11] Revert "1. fix for bug #19" This reverts commit 63dcc380 --- .../chronosx88/yggdrasil/MainActivity.kt | 28 +++++++++++++++---- .../chronosx88/yggdrasil/PeerListActivity.kt | 3 +- .../yggdrasil/YggdrasilTunService.kt | 7 ++--- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt index 9507f18..6209ae0 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt @@ -143,16 +143,24 @@ class MainActivity : AppCompatActivity() { ipLayout.visibility = View.VISIBLE findViewById(R.id.ip).text = address } - + /* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { val connectivityManager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager connectivityManager?.let { it.registerDefaultNetworkCallback(object : ConnectivityManager.NetworkCallback() { override fun onAvailable(network: Network) { - startVpn() + if(isStarted) { + stopVpn() + Thread.sleep(1000) + startVpn() + } } override fun onLost(network: Network?) { - stopVpn() + if(isStarted) { + stopVpn() + Thread.sleep(1000) + startVpn() + } } }) } @@ -163,14 +171,22 @@ class MainActivity : AppCompatActivity() { Log.i(TAG, "Network state has been changed") if ("android.net.conn.CONNECTIVITY_CHANGE" == intent.action) { if (status == NetworkUtils.NETWORK_STATUS_NOT_CONNECTED) { - stopVpn() + if(isStarted) { + stopVpn() + Thread.sleep(1000) + startVpn() + } } else { - startVpn() + if(isStarted) { + stopVpn() + Thread.sleep(1000) + startVpn() + } } } } } - } + }*/ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { val sourceDir: String = this.applicationInfo.sourceDir val dexFile = DexFile(sourceDir) diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt index e516138..37f3fac 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt @@ -34,13 +34,14 @@ import java.net.URI import java.net.URL import java.nio.charset.Charset + class PeerListActivity : AppCompatActivity() { companion object { const val PEER_LIST_URL = "https://publicpeers.neilalexander.dev/publicnodes.json" } - private fun downloadJson(link: String): String { + fun downloadJson(link: String): String { URL(link).openStream().use { input -> var outStream = ByteArrayOutputStream() outStream.use { output -> diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt index 3d1a797..52a0892 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt @@ -31,7 +31,7 @@ import kotlin.concurrent.thread class YggdrasilTunService : VpnService() { - //private lateinit var ygg: Yggdrasil + private lateinit var ygg: Yggdrasil private lateinit var tunInputStream: InputStream private lateinit var tunOutputStream: OutputStream private lateinit var address: String @@ -43,7 +43,6 @@ class YggdrasilTunService : VpnService() { companion object { private const val TAG = "Yggdrasil-service" - private val ygg = Yggdrasil() } private val FOREGROUND_ID = 1338 @@ -59,7 +58,7 @@ class YggdrasilTunService : VpnService() { val peers = deserializeStringList2PeerInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_PEERS)) val dns = deserializeStringList2DNSInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_DNS)) val staticIP: Boolean = intent.getBooleanExtra(MainActivity.STATIC_IP, false) - + ygg = Yggdrasil() setupTunInterface(pi, peers, dns, staticIP) foregroundNotification(FOREGROUND_ID, "Yggdrasil service started") } @@ -236,7 +235,7 @@ class YggdrasilTunService : VpnService() { tunOutputStream.close() tunInterface!!.close() Log.d(TAG,"Stop is running from service") - //ygg.stop() + ygg.stop() val intent: Intent = Intent() pi!!.send(this, MainActivity.STATUS_STOP, intent) stopForeground(true) From 9cfd0b32ecd7422b0ff0146f443b49e80f7eeddf Mon Sep 17 00:00:00 2001 From: vadym Date: Tue, 29 Sep 2020 19:13:44 +0300 Subject: [PATCH 05/11] 1. libraries upgrade --- app/build.gradle | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8890da4..a6e4036 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,13 +3,13 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 29 + compileSdkVersion 30 defaultConfig { applicationId "io.github.chronosx88.yggdrasil" minSdkVersion 15 - targetSdkVersion 29 - versionCode 4 - versionName "1.4" + targetSdkVersion 30 + versionCode 5 + versionName "1.5" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" project.ext.set("archivesBaseName", project.getParent().name+"-"+versionName) } @@ -58,8 +58,8 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(path: ':yggdrasil') - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.1' implementation "androidx.preference:preference-ktx:1.1.1" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" From 10108c6c1e4c1eda525d614f22f5a7b9802ce55c Mon Sep 17 00:00:00 2001 From: vadym Date: Tue, 29 Sep 2020 20:02:08 +0300 Subject: [PATCH 06/11] 1. upgrade core to 0.3.15 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a6e4036..1fbd9ab 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -69,6 +69,6 @@ dependencies { implementation 'com.hbb20:ccp:2.4.0' testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.2.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + androidTestImplementation 'androidx.test:runner:1.3.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' } \ No newline at end of file From 37748ad30432a024edb7c48892f4af74c42a32cb Mon Sep 17 00:00:00 2001 From: vadym Date: Tue, 13 Oct 2020 13:45:07 +0300 Subject: [PATCH 07/11] 1. upgrade gradle version --- .idea/gradle.xml | 1 + build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 1c8f0f8..d3183f2 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -15,6 +15,7 @@ diff --git a/build.gradle b/build.gradle index bbc207a..fa33d29 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.1' + classpath 'com.android.tools.build:gradle:4.1.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a12bfeb..c98916b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Jun 09 01:07:00 PDT 2020 +#Tue Oct 13 09:25:31 EEST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip From 09d4e6b3fa593a8623f6504cda34cbd688d9fe68 Mon Sep 17 00:00:00 2001 From: vadym Date: Tue, 13 Oct 2020 20:20:12 +0300 Subject: [PATCH 08/11] 1. style fixes 2. added about screen --- .../chronosx88/yggdrasil/MainActivity.kt | 59 +++++++++++++------ app/src/main/res/layout/activity_about.xml | 22 +++++++ app/src/main/res/layout/activity_main.xml | 4 +- app/src/main/res/layout/content_main.xml | 9 ++- app/src/main/res/values-v21/styles.xml | 2 +- 5 files changed, 73 insertions(+), 23 deletions(-) create mode 100644 app/src/main/res/layout/activity_about.xml diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt index 6209ae0..5142a41 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt @@ -3,8 +3,6 @@ package io.github.chronosx88.yggdrasil import android.app.Activity import android.app.ActivityManager import android.content.* -import android.net.ConnectivityManager -import android.net.Network import android.net.VpnService import android.os.Build import android.os.Bundle @@ -13,12 +11,12 @@ import android.view.Gravity import android.view.View import android.widget.* import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.widget.SwitchCompat import androidx.preference.PreferenceManager import dalvik.system.DexFile import io.github.chronosx88.yggdrasil.models.DNSInfo import io.github.chronosx88.yggdrasil.models.PeerInfo import io.github.chronosx88.yggdrasil.models.config.DNSInfoListAdapter -import io.github.chronosx88.yggdrasil.models.config.NetworkUtils import io.github.chronosx88.yggdrasil.models.config.PeerInfoListAdapter import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializePeerStringList2PeerInfoSet import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2DNSInfoSet @@ -74,7 +72,7 @@ class MainActivity : AppCompatActivity() { setContentView(R.layout.activity_main) setSupportActionBar(findViewById(R.id.toolbar)) isStarted = isYggServiceRunning(this) - val switchOn = findViewById(R.id.switchOn) + val switchOn = findViewById(R.id.switchOn) switchOn.isChecked = isStarted switchOn.setOnCheckedChangeListener { _, isChecked -> @@ -92,12 +90,17 @@ class MainActivity : AppCompatActivity() { //save to shared preferences val preferences = PreferenceManager.getDefaultSharedPreferences(this.baseContext) - val staticIP = findViewById(R.id.staticIP) + val staticIP = findViewById(R.id.staticIP) staticIP.isChecked = preferences.getString(STATIC_IP, null) != null val peersListView = findViewById(R.id.peers) - currentPeers = deserializeStringSet2PeerInfoSet(preferences.getStringSet(CURRENT_PEERS, HashSet())!!) + currentPeers = deserializeStringSet2PeerInfoSet( + preferences.getStringSet( + CURRENT_PEERS, + HashSet() + )!! + ) val adapter = PeerInfoListAdapter(this, currentPeers.sortedWith(compareBy { it.ping })) peersListView.adapter = adapter if(isStarted && this.currentPeers.isEmpty()) { @@ -125,7 +128,12 @@ class MainActivity : AppCompatActivity() { } val listViewDNS = findViewById(R.id.dns) - currentDNS = deserializeStringSet2DNSInfoSet(preferences.getStringSet(CURRENT_DNS, HashSet())!!) + currentDNS = deserializeStringSet2DNSInfoSet( + preferences.getStringSet( + CURRENT_DNS, + HashSet() + )!! + ) val adapterDns = DNSInfoListAdapter(this, currentDNS.sortedWith(compareBy { it.ping })) listViewDNS.adapter = adapterDns val editDnsButton = findViewById