From a2199626242da2113b1f4f75610bede17176742a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Fri, 18 Oct 2019 03:39:04 -0300 Subject: [PATCH 01/25] Adding random hashes for OnGetDataMessageReceived --- neo/Network/P2P/ProtocolHandler.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neo/Network/P2P/ProtocolHandler.cs b/neo/Network/P2P/ProtocolHandler.cs index aa7f0e06f2..59ddbc424b 100644 --- a/neo/Network/P2P/ProtocolHandler.cs +++ b/neo/Network/P2P/ProtocolHandler.cs @@ -178,7 +178,8 @@ private void OnGetBlocksMessageReceived(GetBlocksPayload payload) private void OnGetDataMessageReceived(InvPayload payload) { UInt256[] hashes = payload.Hashes.Where(p => sentHashes.Add(p)).ToArray(); - foreach (UInt256 hash in hashes) + var randomHashes = hashes.OrderBy(x => random.Next()).ToArray(); + foreach (UInt256 hash in randomHashes) { switch (payload.Type) { From 9efa148a106994cb72c81100430284de7a274674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Fri, 18 Oct 2019 03:40:08 -0300 Subject: [PATCH 02/25] Adding static readonly Random --- neo/Network/P2P/ProtocolHandler.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/neo/Network/P2P/ProtocolHandler.cs b/neo/Network/P2P/ProtocolHandler.cs index 59ddbc424b..7f04b42311 100644 --- a/neo/Network/P2P/ProtocolHandler.cs +++ b/neo/Network/P2P/ProtocolHandler.cs @@ -27,6 +27,8 @@ public class SetFilter { public BloomFilter Filter; } private bool verack = false; private BloomFilter bloom_filter; + private static readonly Random random = new Random(); + public ProtocolHandler(NeoSystem system) { this.system = system; From f381677a4d14b72fa384c996a530cb2534ce9416 Mon Sep 17 00:00:00 2001 From: Vitor Date: Fri, 8 Nov 2019 12:13:32 -0300 Subject: [PATCH 03/25] Adding some comments to Peers class --- neo/Helper.cs | 3 +++ neo/Network/P2P/LocalNode.cs | 7 +++++++ neo/Network/P2P/Peer.cs | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/neo/Helper.cs b/neo/Helper.cs index fa3b384a35..a722044489 100644 --- a/neo/Helper.cs +++ b/neo/Helper.cs @@ -248,6 +248,9 @@ internal static IPAddress Unmap(this IPAddress address) return address; } + /// + /// Checks IPv4 and IPv6 formats and unmap, if necessary + /// internal static IPEndPoint Unmap(this IPEndPoint endPoint) { if (!endPoint.Address.IsIPv4MappedToIPv6) diff --git a/neo/Network/P2P/LocalNode.cs b/neo/Network/P2P/LocalNode.cs index 0efd8a3287..de694596e2 100644 --- a/neo/Network/P2P/LocalNode.cs +++ b/neo/Network/P2P/LocalNode.cs @@ -122,6 +122,11 @@ public IEnumerable GetUnconnectedPeers() return UnconnectedPeers; } + /// + /// Override of abstract class that is triggered UnconnectedPeers is empty + /// Performs a BroadcastMessage with the command `MessageCommand.GetAddr`, which, eventually, tells all known connections + /// If there are no connected peers it will try with the default, respecting MaxCountFromSeedList limit + /// protected override void NeedMorePeers(int count) { count = Math.Max(count, MaxCountFromSeedList); @@ -131,6 +136,8 @@ protected override void NeedMorePeers(int count) } else { + // Will call AddPeers with default SeedList set on Protocol.json + // trying to adding those to the list of currently uncconected ones AddPeers(GetIPEndPointsFromSeedList(count)); } } diff --git a/neo/Network/P2P/Peer.cs b/neo/Network/P2P/Peer.cs index 0665567fc8..61094c98a0 100644 --- a/neo/Network/P2P/Peer.cs +++ b/neo/Network/P2P/Peer.cs @@ -62,10 +62,16 @@ static Peer() localAddresses.UnionWith(NetworkInterface.GetAllNetworkInterfaces().SelectMany(p => p.GetIPProperties().UnicastAddresses).Select(p => p.Address.Unmap())); } + /// + /// Tries to add a set ff peers to an immutable hashset of UnconnectedPeers + /// + /// Peers that the method will try to add (union) to (with) UnconnectedPeers protected void AddPeers(IEnumerable peers) { if (UnconnectedPeers.Count < UnconnectedMax) { + // Do not select peers to be added that are already on the ConnectedPeers + // If the address is the same, the ListenerTcpPort should be different peers = peers.Where(p => (p.Port != ListenerTcpPort || !localAddresses.Contains(p.Address)) && !ConnectedPeers.Values.Contains(p)); ImmutableInterlocked.Update(ref UnconnectedPeers, p => p.Union(peers)); } @@ -74,6 +80,7 @@ protected void AddPeers(IEnumerable peers) protected void ConnectToPeer(IPEndPoint endPoint, bool isTrusted = false) { endPoint = endPoint.Unmap(); + // If the address is the same, the ListenerTcpPort should be different, otherwise, return if (endPoint.Port == ListenerTcpPort && localAddresses.Contains(endPoint.Address)) return; if (isTrusted) TrustedIpAddresses.Add(endPoint.Address); @@ -96,6 +103,11 @@ private static bool IsIntranetAddress(IPAddress address) return (value & 0xff000000) == 0x0a000000 || (value & 0xff000000) == 0x7f000000 || (value & 0xfff00000) == 0xac100000 || (value & 0xffff0000) == 0xc0a80000 || (value & 0xffff0000) == 0xa9fe0000; } + /// + /// Abstract class for asking for more peers + /// Currently triggered when UnconnectedPeers is empty + /// + /// Number of peers that are being requested protected abstract void NeedMorePeers(int count); protected override void OnReceive(object message) From 139005712927dc59e9fdae9d01ff04946c149a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Fri, 8 Nov 2019 12:19:11 -0300 Subject: [PATCH 04/25] Reverting change on ProtocolHandler --- neo/Network/P2P/ProtocolHandler.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/neo/Network/P2P/ProtocolHandler.cs b/neo/Network/P2P/ProtocolHandler.cs index 232f1e2ad1..eef68c4b6d 100644 --- a/neo/Network/P2P/ProtocolHandler.cs +++ b/neo/Network/P2P/ProtocolHandler.cs @@ -26,9 +26,7 @@ public class SetFilter { public BloomFilter Filter; } private VersionPayload version; private bool verack = false; private BloomFilter bloom_filter; - - private static readonly Random random = new Random(); - + public ProtocolHandler(NeoSystem system) { this.system = system; @@ -203,8 +201,7 @@ private void OnGetBlockDataMessageReceived(GetBlockDataPayload payload) private void OnGetDataMessageReceived(InvPayload payload) { UInt256[] hashes = payload.Hashes.Where(p => sentHashes.Add(p)).ToArray(); - var randomHashes = hashes.OrderBy(x => random.Next()).ToArray(); - foreach (UInt256 hash in randomHashes) + foreach (UInt256 hash in hashes) { switch (payload.Type) { From 7172645493cf0e721db0cbd88cd1d64dd8b84e87 Mon Sep 17 00:00:00 2001 From: Vitor Date: Fri, 8 Nov 2019 12:19:55 -0300 Subject: [PATCH 05/25] dotnet format --- neo/Network/P2P/ProtocolHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/Network/P2P/ProtocolHandler.cs b/neo/Network/P2P/ProtocolHandler.cs index eef68c4b6d..1e62e4dfbf 100644 --- a/neo/Network/P2P/ProtocolHandler.cs +++ b/neo/Network/P2P/ProtocolHandler.cs @@ -26,7 +26,7 @@ public class SetFilter { public BloomFilter Filter; } private VersionPayload version; private bool verack = false; private BloomFilter bloom_filter; - + public ProtocolHandler(NeoSystem system) { this.system = system; From 8c79d93b467e1d264835328159c0feb5e0535c8a Mon Sep 17 00:00:00 2001 From: Vitor Date: Fri, 8 Nov 2019 12:55:58 -0300 Subject: [PATCH 06/25] Additional comments --- neo/Network/P2P/Peer.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/neo/Network/P2P/Peer.cs b/neo/Network/P2P/Peer.cs index 61094c98a0..d9365a451c 100644 --- a/neo/Network/P2P/Peer.cs +++ b/neo/Network/P2P/Peer.cs @@ -27,6 +27,8 @@ private class WsConnected { public WebSocket Socket; public IPEndPoint Remote; p public const int DefaultMinDesiredConnections = 10; public const int DefaultMaxConnections = DefaultMinDesiredConnections * 4; + private const int TimerMillisecondsInterval = 5000; + private static readonly IActorRef tcp_manager = Context.System.Tcp(); private IActorRef tcp_listener; private IWebHost ws_host; @@ -153,7 +155,8 @@ private void OnStart(ChannelsConfig config) MaxConnections = config.MaxConnections; MaxConnectionsPerAddress = config.MaxConnectionsPerAddress; - timer = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(0, 5000, Context.Self, new Timer(), ActorRefs.NoSender); + // schedule time to trigger `OnTimer` event every TimerMillisecondsInterval ms + timer = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(0, TimerMillisecondsInterval, Context.Self, new Timer(), ActorRefs.NoSender); if ((ListenerTcpPort > 0 || ListenerWsPort > 0) && localAddresses.All(p => !p.IsIPv4MappedToIPv6 || IsIntranetAddress(p)) && UPnP.Discover()) @@ -235,7 +238,10 @@ private void OnTerminated(IActorRef actorRef) private void OnTimer() { + // Check if the number of desired connections is already enough if (ConnectedPeers.Count >= MinDesiredConnections) return; + + // If there are not available UnconnectedPeers triggers abstract implementation of NeedMorePeers if (UnconnectedPeers.Count == 0) NeedMorePeers(MinDesiredConnections - ConnectedPeers.Count); IPEndPoint[] endpoints = UnconnectedPeers.Take(MinDesiredConnections - ConnectedPeers.Count).ToArray(); From 5d7f0fdad8fa4fc63500e0884ae67819937b20ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Sun, 10 Nov 2019 11:37:32 -0300 Subject: [PATCH 07/25] Adding extra comments --- neo/Network/P2P/TaskManager.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/neo/Network/P2P/TaskManager.cs b/neo/Network/P2P/TaskManager.cs index 82e2e9b87a..c08124704a 100644 --- a/neo/Network/P2P/TaskManager.cs +++ b/neo/Network/P2P/TaskManager.cs @@ -52,16 +52,20 @@ private void OnNewTasks(InvPayload payload) { if (!sessions.TryGetValue(Sender, out TaskSession session)) return; + // Do not accept payload of type InventoryType.TX if not synced on best known top HeaderHeight if (payload.Type == InventoryType.TX && Blockchain.Singleton.Height < Blockchain.Singleton.HeaderHeight) { RequestTasks(session); return; } HashSet hashes = new HashSet(payload.Hashes); + // Remove all previously processed knownHashes from the list that is being requested hashes.Remove(knownHashes); + // Add to AvailableTasks the ones, of type InventoryType.Block, that are global (already under processement by other sessions) if (payload.Type == InventoryType.Block) session.AvailableTasks.UnionWith(hashes.Where(p => globalTasks.ContainsKey(p))); + // Remove those that are already in processement by other sessions hashes.Remove(globalTasks); if (hashes.Count == 0) { @@ -69,6 +73,7 @@ private void OnNewTasks(InvPayload payload) return; } + // Update globalTasks with the ones that will be requested within this current session foreach (UInt256 hash in hashes) { IncrementGlobalTask(hash); From 871f14f15c33e0166b582b7435c49d95b8276043 Mon Sep 17 00:00:00 2001 From: Ricardo Prado <38396062+lock9@users.noreply.github.com> Date: Thu, 14 Nov 2019 15:20:35 -0300 Subject: [PATCH 08/25] Fixing typo --- neo/Network/P2P/LocalNode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/Network/P2P/LocalNode.cs b/neo/Network/P2P/LocalNode.cs index de694596e2..aec90a9f30 100644 --- a/neo/Network/P2P/LocalNode.cs +++ b/neo/Network/P2P/LocalNode.cs @@ -123,7 +123,7 @@ public IEnumerable GetUnconnectedPeers() } /// - /// Override of abstract class that is triggered UnconnectedPeers is empty + /// Override of abstract class that is triggered when UnconnectedPeers is empty /// Performs a BroadcastMessage with the command `MessageCommand.GetAddr`, which, eventually, tells all known connections /// If there are no connected peers it will try with the default, respecting MaxCountFromSeedList limit /// From bb89d9eb4515812a5944f95d5b702fe856b596a7 Mon Sep 17 00:00:00 2001 From: Ricardo Prado <38396062+lock9@users.noreply.github.com> Date: Thu, 14 Nov 2019 15:22:20 -0300 Subject: [PATCH 09/25] Fixing typo --- neo/Network/P2P/Peer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/Network/P2P/Peer.cs b/neo/Network/P2P/Peer.cs index 61094c98a0..1db8182396 100644 --- a/neo/Network/P2P/Peer.cs +++ b/neo/Network/P2P/Peer.cs @@ -104,7 +104,7 @@ private static bool IsIntranetAddress(IPAddress address) } /// - /// Abstract class for asking for more peers + /// Abstract method for asking for more peers /// Currently triggered when UnconnectedPeers is empty /// /// Number of peers that are being requested From 4356483e43b67b6102828706d9c44324449d1f64 Mon Sep 17 00:00:00 2001 From: Ricardo Prado <38396062+lock9@users.noreply.github.com> Date: Thu, 14 Nov 2019 15:24:06 -0300 Subject: [PATCH 10/25] Fixing typo --- neo/Network/P2P/TaskManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neo/Network/P2P/TaskManager.cs b/neo/Network/P2P/TaskManager.cs index c08124704a..3227999d35 100644 --- a/neo/Network/P2P/TaskManager.cs +++ b/neo/Network/P2P/TaskManager.cs @@ -61,11 +61,11 @@ private void OnNewTasks(InvPayload payload) HashSet hashes = new HashSet(payload.Hashes); // Remove all previously processed knownHashes from the list that is being requested hashes.Remove(knownHashes); - // Add to AvailableTasks the ones, of type InventoryType.Block, that are global (already under processement by other sessions) + // Add to AvailableTasks the ones, of type InventoryType.Block, that are global (already under process by other sessions) if (payload.Type == InventoryType.Block) session.AvailableTasks.UnionWith(hashes.Where(p => globalTasks.ContainsKey(p))); - // Remove those that are already in processement by other sessions + // Remove those that are already in process by other sessions hashes.Remove(globalTasks); if (hashes.Count == 0) { From 1653ec0da9fd8e1ba599603b4a61c4ff6c3a91d4 Mon Sep 17 00:00:00 2001 From: Vitor Date: Mon, 25 Nov 2019 14:07:27 -0300 Subject: [PATCH 11/25] Adding more comments --- neo/Network/P2P/TaskManager.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/neo/Network/P2P/TaskManager.cs b/neo/Network/P2P/TaskManager.cs index 82e2e9b87a..b640826708 100644 --- a/neo/Network/P2P/TaskManager.cs +++ b/neo/Network/P2P/TaskManager.cs @@ -52,13 +52,16 @@ private void OnNewTasks(InvPayload payload) { if (!sessions.TryGetValue(Sender, out TaskSession session)) return; + // Do not accept payload of type InventoryType.TX if not synced on best known top HeaderHeight if (payload.Type == InventoryType.TX && Blockchain.Singleton.Height < Blockchain.Singleton.HeaderHeight) { RequestTasks(session); return; } HashSet hashes = new HashSet(payload.Hashes); + // Remove all previously processed knownHashes from the list that is being requested hashes.Remove(knownHashes); + // Add to AvailableTasks the ones that are global (already in processing by other sessions) if (payload.Type == InventoryType.Block) session.AvailableTasks.UnionWith(hashes.Where(p => globalTasks.ContainsKey(p))); @@ -201,9 +204,11 @@ public static Props Props(NeoSystem system) private void RequestTasks(TaskSession session) { if (session.HasTask) return; + // If there are pending tasks of InventoryType.Block we should process them if (session.AvailableTasks.Count > 0) { session.AvailableTasks.Remove(knownHashes); + // Search any similar hash that is on Singleton's knowledge, which means, on the way or already processed session.AvailableTasks.RemoveWhere(p => Blockchain.Singleton.ContainsBlock(p)); HashSet hashes = new HashSet(session.AvailableTasks); if (hashes.Count > 0) From caf3e0a91324fb2e8dba6b39399c570bae8d0c88 Mon Sep 17 00:00:00 2001 From: Vitor Date: Mon, 25 Nov 2019 14:10:56 -0300 Subject: [PATCH 12/25] adding more comments --- src/neo/Network/P2P/TaskManager.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/neo/Network/P2P/TaskManager.cs b/src/neo/Network/P2P/TaskManager.cs index b640826708..c898956607 100644 --- a/src/neo/Network/P2P/TaskManager.cs +++ b/src/neo/Network/P2P/TaskManager.cs @@ -61,10 +61,11 @@ private void OnNewTasks(InvPayload payload) HashSet hashes = new HashSet(payload.Hashes); // Remove all previously processed knownHashes from the list that is being requested hashes.Remove(knownHashes); - // Add to AvailableTasks the ones that are global (already in processing by other sessions) + // Add to AvailableTasks the ones, of type InventoryType.Block, that are global (already under process by other sessions) if (payload.Type == InventoryType.Block) session.AvailableTasks.UnionWith(hashes.Where(p => globalTasks.ContainsKey(p))); + // Remove those that are already in process by other sessions hashes.Remove(globalTasks); if (hashes.Count == 0) { @@ -72,6 +73,7 @@ private void OnNewTasks(InvPayload payload) return; } + // Update globalTasks with the ones that will be requested within this current session foreach (UInt256 hash in hashes) { IncrementGlobalTask(hash); From a1c8f3d2b8df1c1720d726584bc5de7814da463f Mon Sep 17 00:00:00 2001 From: ShawnYun <42930111+ShawnYun@users.noreply.github.com> Date: Fri, 29 Nov 2019 20:41:33 +0800 Subject: [PATCH 13/25] Add some comments of P2P (#1303) * add some comments of P2P * fix * Minor changes * Minor changes * Minor Changes * Minor changes * Minor changes --- src/neo/Network/P2P/LocalNode.cs | 11 ++++++++++ src/neo/Network/P2P/Message.cs | 4 ++++ src/neo/Network/P2P/Peer.cs | 28 ++++++++++++++++++++++++-- src/neo/Network/P2P/ProtocolHandler.cs | 24 ++++++++++++++++++++++ src/neo/Network/P2P/RemoteNode.cs | 10 +++++++++ src/neo/Network/P2P/TaskManager.cs | 5 +++++ 6 files changed, 80 insertions(+), 2 deletions(-) diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index aec90a9f30..d93563d3d5 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -64,6 +64,10 @@ private void BroadcastMessage(MessageCommand command, ISerializable payload = nu BroadcastMessage(Message.Create(command, payload)); } + /// + /// Broadcast a message to all connected nodes. + /// + /// The message to be broadcasted. private void BroadcastMessage(Message message) { Connections.Tell(message); @@ -127,6 +131,7 @@ public IEnumerable GetUnconnectedPeers() /// Performs a BroadcastMessage with the command `MessageCommand.GetAddr`, which, eventually, tells all known connections /// If there are no connected peers it will try with the default, respecting MaxCountFromSeedList limit /// + /// The count of peers required protected override void NeedMorePeers(int count) { count = Math.Max(count, MaxCountFromSeedList); @@ -164,6 +169,12 @@ protected override void OnReceive(object message) } } + /// + /// For Transaction type of IInventory, it will tell Transaction to the actor of Consensus. + /// Otherwise, tell the inventory to the actor of Blockchain. + /// There are, currently, three implementations of IInventory: TX, Block and ConsensusPayload + /// + /// The inventory to be relayed. private void OnRelay(IInventory inventory) { if (inventory is Transaction transaction) diff --git a/src/neo/Network/P2P/Message.cs b/src/neo/Network/P2P/Message.cs index 578259f789..2d45f254ad 100644 --- a/src/neo/Network/P2P/Message.cs +++ b/src/neo/Network/P2P/Message.cs @@ -13,6 +13,10 @@ public class Message : ISerializable private const int CompressionMinSize = 128; private const int CompressionThreshold = 64; + /// + /// Flags that represents whether a message is compressed. + /// 0 for None, 1 for Compressed. + /// public MessageFlags Flags; public MessageCommand Command; public ISerializable Payload; diff --git a/src/neo/Network/P2P/Peer.cs b/src/neo/Network/P2P/Peer.cs index d1afd6246a..131d9087a1 100644 --- a/src/neo/Network/P2P/Peer.cs +++ b/src/neo/Network/P2P/Peer.cs @@ -37,8 +37,19 @@ private class WsConnected { public WebSocket Socket; public IPEndPoint Remote; p private static readonly HashSet localAddresses = new HashSet(); private readonly Dictionary ConnectedAddresses = new Dictionary(); + /// + /// A dictionary that stores the connected nodes. + /// protected readonly ConcurrentDictionary ConnectedPeers = new ConcurrentDictionary(); + /// + /// An ImmutableHashSet that stores the Peers received: 1) from other nodes or 2) from default file. + /// If the number of desired connections is not enough, first try to connect with the peers from this set. + /// protected ImmutableHashSet UnconnectedPeers = ImmutableHashSet.Empty; + /// + /// When a TCP connection request is sent to a peer, the peer will be added to the ImmutableHashSet. + /// If a Tcp.Connected or a Tcp.CommandFailed (with TCP.Command of type Tcp.Connect) is received, the related peer will be removed. + /// protected ImmutableHashSet ConnectingPeers = ImmutableHashSet.Empty; protected HashSet TrustedIpAddresses { get; } = new HashSet(); @@ -65,7 +76,7 @@ static Peer() } /// - /// Tries to add a set ff peers to an immutable hashset of UnconnectedPeers + /// Tries to add a set of peers to the immutable ImmutableHashSet of UnconnectedPeers /// /// Peers that the method will try to add (union) to (with) UnconnectedPeers protected void AddPeers(IEnumerable peers) @@ -86,6 +97,7 @@ protected void ConnectToPeer(IPEndPoint endPoint, bool isTrusted = false) if (endPoint.Port == ListenerTcpPort && localAddresses.Contains(endPoint.Address)) return; if (isTrusted) TrustedIpAddresses.Add(endPoint.Address); + // If connections with the peer greater than or equal to MaxConnectionsPerAddress, return. if (ConnectedAddresses.TryGetValue(endPoint.Address, out int count) && count >= MaxConnectionsPerAddress) return; if (ConnectedPeers.Values.Contains(endPoint)) return; @@ -189,6 +201,13 @@ private void OnStart(ChannelsConfig config) } } + /// + /// Will be triggered when a Tcp.Connected message is received. + /// If the conditions are met, the remote endpoint will be added to ConnectedPeers. + /// Increase the connection number with the remote endpoint by one. + /// + /// The remote endpoint of TCP connection + /// The local endpoint of TCP connection private void OnTcpConnected(IPEndPoint remote, IPEndPoint local) { ImmutableInterlocked.Update(ref ConnectingPeers, p => p.Remove(remote)); @@ -197,7 +216,7 @@ private void OnTcpConnected(IPEndPoint remote, IPEndPoint local) Sender.Tell(Tcp.Abort.Instance); return; } - + ConnectedAddresses.TryGetValue(remote.Address, out int count); if (count >= MaxConnectionsPerAddress) { @@ -213,6 +232,11 @@ private void OnTcpConnected(IPEndPoint remote, IPEndPoint local) } } + /// + /// Will be triggered when a Tcp.CommandFailed message is received. + /// If it's a Tcp.Connect command, remove the related endpoint from ConnectingPeers. + /// + /// private void OnTcpCommandFailed(Tcp.Command cmd) { switch (cmd) diff --git a/src/neo/Network/P2P/ProtocolHandler.cs b/src/neo/Network/P2P/ProtocolHandler.cs index e16d7f238c..40939bd574 100644 --- a/src/neo/Network/P2P/ProtocolHandler.cs +++ b/src/neo/Network/P2P/ProtocolHandler.cs @@ -145,6 +145,11 @@ private void OnFilterLoadMessageReceived(FilterLoadPayload payload) Context.Parent.Tell(new SetFilter { Filter = bloom_filter }); } + /// + /// Will be triggered when a MessageCommand.GetAddr message is received. + /// Randomly select nodes from the local RemoteNodes and tells to RemoteNode actors a MessageCommand.Addr message. + /// The message contains a list of networkAddresses from those selected random peers. + /// private void OnGetAddrMessageReceived() { Random rand = new Random(); @@ -158,9 +163,16 @@ private void OnGetAddrMessageReceived() Context.Parent.Tell(Message.Create(MessageCommand.Addr, AddrPayload.Create(networkAddresses))); } + /// + /// Will be triggered when a MessageCommand.GetBlocks message is received. + /// Tell the specified number of blocks' hashes starting with the requested HashStart until payload.Count or MaxHashesCount + /// Responses are sent to RemoteNode actor as MessageCommand.Inv Message. + /// + /// A GetBlocksPayload including start block Hash and number of blocks requested private void OnGetBlocksMessageReceived(GetBlocksPayload payload) { UInt256 hash = payload.HashStart; + // The default value of payload.Count is -1 int count = payload.Count < 0 || payload.Count > InvPayload.MaxHashesCount ? InvPayload.MaxHashesCount : payload.Count; TrimmedBlock state = Blockchain.Singleton.View.Blocks.TryGet(hash); if (state == null) return; @@ -198,6 +210,12 @@ private void OnGetBlockDataMessageReceived(GetBlockDataPayload payload) } } + /// + /// Will be triggered when a MessageCommand.GetData message is received. + /// The payload includes an array of hash values. + /// For different payload.Type (Tx, Block, Consensus), get the corresponding (Tx, Block, Consensus) and tell it to RemoteNode actor. + /// + /// The payload containing the requested information private void OnGetDataMessageReceived(InvPayload payload) { UInt256[] hashes = payload.Hashes.Where(p => sentHashes.Add(p)).ToArray(); @@ -233,6 +251,12 @@ private void OnGetDataMessageReceived(InvPayload payload) } } + /// + /// Will be triggered when a MessageCommand.GetHeaders message is received. + /// Tell the specified number of blocks' headers starting with the requested HashStart to RemoteNode actor. + /// A limit set by HeadersPayload.MaxHeadersCount is also applied to the number of requested Headers, namely payload.Count. + /// + /// A GetBlocksPayload including start block Hash and number of blocks' headers requested private void OnGetHeadersMessageReceived(GetBlocksPayload payload) { UInt256 hash = payload.HashStart; diff --git a/src/neo/Network/P2P/RemoteNode.cs b/src/neo/Network/P2P/RemoteNode.cs index ec2a16e047..a7cab65902 100644 --- a/src/neo/Network/P2P/RemoteNode.cs +++ b/src/neo/Network/P2P/RemoteNode.cs @@ -50,6 +50,12 @@ public RemoteNode(NeoSystem system, object connection, IPEndPoint remote, IPEndP SendMessage(Message.Create(MessageCommand.Version, VersionPayload.Create(LocalNode.Nonce, LocalNode.UserAgent, capabilities.ToArray()))); } + /// + /// It defines the message queue to be used for dequeuing. + /// If the high-priority message queue is not empty, choose the high-priority message queue. + /// Otherwise, choose the low-priority message queue. + /// Finally, it sends the first message of the queue. + /// private void CheckMessageQueue() { if (!verack || !ack) return; @@ -67,6 +73,10 @@ private void EnqueueMessage(MessageCommand command, ISerializable payload = null EnqueueMessage(Message.Create(command, payload)); } + /// + /// Add message to high priority queue or low priority queue depending on the message type. + /// + /// The message to be added private void EnqueueMessage(Message message) { bool is_single = false; diff --git a/src/neo/Network/P2P/TaskManager.cs b/src/neo/Network/P2P/TaskManager.cs index 866528f618..423572c958 100644 --- a/src/neo/Network/P2P/TaskManager.cs +++ b/src/neo/Network/P2P/TaskManager.cs @@ -25,6 +25,9 @@ private class Timer { } private readonly NeoSystem system; private const int MaxConncurrentTasks = 3; + /// + /// A set of known hashes for inventories or payloads already received + /// private readonly FIFOSet knownHashes; private readonly Dictionary globalTasks = new Dictionary(); private readonly Dictionary sessions = new Dictionary(); @@ -228,6 +231,8 @@ private void RequestTasks(TaskSession session) return; } } + // When the number of AvailableTasks is no more than 0, no pending tasks of InventoryType.Block, it should process pending the tasks of headers + // If not HeaderTask pending to be processed it should ask for more Blocks if ((!HasHeaderTask || globalTasks[HeaderTaskHash] < MaxConncurrentTasks) && Blockchain.Singleton.HeaderHeight < session.StartHeight) { session.Tasks[HeaderTaskHash] = DateTime.UtcNow; From 6d7b0ff5f0c2a0e2c88a2b0dfaf6912b333ad6c7 Mon Sep 17 00:00:00 2001 From: Vitor Date: Fri, 29 Nov 2019 09:42:53 -0300 Subject: [PATCH 14/25] dotnet format --- src/neo/Network/P2P/LocalNode.cs | 2 +- src/neo/Network/P2P/Peer.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index d93563d3d5..0188c10686 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -172,7 +172,7 @@ protected override void OnReceive(object message) /// /// For Transaction type of IInventory, it will tell Transaction to the actor of Consensus. /// Otherwise, tell the inventory to the actor of Blockchain. - /// There are, currently, three implementations of IInventory: TX, Block and ConsensusPayload + /// There are, currently, three implementations of IInventory: TX, Block and ConsensusPayload /// /// The inventory to be relayed. private void OnRelay(IInventory inventory) diff --git a/src/neo/Network/P2P/Peer.cs b/src/neo/Network/P2P/Peer.cs index 131d9087a1..5e0e2589ef 100644 --- a/src/neo/Network/P2P/Peer.cs +++ b/src/neo/Network/P2P/Peer.cs @@ -216,7 +216,7 @@ private void OnTcpConnected(IPEndPoint remote, IPEndPoint local) Sender.Tell(Tcp.Abort.Instance); return; } - + ConnectedAddresses.TryGetValue(remote.Address, out int count); if (count >= MaxConnectionsPerAddress) { From 8dff6747bd6f1a416465b0d18f815fb9b4070b08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Fri, 29 Nov 2019 09:55:07 -0300 Subject: [PATCH 15/25] Minor changes --- src/neo/Helper.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/neo/Helper.cs b/src/neo/Helper.cs index 058be1af1e..db6a32bb09 100644 --- a/src/neo/Helper.cs +++ b/src/neo/Helper.cs @@ -249,6 +249,10 @@ unsafe internal static ulong ToUInt64(this byte[] value, int startIndex) } } + /// + /// Checks if address is IPv4 Maped to IPv6 format, if so, Map to IPv4. + /// Otherwise, return current address. + /// internal static IPAddress Unmap(this IPAddress address) { if (address.IsIPv4MappedToIPv6) @@ -257,7 +261,8 @@ internal static IPAddress Unmap(this IPAddress address) } /// - /// Checks IPv4 and IPv6 formats and unmap, if necessary + /// Checks if IPEndPoint is IPv4 Maped to IPv6 format, if so, unmap to IPv4. + /// Otherwise, return current endpoint. /// internal static IPEndPoint Unmap(this IPEndPoint endPoint) { From 0b03c8349a3b68c448aaba700d7d6e8ad49c3c6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Fri, 29 Nov 2019 09:59:52 -0300 Subject: [PATCH 16/25] Minor changes --- src/neo/Network/P2P/LocalNode.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index 0188c10686..2f7bcfbf1f 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -59,13 +59,19 @@ public LocalNode(NeoSystem system) } } + /// + /// Packs a MessageCommand to a full Message with an optional ISerializable payload. + /// Forwards it to . + /// + /// The message command to be packed. + /// Optional payload to be Serialized along the message. private void BroadcastMessage(MessageCommand command, ISerializable payload = null) { BroadcastMessage(Message.Create(command, payload)); } /// - /// Broadcast a message to all connected nodes. + /// Broadcast a message to all connected nodes, namely . /// /// The message to be broadcasted. private void BroadcastMessage(Message message) From cf5dacd2bd3d0764e15b43cc178f6f26b94f1c03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Fri, 29 Nov 2019 10:03:12 -0300 Subject: [PATCH 17/25] Additional comments --- src/neo/Network/P2P/LocalNode.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index 2f7bcfbf1f..762a0cc87b 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -97,6 +97,10 @@ private static IPEndPoint GetIPEndpointFromHostPort(string hostNameOrAddress, in return new IPEndPoint(ipAddress, port); } + /// + /// Return an amount of random seeds nodes from the default SeedList file defined on . + /// + /// Limit of random seed nodes to be obtained, also limited by the available seeds from file. private static IEnumerable GetIPEndPointsFromSeedList(int seedsToTake) { if (seedsToTake > 0) From cc4825bcf2beb047d4373d521da29b85b6bbe912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Fri, 29 Nov 2019 10:09:47 -0300 Subject: [PATCH 18/25] Minor changes --- src/neo/Network/P2P/LocalNode.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index 762a0cc87b..e8a9a22332 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -137,7 +137,7 @@ public IEnumerable GetUnconnectedPeers() } /// - /// Override of abstract class that is triggered when UnconnectedPeers is empty + /// Override of abstract class that is triggered when is empty. /// Performs a BroadcastMessage with the command `MessageCommand.GetAddr`, which, eventually, tells all known connections /// If there are no connected peers it will try with the default, respecting MaxCountFromSeedList limit /// @@ -151,8 +151,8 @@ protected override void NeedMorePeers(int count) } else { - // Will call AddPeers with default SeedList set on Protocol.json - // trying to adding those to the list of currently uncconected ones + // Will call AddPeers with default SeedList set cached on . + // It will try to add those, sequentially, to the list of currently uncconected ones. AddPeers(GetIPEndPointsFromSeedList(count)); } } From a68e828d9404904fa2d38765dbcd39614abd194d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Fri, 29 Nov 2019 11:28:46 -0300 Subject: [PATCH 19/25] Reverting variable change --- src/neo/Network/P2P/Peer.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/neo/Network/P2P/Peer.cs b/src/neo/Network/P2P/Peer.cs index 5e0e2589ef..c6a16b595f 100644 --- a/src/neo/Network/P2P/Peer.cs +++ b/src/neo/Network/P2P/Peer.cs @@ -27,8 +27,6 @@ private class WsConnected { public WebSocket Socket; public IPEndPoint Remote; p public const int DefaultMinDesiredConnections = 10; public const int DefaultMaxConnections = DefaultMinDesiredConnections * 4; - private const int TimerMillisecondsInterval = 5000; - private static readonly IActorRef tcp_manager = Context.System.Tcp(); private IActorRef tcp_listener; private IWebHost ws_host; @@ -168,7 +166,7 @@ private void OnStart(ChannelsConfig config) MaxConnectionsPerAddress = config.MaxConnectionsPerAddress; // schedule time to trigger `OnTimer` event every TimerMillisecondsInterval ms - timer = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(0, TimerMillisecondsInterval, Context.Self, new Timer(), ActorRefs.NoSender); + timer = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(0, 5000, Context.Self, new Timer(), ActorRefs.NoSender); if ((ListenerTcpPort > 0 || ListenerWsPort > 0) && localAddresses.All(p => !p.IsIPv4MappedToIPv6 || IsIntranetAddress(p)) && UPnP.Discover()) From bf28f7dcd84eb6115b58348a6182e285325a9c5a Mon Sep 17 00:00:00 2001 From: Vitor Date: Thu, 5 Dec 2019 14:35:14 -0300 Subject: [PATCH 20/25] Dotnet format --- src/neo/Helper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neo/Helper.cs b/src/neo/Helper.cs index 8ed9979781..b8a0a7f79e 100644 --- a/src/neo/Helper.cs +++ b/src/neo/Helper.cs @@ -236,7 +236,7 @@ public static ulong ToTimestampMS(this DateTime time) { return (ulong)(time.ToUniversalTime() - unixEpoch).TotalMilliseconds; } - + /// /// Checks if address is IPv4 Maped to IPv6 format, if so, Map to IPv4. /// Otherwise, return current address. From c9d3ad1d4de79b8dac5b292b4252aef377730cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Mon, 9 Dec 2019 20:41:53 -0300 Subject: [PATCH 21/25] Minor changes --- src/neo/Network/P2P/LocalNode.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index e8a9a22332..a651d46a16 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -138,8 +138,8 @@ public IEnumerable GetUnconnectedPeers() /// /// Override of abstract class that is triggered when is empty. - /// Performs a BroadcastMessage with the command `MessageCommand.GetAddr`, which, eventually, tells all known connections - /// If there are no connected peers it will try with the default, respecting MaxCountFromSeedList limit + /// Performs a BroadcastMessage with the command `MessageCommand.GetAddr`, which, eventually, tells all known connections. + /// If there are no connected peers it will try with the default, respecting MaxCountFromSeedList limit. /// /// The count of peers required protected override void NeedMorePeers(int count) @@ -182,7 +182,7 @@ protected override void OnReceive(object message) /// /// For Transaction type of IInventory, it will tell Transaction to the actor of Consensus. /// Otherwise, tell the inventory to the actor of Blockchain. - /// There are, currently, three implementations of IInventory: TX, Block and ConsensusPayload + /// There are, currently, three implementations of IInventory: TX, Block and ConsensusPayload. /// /// The inventory to be relayed. private void OnRelay(IInventory inventory) From 8e238c59ba47092475aca0ae0cfc5e7f6dfcfad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Mon, 9 Dec 2019 20:45:03 -0300 Subject: [PATCH 22/25] Minor changes --- src/neo/Network/P2P/Peer.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/neo/Network/P2P/Peer.cs b/src/neo/Network/P2P/Peer.cs index 46210a5a50..8e7eb21bd2 100644 --- a/src/neo/Network/P2P/Peer.cs +++ b/src/neo/Network/P2P/Peer.cs @@ -75,9 +75,9 @@ static Peer() } /// - /// Tries to add a set of peers to the immutable ImmutableHashSet of UnconnectedPeers + /// Tries to add a set of peers to the immutable ImmutableHashSet of UnconnectedPeers. /// - /// Peers that the method will try to add (union) to (with) UnconnectedPeers + /// Peers that the method will try to add (union) to (with) UnconnectedPeers. protected void AddPeers(IEnumerable peers) { if (UnconnectedPeers.Count < UnconnectedMax) @@ -116,10 +116,9 @@ private static bool IsIntranetAddress(IPAddress address) } /// - /// Abstract method for asking for more peers - /// Currently triggered when UnconnectedPeers is empty + /// Abstract method for asking for more peers. Currently triggered when UnconnectedPeers is empty. /// - /// Number of peers that are being requested + /// Number of peers that are being requested. protected abstract void NeedMorePeers(int count); protected override void OnReceive(object message) @@ -204,8 +203,8 @@ private void OnStart(ChannelsConfig config) /// If the conditions are met, the remote endpoint will be added to ConnectedPeers. /// Increase the connection number with the remote endpoint by one. /// - /// The remote endpoint of TCP connection - /// The local endpoint of TCP connection + /// The remote endpoint of TCP connection. + /// The local endpoint of TCP connection. private void OnTcpConnected(IPEndPoint remote, IPEndPoint local) { ImmutableInterlocked.Update(ref ConnectingPeers, p => p.Remove(remote)); @@ -234,7 +233,7 @@ private void OnTcpConnected(IPEndPoint remote, IPEndPoint local) /// Will be triggered when a Tcp.CommandFailed message is received. /// If it's a Tcp.Connect command, remove the related endpoint from ConnectingPeers. /// - /// + /// Tcp.Command message/event. private void OnTcpCommandFailed(Tcp.Command cmd) { switch (cmd) @@ -263,7 +262,7 @@ private void OnTimer() // Check if the number of desired connections is already enough if (ConnectedPeers.Count >= MinDesiredConnections) return; - // If there are not available UnconnectedPeers triggers abstract implementation of NeedMorePeers + // If there aren't available UnconnectedPeers, it triggers an abstract implementation of NeedMorePeers if (UnconnectedPeers.Count == 0) NeedMorePeers(MinDesiredConnections - ConnectedPeers.Count); IPEndPoint[] endpoints = UnconnectedPeers.Take(MinDesiredConnections - ConnectedPeers.Count).ToArray(); From 945d0b78aa8ab9c52baf799988b0396b070787da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Mon, 9 Dec 2019 20:46:59 -0300 Subject: [PATCH 23/25] Minor changes --- src/neo/Network/P2P/ProtocolHandler.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/neo/Network/P2P/ProtocolHandler.cs b/src/neo/Network/P2P/ProtocolHandler.cs index 99d93ba793..cecbb02796 100644 --- a/src/neo/Network/P2P/ProtocolHandler.cs +++ b/src/neo/Network/P2P/ProtocolHandler.cs @@ -197,7 +197,7 @@ private void OnGetAddrMessageReceived() /// Tell the specified number of blocks' hashes starting with the requested HashStart until payload.Count or MaxHashesCount /// Responses are sent to RemoteNode actor as MessageCommand.Inv Message. /// - /// A GetBlocksPayload including start block Hash and number of blocks requested + /// A GetBlocksPayload including start block Hash and number of blocks requested. private void OnGetBlocksMessageReceived(GetBlocksPayload payload) { UInt256 hash = payload.HashStart; @@ -242,9 +242,9 @@ private void OnGetBlockDataMessageReceived(GetBlockDataPayload payload) /// /// Will be triggered when a MessageCommand.GetData message is received. /// The payload includes an array of hash values. - /// For different payload.Type (Tx, Block, Consensus), get the corresponding (Tx, Block, Consensus) and tell it to RemoteNode actor. + /// For different payload.Type (Tx, Block, Consensus), get the corresponding (Txs, Blocks, Consensus) and tell them to RemoteNode actor. /// - /// The payload containing the requested information + /// The payload containing the requested information. private void OnGetDataMessageReceived(InvPayload payload) { UInt256[] hashes = payload.Hashes.Where(p => sentHashes.Add(p)).ToArray(); @@ -285,7 +285,7 @@ private void OnGetDataMessageReceived(InvPayload payload) /// Tell the specified number of blocks' headers starting with the requested HashStart to RemoteNode actor. /// A limit set by HeadersPayload.MaxHeadersCount is also applied to the number of requested Headers, namely payload.Count. /// - /// A GetBlocksPayload including start block Hash and number of blocks' headers requested + /// A GetBlocksPayload including start block Hash and number of blocks' headers requested. private void OnGetHeadersMessageReceived(GetBlocksPayload payload) { UInt256 hash = payload.HashStart; From 86fd90118cf137dd6c8a594721c1722ea9a7ff1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Mon, 9 Dec 2019 20:47:37 -0300 Subject: [PATCH 24/25] Minor changes --- src/neo/Network/P2P/RemoteNode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neo/Network/P2P/RemoteNode.cs b/src/neo/Network/P2P/RemoteNode.cs index f85c4d4e38..44bb2ef107 100644 --- a/src/neo/Network/P2P/RemoteNode.cs +++ b/src/neo/Network/P2P/RemoteNode.cs @@ -76,7 +76,7 @@ private void EnqueueMessage(MessageCommand command, ISerializable payload = null /// /// Add message to high priority queue or low priority queue depending on the message type. /// - /// The message to be added + /// The message to be added. private void EnqueueMessage(Message message) { bool is_single = false; From 055b6d4942c02532a4c99eb3ed53ee3d160af994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Mon, 9 Dec 2019 20:49:12 -0300 Subject: [PATCH 25/25] Minor changes --- src/neo/Network/P2P/TaskManager.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/neo/Network/P2P/TaskManager.cs b/src/neo/Network/P2P/TaskManager.cs index 61f9c620bb..818973ea4b 100644 --- a/src/neo/Network/P2P/TaskManager.cs +++ b/src/neo/Network/P2P/TaskManager.cs @@ -28,10 +28,10 @@ private class Timer { } private readonly NeoSystem system; private const int MaxConncurrentTasks = 3; - /// - /// A set of known hashes for inventories or payloads already received - /// private const int PingCoolingOffPeriod = 60; // in secconds. + /// + /// A set of known hashes, of inventories or payloads, already received. + /// private readonly FIFOSet knownHashes; private readonly Dictionary globalTasks = new Dictionary(); private readonly Dictionary sessions = new Dictionary(); @@ -59,7 +59,7 @@ private void OnNewTasks(InvPayload payload) { if (!sessions.TryGetValue(Sender, out TaskSession session)) return; - // Do not accept payload of type InventoryType.TX if not synced on best known top HeaderHeight + // Do not accept payload of type InventoryType.TX if not synced on best known HeaderHeight if (payload.Type == InventoryType.TX && Blockchain.Singleton.Height < Blockchain.Singleton.HeaderHeight) { RequestTasks(session);