Ejemplo n.º 1
0
        /// <summary>
        /// Adds a new chain of proxy client.
        /// </summary>
        /// <param name="proxy">The added proxy client.</param>
        /// <exception cref="System.ArgumentNullException">parameter <paramref name="proxy"/> equally <see langword="null"/>.</exception>
        public void AddProxy(ProxyClient proxy)
        {
            #region Check settings

            if (proxy == null)
            {
                throw new ArgumentNullException("proxy");
            }

            #endregion

            _proxies.Add(proxy);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts a string to an instance <see cref="Socks4aProxyClient"/>. Gets a value indicating whether the conversion was successfully.
        /// </summary>
        /// <param name="proxyAddress">String type - host:port:username:password.   The last three are optional.</param>
        /// <param name="result">If the conversion is successful, it contains an instance <see cref="Socks4aProxyClient"/>, otherwise <see langword="null"/>.</param>
        /// <returns>Value <see langword="true"/>, if the parameter <paramref name="proxyAddress"/> It converted successfully, otherwise <see langword="false"/>.</returns>
        public static bool TryParse(string proxyAddress, out Socks4aProxyClient result)
        {
            ProxyClient proxy;

            if (ProxyClient.TryParse(ProxyType.Socks4a, proxyAddress, out proxy))
            {
                result = proxy as Socks4aProxyClient;
                return(true);
            }
            else
            {
                result = null;
                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// It creates a connection to the server through a chain of proxy servers.
        /// </summary>
        /// <param name="destinationHost">Host server with which to connect through a proxy server.</param>
        /// <param name="destinationPort">Server port to which you want to communicate through a proxy server.</param>
        /// <param name="tcpClient">The connection through which to work, or value <see langword="null"/>.</param>
        /// <returns>The connection to the server through a chain of proxy servers.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// Number of proxy servers is 0.
        /// -or-
        /// property value <see cref="Host"/> equally <see langword="null"/> or is 0 length.
        /// -or-
        /// property value <see cref="Port"/> less than 1 or greater than 65535.
        /// -or-
        /// property value <see cref="Username"/> is longer than 255 characters.
        /// -or-
        /// property value <see cref="Password"/> is longer than 255 characters.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">parameter <paramref name="destinationHost"/> equally <see langword="null"/>.</exception>
        /// <exception cref="System.ArgumentException">parameter <paramref name="destinationHost"/> is an empty string.</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">parameter <paramref name="destinationPort"/> less than 1 or greater than 65535.</exception>
        /// <exception cref="xNet.Net.ProxyException">Failed to work with a proxy server.</exception>
        public override TcpClient CreateConnection(string destinationHost, int destinationPort, TcpClient tcpClient = null)
        {
            #region Checking status

            if (_proxies.Count == 0)
            {
                throw new InvalidOperationException(
                          Resources.InvalidOperationException_ChainProxyClient_NotProxies);
            }

            #endregion

            List <ProxyClient> proxies;

            if (EnableShuffle)
            {
                proxies = _proxies.ToList();

                // Mix proxy.
                for (int i = 0; i < proxies.Count; i++)
                {
                    int randI = Rand.Next(proxies.Count);

                    ProxyClient proxy = proxies[i];
                    proxies[i]     = proxies[randI];
                    proxies[randI] = proxy;
                }
            }
            else
            {
                proxies = _proxies;
            }

            int       length       = proxies.Count - 1;
            TcpClient curTcpClient = tcpClient;

            for (int i = 0; i < length; i++)
            {
                curTcpClient = proxies[i].CreateConnection(
                    proxies[i + 1].Host, proxies[i + 1].Port, curTcpClient);
            }

            curTcpClient = proxies[length].CreateConnection(
                destinationHost, destinationPort, curTcpClient);

            return(curTcpClient);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Converts a string to an instance <see cref="Socks4aProxyClient"/>.
 /// </summary>
 /// <param name="proxyAddress">String type - host: port: username: password.   The last three are optional.</param>
 /// <returns>An instance <see cref="Socks4aProxyClient"/>.</returns>
 /// <exception cref="System.ArgumentNullException">parameter <paramref name="proxyAddress"/> equally <see langword="null"/>.</exception>
 /// <exception cref="System.ArgumentException">parameter <paramref name="proxyAddress"/> is an empty string.</exception>
 /// <exception cref="System.FormatException">port format is wrong.</exception>
 public static Socks4aProxyClient Parse(string proxyAddress)
 {
     return(ProxyClient.Parse(ProxyType.Socks4a, proxyAddress) as Socks4aProxyClient);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the class <see cref="xNet.Net.ProxyException"/> specified error message and a proxy client.
 /// </summary>
 /// <param name="message">The error message explaining the reason for the exception.</param>
 /// <param name="proxyClient">Proxy client, in which the error occurred.</param>
 /// <param name="innerException">The exception that caused the current exception, or value <see langword="null"/>.</param>
 public ProxyException(string message, ProxyClient proxyClient, Exception innerException = null)
     : base(message, innerException)
 {
     ProxyClient = proxyClient;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Converts a string to an instance <see cref="HttpProxyClient"/>.
 /// </summary>
 /// <param name="proxyAddress">String type - host:port:username:password. The last three are optional.</param>
 /// <returns>An instance <see cref="HttpProxyClient"/>.</returns>
 /// <exception cref="System.ArgumentNullException">parameter <paramref name="proxyAddress"/> equally <see langword="null"/>.</exception>
 /// <exception cref="System.ArgumentException">parameter <paramref name="proxyAddress"/> It is an empty string.</exception>
 /// <exception cref="System.FormatException">port format is wrong.</exception>
 public static HttpProxyClient Parse(string proxyAddress)
 {
     return(ProxyClient.Parse(ProxyType.Http, proxyAddress) as HttpProxyClient);
 }