mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2025-01-22 07:56:30 +00:00
1. code refactoring
This commit is contained in:
parent
4865e16854
commit
b2b6f2c8ef
@ -62,7 +62,7 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
@JvmStatic var isStarted = false
|
||||
@JvmStatic var isCancelled = false
|
||||
@JvmStatic var address = ""
|
||||
@JvmStatic var address:String? = ""
|
||||
}
|
||||
|
||||
private var currentPeers = setOf<PeerInfo>()
|
||||
@ -230,7 +230,7 @@ class MainActivity : AppCompatActivity() {
|
||||
//save to shared preferences
|
||||
val preferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||
preferences.edit().putStringSet(CURRENT_PEERS, HashSet(currentPeers)).apply()
|
||||
preferences.edit().putStringSet(CURRENT_PEERS, currentPeers!!.toHashSet()).apply()
|
||||
if(isStarted){
|
||||
//TODO implement UpdateConfig method in native interface and apply peer changes
|
||||
stopVpn()
|
||||
@ -254,7 +254,7 @@ class MainActivity : AppCompatActivity() {
|
||||
//save to shared preferences
|
||||
val preferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||
preferences.edit().putStringSet(CURRENT_DNS, HashSet(currentDNS)).apply()
|
||||
preferences.edit().putStringSet(CURRENT_DNS, currentDNS!!.toHashSet()).apply()
|
||||
if(isStarted){
|
||||
updateDNS()
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ import java.net.Inet6Address
|
||||
class YggdrasilTunService : VpnService() {
|
||||
|
||||
private lateinit var ygg: Yggdrasil
|
||||
private lateinit var tunInterface: ParcelFileDescriptor
|
||||
private lateinit var tunInputStream: InputStream
|
||||
private lateinit var tunOutputStream: OutputStream
|
||||
private lateinit var address: String
|
||||
@ -39,6 +38,7 @@ class YggdrasilTunService : VpnService() {
|
||||
|
||||
/** Maximum packet size is constrained by the MTU, which is given as a signed short/2 */
|
||||
private val MAX_PACKET_SIZE = Short.MAX_VALUE/2
|
||||
private var tunInterface: ParcelFileDescriptor? = null
|
||||
|
||||
companion object {
|
||||
private const val TAG = "Yggdrasil-service"
|
||||
@ -103,8 +103,8 @@ class YggdrasilTunService : VpnService() {
|
||||
builder.addRoute("2000::",3)
|
||||
}
|
||||
tunInterface = builder.establish()
|
||||
tunInputStream = FileInputStream(tunInterface.fileDescriptor)
|
||||
tunOutputStream = FileOutputStream(tunInterface.fileDescriptor)
|
||||
tunInputStream = FileInputStream(tunInterface!!.fileDescriptor)
|
||||
tunOutputStream = FileOutputStream(tunInterface!!.fileDescriptor)
|
||||
}
|
||||
|
||||
private fun setupTunInterface(
|
||||
@ -144,7 +144,7 @@ class YggdrasilTunService : VpnService() {
|
||||
|
||||
private fun sendMeshPeerStatus(pi: PendingIntent?){
|
||||
class Token : TypeToken<List<Peer>>()
|
||||
var add = ygg.addressString
|
||||
ygg.addressString
|
||||
var meshPeers: List<Peer> = gson.fromJson(ygg.peersJSON, Token().type)
|
||||
val intent: Intent = Intent().putStringArrayListExtra(
|
||||
MainActivity.MESH_PEERS,
|
||||
@ -238,7 +238,7 @@ class YggdrasilTunService : VpnService() {
|
||||
scope!!.coroutineContext.cancelChildren()
|
||||
tunInputStream.close()
|
||||
tunOutputStream.close()
|
||||
tunInterface.close()
|
||||
tunInterface!!.close()
|
||||
Log.d(TAG,"Stop is running from service")
|
||||
ygg.stop()
|
||||
val intent: Intent = Intent()
|
||||
|
Loading…
x
Reference in New Issue
Block a user