Skip to content

Commit

Permalink
add dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
bettybao1209 committed Mar 30, 2020
1 parent 1bb7479 commit 007ff3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions src/RpcServer/RelayActor.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using Akka.Actor;
using Neo.Network.P2P.Payloads;
using System.Collections.Generic;
using static Neo.Ledger.Blockchain;

namespace Neo.Plugins
{
public class RelayActor : UntypedActor
{
private readonly IActorRef blockchain;
private IInventory inventory;
private IActorRef sender;
private readonly NeoSystem neoSystem;
private readonly Dictionary<UInt256, IActorRef> senders = new Dictionary<UInt256, IActorRef>();

public RelayActor(IActorRef blockchain)
public RelayActor(NeoSystem neoSystem)
{
this.blockchain = blockchain;
this.neoSystem = neoSystem;
Context.System.EventStream.Subscribe(Self, typeof(RelayResult));
}

Expand All @@ -21,20 +21,23 @@ protected override void OnReceive(object message)
switch (message)
{
case IInventory inventory:
this.inventory = inventory;
this.sender = Sender;
blockchain.Tell(inventory);
this.senders.Add(inventory.Hash, Sender);
neoSystem.Blockchain.Tell(inventory);
break;
case RelayResult reason:
if (reason.Inventory.Hash.Equals(inventory.Hash))
sender.Tell(reason);
UInt256 hash = reason.Inventory.Hash;
if (senders.ContainsKey(reason.Inventory.Hash))
{
senders[hash].Tell(reason);
senders.Remove(hash);
}
break;
}
}

public static Props Props(IActorRef blockchain)
public static Props Props(NeoSystem neoSystem)
{
return Akka.Actor.Props.Create(() => new RelayActor(blockchain));
return Akka.Actor.Props.Create(() => new RelayActor(neoSystem));
}
}
}
2 changes: 1 addition & 1 deletion src/RpcServer/RpcServer.Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Neo.Plugins
{
partial class RpcServer
{
private static readonly IActorRef relayActor = System.ActorSystem.ActorOf(RelayActor.Props(System.Blockchain));
private static readonly IActorRef relayActor = System.ActorSystem.ActorOf(RelayActor.Props(System));

[RpcMethod]
private JObject GetConnectionCount(JArray _params)
Expand Down

0 comments on commit 007ff3e

Please sign in to comment.