Skip to content

Commit

Permalink
Add relay-block-filter (neo-project#1380)
Browse files Browse the repository at this point in the history
* add relay-block-filter

* modify

* modify

* modify

* modify

Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
  • Loading branch information
2 people authored and Tommo-L committed Jun 22, 2020
1 parent 830c4a5 commit dba911b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/neo/Network/P2P/LocalNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected override void NeedMorePeers(int count)
else
{
// Will call AddPeers with default SeedList set cached on <see cref="ProtocolSettings"/>.
// It will try to add those, sequentially, to the list of currently uncconected ones.
// It will try to add those, sequentially, to the list of currently unconnected ones.

Random rand = new Random();
AddPeers(SeedList.Where(u => u != null).OrderBy(p => rand.Next()).Take(count));
Expand Down Expand Up @@ -197,7 +197,22 @@ private void OnRelay(IInventory inventory)
system.Blockchain.Tell(inventory);
}

private void OnRelayDirectly(IInventory inventory) => SendToRemoteNodes(new RemoteNode.Relay { Inventory = inventory });
private void OnRelayDirectly(IInventory inventory)
{
var message = new RemoteNode.Relay { Inventory = inventory };
// When relaying a block, if the block's index is greater than 'LastBlockIndex' of the RemoteNode, relay the block;
// otherwise, don't relay.
if (inventory is Block block)
{
foreach (KeyValuePair<IActorRef, RemoteNode> kvp in RemoteNodes)
{
if (block.Index > kvp.Value.LastBlockIndex)
kvp.Key.Tell(message);
}
}
else
SendToRemoteNodes(message);
}

private void OnSendDirectly(IInventory inventory) => SendToRemoteNodes(inventory);

Expand Down

0 comments on commit dba911b

Please sign in to comment.