mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2024-11-09 12:01:01 +00:00
1. migration to v0.4 API changes
This commit is contained in:
parent
85db5de358
commit
c0847e2eb3
@ -6,7 +6,6 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import io.github.chronosx88.yggdrasil.models.NodeInfo
|
import io.github.chronosx88.yggdrasil.models.NodeInfo
|
||||||
import io.github.chronosx88.yggdrasil.models.config.CopyInfoAdapter
|
import io.github.chronosx88.yggdrasil.models.config.CopyInfoAdapter
|
||||||
import io.github.chronosx88.yggdrasil.models.config.SelectDNSInfoListAdapter
|
|
||||||
|
|
||||||
class CopyLocalNodeInfoActivity: AppCompatActivity() {
|
class CopyLocalNodeInfoActivity: AppCompatActivity() {
|
||||||
|
|
||||||
@ -17,10 +16,9 @@ class CopyLocalNodeInfoActivity: AppCompatActivity() {
|
|||||||
val preferences =
|
val preferences =
|
||||||
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||||
val ipv6Address = intent.extras!!.getString(MainActivity.IPv6, "")
|
val ipv6Address = intent.extras!!.getString(MainActivity.IPv6, "")
|
||||||
val signingPublicKey = preferences.getString(MainActivity.signingPublicKey, "")
|
val publicKey = preferences.getString(MainActivity.publicKey, "")
|
||||||
val encryptionPublicKey = preferences.getString(MainActivity.encryptionPublicKey, "")
|
|
||||||
var nodeInfoListView = findViewById<ListView>(R.id.nodeInfoList)
|
var nodeInfoListView = findViewById<ListView>(R.id.nodeInfoList)
|
||||||
val nodeInfoList = listOf<NodeInfo>(NodeInfo("IP address", ipv6Address!!), NodeInfo("Encryption Public Key", encryptionPublicKey!!), NodeInfo("Signing Public Key", signingPublicKey!!));
|
val nodeInfoList = listOf<NodeInfo>(NodeInfo("IP address", ipv6Address!!), NodeInfo("Public Key", publicKey!!));
|
||||||
var adapter = CopyInfoAdapter(this, nodeInfoList)
|
var adapter = CopyInfoAdapter(this, nodeInfoList)
|
||||||
nodeInfoListView.adapter = adapter
|
nodeInfoListView.adapter = adapter
|
||||||
}
|
}
|
||||||
|
@ -34,10 +34,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
const val STATUS_PEERS_UPDATE = 12
|
const val STATUS_PEERS_UPDATE = 12
|
||||||
const val MESH_PEERS = "MESH_PEERS"
|
const val MESH_PEERS = "MESH_PEERS"
|
||||||
const val STATIC_IP = "STATIC_IP_FLAG"
|
const val STATIC_IP = "STATIC_IP_FLAG"
|
||||||
const val signingPrivateKey = "signingPrivateKey"
|
const val privateKey = "privateKey"
|
||||||
const val signingPublicKey = "signingPublicKey"
|
const val publicKey = "publicKey"
|
||||||
const val encryptionPrivateKey = "encryptionPrivateKey"
|
|
||||||
const val encryptionPublicKey = "encryptionPublicKey"
|
|
||||||
const val COMMAND = "COMMAND"
|
const val COMMAND = "COMMAND"
|
||||||
const val STOP = "STOP"
|
const val STOP = "STOP"
|
||||||
const val START = "START"
|
const val START = "START"
|
||||||
|
@ -11,14 +11,12 @@ val gson = Gson()
|
|||||||
fun createNativeYggConfig(config: Config): NodeConfig {
|
fun createNativeYggConfig(config: Config): NodeConfig {
|
||||||
val nativeConfig = NodeConfig()
|
val nativeConfig = NodeConfig()
|
||||||
nativeConfig.adminListen = config.adminListen
|
nativeConfig.adminListen = config.adminListen
|
||||||
nativeConfig.encryptionPrivateKey = config.encryptionPrivateKey
|
nativeConfig.privateKey = config.privateKey
|
||||||
nativeConfig.encryptionPublicKey = config.encryptionPublicKey
|
nativeConfig.publicKey = config.publicKey
|
||||||
//nativeConfig.ifMTU = config.ifMTU
|
//nativeConfig.ifMTU = config.ifMTU
|
||||||
nativeConfig.ifName = config.ifName
|
nativeConfig.ifName = config.ifName
|
||||||
//nativeConfig.ifTAPMode = config.ifTAPMode
|
//nativeConfig.ifTAPMode = config.ifTAPMode
|
||||||
nativeConfig.nodeInfoPrivacy = config.nodeInfoPrivacy
|
nativeConfig.nodeInfoPrivacy = config.nodeInfoPrivacy
|
||||||
nativeConfig.signingPrivateKey = config.signingPrivateKey
|
|
||||||
nativeConfig.signingPublicKey = config.signingPublicKey
|
|
||||||
return nativeConfig
|
return nativeConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ import androidx.core.app.NotificationCompat
|
|||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import dummy.ConduitEndpoint
|
|
||||||
import io.github.chronosx88.yggdrasil.models.DNSInfo
|
import io.github.chronosx88.yggdrasil.models.DNSInfo
|
||||||
import io.github.chronosx88.yggdrasil.models.PeerInfo
|
import io.github.chronosx88.yggdrasil.models.PeerInfo
|
||||||
import io.github.chronosx88.yggdrasil.models.config.Peer
|
import io.github.chronosx88.yggdrasil.models.config.Peer
|
||||||
@ -22,7 +21,6 @@ import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.convertPeer2
|
|||||||
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.convertPeerInfoSet2PeerIdSet
|
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.convertPeerInfoSet2PeerIdSet
|
||||||
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2DNSInfoSet
|
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2DNSInfoSet
|
||||||
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2PeerInfoSet
|
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2PeerInfoSet
|
||||||
import kotlinx.coroutines.*
|
|
||||||
import mobile.Mobile
|
import mobile.Mobile
|
||||||
import mobile.Yggdrasil
|
import mobile.Yggdrasil
|
||||||
import java.io.*
|
import java.io.*
|
||||||
@ -119,19 +117,19 @@ class YggdrasilTunService : VpnService() {
|
|||||||
|
|
||||||
configJson = gson.toJson(config).toByteArray()
|
configJson = gson.toJson(config).toByteArray()
|
||||||
|
|
||||||
var yggConduitEndpoint = ygg.startJSON(configJson)
|
ygg.startJSON(configJson)
|
||||||
|
|
||||||
setupIOStreams(dns)
|
setupIOStreams(dns)
|
||||||
|
|
||||||
thread(start = true) {
|
thread(start = true) {
|
||||||
val buffer = ByteArray(MAX_PACKET_SIZE)
|
val buffer = ByteArray(MAX_PACKET_SIZE)
|
||||||
while (!isClosed) {
|
while (!isClosed) {
|
||||||
readPacketsFromTun(yggConduitEndpoint, buffer)
|
readPacketsFromTun(buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
thread(start = true) {
|
thread(start = true) {
|
||||||
while (!isClosed) {
|
while (!isClosed) {
|
||||||
writePacketsToTun(yggConduitEndpoint)
|
writePacketsToTun()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val intent: Intent = Intent().putExtra(MainActivity.IPv6, address)
|
val intent: Intent = Intent().putExtra(MainActivity.IPv6, address)
|
||||||
@ -168,37 +166,27 @@ class YggdrasilTunService : VpnService() {
|
|||||||
val preferences =
|
val preferences =
|
||||||
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||||
if(preferences.getString(MainActivity.STATIC_IP, null)==null) {
|
if(preferences.getString(MainActivity.STATIC_IP, null)==null) {
|
||||||
val encryptionPublicKey = config["EncryptionPublicKey"].toString()
|
val publicKey = config["PublicKey"].toString()
|
||||||
val encryptionPrivateKey = config["EncryptionPrivateKey"].toString()
|
val privateKey = config["PrivateKey"].toString()
|
||||||
val signingPublicKey = config["SigningPublicKey"].toString()
|
|
||||||
val signingPrivateKey = config["SigningPrivateKey"].toString()
|
|
||||||
preferences.edit()
|
preferences.edit()
|
||||||
.putString(MainActivity.signingPrivateKey, signingPrivateKey)
|
.putString(MainActivity.privateKey, privateKey)
|
||||||
.putString(MainActivity.signingPublicKey, signingPublicKey)
|
.putString(MainActivity.publicKey, publicKey)
|
||||||
.putString(MainActivity.encryptionPrivateKey, encryptionPrivateKey)
|
|
||||||
.putString(MainActivity.encryptionPublicKey, encryptionPublicKey)
|
|
||||||
.putString(MainActivity.STATIC_IP, MainActivity.STATIC_IP).apply()
|
.putString(MainActivity.STATIC_IP, MainActivity.STATIC_IP).apply()
|
||||||
} else {
|
} else {
|
||||||
val signingPrivateKey = preferences.getString(MainActivity.signingPrivateKey, null)
|
val privateKey = preferences.getString(MainActivity.privateKey, null)
|
||||||
val signingPublicKey = preferences.getString(MainActivity.signingPublicKey, null)
|
val publicKey = preferences.getString(MainActivity.publicKey, null)
|
||||||
val encryptionPrivateKey = preferences.getString(MainActivity.encryptionPrivateKey, null)
|
|
||||||
val encryptionPublicKey = preferences.getString(MainActivity.encryptionPublicKey, null)
|
|
||||||
|
|
||||||
config["SigningPrivateKey"] = signingPrivateKey
|
config["PrivateKey"] = privateKey
|
||||||
config["SigningPublicKey"] = signingPublicKey
|
config["PublicKey"] = publicKey
|
||||||
config["EncryptionPrivateKey"] = encryptionPrivateKey
|
|
||||||
config["EncryptionPublicKey"] = encryptionPublicKey
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(config["SessionFirewall"] as MutableMap<Any, Any>)["Enable"] = false
|
|
||||||
//(config["SessionFirewall"] as MutableMap<Any, Any>)["AllowFromDirect"] = true
|
//(config["SessionFirewall"] as MutableMap<Any, Any>)["AllowFromDirect"] = true
|
||||||
//(config["SessionFirewall"] as MutableMap<Any, Any>)["AllowFromRemote"] = true
|
//(config["SessionFirewall"] as MutableMap<Any, Any>)["AllowFromRemote"] = true
|
||||||
//(config["SessionFirewall"] as MutableMap<Any, Any>)["AlwaysAllowOutbound"] = true
|
//(config["SessionFirewall"] as MutableMap<Any, Any>)["AlwaysAllowOutbound"] = true
|
||||||
//(config["SessionFirewall"] as MutableMap<Any, Any>)["WhitelistEncryptionPublicKeys"] = whiteList
|
//(config["SessionFirewall"] as MutableMap<Any, Any>)["WhitelistEncryptionPublicKeys"] = whiteList
|
||||||
//(config["SessionFirewall"] as MutableMap<Any, Any>)["BlacklistEncryptionPublicKeys"] = blackList
|
//(config["SessionFirewall"] as MutableMap<Any, Any>)["BlacklistEncryptionPublicKeys"] = blackList
|
||||||
|
|
||||||
(config["SwitchOptions"] as MutableMap<Any, Any>)["MaxTotalQueueSize"] = 4194304
|
//(config["SwitchOptions"] as MutableMap<Any, Any>)["MaxTotalQueueSize"] = 4194304
|
||||||
if (config["AutoStart"] == null) {
|
if (config["AutoStart"] == null) {
|
||||||
val tmpMap = emptyMap<String, Boolean>().toMutableMap()
|
val tmpMap = emptyMap<String, Boolean>().toMutableMap()
|
||||||
tmpMap["WiFi"] = false
|
tmpMap["WiFi"] = false
|
||||||
@ -208,18 +196,18 @@ class YggdrasilTunService : VpnService() {
|
|||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun readPacketsFromTun(yggConduitEndpoint: ConduitEndpoint, buffer: ByteArray) {
|
private fun readPacketsFromTun(buffer: ByteArray) {
|
||||||
try {
|
try {
|
||||||
// Read the outgoing packet from the input stream.
|
// Read the outgoing packet from the input stream.
|
||||||
val length = tunInputStream.read(buffer)
|
val length = tunInputStream.read(buffer)
|
||||||
yggConduitEndpoint.send(buffer.sliceArray(IntRange(0, length - 1)))
|
ygg.send(buffer.sliceArray(IntRange(0, length - 1)))
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun writePacketsToTun(yggConduitEndpoint: ConduitEndpoint) {
|
private fun writePacketsToTun() {
|
||||||
val buffer = yggConduitEndpoint.recv()
|
val buffer = ygg.recv()
|
||||||
if(buffer!=null) {
|
if(buffer!=null) {
|
||||||
try {
|
try {
|
||||||
tunOutputStream.write(buffer)
|
tunOutputStream.write(buffer)
|
||||||
|
@ -4,23 +4,21 @@ import com.google.gson.annotations.SerializedName
|
|||||||
|
|
||||||
// FIXME This is old config scheme
|
// FIXME This is old config scheme
|
||||||
data class Config (
|
data class Config (
|
||||||
@SerializedName("peers") var peers : List<String>,
|
@SerializedName("peers") var peers : List<String>,
|
||||||
@SerializedName("interfacePeers") var interfacePeers : Map<String, List<String>>,
|
@SerializedName("interfacePeers") var interfacePeers : Map<String, List<String>>,
|
||||||
@SerializedName("listen") var listen : List<String>,
|
@SerializedName("listen") var listen : List<String>,
|
||||||
@SerializedName("adminListen") var adminListen : String,
|
@SerializedName("adminListen") var adminListen : String,
|
||||||
@SerializedName("multicastInterfaces") var multicastInterfaces : List<String>,
|
@SerializedName("multicastInterfaces") var multicastInterfaces : List<String>,
|
||||||
@SerializedName("allowedEncryptionPublicKeys") var allowedEncryptionPublicKeys : List<String>,
|
@SerializedName("allowedEncryptionPublicKeys") var allowedEncryptionPublicKeys : List<String>,
|
||||||
@SerializedName("encryptionPublicKey") var encryptionPublicKey : String,
|
@SerializedName("publicKey") var publicKey : String,
|
||||||
@SerializedName("encryptionPrivateKey") var encryptionPrivateKey : String,
|
@SerializedName("privateKey") var privateKey : String,
|
||||||
@SerializedName("signingPublicKey") var signingPublicKey : String,
|
@SerializedName("linkLocalTCPPort") var linkLocalTCPPort : Int,
|
||||||
@SerializedName("signingPrivateKey") var signingPrivateKey : String,
|
@SerializedName("ifName") var ifName : String,
|
||||||
@SerializedName("linkLocalTCPPort") var linkLocalTCPPort : Int,
|
@SerializedName("ifTAPMode") var ifTAPMode : Boolean,
|
||||||
@SerializedName("ifName") var ifName : String,
|
@SerializedName("ifMTU") var ifMTU : Long,
|
||||||
@SerializedName("ifTAPMode") var ifTAPMode : Boolean,
|
@SerializedName("sessionFirewall") var sessionFirewall : SessionFirewall,
|
||||||
@SerializedName("ifMTU") var ifMTU : Long,
|
@SerializedName("tunnelRouting") var tunnelRouting : TunnelRouting,
|
||||||
@SerializedName("sessionFirewall") var sessionFirewall : SessionFirewall,
|
@SerializedName("switchOptions") var switchOptions : SwitchOptions,
|
||||||
@SerializedName("tunnelRouting") var tunnelRouting : TunnelRouting,
|
@SerializedName("nodeInfoPrivacy") var nodeInfoPrivacy : Boolean,
|
||||||
@SerializedName("switchOptions") var switchOptions : SwitchOptions,
|
@SerializedName("nodeInfo") var nodeInfo : Map<String, Any>
|
||||||
@SerializedName("nodeInfoPrivacy") var nodeInfoPrivacy : Boolean,
|
|
||||||
@SerializedName("nodeInfo") var nodeInfo : Map<String, Any>
|
|
||||||
)
|
)
|
Loading…
Reference in New Issue
Block a user