public NatDeviceWrapper(INatDevice device, IPAddress externalIP, NatProtocol type) { this.Device = device; this.ExternalIP = externalIP; this.Type = type; this.TypeName = Type == NatProtocol.Upnp ? "UPnP" : "NAT-PMP"; }
internal DeviceEventUnknownArgs(IPAddress address, EndPoint endPoint, string data, NatProtocol protocol) { Address = address; Data = data; EndPoint = endPoint; Protocol = protocol; }
static ISearcher GetOrCreate(NatProtocol protocol) { if (!Searchers.TryGetValue(protocol, out ISearcher searcher)) { searcher = protocol == NatProtocol.Pmp ? (ISearcher)PmpSearcher.Create() : UpnpSearcher.Create(); searcher.DeviceFound += HandleDeviceFound; searcher.UnknownDeviceFound += HandleUnknownDeviceFound; Searchers[protocol] = searcher; } return(searcher); }
/// <summary> /// Sends a single (non-periodic) message to the specified IP address to see if it supports the /// specified port mapping protocol, and begin listening indefinitely for responses. /// </summary> /// <param name="gatewayAddress">The IP address</param> /// <param name="type"></param> public static void Search(IPAddress gatewayAddress, NatProtocol type) { lock (Locker) { if (type == NatProtocol.Pmp) { PmpSearcher.Instance.SearchAsync(gatewayAddress).FireAndForget(); } else if (type == NatProtocol.Upnp) { UpnpSearcher.Instance.SearchAsync(gatewayAddress).FireAndForget(); } else { throw new InvalidOperationException("Unsuported type given"); } } }
public static async Task Handle(IPAddress localAddress, UpnpDeviceInfo deviceInfo, IPEndPoint endpoint, NatProtocol protocol) { switch (protocol) { case NatProtocol.Upnp: var searcher = new UpnpSearcher(Logger, HttpClient); searcher.DeviceFound += Searcher_DeviceFound; await searcher.Handle(localAddress, deviceInfo, endpoint).ConfigureAwait(false); break; default: throw new ArgumentException("Unexpected protocol: " + protocol); } }
public static void Handle(IPAddress localAddress, UpnpDeviceInfo deviceInfo, IPEndPoint endpoint, NatProtocol protocol) { switch (protocol) { case NatProtocol.Upnp: UpnpSearcher.Instance.Handle(localAddress, deviceInfo, endpoint); break; default: throw new ArgumentException("Unexpected protocol: " + protocol); } }
public static void Handle(IPAddress localAddress, byte[] response, IPEndPoint endpoint, NatProtocol protocol) { switch (protocol) { case NatProtocol.Upnp: UpnpSearcher.Instance.Handle(localAddress, response, endpoint); break; case NatProtocol.Pmp: PmpSearcher.Instance.Handle(localAddress, response, endpoint); break; default: throw new ArgumentException("Unexpected protocol: " + protocol); } }
public Task Handle(IPAddress localAddress, UpnpDeviceInfo deviceInfo, IPEndPoint endpoint, NatProtocol protocol) { switch (protocol) { case NatProtocol.Upnp: var searcher = new UpnpSearcher(Logger, HttpClient); searcher.DeviceFound += Searcher_DeviceFound; return(searcher.Handle(localAddress, deviceInfo, endpoint)); default: throw new ArgumentException("Unexpected protocol: " + protocol); } }
public static void Handle(IPAddress localAddress, byte[] response, IPEndPoint endpoint, NatProtocol protocol) { switch (protocol) { case NatProtocol.Upnp: //UpnpSearcher.Instance.Handle(localAddress, response, endpoint); break; case NatProtocol.Pmp: PmpSearcher.Instance.Handle(localAddress, response, endpoint); break; default: throw new ArgumentException("Unexpected protocol: " + protocol); } }
protected NatDevice(IPEndPoint deviceEndpoint, NatProtocol natProtocol) { LastSeen = DateTime.UtcNow; DeviceEndpoint = deviceEndpoint; NatProtocol = natProtocol; }
/// <summary> /// Sends a single (non-periodic) message to the specified IP address to see if it supports the /// specified port mapping protocol, and begin listening indefinitely for responses. /// </summary> /// <param name="gatewayAddress">The IP address</param> /// <param name="type"></param> public static void Search(IPAddress gatewayAddress, NatProtocol type) { lock (Locker) GetOrCreate(type).BeginSearching(gatewayAddress); }
/// <summary> /// Parses a message received elsewhere. /// </summary> /// <param name="type">Type of message.</param> /// <param name="localAddress"></param> /// <param name="content"></param> /// <param name="source"></param> public static void ParseMessage(NatProtocol type, IPAddress localAddress, byte[] content, IPEndPoint source) { lock (Locker) GetOrCreate(type).HandleMessageReceived(localAddress, content, source, CancellationToken.None); }
protected void RaiseDeviceUnknown(IPAddress address, EndPoint remote, string response, NatProtocol protocol) { UnknownDeviceFound?.Invoke(this, new DeviceEventUnknownArgs(address, remote, response, protocol)); }
/// <summary> /// Sends a single (non-periodic) message to the specified IP address to see if it supports the /// specified port mapping protocol, and begin listening indefinitely for responses. /// </summary> /// <param name="gatewayAddress">The IP address</param> /// <param name="type"></param> public static void Search(IPAddress gatewayAddress, NatProtocol type) { lock (Locker) GetOrCreate(type).SearchAsync(gatewayAddress).FireAndForget(); }