2. getPeers parsing fixes

This commit is contained in:
vadym 2020-07-01 02:56:30 -07:00
parent bca4b88d3d
commit 010051da50
2 changed files with 9 additions and 5 deletions

View File

@ -269,7 +269,7 @@ class MainActivity : AppCompatActivity() {
thread(start = true) { thread(start = true) {
while(true) { while(true) {
Thread.sleep(5000) Thread.sleep(5000)
if(isStarted) { if(isStarted && this.currentPeers.isEmpty()) {
updatePeers() updatePeers()
} }
} }
@ -297,7 +297,7 @@ class MainActivity : AppCompatActivity() {
val listView = findViewById<ListView>(R.id.peers) val listView = findViewById<ListView>(R.id.peers)
val adapter = PeerInfoListAdapter( val adapter = PeerInfoListAdapter(
this@MainActivity, this@MainActivity,
meshPeers.sortedWith(compareBy { it.ping }) meshPeers.filter { it.schema!="self" }.sortedWith(compareBy { it.ping })
) )
runOnUiThread { runOnUiThread {
listView.adapter = adapter listView.adapter = adapter

View File

@ -6,6 +6,7 @@ import io.github.chronosx88.yggdrasil.models.PeerInfo
import java.net.InetAddress import java.net.InetAddress
import java.net.InetSocketAddress import java.net.InetSocketAddress
import java.net.Socket import java.net.Socket
import java.net.URI
class Utils { class Utils {
@ -119,11 +120,14 @@ class Utils {
if(p.endpoint == "(self)"){ if(p.endpoint == "(self)"){
out.add(PeerInfo(p.protocol, InetAddress.getByName("localhost"), p.port, null, true)) out.add(PeerInfo(p.protocol, InetAddress.getByName("localhost"), p.port, null, true))
} else { } else {
var fixWlanPart = p.endpoint.substring(p.endpoint.indexOf('%'), p.endpoint.indexOf(']'))
var fixedUrlString = p.endpoint.replace(fixWlanPart, "")
var url = URI(fixedUrlString)
out.add( out.add(
PeerInfo( PeerInfo(
p.protocol, url.scheme,
InetAddress.getByName(p.endpoint), InetAddress.getByName(url.host),
p.port, url.port,
null, null,
true true
) )