-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ETCM-178] Disallow duplicated connections and connections to self #763
Conversation
d60cd85
to
9422464
Compare
9422464
to
ef84bec
Compare
nodesInfo.map { nodeInfo => nodeInfo.node.id -> nodeInfo }.toMap | ||
val startingNodesInfo = knownNodesURIs.map(uri => DiscoveryNodeInfo.fromUri(uri)) ++ bootStrapNodesInfo | ||
val startingNodesInfoWithoutSelf = startingNodesInfo.filterNot { | ||
_.node.id == ByteString(nodeStatusHolder.get().nodeId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we filter self
every time manager responds to GetDiscoveredNodesInfo
message ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This depends on what discovery guarantees, given we are in the process of integrating our new discovery implementation I didn't want to get in the middle
(for example on the other project it does guarantee that it won't yourself as a discovered peer)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats a valid point. We can always fix it after integration with new discovery.
However, with checking the node id of only handshaked peers we prioritize handshaked peers over pending ones, | ||
in the above mentioned case the repeated pending peer connection will eventually die out | ||
*/ | ||
def hasHandshakedWith(nodeId: ByteString): Boolean = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we have lazy val
with all handshaked peer id to avoid this traversing every time ?
private lazy val allPeers: Map[PeerId, Peer] = outgoingPendingPeers ++ handshakedPeers ++ incomingPendingPeers | ||
|
||
def isConnectionHandled(remoteAddress: InetSocketAddress): Boolean = | ||
allPeers.values.map(_.remoteAddress).toSet.contains(remoteAddress) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we have lazy val with all connected peers adresses to avoid this traversing every time ?
): Unit = { | ||
val connectionHandled = isConnectionHandled(remoteAddress, pendingPeers, peers) | ||
val isPendingPeersNotMaxValue = pendingPeers.size < peerConfiguration.maxPendingPeers | ||
val alreadyConnectedToPeer = connectedPeers.isConnectionHandled(remoteAddress) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder, sholdn't we check this only based only on InetAddress
(not InetSocketAddress
) , as every incoming connection can have different ephemeral port, so the same peer can create several outgoing connections to us from different ports. I remember in other project, I did it as temporarly solution before migrating to indentifing peers here by their NodeIds
.
It can have downside, that if there are two peers in the same subnet, we will allow only one of them, but if we will improve it later to identifing peers by node ids, then it can be good temporary solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so the same peer can create several outgoing connections to us from different ports
The only consequence from this is that those peers will be detected as repeated only after the handshake, right? Because at least as I was able to test out that might only happen initially, eventually those repeated connections will die our and no new ones will be started
If we had planned to continue improving on this I'd agree with your proposal, but as I'm not sure for how long we'll have to keep that temporary solution I prefer keeping it as is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, then maybe leave a comment about it here ?
…-178-remove-repeated-connections
nodesInfo.map { nodeInfo => nodeInfo.node.id -> nodeInfo }.toMap | ||
val startingNodesInfo = knownNodesURIs.map(uri => DiscoveryNodeInfo.fromUri(uri)) ++ bootStrapNodesInfo | ||
val startingNodesInfoWithoutSelf = startingNodesInfo.filterNot { | ||
_.node.id == ByteString(nodeStatusHolder.get().nodeId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats a valid point. We can always fix it after integration with new discovery.
): Unit = { | ||
val connectionHandled = isConnectionHandled(remoteAddress, pendingPeers, peers) | ||
val isPendingPeersNotMaxValue = pendingPeers.size < peerConfiguration.maxPendingPeers | ||
val alreadyConnectedToPeer = connectedPeers.isConnectionHandled(remoteAddress) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, then maybe leave a comment about it here ?
@@ -80,7 +80,7 @@ class DebugServiceSpec | |||
bestBlockHash = peerStatus.bestHash | |||
) | |||
val peer1Probe = TestProbe() | |||
val peer1 = Peer(new InetSocketAddress("127.0.0.1", 1), peer1Probe.ref, incomingConnection = false) | |||
val peer1 = Peer(new InetSocketAddress("127.0.0.1", 1), peer1Probe.ref, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:(
@@ -231,12 +288,15 @@ class PeerManagerSpec extends AnyFlatSpec with Matchers with Eventually with Nor | |||
) | |||
)(system) | |||
|
|||
def startConnecting(): Unit = { | |||
def start(): Unit = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:(
Description
Proposed Solution
Scenarios addressed
Connection to self
Duplicated connections
Testing
Note that the connection node 1 to node 2 will take a while to be closed, at it will do so only after re-attempting and succeeding the handshake
Pending