/// <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); } }
/// <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; }
/// <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(); }
/// <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; } } }