示例#1
0
        /// <summary>
        /// Starts the process of routing the request by parsing the request information of the client and
        /// creating a destination socket as required.
        /// </summary>
        public void Start()
        {
            if (disposed)
            {
                throw new ObjectDisposedException("this");
            }

            lock (synchronize)
            {
                if (destinationSocket != null)
                {
                    return;
                }

                destinationSocket = new ForwardSocket(client);
                destinationSocket.ProxyAddress = client.GetClientAddress();
                destinationSocket.ProxyPort    = client.Configuration.SocksPort;

                string proxyConnection;

                if (connection.Headers.TryGetValue("Proxy-Connection", out proxyConnection) && proxyConnection.Equals("keep-alive", StringComparison.CurrentCultureIgnoreCase))
                {
                    destinationSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 1);
                }

                destinationSocket.BeginConnect(connection.Host, connection.Port, OnSocketConnected, null);
            }
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Socks5Processor"/> class.
 /// </summary>
 /// <param name="socket">The socket which is connected to the proxy network.</param>
 public Socks5Processor(ForwardSocket socket)
 {
     this.asyncResult = new Socks5AsyncResult();
     this.buffer      = new byte[512];
     this.endAddress  = null;
     this.endPoint    = null;
     this.endPort     = 0;
     this.finalLength = 0;
     this.socket      = socket;
 }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConnectionProcessor"/> class.
 /// </summary>
 /// <param name="client">The client hosting the proxy connection.</param>
 /// <param name="connection">The connection associated with the connected client.</param>
 public ConnectionProcessor(Client client, Connection connection, ConnectionProcessorDisposedCallback disposedCallback)
 {
     this.client            = client;
     this.connection        = connection;
     this.connectionBuffer  = new byte[2048];
     this.destinationBuffer = new byte[2048];
     this.destinationSocket = null;
     this.disposed          = false;
     this.disposedCallback  = disposedCallback;
     this.synchronize       = new object();
 }
示例#4
0
        /// <summary>
        /// Shuts down the connection processor by terminating the proxy connection.
        /// </summary>
        public void Shutdown()
        {
            lock (synchronize)
            {
                if (destinationSocket != null)
                {
                    try
                    {
                        destinationSocket.Shutdown(SocketShutdown.Both);
                    }
                    catch { }

                    destinationSocket.Dispose();
                    destinationSocket = null;
                }
            }
        }