Hush

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ HEAD  →  ?path2? @ 1
/trunk/Hush/Discovery/Discovery.cs
@@ -14,16 +14,16 @@
NatDiscoverer = new NatDiscoverer();
}
 
public Discovery(string mappingName, CancellationToken cancellationToken,
public Discovery(string mappingName, CancellationTokenSource cancellationTokenSource,
TaskScheduler taskScheduler) : this()
{
MappingName = mappingName;
CancellationToken = cancellationToken;
CancellationTokenSource = cancellationTokenSource;
TaskScheduler = taskScheduler;
}
 
private static string MappingName { get; set; }
private static CancellationToken CancellationToken { get; set; }
private static CancellationTokenSource CancellationTokenSource { get; set; }
private static NatDiscoverer NatDiscoverer { get; set; }
private static TaskScheduler TaskScheduler { get; set; }
 
@@ -74,7 +74,7 @@
UpnPCancellationTokenSource = new CancellationTokenSource();
var linkedCancellationTokenSource =
CancellationTokenSource.CreateLinkedTokenSource(UpnPCancellationTokenSource.Token,
CancellationToken);
CancellationTokenSource.Token);
var device = await NatDiscoverer.DiscoverDeviceAsync(PortMapper.Upnp, linkedCancellationTokenSource);
await device.DeletePortMapAsync(new Mapping(Protocol.Tcp, port, port, MappingName));
 
@@ -93,7 +93,7 @@
UpnPCancellationTokenSource = new CancellationTokenSource();
var linkedCancellationTokenSource =
CancellationTokenSource.CreateLinkedTokenSource(UpnPCancellationTokenSource.Token,
CancellationToken);
CancellationTokenSource.Token);
var device = await NatDiscoverer.DiscoverDeviceAsync(PortMapper.Upnp, linkedCancellationTokenSource);
await device.CreatePortMapAsync(new Mapping(Protocol.Tcp, port, port, MappingName));
 
@@ -101,9 +101,9 @@
}
catch (Exception ex)
{
await Task.Delay(0, CancellationToken).ContinueWith(_ =>
await Task.Delay(0, CancellationTokenSource.Token).ContinueWith(_ =>
OnPortMapFailed?.Invoke(this, new DiscoveryFailedEventArgs(DiscoveryType.Upnp, ex)),
CancellationToken, TaskContinuationOptions.None, TaskScheduler);
CancellationTokenSource.Token, TaskContinuationOptions.None, TaskScheduler);
 
return false;
}
@@ -116,7 +116,7 @@
PmpCancellationTokenSource = new CancellationTokenSource();
var linkedCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(
PmpCancellationTokenSource.Token,
CancellationToken);
CancellationTokenSource.Token);
var device = await NatDiscoverer.DiscoverDeviceAsync(PortMapper.Pmp, linkedCancellationTokenSource);
await device.DeletePortMapAsync(new Mapping(Protocol.Tcp, port, port, MappingName));
return true;
@@ -134,7 +134,7 @@
PmpCancellationTokenSource = new CancellationTokenSource();
var linkedCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(
PmpCancellationTokenSource.Token,
CancellationToken);
CancellationTokenSource.Token);
var device = await NatDiscoverer.DiscoverDeviceAsync(PortMapper.Pmp, linkedCancellationTokenSource);
await device.CreatePortMapAsync(new Mapping(Protocol.Tcp, port, port, MappingName));
return true;
@@ -141,9 +141,9 @@
}
catch (Exception ex)
{
await Task.Delay(0, CancellationToken).ContinueWith(_ =>
await Task.Delay(0, CancellationTokenSource.Token).ContinueWith(_ =>
OnPortMapFailed?.Invoke(this, new DiscoveryFailedEventArgs(DiscoveryType.Pmp, ex)),
CancellationToken, TaskContinuationOptions.None, TaskScheduler);
CancellationTokenSource.Token, TaskContinuationOptions.None, TaskScheduler);
 
return false;
}