mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-08 23:00:51 +02:00
simplify PmpNatDevice
This commit is contained in:
parent
a7339f23a5
commit
5dca85fe15
|
@ -52,93 +52,12 @@ namespace Mono.Nat.Pmp
|
|||
get { return localAddress; }
|
||||
}
|
||||
|
||||
public override IPAddress GetExternalIP ()
|
||||
{
|
||||
return publicAddress;
|
||||
}
|
||||
|
||||
public override Task CreatePortMap(Mapping mapping)
|
||||
{
|
||||
CreatePortMap(mapping, true);
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
public override IAsyncResult BeginCreatePortMap(Mapping mapping, AsyncCallback callback, object asyncState)
|
||||
{
|
||||
PortMapAsyncResult pmar = new PortMapAsyncResult (mapping.Protocol, mapping.PublicPort, PmpConstants.DefaultLeaseTime, callback, asyncState);
|
||||
ThreadPool.QueueUserWorkItem (delegate
|
||||
{
|
||||
try
|
||||
{
|
||||
CreatePortMap(pmar.Mapping, true);
|
||||
pmar.Complete();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pmar.Complete(e);
|
||||
}
|
||||
});
|
||||
return pmar;
|
||||
}
|
||||
|
||||
public override IAsyncResult BeginDeletePortMap (Mapping mapping, AsyncCallback callback, object asyncState)
|
||||
{
|
||||
PortMapAsyncResult pmar = new PortMapAsyncResult (mapping, callback, asyncState);
|
||||
ThreadPool.QueueUserWorkItem (delegate {
|
||||
try {
|
||||
CreatePortMap(pmar.Mapping, false);
|
||||
pmar.Complete();
|
||||
} catch (Exception e) {
|
||||
pmar.Complete(e);
|
||||
}
|
||||
});
|
||||
return pmar;
|
||||
}
|
||||
|
||||
public override void EndCreatePortMap (IAsyncResult result)
|
||||
{
|
||||
PortMapAsyncResult pmar = result as PortMapAsyncResult;
|
||||
pmar.AsyncWaitHandle.WaitOne ();
|
||||
}
|
||||
|
||||
public override void EndDeletePortMap (IAsyncResult result)
|
||||
{
|
||||
PortMapAsyncResult pmar = result as PortMapAsyncResult;
|
||||
pmar.AsyncWaitHandle.WaitOne ();
|
||||
}
|
||||
|
||||
public override IAsyncResult BeginGetAllMappings (AsyncCallback callback, object asyncState)
|
||||
{
|
||||
//NAT-PMP does not specify a way to get all port mappings
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
|
||||
public override IAsyncResult BeginGetExternalIP (AsyncCallback callback, object asyncState)
|
||||
{
|
||||
StartOp(ref externalIpResult, callback, asyncState);
|
||||
AsyncResult result = externalIpResult;
|
||||
result.Complete();
|
||||
return result;
|
||||
}
|
||||
|
||||
public override IAsyncResult BeginGetSpecificMapping (Protocol protocol, int port, AsyncCallback callback, object asyncState)
|
||||
{
|
||||
//NAT-PMP does not specify a way to get a specific port map
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
|
||||
public override Mapping[] EndGetAllMappings (IAsyncResult result)
|
||||
{
|
||||
//NAT-PMP does not specify a way to get all port mappings
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
|
||||
public override IPAddress EndGetExternalIP (IAsyncResult result)
|
||||
{
|
||||
EndOp(result, ref externalIpResult);
|
||||
return publicAddress;
|
||||
}
|
||||
|
||||
private void StartOp(ref AsyncResult result, AsyncCallback callback, object asyncState)
|
||||
{
|
||||
if (pendingOp == true)
|
||||
|
@ -165,12 +84,6 @@ namespace Mono.Nat.Pmp
|
|||
pendingOp = false;
|
||||
actual = null;
|
||||
}
|
||||
|
||||
public override Mapping EndGetSpecificMapping (IAsyncResult result)
|
||||
{
|
||||
//NAT-PMP does not specify a way to get a specific port map
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue