Skip to content

Commit

Permalink
Revert "CreateActor"
Browse files Browse the repository at this point in the history
This reverts commit 3ad56f7.
  • Loading branch information
igormcoelho committed Jul 1, 2019
1 parent 3ad56f7 commit 3f3e38b
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 36 deletions.
6 changes: 2 additions & 4 deletions neo.UnitTests/UT_RemoteNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public void RemoteNode_Test_Abort_DifferentMagic()
var testProbe = CreateTestProbe();
var connectionTestProbe = CreateTestProbe();
var protocolActor = ActorOfAsTestActorRef<ProtocolHandler>(() => new ProtocolHandler(testBlockchain));
// TODO: setup 'testBlockchain' mock CreateActor to return desired 'protocolActor' (using ActorOfAsTestActorRef)
var remoteNodeActor = ActorOfAsTestActorRef<RemoteNode>(() => new RemoteNode(testBlockchain, connectionTestProbe, null, null));
var remoteNodeActor = ActorOfAsTestActorRef<RemoteNode>(() => new RemoteNode(testBlockchain, connectionTestProbe, null, null, protocolActor));

connectionTestProbe.ExpectMsg<Tcp.Write>();

Expand Down Expand Up @@ -61,8 +60,7 @@ public void RemoteNode_Test_Accept_IfSameMagic()
var testProbe = CreateTestProbe();
var connectionTestProbe = CreateTestProbe();
var protocolActor = ActorOfAsTestActorRef<ProtocolHandler>(() => new ProtocolHandler(testBlockchain));
// TODO: setup 'testBlockchain' mock CreateActor to return desired 'protocolActor' (using ActorOfAsTestActorRef)
var remoteNodeActor = ActorOfAsTestActorRef<RemoteNode>(() => new RemoteNode(testBlockchain, connectionTestProbe, null, null));
var remoteNodeActor = ActorOfAsTestActorRef<RemoteNode>(() => new RemoteNode(testBlockchain, connectionTestProbe, null, null, protocolActor));

connectionTestProbe.ExpectMsg<Tcp.Write>();

Expand Down
2 changes: 1 addition & 1 deletion neo/Consensus/ConsensusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ protected override void PostStop()

public static Props Props(IActorRef localNode, IActorRef taskManager, Store store, Wallet wallet)
{
return Akka.Actor.Props.Create(() => new ConsensusService(localNode, taskManager, store, wallet));
return Akka.Actor.Props.Create(() => new ConsensusService(localNode, taskManager, store, wallet)).WithMailbox("consensus-service-mailbox");
}

private void RequestChangeView()
Expand Down
2 changes: 1 addition & 1 deletion neo/Ledger/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ protected override void PostStop()

public static Props Props(NeoSystem system, Store store)
{
return Akka.Actor.Props.Create(() => new Blockchain(system, store));
return Akka.Actor.Props.Create(() => new Blockchain(system, store)).WithMailbox("blockchain-mailbox");
}

private void SaveHeaderHashList(Snapshot snapshot = null)
Expand Down
22 changes: 4 additions & 18 deletions neo/NeoSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Akka.Actor;
using Akka.Configuration;
using Akka.IO;
using Neo.Consensus;
using Neo.Ledger;
using Neo.Network.P2P;
Expand All @@ -10,8 +8,6 @@
using Neo.Wallets;
using System;
using System.Net;
using System.Linq;
using System.Linq.Expressions;

namespace Neo
{
Expand All @@ -30,16 +26,6 @@ public class NeoSystem : IDisposable
public IActorRef Consensus { get; private set; }
public RpcServer RpcServer { get; private set; }

public IActorRef CreateActor(Props props, string mailbox = null, string actorName = null)
{
if(mailbox != null)
props = props.WithMailbox(mailbox);
if(actorName != null)
return this.ActorSystem.ActorOf(props, actorName);
else
return this.ActorSystem.ActorOf(props);
}

private readonly Store store;
private ChannelsConfig start_message = null;
private bool suspend = false;
Expand All @@ -48,9 +34,9 @@ public NeoSystem(Store store)
{
this.store = store;
Plugin.LoadPlugins(this);
this.Blockchain = CreateActor(Ledger.Blockchain.Props(this, store), "blockchain-mailbox");
this.LocalNode = CreateActor(Network.P2P.LocalNode.Props(this));
this.TaskManager = CreateActor(Network.P2P.TaskManager.Props(this), "task-manager-mailbox");
this.Blockchain = ActorSystem.ActorOf(Ledger.Blockchain.Props(this, store));
this.LocalNode = ActorSystem.ActorOf(Network.P2P.LocalNode.Props(this));
this.TaskManager = ActorSystem.ActorOf(Network.P2P.TaskManager.Props(this));
Plugin.NotifyPluginsLoadedAfterSystemConstructed();
}

Expand Down Expand Up @@ -83,7 +69,7 @@ internal void ResumeNodeStartup()

public void StartConsensus(Wallet wallet, Store consensus_store = null, bool ignoreRecoveryLogs = false)
{
Consensus = CreateActor(ConsensusService.Props(this.LocalNode, this.TaskManager, consensus_store ?? store, wallet), "consensus-service-mailbox");
Consensus = ActorSystem.ActorOf(ConsensusService.Props(this.LocalNode, this.TaskManager, consensus_store ?? store, wallet));
Consensus.Tell(new ConsensusService.Start { IgnoreRecoveryLogs = ignoreRecoveryLogs }, Blockchain);
}

Expand Down
4 changes: 2 additions & 2 deletions neo/Network/P2P/LocalNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ public static Props Props(NeoSystem system)
return Akka.Actor.Props.Create(() => new LocalNode(system));
}

protected override IActorRef ProtocolActor(NeoSystem system, string actorName, object connection, IPEndPoint remote, IPEndPoint local)
protected override Props ProtocolProps(object connection, IPEndPoint remote, IPEndPoint local)
{
return system.CreateActor(RemoteNode.Props(system, connection, remote, local), "remote-node-mailbox", actorName);
return RemoteNode.Props(system, connection, remote, local);
}
}
}
8 changes: 3 additions & 5 deletions neo/Network/P2P/Peer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class Connect { public IPEndPoint EndPoint; public bool IsTrusted = false
private class Timer { }
private class WsConnected { public WebSocket Socket; public IPEndPoint Remote; public IPEndPoint Local; }

public NeoSystem neoSystem; // TODO: initialize

public const int DefaultMinDesiredConnections = 10;
public const int DefaultMaxConnections = DefaultMinDesiredConnections * 4;

Expand Down Expand Up @@ -193,7 +191,7 @@ private void OnTcpConnected(IPEndPoint remote, IPEndPoint local)
else
{
ConnectedAddresses[remote.Address] = count + 1;
IActorRef connection = ProtocolActor(neoSystem, $"connection_{Guid.NewGuid()}", Sender, remote, local);
IActorRef connection = Context.ActorOf(ProtocolProps(Sender, remote, local), $"connection_{Guid.NewGuid()}");
Context.Watch(connection);
Sender.Tell(new Tcp.Register(connection));
ConnectedPeers.TryAdd(connection, remote);
Expand Down Expand Up @@ -246,7 +244,7 @@ private void OnWsConnected(WebSocket ws, IPEndPoint remote, IPEndPoint local)
else
{
ConnectedAddresses[remote.Address] = count + 1;
ProtocolActor(neoSystem, $"connection_{Guid.NewGuid()}", ws, remote, local);
Context.ActorOf(ProtocolProps(ws, remote, local), $"connection_{Guid.NewGuid()}");
}
}

Expand All @@ -270,6 +268,6 @@ private async Task ProcessWebSocketAsync(HttpContext context)
});
}

protected abstract IActorRef ProtocolActor(NeoSystem system, string actorName, object connection, IPEndPoint remote, IPEndPoint local);
protected abstract Props ProtocolProps(object connection, IPEndPoint remote, IPEndPoint local);
}
}
2 changes: 1 addition & 1 deletion neo/Network/P2P/ProtocolHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private void OnVersionMessageReceived(VersionPayload payload)

public static Props Props(NeoSystem system)
{
return Akka.Actor.Props.Create(() => new ProtocolHandler(system));
return Akka.Actor.Props.Create(() => new ProtocolHandler(system)).WithMailbox("protocol-handler-mailbox");
}
}

Expand Down
7 changes: 4 additions & 3 deletions neo/Network/P2P/RemoteNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ internal class Relay { public IInventory Inventory; }
public uint LastBlockIndex { get; private set; } = 0;
public bool IsFullNode { get; private set; } = false;

public RemoteNode(NeoSystem system, object connection, IPEndPoint remote, IPEndPoint local)
public RemoteNode(NeoSystem system, object connection, IPEndPoint remote, IPEndPoint local, IActorRef protocolHandler)
: base(connection, remote, local)
{
this.system = system;
this.protocol = system.CreateActor(ProtocolHandler.Props(system), "protocol-handler-mailbox");
this.protocol = protocolHandler;
LocalNode.Singleton.RemoteNodes.TryAdd(Self, this);

var capabilities = new List<NodeCapability>
Expand Down Expand Up @@ -224,7 +224,8 @@ protected override void PostStop()

internal static Props Props(NeoSystem system, object connection, IPEndPoint remote, IPEndPoint local)
{
return Akka.Actor.Props.Create(() => new RemoteNode(system, connection, remote, local));
var protocol = system.ActorSystem.ActorOf(ProtocolHandler.Props(system));
return Akka.Actor.Props.Create(() => new RemoteNode(system, connection, remote, local, protocol)).WithMailbox("remote-node-mailbox");
}

private void SendMessage(Message message)
Expand Down
2 changes: 1 addition & 1 deletion neo/Network/P2P/TaskManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected override void PostStop()

public static Props Props(NeoSystem system)
{
return Akka.Actor.Props.Create(() => new TaskManager(system));
return Akka.Actor.Props.Create(() => new TaskManager(system)).WithMailbox("task-manager-mailbox");
}

private void RequestTasks(TaskSession session)
Expand Down

0 comments on commit 3f3e38b

Please sign in to comment.