From 887c26910853e57762cb14e3341117055b0e32c6 Mon Sep 17 00:00:00 2001 From: Charis Date: Wed, 11 Dec 2019 16:38:05 +0800 Subject: [PATCH 1/4] update connections.tell --- src/neo/Network/P2P/LocalNode.cs | 15 ++++++++++++--- src/neo/Network/P2P/Peer.cs | 1 - 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index a651d46a16..18d49aba4b 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -76,7 +76,10 @@ private void BroadcastMessage(MessageCommand command, ISerializable payload = nu /// The message to be broadcasted. private void BroadcastMessage(Message message) { - Connections.Tell(message); + foreach (var connection in RemoteNodes.Keys) + { + connection.Tell(message); + } } private static IPEndPoint GetIPEndpointFromHostPort(string hostNameOrAddress, int port) @@ -194,12 +197,18 @@ private void OnRelay(IInventory inventory) private void OnRelayDirectly(IInventory inventory) { - Connections.Tell(new RemoteNode.Relay { Inventory = inventory }); + foreach (var connection in RemoteNodes.Keys) + { + connection.Tell(new RemoteNode.Relay { Inventory = inventory }); + } } private void OnSendDirectly(IInventory inventory) { - Connections.Tell(inventory); + foreach (var connection in RemoteNodes.Keys) + { + connection.Tell(inventory); + } } public static Props Props(NeoSystem system) diff --git a/src/neo/Network/P2P/Peer.cs b/src/neo/Network/P2P/Peer.cs index 8e7eb21bd2..054ec26aa8 100644 --- a/src/neo/Network/P2P/Peer.cs +++ b/src/neo/Network/P2P/Peer.cs @@ -32,7 +32,6 @@ private class WsConnected { public WebSocket Socket; public IPEndPoint Remote; p private IActorRef tcp_listener; private IWebHost ws_host; private ICancelable timer; - protected ActorSelection Connections => Context.ActorSelection("connection_*"); private static readonly HashSet localAddresses = new HashSet(); private readonly Dictionary ConnectedAddresses = new Dictionary(); From 25e7c07c2e40b87959518c6901705ce00263af0f Mon Sep 17 00:00:00 2001 From: Charis Date: Wed, 11 Dec 2019 17:30:01 +0800 Subject: [PATCH 2/4] optimise --- src/neo/Network/P2P/LocalNode.cs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index 18d49aba4b..2d704523ad 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -74,7 +74,9 @@ private void BroadcastMessage(MessageCommand command, ISerializable payload = nu /// Broadcast a message to all connected nodes, namely . /// /// The message to be broadcasted. - private void BroadcastMessage(Message message) + private void BroadcastMessage(Message message) => SendToRemoteNode(message); + + private void SendToRemoteNode(object message) { foreach (var connection in RemoteNodes.Keys) { @@ -195,21 +197,9 @@ private void OnRelay(IInventory inventory) system.Blockchain.Tell(inventory); } - private void OnRelayDirectly(IInventory inventory) - { - foreach (var connection in RemoteNodes.Keys) - { - connection.Tell(new RemoteNode.Relay { Inventory = inventory }); - } - } + private void OnRelayDirectly(IInventory inventory) => SendToRemoteNode(new RemoteNode.Relay { Inventory = inventory }); - private void OnSendDirectly(IInventory inventory) - { - foreach (var connection in RemoteNodes.Keys) - { - connection.Tell(inventory); - } - } + private void OnSendDirectly(IInventory inventory) => SendToRemoteNode(inventory); public static Props Props(NeoSystem system) { From 69d1701292e2000f162f88fbd2d2b2ee87cf5969 Mon Sep 17 00:00:00 2001 From: Charis Date: Thu, 12 Dec 2019 10:14:20 +0800 Subject: [PATCH 3/4] update --- src/neo/Network/P2P/LocalNode.cs | 8 ++++---- src/neo/Network/P2P/Peer.cs | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index 2d704523ad..bbfd86e947 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -74,9 +74,9 @@ private void BroadcastMessage(MessageCommand command, ISerializable payload = nu /// Broadcast a message to all connected nodes, namely . /// /// The message to be broadcasted. - private void BroadcastMessage(Message message) => SendToRemoteNode(message); + private void BroadcastMessage(Message message) => SendToRemoteNodes(message); - private void SendToRemoteNode(object message) + private void SendToRemoteNodes(object message) { foreach (var connection in RemoteNodes.Keys) { @@ -197,9 +197,9 @@ private void OnRelay(IInventory inventory) system.Blockchain.Tell(inventory); } - private void OnRelayDirectly(IInventory inventory) => SendToRemoteNode(new RemoteNode.Relay { Inventory = inventory }); + private void OnRelayDirectly(IInventory inventory) => SendToRemoteNodes(new RemoteNode.Relay { Inventory = inventory }); - private void OnSendDirectly(IInventory inventory) => SendToRemoteNode(inventory); + private void OnSendDirectly(IInventory inventory) => SendToRemoteNodes(inventory); public static Props Props(NeoSystem system) { diff --git a/src/neo/Network/P2P/Peer.cs b/src/neo/Network/P2P/Peer.cs index 054ec26aa8..8e7eb21bd2 100644 --- a/src/neo/Network/P2P/Peer.cs +++ b/src/neo/Network/P2P/Peer.cs @@ -32,6 +32,7 @@ private class WsConnected { public WebSocket Socket; public IPEndPoint Remote; p private IActorRef tcp_listener; private IWebHost ws_host; private ICancelable timer; + protected ActorSelection Connections => Context.ActorSelection("connection_*"); private static readonly HashSet localAddresses = new HashSet(); private readonly Dictionary ConnectedAddresses = new Dictionary(); From 959338a2570b3db6b0b36f9ff2f412e7453ad853 Mon Sep 17 00:00:00 2001 From: Charis Date: Mon, 16 Dec 2019 10:09:56 +0800 Subject: [PATCH 4/4] add comment --- src/neo/Network/P2P/LocalNode.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index 1fe533424e..ffd0ac9930 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -86,6 +86,9 @@ private void BroadcastMessage(MessageCommand command, ISerializable payload = nu /// The message to be broadcasted. private void BroadcastMessage(Message message) => SendToRemoteNodes(message); + /// + /// Send message to all the RemoteNodes connected to other nodes, faster than ActorSelection. + /// private void SendToRemoteNodes(object message) { foreach (var connection in RemoteNodes.Keys)