mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2024-11-09 12:01:01 +00:00
1. PeerInfo optimization.
2. InetAddress deserialization error fix
This commit is contained in:
parent
2689fee039
commit
e7497c50a9
@ -59,11 +59,11 @@ class DNSListActivity : AppCompatActivity() {
|
||||
try {
|
||||
|
||||
for (d in cd) {
|
||||
var ping = ping(d.address, 53)
|
||||
var ping = ping(d.address.hostAddress, 53)
|
||||
d.ping = ping
|
||||
}
|
||||
for (dns in allDNS) {
|
||||
var ping = ping(dns.address, 53)
|
||||
var ping = ping(dns.address.hostAddress, 53)
|
||||
dns.ping = ping
|
||||
runOnUiThread(
|
||||
Runnable
|
||||
@ -110,7 +110,7 @@ class DNSListActivity : AppCompatActivity() {
|
||||
thread(start = true) {
|
||||
var di = DNSInfo(InetAddress.getByName("["+ip+"]"), ccp, "User DNS")
|
||||
try {
|
||||
var ping = ping(di.address, 53)
|
||||
var ping = ping(di.address.hostAddress, 53)
|
||||
di.ping = ping
|
||||
} catch(e: Throwable){
|
||||
di.ping = Int.MAX_VALUE
|
||||
|
@ -99,14 +99,14 @@ class PeerListActivity : AppCompatActivity() {
|
||||
extras!!.getStringArrayList(MainActivity.PEER_LIST)!!
|
||||
)
|
||||
for (pi in cp) {
|
||||
var ping = ping(pi.address, pi.port)
|
||||
var ping = ping(pi.hostName, pi.port)
|
||||
pi.ping = ping
|
||||
}
|
||||
try {
|
||||
var peerInfoCache = peerInfoListCache.get(ONLINE_PEERINFO_LIST)
|
||||
if (peerInfoCache != null && peerInfoCache.isNotEmpty()) {
|
||||
for (peerInfo in peerInfoCache) {
|
||||
var ping = ping(peerInfo.address, peerInfo.port)
|
||||
var ping = ping(peerInfo.hostName, peerInfo.port)
|
||||
peerInfo.ping = ping
|
||||
if (cp.contains(peerInfo)) {
|
||||
continue
|
||||
@ -145,7 +145,7 @@ class PeerListActivity : AppCompatActivity() {
|
||||
url.port,
|
||||
ccp.nameCode
|
||||
)
|
||||
var ping = ping(address, url.port)
|
||||
var ping = ping(url.host, url.port)
|
||||
peerInfo.ping = ping
|
||||
if (cp.contains(peerInfo)) {
|
||||
continue
|
||||
@ -179,7 +179,7 @@ class PeerListActivity : AppCompatActivity() {
|
||||
var onlinePeerInfoList = peerInfoListCache.get(ONLINE_PEERINFO_LIST)
|
||||
if (onlinePeerInfoList != null) {
|
||||
for (peerInfo in onlinePeerInfoList) {
|
||||
var ping = ping(peerInfo.address, peerInfo.port)
|
||||
var ping = ping(peerInfo.hostName, peerInfo.port)
|
||||
peerInfo.ping = ping
|
||||
if (cp.contains(peerInfo)) {
|
||||
continue
|
||||
@ -283,7 +283,7 @@ class PeerListActivity : AppCompatActivity() {
|
||||
GlobalScope.launch {
|
||||
var pi = PeerInfo(schema, InetAddress.getByName(ip), port, ccp)
|
||||
try {
|
||||
var ping = ping(pi.address, pi.port)
|
||||
var ping = ping(pi.hostName, pi.port)
|
||||
pi.ping = ping
|
||||
} catch (e: Throwable){
|
||||
pi.ping = Int.MAX_VALUE
|
||||
@ -375,9 +375,6 @@ class SizeOfPeerList: SizeOf<List<PeerInfo>> {
|
||||
override fun sizeOf(obj: List<PeerInfo>): Int{
|
||||
var size = 0
|
||||
for (o in obj) {
|
||||
if (o.address != null) {
|
||||
size += o.address.toString().length * 2
|
||||
}
|
||||
if (o.hostName != null) {
|
||||
size += o.hostName.length * 2
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ class PeerInfo {
|
||||
|
||||
constructor(schema: String, address: InetAddress, port: Int, countryCode: String){
|
||||
this.schema = schema
|
||||
this.address = address
|
||||
var a = address.toString();
|
||||
if(a.lastIndexOf('/')>0){
|
||||
this.hostName = a.split("/")[0]
|
||||
@ -27,7 +26,6 @@ class PeerInfo {
|
||||
|
||||
constructor(schema: String, address: InetAddress, port: Int, countryCode: String?, isMeshPeer: Boolean){
|
||||
this.schema = schema
|
||||
this.address = address
|
||||
var a = address.toString();
|
||||
if(a.lastIndexOf('/')>0){
|
||||
this.hostName = a.split("/")[0]
|
||||
@ -40,7 +38,6 @@ class PeerInfo {
|
||||
}
|
||||
|
||||
lateinit var schema: String
|
||||
lateinit var address: InetAddress
|
||||
lateinit var hostName: String
|
||||
var port = 0
|
||||
var countryCode: String?=null
|
||||
|
@ -77,15 +77,15 @@ class Utils {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun ping(address: InetAddress, port:Int): Int {
|
||||
fun ping(hostname: String, port:Int): Int {
|
||||
val start = System.currentTimeMillis()
|
||||
val socket = Socket()
|
||||
try {
|
||||
socket.connect(InetSocketAddress(address, port), 5000)
|
||||
socket.connect(InetSocketAddress(hostname, port), 5000)
|
||||
socket.close()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
print(address)
|
||||
print(hostname)
|
||||
return Int.MAX_VALUE
|
||||
}
|
||||
return (System.currentTimeMillis() - start).toInt()
|
||||
|
Loading…
Reference in New Issue
Block a user