Example #1
0
        //================================================================================
        #endregion

        #region Constructor
        //================================================================================
        public ProxyService(int listenPort, string toHost, int toPort, ILogger logger,
                            IByPasser clientLogger = null, IByPasser targetLogger = null)
        {
            _logger     = logger;
            _listenPort = listenPort;
            _toHost     = toHost;
            _toPort     = toPort;

            _clientLogger = clientLogger != null ? clientLogger : ByPasser.Default;
            _targetLogger = targetLogger != null ? targetLogger : ByPasser.Default;
        }
Example #2
0
        //================================================================================
        #endregion

        #region Constructor
        //================================================================================
        public ProxyService(int listenPort, string toHost, int toPort, ILogger logger,
            IByPasser clientLogger = null, IByPasser targetLogger = null)
        {
            _logger = logger;
            _listenPort = listenPort;
            _toHost = toHost;
            _toPort = toPort;

            _clientLogger = clientLogger != null ? clientLogger : ByPasser.Default;
            _targetLogger = targetLogger != null ? targetLogger : ByPasser.Default;
        }
Example #3
0
        //================================================================================
        private bool CopyFromStream(NetworkStream from, NetworkStream to, Action <int> bytesRead, IByPasser logger)
        {
            try
            {
                if (from.CanRead && to.CanWrite)
                {
                    byte[] myReadBuffer      = new byte[1000024];
                    int    numberOfBytesRead = 0;

                    do
                    {
                        numberOfBytesRead = from.Read(myReadBuffer, 0, myReadBuffer.Length);
                        if (_latency != 0)
                        {
                            Thread.Sleep(_latency);
                        }
                        if (numberOfBytesRead != 0)
                        {
                            numberOfBytesRead = logger.Write(to, myReadBuffer, 0, numberOfBytesRead);
                            bytesRead(numberOfBytesRead);
                        }
                        else
                        {
                            return(false);
                        }
                    }while (from.DataAvailable);

                    to.Flush();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch { return(false); }
        }
Example #4
0
 public LoggingBypasser(Action <byte[], int, int> logger, IByPasser piggyback = null)
 {
     _piggyback = piggyback != null ? piggyback : ByPasser.Default;
     _logger    = logger;
 }
Example #5
0
 public HostReplaceBypasser(string realHost, IByPasser piggyback = null)
 {
     _realHost  = realHost;
     _piggyback = piggyback != null ? piggyback : ByPasser.Default;
 }
Example #6
0
        //================================================================================
        private bool CopyFromStream(NetworkStream from, NetworkStream to, Action<int> bytesRead, IByPasser logger)
        {
            try
            {
                if (from.CanRead && to.CanWrite)
                {
                    byte[] myReadBuffer = new byte[1000024];
                    int numberOfBytesRead = 0;

                    do
                    {
                        numberOfBytesRead = from.Read(myReadBuffer, 0, myReadBuffer.Length);
                        if (_latency != 0) Thread.Sleep(_latency);
                        if (numberOfBytesRead != 0)
                        {
                            numberOfBytesRead = logger.Write(to, myReadBuffer, 0, numberOfBytesRead);
                            bytesRead(numberOfBytesRead);
                        }
                        else
                        {
                            return false;
                        }
                    }
                    while (from.DataAvailable);

                    to.Flush();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch { return false; }
        }
Example #7
0
 public LoggingBypasser(Action<byte[], int, int> logger, IByPasser piggyback = null)
 {
     _piggyback = piggyback != null ? piggyback : ByPasser.Default;
     _logger = logger;
 }
Example #8
0
 public HostReplaceBypasser(string realHost, IByPasser piggyback = null)
 {
     _realHost = realHost;
     _piggyback = piggyback != null ? piggyback : ByPasser.Default;
 }