Skip to content

Commit

Permalink
Not found command (#1645)
Browse files Browse the repository at this point in the history
* Not found command

* Remove unused method

Co-authored-by: Vitor Nazário Coelho <[email protected]>
  • Loading branch information
shargon and vncoelho authored May 15, 2020
1 parent 4ead80c commit b90aedf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/neo/Network/P2P/MessageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum MessageCommand : byte
GetData = 0x28,
[ReflectionCache(typeof(GetBlockDataPayload))]
GetBlockData = 0x29,
[ReflectionCache(typeof(InvPayload))]
NotFound = 0x2a,
[ReflectionCache(typeof(Transaction))]
Transaction = 0x2b,
Expand Down
16 changes: 14 additions & 2 deletions src/neo/Network/P2P/RemoteNode.ProtocolHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,17 @@ private void OnGetBlockDataMessageReceived(GetBlockDataPayload payload)
/// <param name="payload">The payload containing the requested information.</param>
private void OnGetDataMessageReceived(InvPayload payload)
{
UInt256[] hashes = payload.Hashes.Where(p => sentHashes.Add(p)).ToArray();
foreach (UInt256 hash in hashes)
var notFound = new List<UInt256>();
foreach (UInt256 hash in payload.Hashes.Where(p => sentHashes.Add(p)))
{
switch (payload.Type)
{
case InventoryType.TX:
Transaction tx = Blockchain.Singleton.GetTransaction(hash);
if (tx != null)
EnqueueMessage(Message.Create(MessageCommand.Transaction, tx));
else
notFound.Add(hash);
break;
case InventoryType.Block:
Block block = Blockchain.Singleton.GetBlock(hash);
Expand All @@ -241,13 +243,23 @@ private void OnGetDataMessageReceived(InvPayload payload)
EnqueueMessage(Message.Create(MessageCommand.MerkleBlock, MerkleBlockPayload.Create(block, flags)));
}
}
else
{
notFound.Add(hash);
}
break;
case InventoryType.Consensus:
if (Blockchain.Singleton.ConsensusRelayCache.TryGet(hash, out IInventory inventoryConsensus))
EnqueueMessage(Message.Create(MessageCommand.Consensus, inventoryConsensus));
break;
}
}

if (notFound.Count > 0)
{
foreach (InvPayload entry in InvPayload.CreateGroup(payload.Type, notFound.ToArray()))
EnqueueMessage(Message.Create(MessageCommand.NotFound, entry));
}
}

/// <summary>
Expand Down

0 comments on commit b90aedf

Please sign in to comment.