A handshake can be enhanced via adding a new PeerFeature, see LocalAddressPeerFeature. Do a new feature with id = 3 which contains network magic bytes (from settings) and a session ID. The session ID should be generated when the node started, 64 random bits (8 bytes) enough. If session ID is not received from other peer, then it equals to 0.
Then the following code needs to be rewritten, isSelf should be based on session Id, not address.
//drop connection to self if occurred or peer already connected
val shouldDrop = isSelf(remoteAddress) ||
connectionForPeerAddress(peerAddress).exists(_.handlerRef != peerHandlerRef)
if (shouldDrop) {
connectedPeer.handlerRef ! CloseConnection
peerManagerRef ! RemovePeer(peerAddress)
connections -= connectedPeer.connectionId.remoteAddress
} else {
peerManagerRef ! AddOrUpdatePeer(peerInfo)
Also, connection should be dropped if handshake is coming from another network (different magic)
Also for the code above, if peer already connected, "
peerManagerRef ! RemovePeer(peerAddress)
connections -= connectedPeer.connectionId.remoteAddress" is not needed (it is needed for self only)
A handshake can be enhanced via adding a new PeerFeature, see LocalAddressPeerFeature. Do a new feature with id = 3 which contains network magic bytes (from settings) and a session ID. The session ID should be generated when the node started, 64 random bits (8 bytes) enough. If session ID is not received from other peer, then it equals to 0.
Then the following code needs to be rewritten, isSelf should be based on session Id, not address.
//drop connection to self if occurred or peer already connected val shouldDrop = isSelf(remoteAddress) || connectionForPeerAddress(peerAddress).exists(_.handlerRef != peerHandlerRef) if (shouldDrop) { connectedPeer.handlerRef ! CloseConnection peerManagerRef ! RemovePeer(peerAddress) connections -= connectedPeer.connectionId.remoteAddress } else { peerManagerRef ! AddOrUpdatePeer(peerInfo)
Also, connection should be dropped if handshake is coming from another network (different magic)
Also for the code above, if peer already connected, " peerManagerRef ! RemovePeer(peerAddress) connections -= connectedPeer.connectionId.remoteAddress" is not needed (it is needed for self only)