Skip to content

Commit

Permalink
improve RpcServer and Plugin system
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang committed Jun 29, 2018
1 parent e7bc99d commit 09878c1
Show file tree
Hide file tree
Showing 20 changed files with 365 additions and 189 deletions.
6 changes: 3 additions & 3 deletions neo/Consensus/ConsensusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void CheckExpectedView(byte view_number)

private bool CheckPolicy(Transaction tx)
{
foreach (PolicyPlugin plugin in PolicyPlugin.Instances)
foreach (IPolicyPlugin plugin in Plugin.Policies)
if (!plugin.CheckPolicy(tx))
return false;
return true;
Expand Down Expand Up @@ -111,7 +111,7 @@ private void CheckSignatures()
private void FillContext()
{
IEnumerable<Transaction> mem_pool = Blockchain.Singleton.GetMemoryPool().Where(p => CheckPolicy(p));
foreach (PolicyPlugin plugin in PolicyPlugin.Instances)
foreach (IPolicyPlugin plugin in Plugin.Policies)
mem_pool = plugin.Filter(mem_pool);
List<Transaction> transactions = mem_pool.ToList();
Fixed8 amount_netfee = Block.CalculateNetFee(transactions);
Expand Down Expand Up @@ -190,7 +190,7 @@ private void InitializeConsensus(byte view_number)

private void Log(string message, LogLevel level = LogLevel.Info)
{
LogPlugin.Log(nameof(ConsensusService), level, message);
Plugin.Log(nameof(ConsensusService), level, message);
}

private void OnChangeViewReceived(ConsensusPayload payload, ChangeView message)
Expand Down
26 changes: 16 additions & 10 deletions neo/NeoSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
using Neo.Network.P2P;
using Neo.Network.RPC;
using Neo.Persistence;
using Neo.Plugins;
using Neo.Wallets;
using System;

namespace Neo
{
public class NeoSystem : IDisposable
{
private readonly ActorSystem actorSystem = ActorSystem.Create(nameof(NeoSystem),
public readonly ActorSystem ActorSystem = ActorSystem.Create(nameof(NeoSystem),
$"akka {{ log-dead-letters = off }}" +
$"blockchain-mailbox {{ mailbox-type: \"{typeof(BlockchainMailbox).AssemblyQualifiedName}\" }}" +
$"task-manager-mailbox {{ mailbox-type: \"{typeof(TaskManagerMailbox).AssemblyQualifiedName}\" }}" +
Expand All @@ -26,32 +27,37 @@ public class NeoSystem : IDisposable

public NeoSystem(Store store)
{
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));
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.LoadPlugins(this);
}

public void Dispose()
{
rpcServer?.Dispose();
actorSystem.Dispose();
ActorSystem.Dispose();
}

public void StartConsensus(Wallet wallet)
{
consensus = actorSystem.ActorOf(ConsensusService.Props(this, wallet));
consensus = ActorSystem.ActorOf(ConsensusService.Props(this, wallet));
consensus.Tell(new ConsensusService.Start());
}

public void StartNode(int port)
public void StartNode(int port = 0, int ws_port = 0)
{
LocalNode.Tell(new Peer.Start { Port = port });
LocalNode.Tell(new Peer.Start
{
Port = port,
WsPort = ws_port
});
}

public void StartRpc(int port)
public void StartRpc(int port, string sslCert = null, string password = null)
{
rpcServer = new RpcServer(this);
rpcServer.Start(port);
rpcServer.Start(port, sslCert, password);
}
}
}
6 changes: 3 additions & 3 deletions neo/Network/P2P/Peer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Neo.Network.P2P
{
public abstract class Peer : UntypedActor
{
public class Start { public int Port; }
public class Start { public int Port; public int WsPort; }
public class Peers { public IEnumerable<IPEndPoint> EndPoints; }
public class Connect { public IPEndPoint EndPoint; }
private class Timer { }
Expand Down Expand Up @@ -85,7 +85,7 @@ protected override void OnReceive(object message)
switch (message)
{
case Start start:
OnStart(start.Port);
OnStart(start.Port, start.WsPort);

This comment has been minimized.

Copy link
@vncoelho

vncoelho Jul 2, 2018

Member

Is the WS being used now? If yes, will it be an option or we just should set the doors correctly?

The seed should keep point to the TCP/IP?

break;
case Timer _:
OnTimer();
Expand All @@ -108,7 +108,7 @@ protected override void OnReceive(object message)
}
}

private void OnStart(int port)
private void OnStart(int port, int ws_port)
{
ListenerPort = port;
timer = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(0, 5000, Context.Self, new Timer(), ActorRefs.NoSender);
Expand Down
Loading

0 comments on commit 09878c1

Please sign in to comment.