예제 #1
0
        // The working thread.
        private void Run()
        {
            try
            {
                // Try to connect to the proxy.
                ProxyConnection = new Socks5ProxyClient(configuration.GetProxyAddress(), configuration.GetProxyPort(), "", "");

                // Try to connect to the pool
                PoolConnection = ProxyConnection.CreateConnection(configuration.GetPoolAddress(), configuration.GetPoolPort());

                // Write to the console that the pool has beenc onnected.
                Program.ConsoleWriteLineWithColor(ConsoleColor.Green, "Successfully connected to your pool!");
                Program.ConsoleWriteLineWithColor(ConsoleColor.Green, "The new miner is ready to mine!");
            }
            catch (Exception exception)
            {
                Program.ConsoleWriteLineWithColor(ConsoleColor.Red, "Failed to establish a connection to the pool, the miner will be disconnected.");
                Console.WriteLine(exception.ToString());
            }

            // Main routine that sleeps and exchanges data to prevent high cpu usage.
            while (MinerConnection.Connected && PoolConnection.Connected)
            {
                // Small sleep so we don't use 100% of the cpu
                Thread.Sleep(10);

                // Exchange the data.
                ExchangeData();
            }

            // See you, space cowboy.
            wantsToBeDisposed = true;
        }
예제 #2
0
        static System.Net.Sockets.TcpClient TcpHandler(string address, int port)
        {
            var socks = new Socks5ProxyClient("orbtl.s5.opennetwork.cc", 999, "262852885", "vmNeknLh");
            var tcp   = socks.CreateConnection(address, port);

            return(tcp);
        }
예제 #3
0
        public static string CreateTcpSend(string Address, string model)
        {
            int ReachPort = 50371; //ReachPort

            try
            {
                proxyClient = new Socks5ProxyClient("127.0.0.1", 9150);
                proxyClient.ProxyUserName = "";
                proxyClient.ProxyPassword = "";
                TCP   = proxyClient.CreateConnection(Address, ReachPort);
                Write = new StreamWriter(TCP.GetStream());
                Write.Write(model);
                Write.Flush();
                Reader = new StreamReader(TCP.GetStream());
                var ResultMessage = "";

                while (Reader.Peek() > -1)
                {
                    ResultMessage += Convert.ToChar(Reader.Read()).ToString();
                }
                return(ResultMessage);
            }
            catch (Exception ex)
            {
                return("Error: " + ex);
            }
        }
예제 #4
0
        public void HandleClient(object obj)
        {
            // Placehonder varaibles for the connections we'll use.
            TcpClient         minerClient = (TcpClient)obj; // Cast the object as a Net.TcpClient (Polymorphism)
            Socks5ProxyClient proxyClient = null;
            TcpClient         poolClient  = null;

            // Let the console know a miner is attempting to connect
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("A miner is attempting to connect...");
            minerCount += 1;

            // Handle the main routine
            try
            {
                // Try to connect to the pool on the socks5 proxy
                proxyClient = new Socks5ProxyClient(configurationClass.configuration.ProxyAddress, configurationClass.configuration.ProxyPort, "", "");
                poolClient  = proxyClient.CreateConnection(configurationClass.configuration.PoolAddress, configurationClass.configuration.PoolPort);
                Console.WriteLine("Successfully connected to your pool!");

                // We can signal that the miner is ready to mine
                Console.WriteLine("The new miner is ready to mine!");

                // Print how many miners are attached.
                Console.WriteLine(String.Format("There are currently {0} miner(s) connected.", minerCount));

                // Lastly, reset the console color for now.
                Console.ResetColor();

                // Main routine that sleeps and exchanges data to prevent high cpu usage.
                while (minerClient.Connected && poolClient.Connected)
                {
                    // Small sleep so we don't use 100% of the cpu
                    Thread.Sleep(10);

                    // Exchange the data.
                    ExchangeData(minerClient, poolClient);
                }
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Failed to connect to the pool or the socks5 proxy - miner will be dropped");
                Console.ResetColor();
            }

            // Close all connections if it's open, this thread is done.
            SafeCloseAndDispose(minerClient);
            SafeCloseAndDispose(poolClient);
            SafeCloseAndDispose(proxyClient.TcpClient);

            // Counter and debug.
            minerCount -= 1;
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("A miner has been disconnected.");
            Console.WriteLine(String.Format("There are currently {0} miner(s) connected.", minerCount));
            Console.ResetColor();
        }
예제 #5
0
        public X509Certificate2 Request(string name, string pass, bool canuse_clear = true, bool canuse_tor = false, bool canuse_i2p = false)
        {
            MessageBox.Show("Automated signing does not yet work, create an issue on github with your csr");
            TcpClient         client = new TcpClient();
            Socks5ProxyClient SPC;
            HttpProxyClient   HPC;
            string            servera = null;
            int i = 0;

            if (canuse_clear)
            {
                servera = SuperNodeDB.ClearSuperNodes[i];
            }
            else if (canuse_tor)
            {
                servera = SuperNodeDB.TorSuperNodes[i];
            }
            else if (canuse_i2p)
            {
                servera = SuperNodeDB.I2PSuperNodes[i];
            }
            try
            {
                if (canuse_i2p)
                {
                    HPC           = new HttpProxyClient();
                    HPC.ProxyHost = "127.0.0.1";
                    HPC.ProxyPort = 4444;
                    client        = HPC.CreateConnection("", 666);
                }
                else if (canuse_clear)
                {
                    client.Connect("127.0.0.1", 1);
                }
                else if (canuse_tor)
                {
                    SPC               = new Socks5ProxyClient();
                    SPC.ProxyHost     = "127.0.0.1";
                    SPC.ProxyPort     = 9050;
                    SPC.ProxyUserName = "";
                    SPC.ProxyPassword = "";
                    client            = SPC.CreateConnection("", 1);
                }
                NetworkStream stream = client.GetStream();

                return(new X509Certificate2());
            }
            catch (Exception ex)
            { return(new X509Certificate2()); }
        }
예제 #6
0
        public void TestSocks5CreateConnection(string proxyHost, int proxyPort, string destHost, int destPort)
        {
            Socks5ProxyClient p = new Socks5ProxyClient();

            p.ProxyHost = proxyHost;
            p.ProxyPort = proxyPort;
            TcpClient c = p.CreateConnection(destHost, destPort);

            byte[] sendBuf = System.Text.ASCIIEncoding.ASCII.GetBytes("GET / HTTP/1.1\n");
            c.GetStream().Write(sendBuf, 0, sendBuf.Length);
            byte[] recvBuf = new byte[1024];
            c.GetStream().Read(recvBuf, 0, recvBuf.Length);
            Console.Out.WriteLine(System.Text.ASCIIEncoding.ASCII.GetString(recvBuf));
            c.Close();
        }
예제 #7
0
        // The running function of each thread.
        private void Run()
        {
            try
            {
                // Try to connect to the proxy.
                ProxyConnection = new Socks5ProxyClient(configuration.GetProxyAddress(), int.Parse(configuration.GetProxyPort().ToString()), "", "");

                // Get the information for the address.
                poolInformation = GetPoolInformationForAddress();

                // Try to connect to the pool
                PoolConnection = ProxyConnection.CreateConnection(
                    poolInformation.hostname,
                    poolInformation.port
                    );

                // Write to the console that the pool has beenc onnected.
                Program.ConsoleWriteLineWithColorAndTime(ConsoleColor.Yellow, (String.Format("Network traffic from Miner {0} will appear from {1}.", id, GetProxyRemoteAddress())));
                Program.ConsoleWriteLineWithColorAndTime(ConsoleColor.Green, "Miner has successfully connected to their desired pool: " + GetPoolInformationFromMiner().hostname);

                // Configure Timeouts
                SetTimeouts();
            }
            catch (Exception exception)
            {
                Program.ConsoleWriteLineWithColorAndTime(ConsoleColor.Red, "Failed to establish a connection to the pool, the miner will be disconnected.");
                Console.WriteLine(exception.ToString());
            }

            if (PoolConnection != null && proxyResolvedRemoteAddress != null)
            {
                while (MinerConnection.Connected && PoolConnection.Connected)
                {
                    // Small sleep so we don't use 100% of the cpu
                    Thread.Sleep(10);

                    // Exchange the data.
                    ExchangeData();
                }
            }

            // See you, space cowboy.
            dispose = true;
        }
        public void DownLoadFileByWebRequest(string host, string filePath, string model)
        {
            int ReachPort = 50371; //ReachPort

            try
            {
                proxyClient = new Socks5ProxyClient("127.0.0.1", 9150);
                proxyClient.ProxyUserName = "";
                proxyClient.ProxyPassword = "";
                TCP   = proxyClient.CreateConnection(host, ReachPort);
                Write = new StreamWriter(TCP.GetStream());
                Write.Write(model);
                Write.Flush();
                //Read
                NetworkStream stream      = TCP.GetStream();
                int           readSoFar   = 0;
                int           messageSize = 20000000;
                byte[]        msg         = new byte[messageSize];
                while (readSoFar < messageSize)
                {
                    var read = stream.Read(msg, readSoFar, msg.Length - readSoFar);
                    readSoFar += read;
                    if (read == 0)
                    {
                        break;
                    }
                }
                stream.Close();
                TCP.Close();

                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }

                FileStream fstr = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write);
                fstr.Write(cutByte(msg), 0, readSoFar);
                fstr.Close();
            }
            catch (Exception e) {
                Console.WriteLine(e.ToString());
            };
        }
예제 #9
0
            public void TwitchChatLogin(string proxy = "")
            {
                if (proxy == "")
                {
                    tcpClient = new TcpClient("irc.twitch.tv", 80);
                }
                else
                {
                    Socks5ProxyClient proxyClient = new Socks5ProxyClient(proxy.Split(':')[0], Convert.ToInt32(proxy.Split(':')[1]));
                    tcpClient = proxyClient.CreateConnection("irc.twitch.tv", 80);
                }

                inoputStream = new StreamReader(tcpClient.GetStream());
                outputStream = new StreamWriter(tcpClient.GetStream());

                outputStream.WriteLine("CAP REQ :twitch.tv/tags twitch.tv/commands");
                outputStream.WriteLine("PASS " + "oauth:" + accountData.token);
                outputStream.WriteLine("NICK " + accountData.username);
                outputStream.WriteLine("USER " + accountData.username + " 8 * :" + accountData.username);
                outputStream.Flush();
            }
예제 #10
0
        public static string CreateTcpSend(string Address, string model)
        {
            int ReachPort = 50371; //ReachPort

            try
            {
                proxyClient = new Socks5ProxyClient("127.0.0.1", 9150);
                proxyClient.ProxyUserName = "";
                proxyClient.ProxyPassword = "";
                TCP = proxyClient.CreateConnection(Address, ReachPort);
                //TCP.SendBufferSize = 1024;
                Write = new StreamWriter(TCP.GetStream());
                Write.Write(model);
                Write.Flush();
                NetworkStream stream      = TCP.GetStream();
                int           messageSize = TCP.ReceiveBufferSize;
                int           readSoFar   = 0;
                byte[]        msg         = new byte[messageSize];

                while (readSoFar < messageSize)
                {
                    var read = stream.Read(msg, readSoFar, msg.Length - readSoFar);
                    readSoFar += read;
                    if (read == 0)
                    {
                        break;
                    }
                }
                stream.Close();
                TCP.Close();
                string responseData = System.Text.Encoding.UTF8.GetString(cutByte(msg), 0, cutByte(msg).Length);
                return(responseData);
            }
            catch (Exception ex)
            {
                return("Error: " + ex);
            }
        }
예제 #11
0
        private static bool TryConnect(out TcpClient tcpClient, out SslStream stream, IpAddressInfo ipAddressInfo)
        {
            tcpClient = null;
            stream    = null;

            TcpClient client = null;

            try
            {
                var proxyProperty = Settings.GetBuilderProperty <ProxyBuilderProperty>();
                if (proxyProperty.ProxyOption != ProxyOption.None)
                {
                    if (proxyProperty.ProxyOption == ProxyOption.AutomaticDetection)
                    {
                        string ipAddress;
                        int    port;
                        ProxyHelper.GetSystemProxy(out ipAddress, out port);
                        for (var i = 0; i < 3; i++)
                        {
                            try
                            {
                                IProxyClient proxyClient;
                                switch (i)
                                {
                                case 0:
                                    proxyClient = new Socks4ProxyClient();
                                    break;

                                case 1:
                                    proxyClient = new Socks4aProxyClient();
                                    break;

                                case 2:
                                    proxyClient = new Socks5ProxyClient();
                                    break;

                                default:
                                    throw new ArgumentException();     //impossible
                                }

                                proxyClient.ProxyHost = ipAddress;
                                proxyClient.ProxyPort = port;
                                client = proxyClient.CreateConnection(ipAddressInfo.Ip, ipAddressInfo.Port);
                                break;
                            }
                            catch (Exception)
                            {
                                // ignored
                            }
                        }
                    }
                    else
                    {
                        IProxyClient proxyClient;
                        switch (proxyProperty.ProxyType)
                        {
                        case 0:
                            proxyClient = new Socks4ProxyClient();
                            break;

                        case 1:
                            proxyClient = new Socks4aProxyClient();
                            break;

                        case 2:
                            proxyClient = new Socks5ProxyClient();
                            break;

                        default:
                            throw new ArgumentException();
                        }

                        proxyClient.ProxyHost = proxyProperty.ProxyAddress;
                        proxyClient.ProxyPort = proxyProperty.ProxyPort;
                        client = proxyClient.CreateConnection(ipAddressInfo.Ip, ipAddressInfo.Port);
                    }
                }
            }
            catch (Exception)
            {
                // ignored
            }

            if (client == null)
            {
                client = new TcpClient();
                try
                {
                    var result  = client.BeginConnect(ipAddressInfo.Ip, ipAddressInfo.Port, null, null);
                    var success = result.AsyncWaitHandle.WaitOne(3000, false);
                    if (!success)
                    {
                        return(false);
                    }

                    client.EndConnect(result);
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            var sslStream = new SslStream(client.GetStream(), false, UserCertificateValidationCallback);

            try
            {
                var serverName = Environment.MachineName;
                sslStream.AuthenticateAsClient(serverName);
            }
            catch (AuthenticationException)
            {
                sslStream.Dispose();
                client.Close();
                return(false);
            }

            tcpClient = client;
            stream    = sslStream;
            return(true);
        }
예제 #12
0
        public static ProxyWithType CheckProxy(string IP, int port, int timeout)
        {
            string connectionTestIPAddress  = ConfigurationManager.AppSettings["ConnectionTestIP"];
            string connectionTestWebAddress = ConfigurationManager.AppSettings["ConnectionTestWebAddress"];
            string connectionTestPort       = ConfigurationManager.AppSettings["ConnectionTestPort"];

            ProxyWithType proxyWithType = new ProxyWithType();

            proxyWithType.IP        = IP;
            proxyWithType.Port      = port.ToString();
            proxyWithType.ProxyType = Model.ProxyType.Dead;

            TaskFactory taskFactory = new TaskFactory();
            List <Task> tasks       = new List <Task>();

            tasks.Add(taskFactory.StartNew(delegate
            {
                try
                {
                    Socks4ProxyClient proxyClient4 = new Socks4ProxyClient(IP, port);
                    proxyClient4.CreateConnection(connectionTestIPAddress, int.Parse(connectionTestPort));
                    proxyWithType.ProxyType = Model.ProxyType.Socks4;
                }
                catch (Exception)
                {
                    //If proxy timeouts don't do anything
                }
            }));
            tasks.Add(taskFactory.StartNew(delegate
            {
                try
                {
                    Socks5ProxyClient proxyClient5 = new Socks5ProxyClient(IP, port);
                    proxyClient5.CreateConnection(connectionTestIPAddress, int.Parse(connectionTestPort));
                    proxyWithType.ProxyType = Model.ProxyType.Socks5;
                }
                catch (Exception)
                {
                    //If proxy timeouts don't do anything
                }
            }));
            tasks.Add(taskFactory.StartNew(delegate
            {
                try
                {
                    WebClient wc = new WebClient();
                    wc.Proxy     = new WebProxy(IP, port);
                    wc.DownloadString(connectionTestWebAddress);
                    proxyWithType.ProxyType = Model.ProxyType.HTTP;
                }
                catch (Exception)
                {
                    //If proxy timeouts don't do anything
                }
            }));
            if (timeout > 0)
            {
                Task.WaitAll(tasks.ToArray(), timeout);
            }
            else
            {
                Task.WaitAll(tasks.ToArray());
            }

            return(proxyWithType);
        }
예제 #13
0
        public static string CreateTcpSend(string Address, string model)
        {
            int ReachPort = 50371; //ReachPort

            try
            {
                proxyClient = new Socks5ProxyClient("127.0.0.1", 9150);
                proxyClient.ProxyUserName = "";
                proxyClient.ProxyPassword = "";
                TCP   = proxyClient.CreateConnection(Address, ReachPort);
                Write = new StreamWriter(TCP.GetStream());
                Write.Write(model);
                Write.Flush();
                StreamReader reader       = new StreamReader(TCP.GetStream());
                var          RespondSize  = "";
                Byte[]       MessageFront = new Byte[0];
                bool         size         = true;
                while (reader.Peek() > -1)
                {
                    char character = Convert.ToChar(reader.Read());
                    if (Char.IsNumber(character) && size)
                    {
                        RespondSize += character;
                    }
                    else
                    {
                        size         = false;
                        MessageFront = addByteToArray(MessageFront, Convert.ToByte(character));
                    }
                }
                NetworkStream stream    = TCP.GetStream();
                int           readSoFar = 0;
                //int messageSize = TCP.ReceiveBufferSize;
                int    messageSize = Int32.Parse(RespondSize);
                byte[] msg         = new byte[messageSize];
                while (readSoFar < messageSize)
                {
                    var read = stream.Read(msg, readSoFar, msg.Length - readSoFar);
                    readSoFar += read;
                    if (read == 0)
                    {
                        break;
                    }
                }
                stream.Close();
                TCP.Close();
                string responseData = "";
                if (MessageFront.Length != 0)
                {
                    responseData = Reverse(System.Text.Encoding.UTF8.GetString(cutByte(MessageFront), 0, cutByte(MessageFront).Length));
                }
                try
                {
                    responseData += System.Text.Encoding.UTF8.GetString(cutByte(msg), 0, cutByte(msg).Length);
                }catch { };
                return(responseData);
            }
            catch (Exception ex)
            {
                var log = new LogModel
                {
                    KeyUnique = "ServerError",
                    Message   = "Error: " + ex.ToString(),
                    Type      = "Error",
                };
                return(JsonConvert.SerializeObject(log));
            }
        }
예제 #14
0
        private static bool TryConnect(out TcpClient tcpClient, out SslStream stream, string ip, int port)
        {
            tcpClient = null;
            stream    = null;

            TcpClient client;

            if (Settings.Current.UseProxyToConnectToServer)
            {
                IProxyClient proxyClient;
                switch (Settings.Current.ProxyType)
                {
                case ProxyType.Socks4:
                    proxyClient = new Socks4ProxyClient();
                    break;

                case ProxyType.Socks4a:
                    proxyClient = new Socks4aProxyClient();
                    break;

                case ProxyType.Socks5:
                    proxyClient = new Socks5ProxyClient();
                    if (Settings.Current.ProxyAuthenticate)
                    {
                        ((Socks5ProxyClient)proxyClient).ProxyUserName = Settings.Current.ProxyUsername;
                        ((Socks5ProxyClient)proxyClient).ProxyPassword = Settings.Current.ProxyPassword;
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                proxyClient.ProxyHost = Settings.Current.ProxyIpAddress;
                proxyClient.ProxyPort = Settings.Current.ProxyPort;
                client = proxyClient.CreateConnection(ip, port);
            }
            else
            {
                client = new TcpClient();
                try
                {
                    var result  = client.BeginConnect(ip, port, null, null);
                    var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(3));

                    if (!success)
                    {
                        return(false);
                    }

                    // we are connected
                    client.EndConnect(result);
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            var sslStream = new SslStream(client.GetStream(), false, UserCertificateValidationCallback);

            try
            {
                var serverName = Environment.MachineName;
                var result     = sslStream.BeginAuthenticateAsClient(serverName, null, null);
                var success    = result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(3));
                if (!success)
                {
                    return(false);
                }

                sslStream.EndAuthenticateAsClient(result);
            }
            catch (AuthenticationException)
            {
                sslStream.Dispose();
                client.Close();
                return(false);
            }

            sslStream.Write(new[] { (byte)AuthentificationIntention.Administration });

            tcpClient = client;
            stream    = sslStream;
            return(true);
        }
예제 #15
0
        public ConnectionBase CreateConnection(string uri)
        {
            Socket         socket     = null;
            ConnectionBase connection = null;

            try
            {
                if (this.ConnectionType == ConnectionType.Tcp)
                {
#if !DEBUG
                    {
                        Regex regex = new Regex(@"(.*?):(.*):(\d*)");
                        var   match = regex.Match(uri);
                        Uri   url   = new Uri(string.Format("{0}://{1}:{2}", match.Groups[1], match.Groups[2], match.Groups[3]));

                        if (url.HostNameType == UriHostNameType.IPv4)
                        {
                            var myIpAddress = IPAddress.Parse(url.Host);

                            if (IPAddress.Any.ToString() == myIpAddress.ToString() ||
                                IPAddress.Loopback.ToString() == myIpAddress.ToString() ||
                                IPAddress.Broadcast.ToString() == myIpAddress.ToString())
                            {
                                return(null);
                            }
                            if (Collection.Compare(myIpAddress.GetAddressBytes(), IPAddress.Parse("10.0.0.0").GetAddressBytes()) >= 0 &&
                                Collection.Compare(myIpAddress.GetAddressBytes(), IPAddress.Parse("10.255.255.255").GetAddressBytes()) <= 0)
                            {
                                return(null);
                            }
                            if (Collection.Compare(myIpAddress.GetAddressBytes(), IPAddress.Parse("172.16.0.0").GetAddressBytes()) >= 0 &&
                                Collection.Compare(myIpAddress.GetAddressBytes(), IPAddress.Parse("172.31.255.255").GetAddressBytes()) <= 0)
                            {
                                return(null);
                            }
                            if (Collection.Compare(myIpAddress.GetAddressBytes(), IPAddress.Parse("127.0.0.0").GetAddressBytes()) >= 0 &&
                                Collection.Compare(myIpAddress.GetAddressBytes(), IPAddress.Parse("127.255.255.255").GetAddressBytes()) <= 0)
                            {
                                return(null);
                            }
                            if (Collection.Compare(myIpAddress.GetAddressBytes(), IPAddress.Parse("192.168.0.0").GetAddressBytes()) >= 0 &&
                                Collection.Compare(myIpAddress.GetAddressBytes(), IPAddress.Parse("192.168.255.255").GetAddressBytes()) <= 0)
                            {
                                return(null);
                            }
                        }
                        else if (url.HostNameType == UriHostNameType.IPv6)
                        {
                            var myIpAddress = IPAddress.Parse(url.Host);

                            if (IPAddress.IPv6Any.ToString() == myIpAddress.ToString() ||
                                IPAddress.IPv6Loopback.ToString() == myIpAddress.ToString() ||
                                IPAddress.IPv6None.ToString() == myIpAddress.ToString())
                            {
                                return(null);
                            }
                            if (myIpAddress.ToString().ToLower().StartsWith("fe80:"))
                            {
                                return(null);
                            }
                        }
                    }
#endif

                    connection = new TcpConnection(SessionManager.Connect(SessionManager.GetIpEndPoint(uri), new TimeSpan(0, 0, 10)), SessionManager.MaxReceiveCount, _bufferManager);
                }
                else if (this.ConnectionType == ConnectionType.Socks4Proxy)
                {
                    Regex regex = new Regex(@"(.*?):(.*):(\d*)");
                    var   match = regex.Match(uri);
                    if (!match.Success)
                    {
                        return(null);
                    }

                    socket = SessionManager.Connect(SessionManager.GetIpEndPoint(this.ProxyUri), new TimeSpan(0, 0, 10));
                    var proxy = new Socks4ProxyClient(socket, match.Groups[2].Value, int.Parse(match.Groups[3].Value));

                    connection = new TcpConnection(proxy.CreateConnection(new TimeSpan(0, 0, 10)), SessionManager.MaxReceiveCount, _bufferManager);
                }
                else if (this.ConnectionType == ConnectionType.Socks4aProxy)
                {
                    Regex regex = new Regex(@"(.*?):(.*):(\d*)");
                    var   match = regex.Match(uri);
                    if (!match.Success)
                    {
                        return(null);
                    }

                    socket = SessionManager.Connect(SessionManager.GetIpEndPoint(this.ProxyUri), new TimeSpan(0, 0, 10));
                    var proxy = new Socks4aProxyClient(socket, match.Groups[2].Value, int.Parse(match.Groups[3].Value));

                    connection = new TcpConnection(proxy.CreateConnection(new TimeSpan(0, 0, 10)), SessionManager.MaxReceiveCount, _bufferManager);
                }
                else if (this.ConnectionType == ConnectionType.Socks5Proxy)
                {
                    Regex regex = new Regex(@"(.*?):(.*):(\d*)");
                    var   match = regex.Match(uri);
                    if (!match.Success)
                    {
                        return(null);
                    }

                    socket = SessionManager.Connect(SessionManager.GetIpEndPoint(this.ProxyUri), new TimeSpan(0, 0, 10));
                    var proxy = new Socks5ProxyClient(socket, match.Groups[2].Value, int.Parse(match.Groups[3].Value));

                    connection = new TcpConnection(proxy.CreateConnection(new TimeSpan(0, 0, 10)), SessionManager.MaxReceiveCount, _bufferManager);
                }
                else if (this.ConnectionType == ConnectionType.HttpProxy)
                {
                    Regex regex = new Regex(@"(.*?):(.*):(\d*)");
                    var   match = regex.Match(uri);
                    if (!match.Success)
                    {
                        return(null);
                    }

                    socket = SessionManager.Connect(SessionManager.GetIpEndPoint(this.ProxyUri), new TimeSpan(0, 0, 10));
                    var proxy = new HttpProxyClient(socket, match.Groups[2].Value, int.Parse(match.Groups[3].Value));

                    connection = new TcpConnection(proxy.CreateConnection(new TimeSpan(0, 0, 10)), SessionManager.MaxReceiveCount, _bufferManager);
                }

                var secureConnection = new SecureClientConnection(connection, null, _bufferManager);
                secureConnection.Connect(new TimeSpan(0, 0, 20));

                return(new CompressConnection(secureConnection, SessionManager.MaxReceiveCount, _bufferManager));
            }
            catch (Exception)
            {
                if (socket != null)
                {
                    socket.Close();
                }
                if (connection != null)
                {
                    connection.Dispose();
                }
            }

            return(null);
        }