mirror of https://github.com/zlatinb/muwire
make sure the pongs uuid matches the last sent ping uuid
parent
e5891de136
commit
5a38154e15
|
@ -49,6 +49,8 @@ abstract class Connection implements Closeable {
|
||||||
protected final String name
|
protected final String name
|
||||||
|
|
||||||
long lastPingSentTime, lastPongReceivedTime
|
long lastPingSentTime, lastPongReceivedTime
|
||||||
|
|
||||||
|
private volatile UUID lastPingUUID
|
||||||
|
|
||||||
Connection(EventBus eventBus, Endpoint endpoint, boolean incoming,
|
Connection(EventBus eventBus, Endpoint endpoint, boolean incoming,
|
||||||
HostCache hostCache, TrustService trustService, MuWireSettings settings) {
|
HostCache hostCache, TrustService trustService, MuWireSettings settings) {
|
||||||
|
@ -132,7 +134,8 @@ 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()
|
lastPingUUID = UUID.randomUUID()
|
||||||
|
ping.uuid = lastPingUUID.toString()
|
||||||
messages.put(ping)
|
messages.put(ping)
|
||||||
lastPingSentTime = System.currentTimeMillis()
|
lastPingSentTime = System.currentTimeMillis()
|
||||||
}
|
}
|
||||||
|
@ -177,6 +180,22 @@ abstract class Connection implements Closeable {
|
||||||
lastPongReceivedTime = System.currentTimeMillis()
|
lastPongReceivedTime = System.currentTimeMillis()
|
||||||
if (pong.pongs == null)
|
if (pong.pongs == null)
|
||||||
throw new Exception("Pong doesn't have pongs")
|
throw new Exception("Pong doesn't have pongs")
|
||||||
|
|
||||||
|
if (lastPingUUID == null) {
|
||||||
|
log.fine "$name received an unexpected pong"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (pong.uuid == null) {
|
||||||
|
log.fine "$name pong doesn't have uuid"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
UUID pongUUID = UUID.fromString(pong.uuid)
|
||||||
|
if (pongUUID != lastPingUUID) {
|
||||||
|
log.fine "$name ping/pong uuid mismatch"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
lastPingUUID = null
|
||||||
|
|
||||||
pong.pongs.stream().limit(2).forEach {
|
pong.pongs.stream().limit(2).forEach {
|
||||||
def dest = new Destination(it)
|
def dest = new Destination(it)
|
||||||
eventBus.publish(new HostDiscoveredEvent(destination: dest))
|
eventBus.publish(new HostDiscoveredEvent(destination: dest))
|
||||||
|
|
Loading…
Reference in New Issue