From fd8742f513977c0772e7c8be8d77e2379d1e0ae7 Mon Sep 17 00:00:00 2001 From: vadym Date: Sun, 23 Aug 2020 11:22:16 +0300 Subject: [PATCH] 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()