Exemplo n.º 1
0
        /// <summary>
        ///     Gets the connection cache key.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="session">The session event arguments.</param>
        /// <param name="applicationProtocol">The application protocol.</param>
        /// <returns></returns>
        internal async Task <string> GetConnectionCacheKey(ProxyServerBase server, SessionEventArgsBase session,
                                                           SslApplicationProtocol applicationProtocol)
        {
            List <SslApplicationProtocol>?applicationProtocols = null;

            if (applicationProtocol != default)
            {
                applicationProtocols = new List <SslApplicationProtocol> {
                    applicationProtocol
                };
            }

            IExternalProxy?customUpStreamProxy = null;

            bool isHttps = session.IsHttps;

            if (server.GetCustomUpStreamProxyFunc != null)
            {
                customUpStreamProxy = await server.GetCustomUpStreamProxyFunc(session);
            }

            session.CustomUpStreamProxyUsed = customUpStreamProxy;

            var uri = session.HttpClient.Request.RequestUri;

            return(GetConnectionCacheKey(
                       uri.Host,
                       uri.Port,
                       isHttps, applicationProtocols,
                       session.HttpClient.UpStreamEndPoint ?? server.UpStreamEndPoint,
                       customUpStreamProxy ?? (isHttps ? server.UpStreamHttpsProxy : server.UpStreamHttpProxy)));
        }
 internal async Task InvokeBeforeSslAuthenticate(ProxyServerBase proxyServer,
                                                 BeforeSslAuthenticateEventArgs connectArgs, ExceptionHandler exceptionFunc)
 {
     if (BeforeSslAuthenticate != null)
     {
         await BeforeSslAuthenticate.InvokeAsync(proxyServer, connectArgs, exceptionFunc);
     }
 }
Exemplo n.º 3
0
 internal async Task InvokeBeforeTunnelConnectRequest(ProxyServerBase proxyServer,
                                                      TunnelConnectSessionEventArgs connectArgs, ExceptionHandler exceptionFunc)
 {
     if (BeforeTunnelConnectRequest != null)
     {
         await BeforeTunnelConnectRequest.InvokeAsync(proxyServer, connectArgs, exceptionFunc);
     }
 }
Exemplo n.º 4
0
 internal async Task InvokeBeforeTunnelConnectResponse(ProxyServerBase proxyServer,
                                                       TunnelConnectSessionEventArgs connectArgs, ExceptionHandler exceptionFunc, bool isClientHello = false)
 {
     if (BeforeTunnelConnectResponse != null)
     {
         connectArgs.IsHttpsConnect = isClientHello;
         await BeforeTunnelConnectResponse.InvokeAsync(proxyServer, connectArgs, exceptionFunc);
     }
 }
        internal TcpServerConnection(ProxyServerBase proxyServer, TcpClient tcpClient, HttpServerStream stream,
                                     string hostName, int port, bool isHttps, SslApplicationProtocol negotiatedApplicationProtocol,
                                     Version version, IExternalProxy?upStreamProxy, IPEndPoint?upStreamEndPoint, string cacheKey)
        {
            TcpClient        = tcpClient;
            LastAccess       = DateTime.Now;
            this.proxyServer = proxyServer;
            this.proxyServer.UpdateServerConnectionCount(true);
            Stream   = stream;
            HostName = hostName;
            Port     = port;
            IsHttps  = isHttps;
            NegotiatedApplicationProtocol = negotiatedApplicationProtocol;
            Version          = version;
            UpStreamProxy    = upStreamProxy;
            UpStreamEndPoint = upStreamEndPoint;

            CacheKey = cacheKey;
        }
Exemplo n.º 6
0
 internal TcpConnectionFactory(ProxyServerBase server)
 {
     this.Server = server;
     Task.Run(async() => await clearOutdatedConnections());
 }
Exemplo n.º 7
0
 internal TcpClientConnection(ProxyServerBase proxyServer, TcpClient tcpClient)
 {
     this.tcpClient   = tcpClient;
     this.proxyServer = proxyServer;
     this.proxyServer.UpdateClientConnectionCount(true);
 }