void server_Connected(object sender, SslServer.ConnectedEventArgs args)
        {
            string connectionInfo = args.RemoteEndPoint.ToString();

            try
            {
                using (TcpClient client = OnConnectTarget(args))
                    using (BinaryLogging logging = new BinaryLogging(_logDirectory, args.RemoteEndPoint, args.LocalEndPoint))
                    {
                        client.Connect();
                        connectionInfo = String.Format("{0} => {1}", args.RemoteEndPoint, client.Client.RemoteEndPoint);
                        string revConnectionInfo = String.Format("{1} => {0}", args.RemoteEndPoint, client.Client.RemoteEndPoint);

                        OnConnectionEstablished(args, client);

                        StreamRedirect recv = new StreamRedirect(args.Stream, client.Stream, connectionInfo, logging.FromServer);
                        StreamRedirect send = new StreamRedirect(client.Stream, args.Stream, revConnectionInfo, logging.FromClient);

                        Log.Verbose("Streaming from {0}", connectionInfo);
                        WaitHandle.WaitAny(new WaitHandle[] { send.WaitClosed, recv.WaitClosed }, -1, true);
                    }
            }
            catch (ThreadAbortException) { throw; }
            catch (Exception e)
            {
                Log.Error(e);
            }
            finally
            {
                args.Close();
                Log.Verbose("Streaming shutdown from {0}", connectionInfo);
            }
        }
Ejemplo n.º 2
0
        protected override TcpClient OnConnectTarget(SslServer.ConnectedEventArgs args)
        {
            byte[] bytes    = new byte[4];
            int    read     = args.Stream.Read(bytes, 0, 4);
            int    origPort = ((int)bytes[0] << 24) | ((int)bytes[1] << 16) | ((int)bytes[2] << 8) | ((int)bytes[3]);

            return(_targets[origPort].Clone());
        }
Ejemplo n.º 3
0
        protected override void OnConnectionEstablished(SslServer.ConnectedEventArgs args, TcpClient client)
        {
            int port = args.LocalEndPoint.Port;

            byte[] bytes = new byte[4]
            {
                (byte)(0x00ff & (port >> 24)),
                (byte)(0x00ff & (port >> 16)),
                (byte)(0x00ff & (port >> 8)),
                (byte)(0x00ff & (port))
            };

            client.Stream.Write(bytes, 0, 4);
        }
 /// <summary>
 /// Called to handle a handshake when connecting to the forwarding target host
 /// </summary>
 protected abstract void OnConnectionEstablished(SslServer.ConnectedEventArgs args, TcpClient client);
 /// <summary>
 /// Called as a connection is established to determin the target of the forwarding
 /// </summary>
 protected abstract TcpClient OnConnectTarget(SslServer.ConnectedEventArgs args);
Ejemplo n.º 6
0
 protected override void OnConnectionEstablished(SslServer.ConnectedEventArgs args, TcpClient client)
 {
 }
 /// <summary>
 /// Returns the target of the forwarding channel
 /// </summary>
 protected override TcpClient OnConnectTarget(SslServer.ConnectedEventArgs args)
 {
     return(_target.Clone());
 }