internal void SetStatus(NetConnectionStatus status, NetConnectionResult reason)
        {
            // user or library thread

            m_status = status;

            if (m_status == NetConnectionStatus.Connected)
            {
                m_timeoutDeadline = NetTime.Now + m_peerConfiguration.m_connectionTimeout;
                m_peer.LogVerbose("Timeout deadline initialized to  " + m_timeoutDeadline);
            }

            if (m_peerConfiguration.IsMessageTypeEnabled(NetIncomingMessageType.StatusChanged))
            {
                if (m_outputtedStatus != status)
                {
                    NetIncomingMessage info = m_peer.CreateIncomingMessage(NetIncomingMessageType.StatusChanged, 1);
                    info.m_senderConnection = this;
                    info.m_senderEndPoint   = m_remoteEndPoint;
                    info.Write((byte)m_status);
                    info.Write((byte)reason);
                    m_peer.ReleaseMessage(info);
                    m_outputtedStatus = status;
                }
            }
            else
            {
                // app dont want those messages, update visible status immediately
                m_outputtedStatus = m_status;
                m_visibleStatus   = m_status;
            }
        }
Exemplo n.º 2
0
        internal void SetStatus(NetConnectionStatus status, string reason)
        {
            // user or library thread

            if (status == m_status)
            {
                return;
            }
            m_status = status;
            if (reason == null)
            {
                reason = string.Empty;
            }

            if (m_status == NetConnectionStatus.Connected)
            {
                m_timeoutDeadline = (float)NetTime.Now + m_peerConfiguration.m_connectionTimeout;
                m_peer.LogVerbose("Timeout deadline initialized to  " + m_timeoutDeadline);
            }

            if (m_peerConfiguration.IsMessageTypeEnabled(NetIncomingMessageType.StatusChanged))
            {
                NetIncomingMessage info = m_peer.CreateIncomingMessage(NetIncomingMessageType.StatusChanged, 4 + reason.Length + (reason.Length > 126 ? 2 : 1));
                info.m_senderConnection = this;
                info.m_senderEndpoint   = m_remoteEndpoint;
                info.Write((byte)m_status);
                info.Write(reason);
                m_peer.ReleaseMessage(info);
            }
            else
            {
                // app dont want those messages, update visible status immediately
                m_visibleStatus = m_status;
            }
        }
Exemplo n.º 3
0
        internal void ExtractServiceUrl(NetEndPoint sender, string resp)
        {
#if !DEBUG
            try
            {
#endif
            XmlDocument desc = new XmlDocument();
            using (var response = WebRequest.Create(resp).GetResponse())
                desc.Load(response.GetResponseStream());

            XmlNamespaceManager nsMgr = new XmlNamespaceManager(desc.NameTable);
            nsMgr.AddNamespace("tns", "urn:schemas-upnp-org:device-1-0");
            XmlNode typen = desc.SelectSingleNode("//tns:device/tns:deviceType/text()", nsMgr);
            if (!typen.Value.Contains("InternetGatewayDevice"))
            {
                return;
            }

            string m_serviceName = "WANIPConnection";
            XmlNode node         = desc.SelectSingleNode("//tns:service[tns:serviceType=\"urn:schemas-upnp-org:service:" + m_serviceName + ":1\"]/tns:controlURL/text()", nsMgr);
            if (node == null)
            {
                // Try another service name
                m_serviceName = "WANPPPConnection";
                node          = desc.SelectSingleNode("//tns:service[tns:serviceType=\"urn:schemas-upnp-org:service:" + m_serviceName + ":1\"]/tns:controlURL/text()", nsMgr);
                if (node == null)
                {
                    return;
                }
            }

            lock (m_discoveryResults) {
                m_discoveryResults.Add(new DiscoveryResult {
                    Sender      = sender,
                    ServiceName = m_serviceName,
                    ServiceUrl  = CombineUrls(resp, node.Value),
                });
            }

            m_peer.LogDebug("UPnP service ready");
            //m_status = UPnPStatus.Available;
            //m_discoveryComplete.Set();
#if !DEBUG
        }

        catch
        {
            m_peer.LogVerbose("Exception ignored trying to parse UPnP XML response");
            return;
        }
#endif
        }
Exemplo n.º 4
0
        internal void SetStatus(NetConnectionStatus status, NetReason reason)
        {
            // user or library thread

            m_status = status;

            if (m_status == NetConnectionStatus.Connected)
            {
                m_timeoutDeadline = NetTime.Now + m_peerConfiguration.m_connectionTimeout;
                m_peer.LogVerbose("Timeout deadline initialized to  " + m_timeoutDeadline);
            }

            if (m_peerConfiguration.IsMessageTypeEnabled(NetIncomingMessageType.StatusChanged))
            {
                if (m_outputtedStatus != status)
                {
                    var outgoingMessage = reason.Message;
                    var info            = m_peer.CreateIncomingMessage(NetIncomingMessageType.StatusChanged, 1 + reason.Length);
                    info.Write((byte)m_status);
                    if (outgoingMessage != null)
                    {
                        Buffer.BlockCopy(outgoingMessage.m_data, 0, info.m_data, 1, outgoingMessage.LengthBytes);
                        info.m_bitLength = outgoingMessage.m_bitLength;
                    }
                    else
                    {
                        info.Write(reason.Text);
                    }

                    info.m_senderConnection = this;
                    info.m_senderEndPoint   = m_remoteEndPoint;
                    m_peer.ReleaseMessage(info);
                    m_outputtedStatus = status;
                }
            }
            else
            {
                // app dont want those messages, update visible status immediately
                m_outputtedStatus = m_status;
                m_visibleStatus   = m_status;
            }
        }