private void ProxyConnectCallback(IAsyncResult ar) { if (_closed) { return; } try { var session = (AsyncSession <ProxyTimer>)ar.AsyncState; ProxyTimer timer = session.State; var destEndPoint = timer.DestEndPoint; var server = timer.Server; timer.Elapsed -= ProxyConnectTimer_Elapsed; timer.Enabled = false; timer.Dispose(); var remote = session.Remote; // Complete the connection. remote.EndConnectProxy(ar); _proxyConnected = true; if (!(remote is DirectConnect)) { Logger.Debug($"Socket connected to proxy {remote.ProxyEndPoint}"); } _startConnectTime = DateTime.Now; ServerTimer connectTimer = new ServerTimer(_serverTimeout) { AutoReset = false }; connectTimer.Elapsed += DestConnectTimer_Elapsed; connectTimer.Enabled = true; connectTimer.Session = session; connectTimer.Server = server; _destConnected = false; NetworkCredential auth = null; if (_config.proxy.useAuth) { auth = new NetworkCredential(_config.proxy.authUser, _config.proxy.authPwd); } // Connect to the remote endpoint. remote.BeginConnectDest(destEndPoint, ConnectCallback, new AsyncSession <ServerTimer>(session, connectTimer), auth); } catch (ArgumentException) { } catch (Exception e) { Logger.LogUsefulException(e); Close(); } }
private void ProxyConnectCallback(IAsyncResult ar) { Server server = null; if (_closed) { return; } try { var session = (AsyncSession <ProxyTimer>)ar.AsyncState; ProxyTimer timer = session.State; var destEndPoint = timer.DestEndPoint; server = timer.Server; timer.Elapsed -= proxyConnectTimer_Elapsed; timer.Enabled = false; timer.Dispose(); var remote = session.Remote; // Complete the connection. remote.EndConnectProxy(ar); _proxyConnected = true; if (_config.isVerboseLogging) { if (!(remote is DirectConnect)) { Logging.Info($"Socket connected to proxy {remote.ProxyEndPoint}"); } } _startConnectTime = DateTime.Now; ServerTimer connectTimer = new ServerTimer(_serverTimeout); connectTimer.AutoReset = false; connectTimer.Elapsed += destConnectTimer_Elapsed; connectTimer.Enabled = true; connectTimer.Session = session; connectTimer.Server = server; _destConnected = false; // Connect to the remote endpoint. remote.BeginConnectDest(destEndPoint, new AsyncCallback(ConnectCallback), new AsyncSession <ServerTimer>(session, connectTimer)); } catch (ArgumentException) { } catch (Exception e) { Logging.LogUsefulException(e); Close(); } }
private void ProxyConnectTimer_Elapsed(object sender, ElapsedEventArgs e) { ProxyTimer timer = (ProxyTimer)sender; timer.Elapsed -= ProxyConnectTimer_Elapsed; timer.Enabled = false; timer.Dispose(); if (_proxyConnected || _destConnected || _closed) { return; } IProxy proxy = timer.Session.Remote; Logger.Info($"Proxy {proxy.ProxyEndPoint} timed out"); proxy.Close(); Close(); }