Esempio n. 1
0
        private void AcceptInboundCallback(IAsyncResult ar)
        {
            TcpClient inbound;

            try
            {
                inbound = listener.EndAcceptTcpClient(ar);
            }
            catch (Exception e)
            {
                if(e is NullReferenceException || e is ObjectDisposedException)
                    return;

                Stop();
                throw;
            }

            var proxy = new TcpProxy(inbound, outboundHost, outboundPort, inboundToOutboundDelay, outboundToInboundDelay, bufferSize);
            proxy.Connect();

            proxy.Closed += ProxyClosed;
            AddProxy(proxy);

            listener.BeginAcceptTcpClient(AcceptInboundCallback, listener);
        }
Esempio n. 2
0
        public TcpProxyViewModel(TcpProxy tcpProxy)
        {
            dispatcher = Dispatcher.CurrentDispatcher;

            this.tcpProxy = tcpProxy;

            Status = TcpProxyStatus.Running;

            RemoteEndpoint = tcpProxy.RemoteEndpoint.ToString();
            tcpProxy.InboundReadChanged += i => InboundRead = i;
            tcpProxy.OutboundReadChanged += i => OutboundRead = i;
            tcpProxy.OutboundWrittenChanged += i => OutboundWritten = i;
            tcpProxy.InboundWrittenChanged += i => InboundWritten = i;
            tcpProxy.Closed += TcpProxyOnClosed;
        }
Esempio n. 3
0
 private void TcpServerOnProxyRemoved(TcpProxy tcpProxy)
 {
     ThreadPool.QueueUserWorkItem(_ =>
     {
         Thread.Sleep(5000);
         dispatcher.Invoke(new Action<TcpProxy>(RemoveProxy), tcpProxy);
     });
 }
Esempio n. 4
0
 private void TcpServerOnProxyAdded(TcpProxy tcpProxy)
 {
     dispatcher.Invoke(new Action<TcpProxy>(AddProxy), tcpProxy);
 }
Esempio n. 5
0
        private void RemoveProxy(TcpProxy proxy)
        {
            var toRemove = Proxies.SingleOrDefault(p => p.UnderlyingProxy == proxy);

            if (toRemove != null)
                Proxies.Remove(toRemove);
        }
Esempio n. 6
0
 private void AddProxy(TcpProxy proxy)
 {
     Proxies.Add(new TcpProxyViewModel(proxy));
 }
Esempio n. 7
0
 private void ProxyClosed(TcpProxy proxy)
 {
     if (proxies.Remove(proxy))
         ProxyRemoved(proxy);
 }
Esempio n. 8
0
 private void AddProxy(TcpProxy proxy)
 {
     proxies.Add(proxy);
     ProxyAdded(proxy);
 }
Esempio n. 9
0
 private void TcpProxyOnClosed(TcpProxy _)
 {
     dispatcher.Invoke(new Action(() => { Status = TcpProxyStatus.Stopped; }));
 }