Skip to content

Commit

Permalink
Declaring timeout variables for connection (#807)
Browse files Browse the repository at this point in the history
* Declaring timeout variables for connection

* Improving comments
  • Loading branch information
vncoelho authored Jun 11, 2019
1 parent 9b11d15 commit e497d95
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions neo/Network/P2P/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ public abstract class Connection : UntypedActor
private readonly IActorRef tcp;
private readonly WebSocket ws;
private bool disconnected = false;
/// <summary>
/// connection initial timeout (in seconds) before any package has been accepted
/// </summary>
private double connectionTimeoutLimitStart = 10;
/// <summary>
/// connection timeout (in seconds) after every `OnReceived(ByteString data)` event
/// </summary>
private double connectionTimeoutLimit = 60;

protected Connection(object connection, IPEndPoint remote, IPEndPoint local)
{
this.Remote = remote;
this.Local = local;
this.timer = Context.System.Scheduler.ScheduleTellOnceCancelable(TimeSpan.FromSeconds(10), Self, Timer.Instance, ActorRefs.NoSender);
this.timer = Context.System.Scheduler.ScheduleTellOnceCancelable(TimeSpan.FromSeconds(connectionTimeoutLimitStart), Self, Timer.Instance, ActorRefs.NoSender);
switch (connection)
{
case IActorRef tcp:
Expand Down Expand Up @@ -100,7 +108,7 @@ protected override void OnReceive(object message)
private void OnReceived(ByteString data)
{
timer.CancelIfNotNull();
timer = Context.System.Scheduler.ScheduleTellOnceCancelable(TimeSpan.FromMinutes(1), Self, Timer.Instance, ActorRefs.NoSender);
timer = Context.System.Scheduler.ScheduleTellOnceCancelable(TimeSpan.FromSeconds(connectionTimeoutLimit), Self, Timer.Instance, ActorRefs.NoSender);
try
{
OnData(data);
Expand Down

0 comments on commit e497d95

Please sign in to comment.