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 isStarted = false
|
||||||
@JvmStatic var isCancelled = false
|
@JvmStatic var isCancelled = false
|
||||||
@JvmStatic var address = ""
|
@JvmStatic var address:String? = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
private var currentPeers = setOf<PeerInfo>()
|
private var currentPeers = setOf<PeerInfo>()
|
||||||
@ -230,7 +230,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
//save to shared preferences
|
//save to shared preferences
|
||||||
val preferences =
|
val preferences =
|
||||||
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||||
preferences.edit().putStringSet(CURRENT_PEERS, HashSet(currentPeers)).apply()
|
preferences.edit().putStringSet(CURRENT_PEERS, currentPeers!!.toHashSet()).apply()
|
||||||
if(isStarted){
|
if(isStarted){
|
||||||
//TODO implement UpdateConfig method in native interface and apply peer changes
|
//TODO implement UpdateConfig method in native interface and apply peer changes
|
||||||
stopVpn()
|
stopVpn()
|
||||||
@ -254,7 +254,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
//save to shared preferences
|
//save to shared preferences
|
||||||
val preferences =
|
val preferences =
|
||||||
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||||
preferences.edit().putStringSet(CURRENT_DNS, HashSet(currentDNS)).apply()
|
preferences.edit().putStringSet(CURRENT_DNS, currentDNS!!.toHashSet()).apply()
|
||||||
if(isStarted){
|
if(isStarted){
|
||||||
updateDNS()
|
updateDNS()
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ import java.net.Inet6Address
|
|||||||
class YggdrasilTunService : VpnService() {
|
class YggdrasilTunService : VpnService() {
|
||||||
|
|
||||||
private lateinit var ygg: Yggdrasil
|
private lateinit var ygg: Yggdrasil
|
||||||
private lateinit var tunInterface: ParcelFileDescriptor
|
|
||||||
private lateinit var tunInputStream: InputStream
|
private lateinit var tunInputStream: InputStream
|
||||||
private lateinit var tunOutputStream: OutputStream
|
private lateinit var tunOutputStream: OutputStream
|
||||||
private lateinit var address: String
|
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 */
|
/** 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 val MAX_PACKET_SIZE = Short.MAX_VALUE/2
|
||||||
|
private var tunInterface: ParcelFileDescriptor? = null
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "Yggdrasil-service"
|
private const val TAG = "Yggdrasil-service"
|
||||||
@ -103,8 +103,8 @@ class YggdrasilTunService : VpnService() {
|
|||||||
builder.addRoute("2000::",3)
|
builder.addRoute("2000::",3)
|
||||||
}
|
}
|
||||||
tunInterface = builder.establish()
|
tunInterface = builder.establish()
|
||||||
tunInputStream = FileInputStream(tunInterface.fileDescriptor)
|
tunInputStream = FileInputStream(tunInterface!!.fileDescriptor)
|
||||||
tunOutputStream = FileOutputStream(tunInterface.fileDescriptor)
|
tunOutputStream = FileOutputStream(tunInterface!!.fileDescriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupTunInterface(
|
private fun setupTunInterface(
|
||||||
@ -144,7 +144,7 @@ class YggdrasilTunService : VpnService() {
|
|||||||
|
|
||||||
private fun sendMeshPeerStatus(pi: PendingIntent?){
|
private fun sendMeshPeerStatus(pi: PendingIntent?){
|
||||||
class Token : TypeToken<List<Peer>>()
|
class Token : TypeToken<List<Peer>>()
|
||||||
var add = ygg.addressString
|
ygg.addressString
|
||||||
var meshPeers: List<Peer> = gson.fromJson(ygg.peersJSON, Token().type)
|
var meshPeers: List<Peer> = gson.fromJson(ygg.peersJSON, Token().type)
|
||||||
val intent: Intent = Intent().putStringArrayListExtra(
|
val intent: Intent = Intent().putStringArrayListExtra(
|
||||||
MainActivity.MESH_PEERS,
|
MainActivity.MESH_PEERS,
|
||||||
@ -238,7 +238,7 @@ class YggdrasilTunService : VpnService() {
|
|||||||
scope!!.coroutineContext.cancelChildren()
|
scope!!.coroutineContext.cancelChildren()
|
||||||
tunInputStream.close()
|
tunInputStream.close()
|
||||||
tunOutputStream.close()
|
tunOutputStream.close()
|
||||||
tunInterface.close()
|
tunInterface!!.close()
|
||||||
Log.d(TAG,"Stop is running from service")
|
Log.d(TAG,"Stop is running from service")
|
||||||
ygg.stop()
|
ygg.stop()
|
||||||
val intent: Intent = Intent()
|
val intent: Intent = Intent()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user