Skip to content

Commit

Permalink
Drop Addr messages if we didn't send GetAddr (#2097)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang committed Nov 25, 2020
1 parent 0c24322 commit 0880ed7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/neo/Network/P2P/RemoteNode.ProtocolHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ private void OnMessage(Message msg)

private void OnAddrMessageReceived(AddrPayload payload)
{
ref bool sent = ref sentCommands[(byte)MessageCommand.GetAddr];
if (!sent) return;
sent = false;
system.LocalNode.Tell(new Peer.Peers
{
EndPoints = payload.AddressList.Select(p => p.EndPoint).Where(p => p.Port > 0)
Expand Down
2 changes: 2 additions & 0 deletions src/neo/Network/P2P/RemoteNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal class Relay { public IInventory Inventory; }
private readonly NeoSystem system;
private readonly Queue<Message> message_queue_high = new Queue<Message>();
private readonly Queue<Message> message_queue_low = new Queue<Message>();
private readonly bool[] sentCommands = new bool[1 << sizeof(MessageCommand)];
private ByteString msg_buffer = ByteString.Empty;
private bool ack = true;

Expand Down Expand Up @@ -197,6 +198,7 @@ private void SendMessage(Message message)
{
ack = false;
SendData(ByteString.FromBytes(message.ToArray()));
sentCommands[(byte)message.Command] = true;
}

private Message TryParseMessage()
Expand Down

0 comments on commit 0880ed7

Please sign in to comment.