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