Browse Source

Recheck for duplicate connection after handshaking to cover race condition with simultaneous bi-directional connections

pull/67/head
catbref 4 years ago
parent
commit
3afbd7aa51
  1. 9
      src/main/java/org/qortal/network/Network.java

9
src/main/java/org/qortal/network/Network.java

@ -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…
Cancel
Save