예제 #1
0
 private bool TryFindProxySession(AcceptedTcpClient acceptedTcpClient, out ProxySession proxySession)
 {
     lock (allProxySessions)
     {
         proxySession = allProxySessions.FirstOrDefault(p => p.SourceClient.RemoteEndPoint == acceptedTcpClient.RemoteEndPoint);
     }
     return(proxySession != null);
 }
예제 #2
0
        private ProxySession GetOrCreateProxySession(AcceptedTcpClient acceptedTcpClient)
        {
            ProxySession proxySession;

            if (!TryFindProxySession(acceptedTcpClient, out proxySession))
            {
                var rule = configuration.FindRule(acceptedTcpClient.RemoteEndPoint.Address);

                // TODO: find a better way to do that so it does not block the server from receiving data.
                var destinationClient = new DataStreamingClient(rule.Destination);
                destinationClient.ConnectAsync().Wait();
                proxySession = new ProxySession(acceptedTcpClient, destinationClient);
                allProxySessions.Add(proxySession);
            }
            return(proxySession);
        }