mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-21 13:10:45 +02:00
simplify PmpNatDevice
This commit is contained in:
parent
a7339f23a5
commit
5dca85fe15
|
@ -52,93 +52,12 @@ namespace Mono.Nat.Pmp
|
||||||
get { return localAddress; }
|
get { return localAddress; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IPAddress GetExternalIP ()
|
|
||||||
{
|
|
||||||
return publicAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Task CreatePortMap(Mapping mapping)
|
public override Task CreatePortMap(Mapping mapping)
|
||||||
{
|
{
|
||||||
CreatePortMap(mapping, true);
|
CreatePortMap(mapping, true);
|
||||||
return Task.FromResult(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)
|
private void StartOp(ref AsyncResult result, AsyncCallback callback, object asyncState)
|
||||||
{
|
{
|
||||||
if (pendingOp == true)
|
if (pendingOp == true)
|
||||||
|
@ -165,12 +84,6 @@ namespace Mono.Nat.Pmp
|
||||||
pendingOp = false;
|
pendingOp = false;
|
||||||
actual = null;
|
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)
|
public override bool Equals(object obj)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue