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

Add relayresult #200

Closed
wants to merge 28 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add dictionary
bettybao1209 committed Mar 30, 2020

Verified

This commit was signed with the committer’s verified signature.
renovate-bot Mend Renovate
commit 007ff3e811a7ac9ef55274a2e78760cc72149e81
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));
}

@@ -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
@@ -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)