示例#1
0
 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;
 }
示例#3
0
        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);
        }
示例#4
0
 /// <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");
         }
     }
 }
示例#5
0
        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);
            }
        }
示例#6
0
 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);
     }
 }
示例#7
0
	    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);
	        }
        }
示例#8
0
        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);
            }
        }
示例#9
0
        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);
            }
        }
示例#10
0
 protected NatDevice(IPEndPoint deviceEndpoint, NatProtocol natProtocol)
 {
     LastSeen       = DateTime.UtcNow;
     DeviceEndpoint = deviceEndpoint;
     NatProtocol    = natProtocol;
 }
示例#11
0
 /// <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);
 }
示例#12
0
 /// <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);
 }
        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);
            }
        }
示例#14
0
 protected void RaiseDeviceUnknown(IPAddress address, EndPoint remote, string response, NatProtocol protocol)
 {
     UnknownDeviceFound?.Invoke(this, new DeviceEventUnknownArgs(address, remote, response, protocol));
 }
示例#15
0
 /// <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();
 }