mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2025-01-22 16:06:30 +00:00
1. added duplication peer records fix
This commit is contained in:
parent
572d487e35
commit
aec660bff0
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
@ -33,7 +33,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
const val PEERS: String = "PEERS"
|
const val PEERS: String = "PEERS"
|
||||||
const val PEER_LIST_CODE = 1000
|
const val PEER_LIST_CODE = 1000
|
||||||
const val PEER_LIST = "PEERS_LIST"
|
const val PEER_LIST = "PEERS_LIST"
|
||||||
const val CURRENT_PEERS = "CURRENT_PEER_INFO"
|
const val CURRENT_PEERS = "CURRENT_PEERS_v1.1"
|
||||||
const val START_VPN = "START_VPN"
|
const val START_VPN = "START_VPN"
|
||||||
private const val TAG="Yggdrasil"
|
private const val TAG="Yggdrasil"
|
||||||
private const val VPN_REQUEST_CODE = 0x0F
|
private const val VPN_REQUEST_CODE = 0x0F
|
||||||
@ -124,7 +124,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
super.onActivityResult(requestCode, resultCode, data)
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
if (requestCode == VPN_REQUEST_CODE && resultCode== Activity.RESULT_OK){
|
if (requestCode == VPN_REQUEST_CODE && resultCode== Activity.RESULT_OK){
|
||||||
if(currentPeers.size==0){
|
if(currentPeers.isEmpty()){
|
||||||
showToast("No peers selected!")
|
showToast("No peers selected!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
showToast("No peers selected!")
|
showToast("No peers selected!")
|
||||||
} else {
|
} else {
|
||||||
this.currentPeers = deserializeStringList2PeerInfoSet(currentPeers)
|
this.currentPeers = deserializeStringList2PeerInfoSet(currentPeers)
|
||||||
val adapter = PeerInfoListAdapter(this, ArrayList(this.currentPeers))
|
val adapter = PeerInfoListAdapter(this, this.currentPeers.sortedWith(compareBy { it.ping }))
|
||||||
val listView = findViewById<ListView>(R.id.peers)
|
val listView = findViewById<ListView>(R.id.peers)
|
||||||
listView.adapter = adapter
|
listView.adapter = adapter
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||||
preferences.edit().putStringSet(CURRENT_PEERS, HashSet(currentPeers)).apply()
|
preferences.edit().putStringSet(CURRENT_PEERS, HashSet(currentPeers)).apply()
|
||||||
if(isStarted){
|
if(isStarted){
|
||||||
//apply peer changes
|
//TODO implement UpdateConfig methon in native interface and apply peer changes
|
||||||
stopVpn()
|
stopVpn()
|
||||||
val i = baseContext.packageManager
|
val i = baseContext.packageManager
|
||||||
.getLaunchIntentForPackage(baseContext.packageName)
|
.getLaunchIntentForPackage(baseContext.packageName)
|
||||||
@ -161,7 +161,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
i.putExtra(START_VPN, true)
|
i.putExtra(START_VPN, true)
|
||||||
finish()
|
finish()
|
||||||
startActivity(i)
|
startActivity(i)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,7 +206,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showToast(text: String){
|
private fun showToast(text: String){
|
||||||
val duration = Toast.LENGTH_SHORT
|
val duration = Toast.LENGTH_SHORT
|
||||||
val toast = Toast.makeText(applicationContext, text, duration)
|
val toast = Toast.makeText(applicationContext, text, duration)
|
||||||
toast.setGravity(Gravity.CENTER, 0, 0)
|
toast.setGravity(Gravity.CENTER, 0, 0)
|
||||||
|
@ -73,13 +73,19 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
try {
|
try {
|
||||||
|
var cp = MainActivity.deserializeStringList2PeerInfoSet(
|
||||||
|
extras!!.getStringArrayList(MainActivity.PEER_LIST)!!
|
||||||
|
)
|
||||||
|
for(pi in cp){
|
||||||
|
var ping = ping(pi.address, pi.port)
|
||||||
|
pi.ping = ping
|
||||||
|
}
|
||||||
var json = downloadJson(PEER_LIST_URL)
|
var json = downloadJson(PEER_LIST_URL)
|
||||||
var countries = CCPCountry.getLibraryMasterCountriesEnglish()
|
var countries = CCPCountry.getLibraryMasterCountriesEnglish()
|
||||||
val mapType: Type = object :
|
val mapType: Type = object :
|
||||||
TypeToken<Map<String?, Map<String, Status>>>() {}.type
|
TypeToken<Map<String?, Map<String, Status>>>() {}.type
|
||||||
val peersMap: Map<String, Map<String, Status>> = Gson().fromJson(json, mapType)
|
val peersMap: Map<String, Map<String, Status>> = Gson().fromJson(json, mapType)
|
||||||
for ((country, peers) in peersMap.entries) {
|
for ((country, peers) in peersMap.entries) {
|
||||||
println("$country:")
|
|
||||||
for ((peer, status) in peers) {
|
for ((peer, status) in peers) {
|
||||||
if (status.up) {
|
if (status.up) {
|
||||||
for (ccp in countries) {
|
for (ccp in countries) {
|
||||||
@ -89,9 +95,12 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
var url = URI(peer)
|
var url = URI(peer)
|
||||||
try {
|
try {
|
||||||
var address = InetAddress.getByName(url.host)
|
var address = InetAddress.getByName(url.host)
|
||||||
var ping = ping(address, url.port)
|
|
||||||
var peerInfo =
|
var peerInfo =
|
||||||
PeerInfo(url.scheme, address, url.port, ccp.nameCode)
|
PeerInfo(url.scheme, address, url.port, ccp.nameCode)
|
||||||
|
if(cp.contains(peerInfo)){
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var ping = ping(address, url.port)
|
||||||
peerInfo.ping = ping
|
peerInfo.ping = ping
|
||||||
adapter.addItem(peerInfo)
|
adapter.addItem(peerInfo)
|
||||||
if(peerList.adapter.count % 5 == 0) {
|
if(peerList.adapter.count % 5 == 0) {
|
||||||
@ -107,15 +116,10 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (extras != null) {
|
|
||||||
var cp = MainActivity.deserializeStringList2PeerInfoSet(
|
|
||||||
extras.getStringArrayList(MainActivity.PEER_LIST)!!
|
|
||||||
)
|
|
||||||
var currentPeers = ArrayList(cp.sortedWith(compareBy { it.ping }))
|
var currentPeers = ArrayList(cp.sortedWith(compareBy { it.ping }))
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
adapter.addAll(0, currentPeers)
|
adapter.addAll(0, currentPeers)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (e: Throwable){
|
} catch (e: Throwable){
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
@ -134,7 +138,7 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
var adapter = findViewById<ListView>(R.id.peerList).adapter as SelectPeerInfoListAdapter
|
var adapter = findViewById<ListView>(R.id.peerList).adapter as SelectPeerInfoListAdapter
|
||||||
val selectedPeers = adapter.getSelectedPeers()
|
val selectedPeers = adapter.getSelectedPeers()
|
||||||
if(selectedPeers.size>0) {
|
if(selectedPeers.size>0) {
|
||||||
result.putExtra(MainActivity.PEER_LIST, MainActivity.serializePeerInfoSet2StringList(adapter.getSelectedPeers()))
|
result.putExtra(MainActivity.PEER_LIST, MainActivity.serializePeerInfoSet2StringList(selectedPeers))
|
||||||
setResult(Activity.RESULT_OK, result)
|
setResult(Activity.RESULT_OK, result)
|
||||||
finish()
|
finish()
|
||||||
} else {
|
} else {
|
||||||
|
@ -150,7 +150,13 @@ class YggdrasilTunService : VpnService() {
|
|||||||
private fun writePacketsToTun() {
|
private fun writePacketsToTun() {
|
||||||
if(tunOutputStream != null) {
|
if(tunOutputStream != null) {
|
||||||
val buffer = yggConduitEndpoint.recv()
|
val buffer = yggConduitEndpoint.recv()
|
||||||
|
if(buffer!=null) {
|
||||||
|
try {
|
||||||
tunOutputStream!!.write(buffer)
|
tunOutputStream!!.write(buffer)
|
||||||
|
}catch(e: IOException){
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,11 +168,10 @@ class YggdrasilTunService : VpnService() {
|
|||||||
tunOutputStream!!.close()
|
tunOutputStream!!.close()
|
||||||
tunInterface!!.close()
|
tunInterface!!.close()
|
||||||
tunInterface = null
|
tunInterface = null
|
||||||
//this hack due to https://github.com/yggdrasil-network/yggdrasil-go/issues/714 bug
|
|
||||||
ygg.startAutoconfigure()
|
|
||||||
ygg.stop()
|
ygg.stop()
|
||||||
val intent: Intent = Intent()
|
val intent: Intent = Intent()
|
||||||
pi.send(this, MainActivity.STATUS_STOP, intent)
|
pi.send(this, MainActivity.STATUS_STOP, intent)
|
||||||
|
stopSelf()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
@ -10,25 +10,27 @@ class PeerInfo {
|
|||||||
constructor(schema: String, address: InetAddress, port: Int, countryCode: String){
|
constructor(schema: String, address: InetAddress, port: Int, countryCode: String){
|
||||||
this.schema = schema
|
this.schema = schema
|
||||||
this.address = address
|
this.address = address
|
||||||
|
var a = address.toString();
|
||||||
|
if(a.lastIndexOf('/')>0){
|
||||||
|
this.hostName = a.split("/")[0]
|
||||||
|
} else {
|
||||||
|
this.hostName = a.substring(1)
|
||||||
|
}
|
||||||
this.port = port
|
this.port = port
|
||||||
this.countryCode = countryCode
|
this.countryCode = countryCode
|
||||||
}
|
}
|
||||||
var schema: String
|
var schema: String
|
||||||
var address: InetAddress
|
var address: InetAddress
|
||||||
|
var hostName: String
|
||||||
var port = 0
|
var port = 0
|
||||||
var countryCode: String
|
var countryCode: String
|
||||||
var ping: Int = Int.MAX_VALUE
|
var ping: Int = Int.MAX_VALUE
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
var a = address.toString();
|
if(this.hostName.contains(":")) {
|
||||||
if(a.indexOf("/")>0){
|
return this.schema + "://[" + this.hostName + "]:" + port
|
||||||
return this.schema+"://"+a.split("/")[0]+":"+port
|
|
||||||
} else {
|
} else {
|
||||||
if(a.contains(":")) {
|
return this.schema + "://" + this.hostName + ":" + port
|
||||||
return this.schema + "://[" + a.substring(1) + "]:" + port
|
|
||||||
} else {
|
|
||||||
return this.schema + ":/" + a + ":" + port
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/peerLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="20dp"
|
android:layout_margin="20dp"
|
||||||
@ -93,4 +94,52 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="20dp"
|
||||||
|
android:background="@drawable/info_panel_rounded_corner"
|
||||||
|
android:gravity="left"
|
||||||
|
android:paddingLeft="20dp"
|
||||||
|
android:orientation="vertical"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/peerLayout">
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/dnsLabel"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:elevation="8dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:text="DNS:"
|
||||||
|
android:textColor="@color/dark_30"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
<Button
|
||||||
|
android:id="@+id/editDNS"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:text="EDIT"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
android:background="@android:color/transparent"/>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/dnsList"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:dividerHeight="0dp"
|
||||||
|
android:divider="@null"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user