Skip to content

Commit

Permalink
gateway that only support permanent lease should work
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed May 24, 2014
1 parent 545e330 commit c9636d7
Showing 1 changed file with 38 additions and 24 deletions.
62 changes: 38 additions & 24 deletions NBitcoin/Protocol/UPnPLease.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,36 +101,50 @@ INatDevice Device
{
Description = RuleName
};
e.Device.CreatePortMap(Mapping);
try
{
e.Device.CreatePortMap(Mapping);
}
catch(MappingException ex)
{
if(ex.ErrorCode != 725) //Does not support lease
throw;
Mapping.Lifetime = 0;
e.Device.CreatePortMap(Mapping);
}
NodeServerTrace.Information("Port mapping added " + Mapping);
LogNextLeaseRenew();
Timer = new Timer(o =>
if(Mapping.Lifetime != 0)
{
if(isDisposed)
return;
using(Trace.Open(false))
LogNextLeaseRenew();
Timer = new Timer(o =>
{
try
{
e.Device.CreatePortMap(Mapping);
NodeServerTrace.Information("Port mapping renewed");
LogNextLeaseRenew();
}
catch(Exception ex)
{
NodeServerTrace.Error("Error when refreshing the port mapping with UPnP", ex);
}
finally
if(isDisposed)
return;
using(Trace.Open(false))
{
Timer.Change((int)CalculateNextRefresh().TotalMilliseconds, Timeout.Infinite);
try
{
e.Device.CreatePortMap(Mapping);
NodeServerTrace.Information("Port mapping renewed");
LogNextLeaseRenew();
}
catch(Exception ex)
{
NodeServerTrace.Error("Error when refreshing the port mapping with UPnP", ex);
}
finally
{
Timer.Change((int)CalculateNextRefresh().TotalMilliseconds, Timeout.Infinite);
}
}
}
});
Device = e.Device;
Timer.Change((int)CalculateNextRefresh().TotalMilliseconds, Timeout.Infinite);
});
Device = e.Device;
Timer.Change((int)CalculateNextRefresh().TotalMilliseconds, Timeout.Infinite);
}
else
NodeServerTrace.Error("Bitcoin node ports already used " + string.Join(",", BitcoinPorts), null);
}
else
NodeServerTrace.Error("Bitcoin node ports already used " + string.Join(",", BitcoinPorts), null);
}
catch(Exception ex)
{
Expand Down

0 comments on commit c9636d7

Please sign in to comment.