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