Skip to content

Commit

Permalink
Fix p2p filter unconnected peers (neo-project#1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luchuan authored and Tommo-L committed Jun 22, 2020
1 parent 09cb4fa commit dfe21c1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion neo/Network/P2P/LocalNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal class RelayDirectly { public IInventory Inventory; }
internal class SendDirectly { public IInventory Inventory; }

public const uint ProtocolVersion = 0;
private const int MaxCountFromSeedList = 5;

private static readonly object lockObj = new object();
private readonly NeoSystem system;
Expand Down Expand Up @@ -123,7 +124,7 @@ public IEnumerable<IPEndPoint> GetUnconnectedPeers()

protected override void NeedMorePeers(int count)
{
count = Math.Max(count, 5);
count = Math.Max(count, MaxCountFromSeedList);
if (ConnectedPeers.Count > 0)
{
BroadcastMessage(MessageCommand.GetAddr);
Expand Down
2 changes: 1 addition & 1 deletion neo/Network/P2P/Peer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected void AddPeers(IEnumerable<IPEndPoint> peers)
{
if (UnconnectedPeers.Count < UnconnectedMax)
{
peers = peers.Where(p => p.Port != ListenerTcpPort || !localAddresses.Contains(p.Address));
peers = peers.Where(p => (p.Port != ListenerTcpPort || !localAddresses.Contains(p.Address)) && !ConnectedPeers.Values.Contains(p));
ImmutableInterlocked.Update(ref UnconnectedPeers, p => p.Union(peers));
}
}
Expand Down

0 comments on commit dfe21c1

Please sign in to comment.