mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2025-01-22 16:06:30 +00:00
1. added correct exception handling
This commit is contained in:
parent
2a5c6b66e2
commit
68b294df14
@ -97,11 +97,12 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
fun ping(address: InetAddress, port:Int): Int {
|
fun ping(address: InetAddress, port:Int): Int {
|
||||||
val start = System.currentTimeMillis()
|
val start = System.currentTimeMillis()
|
||||||
try {
|
|
||||||
val socket = Socket()
|
val socket = Socket()
|
||||||
|
try {
|
||||||
socket.connect(InetSocketAddress(address, port), 5000)
|
socket.connect(InetSocketAddress(address, port), 5000)
|
||||||
socket.close()
|
socket.close()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
//silently pass
|
||||||
return Int.MAX_VALUE
|
return Int.MAX_VALUE
|
||||||
}
|
}
|
||||||
return (System.currentTimeMillis() - start).toInt()
|
return (System.currentTimeMillis() - start).toInt()
|
||||||
@ -119,6 +120,7 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
var peerList = findViewById<ListView>(R.id.peerList)
|
var peerList = findViewById<ListView>(R.id.peerList)
|
||||||
var instance = this
|
var instance = this
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
|
try {
|
||||||
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 :
|
||||||
@ -130,13 +132,20 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
for ((peer, status) in peers) {
|
for ((peer, status) in peers) {
|
||||||
if (status.up) {
|
if (status.up) {
|
||||||
for (ccp in countries) {
|
for (ccp in countries) {
|
||||||
if(ccp.name.toLowerCase().contains(country.replace(".md","").replace("-", " "))){
|
if (ccp.name.toLowerCase()
|
||||||
|
.contains(country.replace(".md", "").replace("-", " "))
|
||||||
|
) {
|
||||||
var url = URI(peer)
|
var url = URI(peer)
|
||||||
|
try {
|
||||||
var address = InetAddress.getByName(url.host)
|
var address = InetAddress.getByName(url.host)
|
||||||
var ping = ping(address, url.port)
|
var ping = ping(address, url.port)
|
||||||
var peerInfo = PeerInfo(url.scheme, address, url.port, ccp.nameCode)
|
var peerInfo =
|
||||||
|
PeerInfo(url.scheme, address, url.port, ccp.nameCode)
|
||||||
peerInfo.ping = ping
|
peerInfo.ping = ping
|
||||||
allOnlinePeers.add(peerInfo)
|
allOnlinePeers.add(peerInfo)
|
||||||
|
} catch (e: Throwable){
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,7 +156,9 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (extras != null) {
|
if (extras != null) {
|
||||||
var cp = MainActivity.deserializeStringList2PeerInfoList(extras.getStringArrayList(MainActivity.PEER_LIST)!!)
|
var cp = MainActivity.deserializeStringList2PeerInfoList(
|
||||||
|
extras.getStringArrayList(MainActivity.PEER_LIST)!!
|
||||||
|
)
|
||||||
var currentPeers = ArrayList(cp)
|
var currentPeers = ArrayList(cp)
|
||||||
for (peerInfo in allPeers) {
|
for (peerInfo in allPeers) {
|
||||||
if (currentPeers.contains(peerInfo)) {
|
if (currentPeers.contains(peerInfo)) {
|
||||||
@ -167,6 +178,9 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
peerList.adapter = adapter
|
peerList.adapter = adapter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e: Throwable){
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user