mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2025-01-22 16:06:30 +00:00
1. pure threading in packets read/write
This commit is contained in:
parent
cf8d818a7b
commit
fd8742f513
16
.idea/codeStyles/Project.xml
generated
16
.idea/codeStyles/Project.xml
generated
@ -1,6 +1,22 @@
|
|||||||
<component name="ProjectCodeStyleConfiguration">
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
<code_scheme name="Project" version="173">
|
<code_scheme name="Project" version="173">
|
||||||
<JetCodeStyleSettings>
|
<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" />
|
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||||
</JetCodeStyleSettings>
|
</JetCodeStyleSettings>
|
||||||
<codeStyleSettings language="XML">
|
<codeStyleSettings language="XML">
|
||||||
|
@ -241,18 +241,6 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
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()
|
||||||
/* 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))
|
result.putExtra(MainActivity.PEER_LIST, serializePeerInfoSet2StringList(selectedPeers))
|
||||||
setResult(Activity.RESULT_OK, result)
|
setResult(Activity.RESULT_OK, result)
|
||||||
finish()
|
finish()
|
||||||
|
@ -27,6 +27,7 @@ import mobile.Mobile
|
|||||||
import mobile.Yggdrasil
|
import mobile.Yggdrasil
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.net.Inet6Address
|
import java.net.Inet6Address
|
||||||
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
class YggdrasilTunService : VpnService() {
|
class YggdrasilTunService : VpnService() {
|
||||||
|
|
||||||
@ -44,8 +45,6 @@ class YggdrasilTunService : VpnService() {
|
|||||||
private const val TAG = "Yggdrasil-service"
|
private const val TAG = "Yggdrasil-service"
|
||||||
}
|
}
|
||||||
|
|
||||||
private var scope: CoroutineScope? = null
|
|
||||||
|
|
||||||
private val FOREGROUND_ID = 1338
|
private val FOREGROUND_ID = 1338
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
@ -124,15 +123,13 @@ class YggdrasilTunService : VpnService() {
|
|||||||
|
|
||||||
setupIOStreams(dns)
|
setupIOStreams(dns)
|
||||||
|
|
||||||
val job = SupervisorJob()
|
thread(start = true) {
|
||||||
scope = CoroutineScope(Dispatchers.Default + job)
|
|
||||||
scope!!.launch {
|
|
||||||
val buffer = ByteArray(MAX_PACKET_SIZE)
|
val buffer = ByteArray(MAX_PACKET_SIZE)
|
||||||
while (!isClosed) {
|
while (!isClosed) {
|
||||||
readPacketsFromTun(yggConduitEndpoint, buffer)
|
readPacketsFromTun(yggConduitEndpoint, buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scope!!.launch {
|
thread(start = true) {
|
||||||
while (!isClosed) {
|
while (!isClosed) {
|
||||||
writePacketsToTun(yggConduitEndpoint)
|
writePacketsToTun(yggConduitEndpoint)
|
||||||
}
|
}
|
||||||
@ -234,7 +231,6 @@ class YggdrasilTunService : VpnService() {
|
|||||||
|
|
||||||
private fun stopVpn(pi: PendingIntent?) {
|
private fun stopVpn(pi: PendingIntent?) {
|
||||||
isClosed = true;
|
isClosed = true;
|
||||||
scope!!.coroutineContext.cancelChildren()
|
|
||||||
tunInputStream.close()
|
tunInputStream.close()
|
||||||
tunOutputStream.close()
|
tunOutputStream.close()
|
||||||
tunInterface!!.close()
|
tunInterface!!.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user