diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index 990b6572fa..f48656ced1 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -14,6 +14,8 @@ namespace Neo.Network.P2P { public class LocalNode : Peer { + public class GetSnapshot { } + public class Snapshot { public IReadOnlyDictionary RemoteNodes { get; init; } public IReadOnlyCollection UnconnectedPeers { get; init; } } public class RelayDirectly { public IInventory Inventory; } public class SendDirectly { public IInventory Inventory; } @@ -24,8 +26,6 @@ public class SendDirectly { public IInventory Inventory; } private readonly NeoSystem system; internal readonly ConcurrentDictionary RemoteNodes = new ConcurrentDictionary(); - public int ConnectedCount => RemoteNodes.Count; - public int UnconnectedCount => UnconnectedPeers.Count; public static readonly uint Nonce; public static string UserAgent { get; set; } @@ -116,7 +116,7 @@ internal static IPEndPoint GetIpEndPoint(string hostAndPort) /// /// Remote node actor /// Remote node - public bool AllowNewConnection(IActorRef actor, RemoteNode node) + internal bool AllowNewConnection(IActorRef actor, RemoteNode node) { if (node.Version.Magic != system.Settings.Magic) return false; if (node.Version.Nonce == Nonce) return false; @@ -132,16 +132,6 @@ public bool AllowNewConnection(IActorRef actor, RemoteNode node) return true; } - public IEnumerable GetRemoteNodes() - { - return RemoteNodes.Values; - } - - public IEnumerable GetUnconnectedPeers() - { - return UnconnectedPeers; - } - /// /// Override of abstract class that is triggered when is empty. /// Performs a BroadcastMessage with the command `MessageCommand.GetAddr`, which, eventually, tells all known connections. @@ -151,7 +141,7 @@ public IEnumerable GetUnconnectedPeers() protected override void NeedMorePeers(int count) { count = Math.Max(count, MaxCountFromSeedList); - if (ConnectedPeers.Count > 0) + if (!ConnectedPeers.IsEmpty) { BroadcastMessage(MessageCommand.GetAddr); } @@ -170,6 +160,13 @@ protected override void OnReceive(object message) base.OnReceive(message); switch (message) { + case GetSnapshot _: + Sender.Tell(new Snapshot + { + RemoteNodes = RemoteNodes, + UnconnectedPeers = UnconnectedPeers + }); + break; case Message msg: BroadcastMessage(msg); break;