forked from Qortal/qortal
Recheck for duplicate connection after handshaking to cover race condition with simultaneous bi-directional connections
This commit is contained in:
parent
0c32afa07f
commit
3afbd7aa51
@ -780,6 +780,15 @@ public class Network {
|
||||
private void onHandshakeCompleted(Peer peer) {
|
||||
LOGGER.debug(String.format("Handshake completed with peer %s", peer));
|
||||
|
||||
// Are we already connected to this peer?
|
||||
Peer existingPeer = getHandshakedPeerWithPublicKey(peer.getPeersPublicKey());
|
||||
// NOTE: actual object reference compare, not Peer.equals()
|
||||
if (existingPeer != peer) {
|
||||
LOGGER.info(() -> String.format("We already have a connection with peer %s - discarding", peer));
|
||||
peer.disconnect("existing connection");
|
||||
return;
|
||||
}
|
||||
|
||||
// Make a note that we've successfully completed handshake (and when)
|
||||
peer.getPeerData().setLastConnected(NTP.getTime());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user