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