Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix akka warning #1533

Merged
merged 12 commits into from
Apr 10, 2020
1 change: 1 addition & 0 deletions src/neo/Network/P2P/Peer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ private void OnTcpConnected(IPEndPoint remote, IPEndPoint local)
Context.Watch(connection);
Sender.Tell(new Tcp.Register(connection));
ConnectedPeers.TryAdd(connection, remote);
connection.Tell(new RemoteNode.SendVersion());
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
27 changes: 17 additions & 10 deletions src/neo/Network/P2P/RemoteNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Neo.Network.P2P
public class RemoteNode : Connection
{
internal class Relay { public IInventory Inventory; }
internal class SendVersion { }

private readonly NeoSystem system;
private readonly IActorRef protocol;
Expand All @@ -38,16 +39,6 @@ public RemoteNode(NeoSystem system, object connection, IPEndPoint remote, IPEndP
this.system = system;
this.protocol = Context.ActorOf(ProtocolHandler.Props(system));
LocalNode.Singleton.RemoteNodes.TryAdd(Self, this);

var capabilities = new List<NodeCapability>
{
new FullNodeCapability(Blockchain.Singleton.Height)
};

if (LocalNode.Singleton.ListenerTcpPort > 0) capabilities.Add(new ServerCapability(NodeCapabilityType.TcpServer, (ushort)LocalNode.Singleton.ListenerTcpPort));
if (LocalNode.Singleton.ListenerWsPort > 0) capabilities.Add(new ServerCapability(NodeCapabilityType.WsServer, (ushort)LocalNode.Singleton.ListenerWsPort));

SendMessage(Message.Create(MessageCommand.Version, VersionPayload.Create(LocalNode.Nonce, LocalNode.UserAgent, capabilities.ToArray())));
}

/// <summary>
Expand Down Expand Up @@ -153,9 +144,25 @@ protected override void OnReceive(object message)
case PingPayload payload:
OnPingPayload(payload);
break;
case SendVersion _:
OnSendVersion();
break;
}
}

private void OnSendVersion()
{
var capabilities = new List<NodeCapability>
{
new FullNodeCapability(Blockchain.Singleton.Height)
};

if (LocalNode.Singleton.ListenerTcpPort > 0) capabilities.Add(new ServerCapability(NodeCapabilityType.TcpServer, (ushort)LocalNode.Singleton.ListenerTcpPort));
if (LocalNode.Singleton.ListenerWsPort > 0) capabilities.Add(new ServerCapability(NodeCapabilityType.WsServer, (ushort)LocalNode.Singleton.ListenerWsPort));

SendMessage(Message.Create(MessageCommand.Version, VersionPayload.Create(LocalNode.Nonce, LocalNode.UserAgent, capabilities.ToArray())));
}
erikzhang marked this conversation as resolved.
Show resolved Hide resolved

private void OnPingPayload(PingPayload payload)
{
if (payload.LastBlockIndex > LastBlockIndex)
Expand Down
4 changes: 0 additions & 4 deletions tests/neo.UnitTests/Network/P2P/UT_RemoteNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public void RemoteNode_Test_Abort_DifferentMagic()
var connectionTestProbe = CreateTestProbe();
var remoteNodeActor = ActorOfAsTestActorRef(() => new RemoteNode(testBlockchain, connectionTestProbe, null, null));

connectionTestProbe.ExpectMsg<Tcp.Write>();

var payload = new VersionPayload()
{
UserAgent = "".PadLeft(1024, '0'),
Expand All @@ -58,8 +56,6 @@ public void RemoteNode_Test_Accept_IfSameMagic()
var connectionTestProbe = CreateTestProbe();
var remoteNodeActor = ActorOfAsTestActorRef(() => new RemoteNode(testBlockchain, connectionTestProbe, null, null));

connectionTestProbe.ExpectMsg<Tcp.Write>();

var payload = new VersionPayload()
{
UserAgent = "Unit Test".PadLeft(1024, '0'),
Expand Down