send an uuid with pings and echo it in pongs

pull/53/head
Zlatin Balevsky 2020-09-17 16:11:32 +01:00
parent ac8d9c1281
commit 20aac03789
No known key found for this signature in database
GPG Key ID: A72832072D525E41
2 changed files with 5 additions and 2 deletions

View File

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

View File

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