mirror of https://github.com/zlatinb/muwire
send an uuid with pings and echo it in pongs
parent
ac8d9c1281
commit
20aac03789
|
@ -132,6 +132,7 @@ abstract class Connection implements Closeable {
|
||||||
def ping = [:]
|
def ping = [:]
|
||||||
ping.type = "Ping"
|
ping.type = "Ping"
|
||||||
ping.version = 1
|
ping.version = 1
|
||||||
|
ping.uuid = UUID.randomUUID().toString()
|
||||||
messages.put(ping)
|
messages.put(ping)
|
||||||
lastPingSentTime = System.currentTimeMillis()
|
lastPingSentTime = System.currentTimeMillis()
|
||||||
}
|
}
|
||||||
|
@ -160,11 +161,13 @@ abstract class Connection implements Closeable {
|
||||||
messages.put(query)
|
messages.put(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handlePing() {
|
protected void handlePing(def ping) {
|
||||||
log.fine("$name received ping")
|
log.fine("$name received ping")
|
||||||
def pong = [:]
|
def pong = [:]
|
||||||
pong.type = "Pong"
|
pong.type = "Pong"
|
||||||
pong.version = 1
|
pong.version = 1
|
||||||
|
if (ping.uuid != null)
|
||||||
|
pong.uuid = ping.uuid
|
||||||
pong.pongs = hostCache.getGoodHosts(10).collect { d -> d.toBase64() }
|
pong.pongs = hostCache.getGoodHosts(10).collect { d -> d.toBase64() }
|
||||||
messages.put(pong)
|
messages.put(pong)
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ class PeerConnection extends Connection {
|
||||||
if (json.type == null)
|
if (json.type == null)
|
||||||
throw new Exception("missing json type")
|
throw new Exception("missing json type")
|
||||||
switch(json.type) {
|
switch(json.type) {
|
||||||
case "Ping" : handlePing(); break;
|
case "Ping" : handlePing(json); break;
|
||||||
case "Pong" : handlePong(json); break;
|
case "Pong" : handlePong(json); break;
|
||||||
case "Search": handleSearch(json); break
|
case "Search": handleSearch(json); break
|
||||||
default :
|
default :
|
||||||
|
|
Loading…
Reference in New Issue