public void Process()
        {
            var localEndPoint  = (IPEndPoint)client.LocalEndPoint;
            var remoteEndPoint = (IPEndPoint)client.RemoteEndPoint;
            var connection     = connectionTracker[new Connection(ProtocolType.Tcp, localEndPoint, remoteEndPoint)].Mirror;

            if (connection != null)
            {
                var initialEndPoint   = connection.Source;
                var requestedEndPoint = connection.Destination;
                var tcpConnection     = connectionTracker.GetTCPConnection(initialEndPoint, requestedEndPoint);

                var logMessage = string.Format("{0}[{1}] {2} {{0}} connection to {3}",
                                               tcpConnection != null ? tcpConnection.ProcessName : "unknown",
                                               tcpConnection != null ? tcpConnection.PID : 0,
                                               initialEndPoint, requestedEndPoint);
                try
                {
                    var proxy = new ProxySocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    configureProxySocket(proxy, requestedEndPoint);

                    debug.Log(1, logMessage + " via {1}", "requested", proxy.ProxyEndPoint);

                    proxy.Connect(requestedEndPoint);

                    SocketPump.Pump(client, proxy);

                    proxy.Close();
                    debug.Log(1, logMessage, "closing");
                }
                catch (Exception ex)
                {
                    debug.Log(1, logMessage + ": {1}", "failed", ex.Message);
                }

                connectionTracker.QueueForCleanUp(connection);
            }
            else
            {
                var tcpConnection = connectionTracker.GetTCPConnection(remoteEndPoint, localEndPoint);
                debug.Log(1, "{0}[{1}] {2} has no mapping",
                          tcpConnection != null ? tcpConnection.ProcessName : "unknown",
                          tcpConnection != null ? tcpConnection.PID : 0,
                          remoteEndPoint);
                client.Send(Encoding.ASCII.GetBytes("No mapping\r\n"));
            }

            client.Close();
        }
Beispiel #2
0
        public void Process()
        {
            connected = true;
            var writer = new StreamWriter(stream);

            stream.BeginRead(buffer, 0, 0x1000, ReadComplete, null);

            var localEndPoint  = (IPEndPoint)client.Client.LocalEndPoint;
            var remoteEndPoint = (IPEndPoint)client.Client.RemoteEndPoint;

            var tcpConnection = connectionTracker.GetTCPConnection(remoteEndPoint, localEndPoint);

            var logMessage = string.Format("{0}[{1}] {2} {{0}} log",
                                           tcpConnection != null ? tcpConnection.ProcessName : "unknown",
                                           tcpConnection != null ? tcpConnection.PID : 0,
                                           client.Client.RemoteEndPoint);

            debug.Log(1, logMessage, "connected to");
            debug.Log(2, natter.GetStatus());

            try
            {
                writer.Write(debug.Status);
                writer.Flush();
                while (connected && client.Connected)
                {
                    string line;
                    if (!debug.Queue.TryDequeue(1000, out line))
                    {
                        continue;
                    }
                    writer.WriteLine(line);
                    writer.Flush();
                }
            }
            catch (SystemException)
            {
            }

            writer.Close();

            debug.Log(1, logMessage, "disconnected from");
        }