1. pure threading in packets read/write

This commit is contained in:
vadym 2020-08-23 11:22:16 +03:00
parent cf8d818a7b
commit fd8742f513
3 changed files with 19 additions and 19 deletions

View File

@ -1,6 +1,22 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
<package name="java.util" alias="false" withSubpackages="false" />
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
<package name="io.ktor" alias="false" withSubpackages="true" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
<value>
<package name="" alias="false" withSubpackages="true" />
<package name="java" alias="false" withSubpackages="true" />
<package name="javax" alias="false" withSubpackages="true" />
<package name="kotlin" alias="false" withSubpackages="true" />
<package name="" alias="true" withSubpackages="true" />
</value>
</option>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="XML">

View File

@ -241,18 +241,6 @@ class PeerListActivity : AppCompatActivity() {
val result = Intent(this, MainActivity::class.java)
var adapter = findViewById<ListView>(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()

View File

@ -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()