Ejemplo n.º 1
0
 public ProxyConnection(ProxyHost host, ProxyInfo proxy, TcpClient client)
 {
     this.Host         = host;
     this.ProxyInfo    = proxy;
     this.originClient = client;
     rulesEngine       = new RulesEngine();
     ConnectionId      = Interlocked.Increment(ref _connectionId);
 }
Ejemplo n.º 2
0
 public virtual void Add(ProxyInfo proxy)
 {
     _proxies.Add(proxy);
     proxy.PropertyChanged += ProxyInfo_PropertyChanged;
     if (proxy.Enabled)
     {
         new ProxyHost(proxy).Start();
     }
 }
Ejemplo n.º 3
0
 private void ProxyInfo_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "Enabled")
     {
         ProxyInfo proxyInfo = sender as ProxyInfo;
         if (proxyInfo.Enabled)
         {
             new ProxyHost(proxyInfo).Start();
         }
     }
 }
Ejemplo n.º 4
0
        public virtual void Remove(string name)
        {
            ProxyInfo proxyInfo = _proxies.FirstOrDefault(proxy => proxy.Name == name);

            if (proxyInfo != null)
            {
                proxyInfo.Enabled = false;
                _proxies.Remove(proxyInfo);
                proxyInfo.PropertyChanged -= ProxyInfo_PropertyChanged;
            }
        }
Ejemplo n.º 5
0
        public Task <SelfConnector> Connect(ProxyInfo proxyInfo)
        {
            this._proxyInfo = proxyInfo;
            Task <SelfConnector> connectionPromise = new Task <SelfConnector>(() =>
            {
                if (_channel?.Connected ?? false)
                {
                    return(this);
                }
                else
                {
                    throw new SocketException();
                }
            });

            _connectionThread = new Thread(() =>
            {
                _client = new TcpClient();
                _client.ConnectAsync("127.0.0.1", proxyInfo.Port).ContinueWith(OnConnected, connectionPromise);
            });
            _connectionThread.Start();
            return(connectionPromise);
        }
Ejemplo n.º 6
0
 public ProxyHost(ProxyInfo proxy)
 {
     this._proxy = proxy;
 }