mirror of
https://github.com/yggdrasil-network/yggdrasil-android.git
synced 2025-04-28 22:25:09 +03:00
Initial commit
This commit is contained in:
commit
20ff7378e9
52 changed files with 2155 additions and 0 deletions
|
@ -0,0 +1,53 @@
|
|||
package eu.neilalexander.yggdrasil
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import org.json.JSONArray
|
||||
|
||||
object PacketTunnelState: BroadcastReceiver() {
|
||||
var dhtState: JSONArray? = null
|
||||
private set
|
||||
|
||||
var peersState: JSONArray? = null
|
||||
private set
|
||||
|
||||
const val RECEIVER_INTENT = "eu.neilalexander.yggdrasil.PacketTunnelState.MESSAGE"
|
||||
|
||||
fun peerCount(): Int {
|
||||
if (peersState == null) {
|
||||
return 0
|
||||
}
|
||||
return peersState!!.length()
|
||||
}
|
||||
|
||||
fun dhtCount(): Int {
|
||||
if (dhtState == null) {
|
||||
return 0
|
||||
}
|
||||
return dhtState!!.length()
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context?, intent: Intent) {
|
||||
when (intent.getStringExtra("type")) {
|
||||
"state" -> {
|
||||
var dht = intent.getStringExtra("dht")
|
||||
var peers = intent.getStringExtra("peers")
|
||||
|
||||
if (dht == null || dht == "null") {
|
||||
dht = "[]"
|
||||
}
|
||||
if (peers == null || peers == "null") {
|
||||
peers = "[]"
|
||||
}
|
||||
|
||||
peersState = JSONArray(peers)
|
||||
dhtState = JSONArray(dht)
|
||||
|
||||
intent.action = RECEIVER_INTENT
|
||||
LocalBroadcastManager.getInstance(context!!).sendBroadcast(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue