Skip to content

Commit ace747d

Browse files
author
Michael Catanzariti
committed
Revert useless change in ISearcher
Put back .Net 4.5 implementations that have been replace by .Net 3.5 implementations Fixed indentation
1 parent 37ca95a commit ace747d

File tree

6 files changed

+36
-25
lines changed

6 files changed

+36
-25
lines changed

Open.Nat/Discovery/ISearcher.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2525
//
2626

27-
using System;
2827
using System.Collections.Generic;
2928
using System.Net;
3029
using System.Threading;
@@ -33,11 +32,7 @@ namespace Open.Nat
3332
{
3433
internal interface ISearcher
3534
{
36-
#if NET45
3735
void Search(CancellationToken cancellationToken);
38-
#elif NET35
39-
void Search();
40-
#endif
4136
IEnumerable<NatDevice> Receive();
4237
NatDevice AnalyseReceivedResponse(IPAddress localAddress, byte[] response, IPEndPoint endpoint);
4338
}

Open.Nat/Discovery/Searcher.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ await Task.Factory.StartNew(_ =>
7474
return _devices;
7575
}
7676
#endif
77+
7778
private void Discover(CancellationToken cancelationToken)
7879
{
7980
if(DateTime.UtcNow < NextSearch) return;

Open.Nat/NatDiscoverer.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public async Task<NatDevice> DiscoverDeviceAsync(PortMapper portMapper, Cancella
108108
return device;
109109
}
110110
#endif
111+
111112
/// <summary>
112113
/// Discovers and returns all NAT devices for the specified type. If no NAT device is found it returns an empty enumerable
113114
/// </summary>
@@ -237,6 +238,7 @@ internal static void ReleaseSessionMappings()
237238

238239
private static void RenewMappings(object state)
239240
{
241+
#if NET35
240242
Task.Factory.StartNew(()=>
241243
{
242244
Task task = null;
@@ -246,6 +248,15 @@ private static void RenewMappings(object state)
246248
task = (task == null) ? device.RenewMappings() : task.ContinueWith(t => d.RenewMappings());
247249
}
248250
});
251+
#else
252+
Task.Factory.StartNew(async () =>
253+
{
254+
foreach (var device in Devices.Values)
255+
{
256+
await device.RenewMappings();
257+
}
258+
});
259+
#endif
249260
}
250261
}
251262
}

Open.Nat/Pmp/PmpNatDevice.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ public override Task<IEnumerable<Mapping>> GetAllMappingsAsync()
8686

8787
public override Task<IPAddress> GetExternalIPAsync()
8888
{
89+
#if NET35
8990
return Task.Factory.StartNew(() => _publicAddress)
91+
#else
92+
return Task.Run(() => _publicAddress)
93+
#endif
9094
.TimeoutAfter(TimeSpan.FromSeconds(4));
9195
}
9296

Open.Nat/Upnp/UpnpNatDevice.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@
3737
namespace Open.Nat
3838
{
3939
internal sealed class UpnpNatDevice : NatDevice
40-
{
41-
internal readonly UpnpNatDeviceInfo DeviceInfo;
40+
{
41+
internal readonly UpnpNatDeviceInfo DeviceInfo;
4242
private readonly SoapClient _soapClient;
4343

44-
internal UpnpNatDevice (UpnpNatDeviceInfo deviceInfo)
45-
{
44+
internal UpnpNatDevice(UpnpNatDeviceInfo deviceInfo)
45+
{
4646
Touch();
4747
DeviceInfo = deviceInfo;
4848
_soapClient = new SoapClient(DeviceInfo.ServiceControlUri, DeviceInfo.ServiceType);
49-
}
49+
}
5050

5151
#if NET35
5252
public override Task<IPAddress> GetExternalIPAsync()
@@ -65,7 +65,7 @@ public override Task<IPAddress> GetExternalIPAsync()
6565
}
6666
#else
6767
public override async Task<IPAddress> GetExternalIPAsync()
68-
{
68+
{
6969
NatDiscoverer.TraceSource.LogInfo("GetExternalIPAsync - Getting external IP address");
7070
var message = new GetExternalIPAddressRequestMessage();
7171
var responseData = await _soapClient
@@ -216,30 +216,30 @@ public override Task DeletePortMapAsync(Mapping mapping)
216216
}
217217
#else
218218
public override async Task DeletePortMapAsync(Mapping mapping)
219-
{
219+
{
220220
Guard.IsNotNull(mapping, "mapping");
221221

222222
if (mapping.PrivateIP.Equals(IPAddress.None)) mapping.PrivateIP = DeviceInfo.LocalAddress;
223223

224224
NatDiscoverer.TraceSource.LogInfo("DeletePortMapAsync - Deleteing port mapping {0}", mapping);
225225

226226
try
227-
{
227+
{
228228
var message = new DeletePortMappingRequestMessage(mapping);
229229
await _soapClient
230230
.InvokeAsync("DeletePortMapping", message.ToXml())
231231
.TimeoutAfter(TimeSpan.FromSeconds(4));
232232
UnregisterMapping(mapping);
233233
}
234-
catch (MappingException e)
235-
{
234+
catch (MappingException e)
235+
{
236236
if(e.ErrorCode != UpnpConstants.NoSuchEntryInArray) throw;
237-
}
237+
}
238238
}
239239
#endif
240240

241241
#if NET35
242-
public void GetGenericMappingAsync(int index, List<Mapping> mappings,
242+
public void GetGenericMappingAsync(int index, List<Mapping> mappings,
243243
TaskCompletionSource<IEnumerable<Mapping>> taskCompletionSource)
244244
{
245245
var message = new GetGenericPortMappingEntry(index);
@@ -314,9 +314,9 @@ public override Task<IEnumerable<Mapping>> GetAllMappingsAsync()
314314
}
315315
#else
316316
public override async Task<IEnumerable<Mapping>> GetAllMappingsAsync()
317-
{
317+
{
318318
var index = 0;
319-
var mappings = new List<Mapping>();
319+
var mappings = new List<Mapping>();
320320

321321
NatDiscoverer.TraceSource.LogInfo("GetAllMappingsAsync - Getting all mappings");
322322
while (true)
@@ -410,7 +410,7 @@ public override Task<Mapping> GetSpecificMappingAsync(Protocol protocol, int por
410410
}
411411
#else
412412
public override async Task<Mapping> GetSpecificMappingAsync (Protocol protocol, int port)
413-
{
413+
{
414414
Guard.IsTrue(protocol == Protocol.Tcp || protocol == Protocol.Udp, "protocol");
415415
Guard.IsInRange(port, 0, ushort.MaxValue, "port");
416416

@@ -448,12 +448,12 @@ public override async Task<Mapping> GetSpecificMappingAsync (Protocol protocol,
448448
}
449449
#endif
450450

451-
public override string ToString( )
451+
public override string ToString()
452452
{
453453
//GetExternalIP is blocking and can throw exceptions, can't use it here.
454-
return String.Format(
454+
return String.Format(
455455
"EndPoint: {0}\nControl Url: {1}\nService Type: {2}\nLast Seen: {3}",
456-
DeviceInfo.HostEndPoint, DeviceInfo.ServiceControlUri, DeviceInfo.ServiceType, LastSeen);
456+
DeviceInfo.HostEndPoint, DeviceInfo.ServiceControlUri, DeviceInfo.ServiceType, LastSeen);
457457
}
458-
}
458+
}
459459
}

Open.Nat/Utils/Extensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public static Task<TResult> TimeoutAfter<TResult>(this Task<TResult> task, TimeS
119119
"The operation has timed out. The network is broken, router has gone or is too busy.");
120120
}
121121
#else
122-
public static async Task<TResult> TimeoutAfter<TResult>(this Task<TResult> task, TimeSpan timeout)
122+
public static async Task<TResult> TimeoutAfter<TResult>(this Task<TResult> task, TimeSpan timeout)
123123
{
124124
#if DEBUG
125125
return await task;

0 commit comments

Comments
 (0)