public HttpProxyServer(IPEndPoint localEP, IProxyServerConnectionManager connectionManager = null, IProxyServerAuthenticationManager authenticationManager = null, int backlog = 10) { _listener = new Socket(localEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp); _listener.Bind(localEP); _listener.Listen(backlog); _listener.NoDelay = true; _localEP = (IPEndPoint)_listener.LocalEndPoint; _connectionManager = connectionManager; _authenticationManager = authenticationManager; if (_connectionManager == null) { _connectionManager = new DefaultProxyServerConnectionManager(); } _ = Task.Factory.StartNew(AcceptRequestAsync, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Current); }
public TransparentProxyServer(IPEndPoint localEP, IProxyServerConnectionManager connectionManager = null, TransparentProxyServerMethod method = TransparentProxyServerMethod.DNAT, int backlog = 10) { if (Environment.OSVersion.Platform != PlatformID.Unix) { throw new NotSupportedException("Only Unix/Linux is supported."); } if ((method == TransparentProxyServerMethod.DNAT) && (localEP.AddressFamily != AddressFamily.InterNetwork)) { throw new NotSupportedException("Only IPv4 is supported with DNAT."); } _listener = new Socket(localEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if (method == TransparentProxyServerMethod.TPROXY) { _listener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1); _listener.SetRawSocketOption(IPPROTO_IP, IP_TRANSPARENT, new byte[] { 1 }); } _listener.Bind(localEP); _listener.Listen(backlog); _listener.NoDelay = true; _localEP = (IPEndPoint)_listener.LocalEndPoint; _connectionManager = connectionManager; _method = method; if (_connectionManager == null) { _connectionManager = new DefaultProxyServerConnectionManager(); } //accept requests async int tasks = Math.Max(1, Environment.ProcessorCount); for (int i = 0; i < tasks; i++) { _ = Task.Factory.StartNew(AcceptRequestAsync, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Current); } }
private async Task <IProxyServerConnectionManager> CheckConnectivityAsync(IProxyServerConnectionManager connectionManager) { Exception lastException = null; foreach (EndPoint connectivityCheckEP in _connectivityCheckEPs) { try { using (Socket socket = await connectionManager.ConnectAsync(connectivityCheckEP).WithTimeout(NETWORK_CHECK_CONNECTION_TIMEOUT)) { } return(connectionManager); } catch (Exception ex) { lastException = ex; } } Errors?.Invoke(this, lastException); return(null); }
public SocksProxyServer(IPEndPoint localEP, IProxyServerConnectionManager connectionManager = null, IProxyServerAuthenticationManager authenticationManager = null, int backlog = 10) { _listener = new Socket(localEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp); _listener.Bind(localEP); _listener.Listen(backlog); _listener.NoDelay = true; _localEP = (IPEndPoint)_listener.LocalEndPoint; _connectionManager = connectionManager; _authenticationManager = authenticationManager; if (_connectionManager == null) { _connectionManager = new DefaultProxyServerConnectionManager(); } //accept requests async int tasks = Math.Max(1, Environment.ProcessorCount); for (int i = 0; i < tasks; i++) { _ = Task.Factory.StartNew(AcceptRequestAsync, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Current); } }
public SocksProxyServer(IProxyServerConnectionManager connectionManager = null, IProxyServerAuthenticationManager authenticationManager = null, int backlog = 10) : this(new IPEndPoint(IPAddress.Loopback, 0), connectionManager, authenticationManager, backlog) { }
public ProxyServerSession(Socket localSocket, IProxyServerConnectionManager connectionManager, IProxyServerAuthenticationManager authenticationManager) { _localSocket = localSocket; _connectionManager = connectionManager; _authenticationManager = authenticationManager; }
public TransparentProxyServer(IProxyServerConnectionManager connectionManager = null, TransparentProxyServerMethod method = TransparentProxyServerMethod.DNAT, int backlog = 10) : this(new IPEndPoint(IPAddress.Any, 8081), connectionManager, method, backlog) { }
public ProxyServerSession(Socket localSocket, IProxyServerConnectionManager connectionManager, TransparentProxyServerMethod method) { _localSocket = localSocket; _connectionManager = connectionManager; _method = method; }