Ejemplo n.º 1
0
        public override async Task CreatePortMapAsync(Mapping mapping)
        {
            Guard.IsNotNull(mapping, "mapping");
            if (mapping.PrivateIP.Equals(IPAddress.None))
            {
                mapping.PrivateIP = DeviceInfo.LocalAddress;
            }

            NatDiscoverer.TraceSource.LogInfo("CreatePortMapAsync - Creating port mapping {0}", mapping);
            bool retry = false;

            try {
                var message = new CreatePortMappingRequestMessage(mapping);
                await _soapClient
                .InvokeAsync("AddPortMapping", message.ToXml())
                .TimeoutAfter(TimeSpan.FromSeconds(4));

                RegisterMapping(mapping);
            } catch (MappingException me) {
                switch (me.ErrorCode)
                {
                case UpnpConstants.OnlyPermanentLeasesSupported:
                    NatDiscoverer.TraceSource.LogWarn("Only Permanent Leases Supported - There is no warranty it will be closed");
                    mapping.Lifetime = 0;
                    // We create the mapping anyway. It must be released on shutdown.
                    mapping.LifetimeType = MappingLifetime.ForcedSession;
                    retry = true;
                    break;

                case UpnpConstants.SamePortValuesRequired:
                    NatDiscoverer.TraceSource.LogWarn("Same Port Values Required - Using internal port {0}", mapping.PrivatePort);
                    mapping.PublicPort = mapping.PrivatePort;
                    retry = true;
                    break;

                case UpnpConstants.RemoteHostOnlySupportsWildcard:
                    NatDiscoverer.TraceSource.LogWarn("Remote Host Only Supports Wildcard");
                    mapping.PublicIP = IPAddress.None;
                    retry            = true;
                    break;

                case UpnpConstants.ExternalPortOnlySupportsWildcard:
                    NatDiscoverer.TraceSource.LogWarn("External Port Only Supports Wildcard");
                    throw;

                case UpnpConstants.ConflictInMappingEntry:
                    NatDiscoverer.TraceSource.LogWarn("Conflict with an already existing mapping");
                    throw;

                default:
                    throw;
                }
            }
            if (retry)
            {
                await CreatePortMapAsync(mapping);
            }
        }
Ejemplo n.º 2
0
        public override async Task CreatePortMapAsync(Mapping mapping)
        {
            Guard.IsNotNull(mapping, "mapping");
            if(mapping.PrivateIP.Equals(IPAddress.None)) mapping.PrivateIP =  DeviceInfo.LocalAddress;

            NatDiscoverer.TraceSource.LogInfo("CreatePortMapAsync - Creating port mapping {0}", mapping);
            try
            {
                var message = new CreatePortMappingRequestMessage(mapping);
                await _soapClient
                    .InvokeAsync("AddPortMapping", message.ToXml())
                    .TimeoutAfter(TimeSpan.FromSeconds(4));
                RegisterMapping(mapping);
            }
            catch(MappingException me)
            {
                switch (me.ErrorCode)
                {
                    case UpnpConstants.OnlyPermanentLeasesSupported:
                        NatDiscoverer.TraceSource.LogWarn("Only Permanent Leases Supported - There is no warranty it will be closed");
                        mapping.Lifetime = 0;
                        // We create the mapping anyway. It must be released on shutdown.
                        mapping.LifetimeType = MappingLifetime.ForcedSession;
                        CreatePortMapAsync(mapping);
                        break;
                    case UpnpConstants.SamePortValuesRequired:
                        NatDiscoverer.TraceSource.LogWarn("Same Port Values Required - Using internal port {0}", mapping.PrivatePort);
                        mapping.PublicPort = mapping.PrivatePort;
                        CreatePortMapAsync(mapping);
                        break;
                    case UpnpConstants.RemoteHostOnlySupportsWildcard:
                        NatDiscoverer.TraceSource.LogWarn("Remote Host Only Supports Wildcard");
                        mapping.PublicIP = IPAddress.None;
                        CreatePortMapAsync(mapping);
                        break;
                    case UpnpConstants.ExternalPortOnlySupportsWildcard:
                        NatDiscoverer.TraceSource.LogWarn("External Port Only Supports Wildcard");
                        throw;
                    case UpnpConstants.ConflictInMappingEntry:
                        NatDiscoverer.TraceSource.LogWarn("Conflict with an already existing mapping");
                        throw;

                    default:
                        throw;
                }
            }
        }
Ejemplo n.º 3
0
        public override async Task CreatePortMapAsync(Mapping mapping)
        {
            Guard.IsNotNull(mapping, "mapping");

            mapping.PrivateIP = DeviceInfo.LocalAddress;
            try
            {
                var message = new CreatePortMappingRequestMessage(mapping);
                await _soapClient
                .InvokeAsync("AddPortMapping", message.ToXml())
                .TimeoutAfter(TimeSpan.FromSeconds(4));

                RegisterMapping(mapping);
            }
            catch (MappingException me)
            {
                switch (me.ErrorCode)
                {
                case UpnpConstants.OnlyPermanentLeasesSupported:
                    NatDiscoverer.TraceSource.LogWarn("Only Permanent Leases Supported - There is no warranty it will be closed");
                    mapping.Lifetime = 0;
                    // We create the mapping anyway. It must be released on shutdown.
                    mapping.LifetimeType = MappingLifetime.Session;
                    CreatePortMapAsync(mapping);
                    break;

                case UpnpConstants.SamePortValuesRequired:
                    NatDiscoverer.TraceSource.LogWarn("Same Port Values Required - Using internal port {0}", mapping.PrivatePort);
                    mapping.PublicPort = mapping.PrivatePort;
                    CreatePortMapAsync(mapping);
                    break;

                case UpnpConstants.RemoteHostOnlySupportsWildcard:
                    NatDiscoverer.TraceSource.LogWarn("Remote Host Only Supports Wildcard");
                    mapping.PublicIP = IPAddress.None;
                    CreatePortMapAsync(mapping);
                    break;
                    //case UpnpConstants.ExternalPortOnlySupportsWildcard:
                    //    NatUtility.TraceSource.LogWarn("External Port Only Supports Wildcard");
                    //    break;
                }
            }
        }