示例#1
0
        public HttpTransport(string address, MTProtoTransportType mtProtoType, TLProxyConfigBase proxyConfig)
        {
            var host = string.IsNullOrEmpty(address) ? Constants.FirstServerIpAddress : address;

            _host = string.Format("http://{0}:80/api", host);

            MTProtoType = mtProtoType;
            ProxyConfig = proxyConfig;

            MessageIdDict = new Dictionary <long, long>();
        }
示例#2
0
        protected TcpTransportBase(string host, int port, MTProtoTransportType mtProtoType, TLProxyConfig proxyConfig)
        {
            MessageIdDict = new Dictionary <long, long>();

            Host        = host;
            Port        = port;
            MTProtoType = mtProtoType;
            ProxyConfig = proxyConfig;

            var random = new Random();

            Id = random.Next(0, 255);

            _timer = new Timer(OnTimerTick, _timer, Timeout.Infinite, Timeout.Infinite);
        }
示例#3
0
        public TcpTransportWinRT(string host, int port, MTProtoTransportType mtProtoType, TLProxyConfig proxyConfig)
            : base(host, port, mtProtoType, proxyConfig)
        {
            _timeout = 25.0;
            _socket  = new StreamSocket();
            var control = _socket.Control;

            control.QualityOfService = SocketQualityOfService.LowLatency;

            _dataReader = new DataReader(_socket.InputStream)
            {
                InputStreamOptions = InputStreamOptions.Partial
            };
            _dataWriter = new DataWriter(_socket.OutputStream);

            //lock (_dataWriterSyncRoot)
            //{
            //    var buffer = GetInitBufferInternal();
            //    _dataWriter.WriteBytes(buffer);
            //}
        }
示例#4
0
        public TcpTransport(string host, int port, MTProtoTransportType mtProtoType, TLProxyConfig proxyConfig)
            : base(host, port, mtProtoType, proxyConfig)
        {
            // ipv6 support

            _address = IPAddress.Parse(host);

            //var addressFamily = AddressFamily.InterNetwork;
            //if (IPAddress.TryParse(host, out _address))
            //{
            //    if (_address.AddressFamily == AddressFamily.InterNetworkV6)
            //    {
            //        addressFamily = AddressFamily.InterNetworkV6;
            //    }
            //}

            _socket = new Socket(_address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            _buffer = new byte[BufferSize];
            _listener.SetBuffer(_buffer, 0, _buffer.Length);
            _listener.Completed += OnReceived;
        }
示例#5
0
        public TcpTransport(string host, int port, string staticHost, int staticPort, MTProtoTransportType mtProtoType, TLProxyConfigBase proxyConfig)
            : base(host, port, staticHost, staticPort, mtProtoType, proxyConfig)
        {
            // ipv6 support
            _address = proxyConfig != null && !proxyConfig.IsEmpty
                ? IPAddress.Parse(staticHost)
                : IPAddress.Parse(host);

            _socket = new Socket(_address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            _buffer = new byte[BufferSize];
            _listener.SetBuffer(_buffer, 0, _buffer.Length);
            _listener.Completed += OnReceived;
        }
        public NativeTcpTransport(string host, int port, string staticHost, int staticPort, MTProtoTransportType mtProtoType, short protocolDCId, byte[] protocolSecret, TLProxyConfigBase proxyConfig)
            : base(host, port, staticHost, staticPort, mtProtoType, proxyConfig)
        {
//            System.Diagnostics.Debug.WriteLine(
//                "  [NativeTcpTransport] .ctor begin host={0} port={1} static_host={2} static_port={3} type={4} protocol_dcid={5} protocol_secret={6} proxy={7}",
//                host, port, staticHost, staticPort, mtProtoType, protocolDCId, protocolSecret, proxyConfig);

            ActualHost = host;
            ActualPort = port;

            var           ipv4          = true;
            ProxySettings proxySettings = null;

            if (proxyConfig != null && proxyConfig.IsEnabled.Value && !proxyConfig.IsEmpty)
            {
                var socks5Proxy = proxyConfig.GetProxy() as TLSocks5Proxy;
                if (socks5Proxy != null)
                {
                    try
                    {
                        ipv4 = new HostName(socks5Proxy.Server.ToString()).Type == HostNameType.Ipv4;
                    }
                    catch (Exception ex)
                    {
                    }
                    proxySettings = new ProxySettings
                    {
                        Type     = ProxyType.Socks5,
                        Host     = socks5Proxy.Server.ToString(),
                        Port     = socks5Proxy.Port.Value,
                        Username = socks5Proxy.Username.ToString(),
                        Password = socks5Proxy.Password.ToString(),
                        IPv4     = ipv4
                    };

                    ActualHost     = staticHost;
                    ActualPort     = staticPort;
                    protocolSecret = null;
                    protocolDCId   = protocolDCId;
                }
                var mtProtoProxy = proxyConfig.GetProxy() as TLMTProtoProxy;
                if (mtProtoProxy != null)
                {
                    try
                    {
                        ipv4 = new HostName(mtProtoProxy.Server.ToString()).Type == HostNameType.Ipv4;
                    }
                    catch (Exception ex)
                    {
                    }
                    proxySettings = new ProxySettings
                    {
                        Type   = ProxyType.MTProto,
                        Host   = mtProtoProxy.Server.ToString(),
                        Port   = mtProtoProxy.Port.Value,
                        Secret = TLUtils.ParseSecret(mtProtoProxy.Secret),
                        IPv4   = ipv4
                    };

                    ActualHost = staticHost;
                    ActualPort = staticPort;
                }
            }

            try
            {
                ipv4 = new HostName(ActualHost).Type == HostNameType.Ipv4;
            }
            catch (Exception ex)
            {
            }

            var connectionSettings = new ConnectionSettings
            {
                Host           = ActualHost,
                Port           = ActualPort,
                IPv4           = ipv4,
                ProtocolDCId   = protocolDCId,
                ProtocolSecret = protocolSecret
            };

            _proxySettings = proxySettings;

//            var proxyString = proxySettings == null
//                ? "null"
//                : string.Format("[host={0} port={1} ipv4={2} type={3} secret={4} username={5} password={6}]",
//                proxySettings.Host,
//                proxySettings.Port,
//                proxySettings.IPv4,
//                proxySettings.Type,
//                proxySettings.Secret,
//                proxySettings.Username,
//                proxySettings.Password);
//            System.Diagnostics.Debug.WriteLine(
//                "  [NativeTcpTransport] .ctor end host={0} port={1} ipv4={2} protocol_dcid={3} protocol_secret={4} proxy={5}",
//                connectionSettings.Host, connectionSettings.Port, connectionSettings.IPv4, connectionSettings.ProtocolDCId, connectionSettings.ProtocolSecret, proxyString);

            _wrapper                 = new ConnectionSocketWrapper(connectionSettings, proxySettings);
            _wrapper.Closed         += Wrapper_OnClosed;
            _wrapper.PacketReceived += Wrapper_OnPacketReceived;
        }
        public TcpTransportWinRT(string host, int port, string staticHost, int staticPort, MTProtoTransportType mtProtoType, TLProxyConfigBase proxyConfig)
            : base(host, port, staticHost, staticPort, mtProtoType, proxyConfig)
        {
            _timeout = 25.0;
            _socket  = new StreamSocket();
            var control = _socket.Control;

            control.QualityOfService = SocketQualityOfService.LowLatency;

            _dataReader = new DataReader(_socket.InputStream)
            {
                InputStreamOptions = InputStreamOptions.Partial
            };
            _dataWriter = new DataWriter(_socket.OutputStream);
        }