neo
neo copied to clipboard
Restore UnconnectedPeers if OnTcpCommandFailed
It looks like that when a node attempts to connect to a new peer, it moves the peer's endpoint from the UnconnectedPeers set to the ConnectingPeers set.
If this TCP connection fails, the OnTcpCommandFailed method correctly removes the endpoint from ConnectingPeers. However, the endpoint is not returned to the UnconnectedPeers set.
https://github.com/neo-project/neo/blob/9b9be47357e9065de524005755212ed54c3f6a11/src/Neo/Network/P2P/Peer.cs#L277
So, maybe change to
switch (cmd)
{
case Tcp.Connect connect:
var endpoint = ((IPEndPoint)connect.RemoteAddress).UnMap();
ImmutableInterlocked.Update(ref ConnectingPeers, p => p.Remove(endpoint));
// Add the failed endpoint back to the pool of unconnected peers to prevent peer-draining attacks.
// A simple re-add is shown here. A more advanced implementation would use a timed backoff.
ImmutableInterlocked.Update(ref UnconnectedPeers, p => p.Add(endpoint));
break;
}
}
Can you verify that assumption, if that proceed I will apply the change and test here?
I will check it