Exemplo n.º 1
0
        public ITransport GetSpecialTransport(string host, int port, string staticHost, int staticPort, TransportType type, short protocolDCId, byte[] protocolSecret, out bool isCreated)
        {
            var random      = TLLong.Random(); // Important! To ping multiple connections to one proxy, will be closed after first ping otherwise
            var proxyConfig = GetProxyConfig();
            var proxy       = proxyConfig != null?proxyConfig.GetProxy() : null;

            var key = string.Format("{0} {1} {2} {3} {4} {5}", host, port, protocolDCId, type, random, proxy != null ? string.Format("{0}:{1}", proxy.Server, proxy.Port) : string.Empty);

            if (_specialCache.ContainsKey(key))
            {
                isCreated = false;

#if LOG_REGISTRATION
                TLUtils.WriteLog(string.Format("Old transport {2} {0}:{1}", host, port, _specialCache[key].Id));
#endif
                return(_specialCache[key]);
            }

#if WINDOWS_PHONE
            if (type == TransportType.Http)
            {
                var transport = new HttpTransport(host, MTProtoTransportType.Special, GetProxyConfig());

                _specialCache.Add(key, transport);
                isCreated = true;
                return(transport);
                //transport.SetAddress(host, port, () => callback(transport));
            }
            else
#endif
            {
                var transport =
#if WIN_RT
                    new TcpTransportWinRT(host, port, staticHost, staticPort, MTProtoTransportType.Special, GetProxyConfig());
#elif NATIVE
                    new NativeTcpTransport(host, port, staticHost, staticPort, MTProtoTransportType.Special, protocolDCId, protocolSecret, GetProxyConfig());
#else
                    new TcpTransport(host, port, staticHost, staticPort, MTProtoTransportType.Special, GetProxyConfig());
#endif
                transport.Connecting     += OnConnecting;
                transport.Connected      += OnConnected;
                transport.ConnectionLost += OnConnectionLost;
                transport.CheckConfig    += OnCheckConfig;

#if LOG_REGISTRATION
                TLUtils.WriteLog(string.Format("New transport {2} {0}:{1}", host, port, transport.Id));
#endif
                TLUtils.WritePerformance(string.Format("  TCP: New transport {0}:{1}", host, port));

                _specialCache.Add(key, transport);
                isCreated = true;

                Debug.WriteLine("  TCP: New transport {0}:{1}", host, port);
                return(transport);
                //trasport.SetAddress(host, port, () => callback(trasport));
            }
        }
Exemplo n.º 2
0
        public ITransport GetSpecialTransport(string host, int port, TransportType type, out bool isCreated)
        {
            //if (host == "149.154.175.50")
            //{
            //    host = "149.154.175.51";
            //}

            var key = string.Format("{0} {1} {2}", host, port, type);

            if (_specialCache.ContainsKey(key))
            {
                isCreated = false;

#if LOG_REGISTRATION
                TLUtils.WriteLog(string.Format("Old transport {2} {0}:{1}", host, port, _specialCache[key].Id));
#endif
                return(_specialCache[key]);
            }

#if WINDOWS_PHONE
            if (type == TransportType.Http)
            {
                var transport = new HttpTransport(host, MTProtoTransportType.Special, GetProxyConfig());

                _specialCache.Add(key, transport);
                isCreated = true;
                return(transport);
                //transport.SetAddress(host, port, () => callback(transport));
            }
            else
#endif
            {
                var transport =
#if WIN_RT
                    new TcpTransportWinRT(host, port, MTProtoTransportType.Special, GetProxyConfig());
#else
                    new TcpTransport(host, port, MTProtoTransportType.Special, GetProxyConfig());
#endif
                transport.Connecting     += OnConnecting;
                transport.Connected      += OnConnected;
                transport.ConnectionLost += OnConnectionLost;
                transport.CheckConfig    += OnCheckConfig;

#if LOG_REGISTRATION
                TLUtils.WriteLog(string.Format("New transport {2} {0}:{1}", host, port, transport.Id));
#endif
                TLUtils.WritePerformance(string.Format("  TCP: New transport {0}:{1}", host, port));

                _specialCache.Add(key, transport);
                isCreated = true;

                Debug.WriteLine("  TCP: New transport {0}:{1}", host, port);
                return(transport);
                //trasport.SetAddress(host, port, () => callback(trasport));
            }
        }
Exemplo n.º 3
0
        public ITransport GetTransport(string host, int port, string staticHost, int staticPort, TransportType type, short protocolDCId, byte[] protocolSecret, out bool isCreated)
        {
            var key = string.Format("{0} {1} {2} {3}", host, port, protocolDCId, type);

            if (_cache.ContainsKey(key))
            {
                isCreated = false;

#if LOG_REGISTRATION
                TLUtils.WriteLog(string.Format("Old transport {2} {0}:{1}", host, port, _cache[key].Id));
#endif
                return(_cache[key]);
            }

#if WINDOWS_PHONE
            if (type == TransportType.Http)
            {
                var transport = new HttpTransport(host, MTProtoTransportType.Main, GetProxyConfig());

                _cache.Add(key, transport);
                isCreated = true;
                return(transport);
                //transport.SetAddress(host, port, () => callback(transport));
            }
            else
#endif
            {
                var transport =
#if WIN_RT
                    new TcpTransportWinRT(host, port, staticHost, staticPort, MTProtoTransportType.Main, GetProxyConfig());
#elif NATIVE
                    new NativeTcpTransport(host, port, staticHost, staticPort, MTProtoTransportType.Main, protocolDCId, protocolSecret, GetProxyConfig());
#else
                    new TcpTransport(host, port, staticHost, staticPort, MTProtoTransportType.Main, GetProxyConfig());
#endif

                transport.Connecting     += OnConnecting;
                transport.Connected      += OnConnected;
                transport.ConnectionLost += OnConnectionLost;
                transport.CheckConfig    += OnCheckConfig;

#if LOG_REGISTRATION
                TLUtils.WriteLog(string.Format("New transport {2} {0}:{1}", host, port, transport.Id));
#endif
                TLUtils.WritePerformance(string.Format("  TCP: New transport {0}:{1}", host, port));

                _cache.Add(key, transport);
                isCreated = true;

                Debug.WriteLine("  TCP: New transport {0}:{1}", host, port);
                return(transport);
                //trasport.SetAddress(host, port, () => callback(trasport));
            }
        }
Exemplo n.º 4
0
        public ITransport GetTransport(string host, int port, TransportType type, out bool isCreated)
        {
            var key = string.Format("{0} {1} {2}", host, port, type);

            if (_cache.ContainsKey(key))
            {
                isCreated = false;

#if LOG_REGISTRATION
                TLUtils.WriteLog(string.Format("Old transport {2} {0}:{1}", host, port, _cache[key].Id));
#endif
                return(_cache[key]);
            }

#if WINDOWS_PHONE
            if (type == TransportType.Http)
            {
                var transport = new HttpTransport(host);

                _cache.Add(key, transport);
                isCreated = true;
                return(transport);
                //transport.SetAddress(host, port, () => callback(transport));
            }
            else
#endif
            {
                var transport =
#if WIN_RT
                    new TcpTransportWinRT(host, port, SettingsHelper.IsProxyEnabled, SettingsHelper.ProxyServer, SettingsHelper.ProxyPort, SettingsHelper.ProxyUsername, SettingsHelper.ProxyPassword);
#else
                    new TcpTransport(host, port);
#endif
                transport.Connecting     += OnConnecting;
                transport.Connected      += OnConnected;
                transport.ConnectionLost += OnConnectionLost;

#if LOG_REGISTRATION
                TLUtils.WriteLog(string.Format("New transport {2} {0}:{1}", host, port, transport.Id));
#endif
                TLUtils.WritePerformance(string.Format("  TCP: New transport {0}:{1}", host, port));

                _cache.Add(key, transport);
                isCreated = true;

                Debug.WriteLine("  TCP: New transport {0}:{1}", host, port);
                return(transport);
                //trasport.SetAddress(host, port, () => callback(trasport));
            }
        }
Exemplo n.º 5
0
        public ITransport GetFileTransport2(string host, int port, string staticHost, int staticPort, TransportType type, short protocolDCId, byte[] protocolSecret, out bool isCreated)
        {
            var key = string.Format("{0} {1} {2} {3}", host, port, protocolDCId, type);

            if (_fileCache2.ContainsKey(key))
            {
                isCreated = false;
                return(_fileCache2[key]);
            }

#if WINDOWS_PHONE
            if (type == TransportType.Http)
            {
                var transport = new HttpTransport(host, MTProtoTransportType.File, GetProxyConfig());

                _fileCache2.Add(key, transport);
                isCreated = true;
                return(transport);
                //transport.SetAddress(host, port, () => callback(transport));
            }
            else
#endif
            {
                var transport =
#if WIN_RT
                    new TcpTransportWinRT(host, port, staticHost, staticPort, MTProtoTransportType.File, GetProxyConfig());
#elif NATIVE
                    new NativeTcpTransport(host, port, staticHost, staticPort, MTProtoTransportType.File, protocolDCId, protocolSecret, GetProxyConfig());
#else
                    new TcpTransport(host, port, staticHost, staticPort, MTProtoTransportType.File, GetProxyConfig());
#endif
                transport.ConnectionLost += OnConnectionLost;
                TLUtils.WritePerformance(string.Format("  TCP: New file transport 2 {0}:{1}", host, port));

                _fileCache2.Add(key, transport);
                isCreated = true;

                Debug.WriteLine("  TCP: New transport {0}:{1}", host, port);
                return(transport);
                //trasport.SetAddress(host, port, () => callback(trasport));
            }
        }
Exemplo n.º 6
0
        public ITransport GetFileTransport2(string host, int port, TransportType type, out bool isCreated)
        {
            var key = string.Format("{0} {1} {2}", host, port, type);

            if (_fileCache2.ContainsKey(key))
            {
                isCreated = false;
                return(_fileCache2[key]);
            }

#if WINDOWS_PHONE
            if (type == TransportType.Http)
            {
                var transport = new HttpTransport(host);

                _fileCache2.Add(key, transport);
                isCreated = true;
                return(transport);
                //transport.SetAddress(host, port, () => callback(transport));
            }
#endif
            else
            {
                var transport =
#if WIN_RT
                    new TcpTransportWinRT(host, port, SettingsHelper.IsProxyEnabled, SettingsHelper.ProxyServer, SettingsHelper.ProxyPort, SettingsHelper.ProxyUsername, SettingsHelper.ProxyPassword);
#else
                    new TcpTransport(host, port);
#endif
                transport.Additional      = true;
                transport.ConnectionLost += OnConnectionLost;
                TLUtils.WritePerformance(string.Format("  TCP: New file transport {0}:{1}", host, port));

                _fileCache2.Add(key, transport);
                isCreated = true;

                Debug.WriteLine("  TCP: New transport {0}:{1}", host, port);
                return(transport);
                //trasport.SetAddress(host, port, () => callback(trasport));
            }
        }
Exemplo n.º 7
0
        public ITransport GetFileTransport(string host, int port, TransportType type, out bool isCreated)
        {
            var key = string.Format("{0} {1} {2}", host, port, type);

            if (_fileCache.ContainsKey(key))
            {
                isCreated = false;
                return(_fileCache[key]);
            }

#if WINDOWS_PHONE
            if (type == TransportType.Http)
            {
                var transport = new HttpTransport(host, MTProtoTransportType.File, GetProxyConfig());

                _fileCache.Add(key, transport);
                isCreated = true;
                return(transport);
                //transport.SetAddress(host, port, () => callback(transport));
            }
#endif
            else
            {
                var transport =
#if WIN_RT
                    new TcpTransportWinRT(host, port, MTProtoTransportType.File, GetProxyConfig());
#else
                    new TcpTransport(host, port, MTProtoTransportType.File, GetProxyConfig());
#endif
                transport.ConnectionLost += OnConnectionLost;
                TLUtils.WritePerformance(string.Format("  TCP: New file transport {0}:{1}", host, port));

                _fileCache.Add(key, transport);
                isCreated = true;

                Debug.WriteLine("  TCP: New transport {0}:{1}", host, port);
                return(transport);
                //trasport.SetAddress(host, port, () => callback(trasport));
            }
        }