send an uuid with pings and echo it in pongs

This commit is contained in:
Zlatin Balevsky
2020-09-17 16:11:32 +01:00
parent ac8d9c1281
commit 20aac03789
2 changed files with 5 additions and 2 deletions

View File

@ -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)
}

View File

@ -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 :