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); }
public virtual void Add(ProxyInfo proxy) { _proxies.Add(proxy); proxy.PropertyChanged += ProxyInfo_PropertyChanged; if (proxy.Enabled) { new ProxyHost(proxy).Start(); } }
private void ProxyInfo_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "Enabled") { ProxyInfo proxyInfo = sender as ProxyInfo; if (proxyInfo.Enabled) { new ProxyHost(proxyInfo).Start(); } } }
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; } }
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); }
public ProxyHost(ProxyInfo proxy) { this._proxy = proxy; }