コード例 #1
0
 protected internal NSMessageProcessor(ConnectivitySettings connectivitySettings)
 {
     if (connectivitySettings.HttpPoll)
     {
         Processor = new HttpSocketMessageProcessor(connectivitySettings, new NSMessagePool());
     }
     else
     {
         Processor = new TcpSocketMessageProcessor(connectivitySettings, new NSMessagePool());
     }
 }
コード例 #2
0
 protected internal NSMessageProcessor(ConnectivitySettings connectivitySettings)
 {
     if (connectivitySettings.HttpPoll)
     {
         Processor = new HttpSocketMessageProcessor(connectivitySettings, new NSMessagePool());
     }
     else
     {
         Processor = new TcpSocketMessageProcessor(connectivitySettings, new NSMessagePool());
     }
 }
コード例 #3
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="x"></param>
 public ConnectivitySettings(ConnectivitySettings x)
     : this(x.LocalHost, x.LocalPort, x.Host, x.Port, x.ProxyHost, x.Port, x.ProxyUsername, x.ProxyPassword, x.ProxyType, x.WebProxy)
 {
 }
コード例 #4
0
        private bool useLifespan; // Don't set lifespan until SignedIn

        #endregion Fields

        #region Constructors

        public HttpSocketMessageProcessor(ConnectivitySettings connectivitySettings, MessagePool messagePool)
            : base(connectivitySettings, messagePool)
        {
            gatewayIP = connectivitySettings.Host;
            host = gatewayIP;
            pollTimer.Elapsed += pollTimer_Elapsed;
            pollTimer.AutoReset = true;
        }
コード例 #5
0
ファイル: P2PSession.DC.cs プロジェクト: quynh68/msnp-sharp
        private static void ProcessDCRespInvite(SLPMessage message, NSMessageHandler ns, P2PSession startupSession)
        {
            MimeDictionary bodyValues = message.BodyValues;

            // Check the protocol
            if (bodyValues.ContainsKey("Bridge") &&
                bodyValues["Bridge"].ToString() == "TCPv1" &&
                bodyValues.ContainsKey("Listening") &&
                bodyValues["Listening"].ToString().ToLowerInvariant().IndexOf("true") >= 0)
            {
                Contact remote = ns.ContactList.GetContactWithCreate(message.FromEmailAccount, IMAddressInfoType.WindowsLive);
                Guid remoteGuid = message.FromEndPoint;

                DCNonceType dcNonceType;
                Guid remoteNonce = ParseDCNonce(message.BodyValues, out dcNonceType);
                bool hashed = (dcNonceType == DCNonceType.Sha1);
                Guid replyGuid = hashed ? remote.dcPlainKey : remoteNonce;

                IPEndPoint[] selectedPoint = SelectIPEndPoint(bodyValues, ns);

                if (selectedPoint != null && selectedPoint.Length > 0)
                {
                    P2PVersion ver = message.P2PVersion;

                    // We must connect to the remote client
                    ConnectivitySettings settings = new ConnectivitySettings();
                    settings.EndPoints = selectedPoint;
                    remote.DirectBridge = CreateDirectConnection(remote, remoteGuid, ver, settings, replyGuid, remoteNonce, hashed, ns, startupSession);

                    bool needConnectingEndpointInfo;
                    if (bodyValues.ContainsKey("NeedConnectingEndpointInfo") &&
                        bool.TryParse(bodyValues["NeedConnectingEndpointInfo"], out needConnectingEndpointInfo) &&
                        needConnectingEndpointInfo == true)
                    {
                        IPEndPoint ipep = ((TCPv1Bridge)remote.DirectBridge).LocalEndPoint;

                        string desc = "stroPdnAsrddAlanretnI4vPI";
                        char[] rev = ipep.ToString().ToCharArray();
                        Array.Reverse(rev);
                        string ipandport = new string(rev);

                        SLPRequestMessage slpResponseMessage = new SLPRequestMessage(message.Source, MSNSLPRequestMethod.ACK);
                        slpResponseMessage.Source = message.Target;
                        slpResponseMessage.Via = message.Via;
                        slpResponseMessage.CSeq = 0;
                        slpResponseMessage.CallId = Guid.Empty;
                        slpResponseMessage.MaxForwards = 0;
                        slpResponseMessage.ContentType = @"application/x-msnmsgr-transdestaddrupdate";

                        slpResponseMessage.BodyValues[desc] = ipandport;
                        slpResponseMessage.BodyValues["Nat-Trav-Msg-Type"] = "WLX-Nat-Trav-Msg-Updated-Connecting-Port";

                        P2PMessage msg = new P2PMessage(ver);
                        msg.InnerMessage = slpResponseMessage;

                        ns.SDGBridge.Send(null, remote, remoteGuid, msg);
                    }

                    return;
                }
            }

            if (startupSession != null)
                startupSession.DirectNegotiationFailed();
        }
コード例 #6
0
ファイル: P2PSession.DC.cs プロジェクト: quynh68/msnp-sharp
        private static TCPv1Bridge ListenForDirectConnection(
            Contact remote,
            Guid remoteGuid,
            NSMessageHandler nsMessageHandler,
            P2PVersion ver,
            P2PSession startupSession,
            IPAddress host, int port, Guid replyGuid, Guid remoteNonce, bool hashed)
        {
            ConnectivitySettings cs = new ConnectivitySettings();
            if (nsMessageHandler.ConnectivitySettings.LocalHost == string.Empty)
            {
                cs.LocalHost = host.ToString();
                cs.LocalPort = port;
            }
            else
            {
                cs.LocalHost = nsMessageHandler.ConnectivitySettings.LocalHost;
                cs.LocalPort = nsMessageHandler.ConnectivitySettings.LocalPort;
            }

            TCPv1Bridge tcpBridge = new TCPv1Bridge(cs, ver, replyGuid, remoteNonce, hashed, startupSession, nsMessageHandler, remote, remoteGuid);

            tcpBridge.Listen(IPAddress.Parse(cs.LocalHost), cs.LocalPort);

            Trace.WriteLineIf(Settings.TraceSwitch.TraceInfo, "Listening on " + cs.LocalHost + ":" + cs.LocalPort.ToString(CultureInfo.InvariantCulture));

            return tcpBridge;
        }
コード例 #7
0
ファイル: P2PSession.DC.cs プロジェクト: quynh68/msnp-sharp
        private static TCPv1Bridge CreateDirectConnection(Contact remote, Guid remoteGuid, P2PVersion ver, ConnectivitySettings cs, Guid replyGuid, Guid remoteNonce, bool hashed, NSMessageHandler nsMessageHandler, P2PSession startupSession)
        {
            string[] points = new string[cs.EndPoints.Length];

            for (int i = 0; i < points.Length; i++)
            {
                points[i] = cs.EndPoints[i].ToString();
            }

            TCPv1Bridge tcpBridge = new TCPv1Bridge(cs, ver, replyGuid, remoteNonce, hashed, startupSession, nsMessageHandler, remote, remoteGuid);

            Trace.WriteLineIf(Settings.TraceSwitch.TraceInfo, "Trying to setup direct connection with remote hosts " + string.Join(",", points));

            tcpBridge.Connect();

            return tcpBridge;
        }
コード例 #8
0
        /// <summary>
        /// Called when a XFR command has been received.
        /// </summary>
        /// <remarks>
        /// Indicates that the notification server has send us the location that we must switch to a new notification server.
        /// <code>XFR 0 [NS] [*.gateway.edge.messenger.live.com:Port] [G] [D] [HopString]</code>
        /// <code>XFR [Transaction] [NS] [IP:Port] [U] [D] [HopString]</code>
        /// </remarks>
        /// <param name="message"></param>
        protected virtual void OnXFRReceived(NSMessage message)
        {
            if ((string)message.CommandValues[0] == "NS")
            {
                // switch to a new notification server. That means reconnecting our current message processor.
                NSMessageProcessor processor = (NSMessageProcessor)MessageProcessor;
                // set new connectivity settings
                ConnectivitySettings newSettings = new ConnectivitySettings(processor.ConnectivitySettings);
                // disconnect first
                processor.Disconnect();
                processor = null;

                string[] hostAndPort = ((string)message.CommandValues[1]).Split(new char[] { ':' });
                bool isGateway = message.CommandValues[2].ToString() == "G";

                // Get hop count. Version: 1\r\nXfrCount: 2\r\n
                if (message.CommandValues.Count >= 5)
                {
                    string hopString = Encoding.ASCII.GetString(Convert.FromBase64String((string)message.CommandValues[4]));
                    Match m = Regex.Match(hopString, @"(\d+)").NextMatch();
                    if (m.Success)
                    {
                        hopCount = Convert.ToInt32(m.Value);
                    }
                }

                if (Settings.DisableHttpPolling && isGateway)
                {
                    newSettings.HttpPoll = false;
                    newSettings.Host = ConnectivitySettings.DefaultHost;
                    newSettings.Port = ConnectivitySettings.DefaultPort;
                }
                else
                {
                    newSettings.HttpPoll = isGateway;
                    newSettings.Host = hostAndPort[0];
                    newSettings.Port = int.Parse(hostAndPort[1], System.Globalization.CultureInfo.InvariantCulture);
                }

                // Register events and handler,
                NSMessageProcessor mp = new NSMessageProcessor(newSettings);
                this.MessageProcessor = mp;
                mp.Connect(); // then reconnect. The login procedure will now start over again.
            }
        }
コード例 #9
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="x"></param>
 public ConnectivitySettings(ConnectivitySettings x)
     : this(x.LocalHost, x.LocalPort, x.Host, x.Port, x.ProxyHost, x.Port, x.ProxyUsername, x.ProxyPassword, x.ProxyType, x.WebProxy)
 {
 }
コード例 #10
0
 public TcpSocketMessageProcessor(ConnectivitySettings connectivitySettings, MessagePool messagePool)
     : base(connectivitySettings, messagePool)
 {
 }
コード例 #11
0
 protected SocketMessageProcessor(ConnectivitySettings connectivitySettings, MessagePool messagePool)
 {
     ConnectivitySettings = connectivitySettings;
     MessagePool = messagePool;
 }