public void Stop()
        {
            if (stopped)
            {
                return;
            }
            stopped = true;

            if (_port_map_listener != null)
            {
                foreach (var l in _port_map_listener)
                {
                    l.Stop();
                }
                _port_map_listener = null;
            }

            _listener?.Stop();
            privoxyRunner?.Stop();
            if (_config.sysProxyMode != (int)ProxyMode.NoModify && _config.sysProxyMode != (int)ProxyMode.Direct)
            {
                SystemProxy.Update(_config, true, null);
            }
            ServerTransferTotal.Save(_transfer);
        }
        public void Stop()
        {
            if (_stopped)
            {
                return;
            }
            _stopped = true;

            StopPortMap();

            _listener?.Stop();
            _privoxyRunner?.Stop();
            SystemProxy.Restore();
            ServerTransferTotal.Save(_transfer, Global.GuiConfig.Configs);
        }
 public void Stop()
 {
     if (stopped)
     {
         return;
     }
     stopped = true;
     _listener?.Stop();
     StopPlugins();
     privoxyRunner?.Stop();
     if (_config.enabled)
     {
         SystemProxy.Update(_config, true);
     }
     Encryption.RNG.Close();
 }
示例#4
0
        public void Stop()
        {
            if (_stopped)
            {
                return;
            }
            _stopped = true;

            StopPortMap();

            _listener?.Stop();
            _privoxyRunner?.Stop();
            if (Global.GuiConfig.SysProxyMode != ProxyMode.NoModify && Global.GuiConfig.SysProxyMode != ProxyMode.Direct)
            {
                SystemProxy.SystemProxy.Update(Global.GuiConfig, true, null);
            }
            ServerTransferTotal.Save(_transfer, Global.GuiConfig.Configs);
        }
 public void Stop()
 {
     if (stopped)
     {
         return;
     }
     stopped = true;
     if (_listener != null)
     {
         _listener.Stop();
     }
     if (polipoRunner != null)
     {
         polipoRunner.Stop();
     }
     if (_config.enabled)
     {
         SystemProxy.Update(_config, true);
     }
 }
示例#6
0
 public void Stop()
 {
     if (stopped)
     {
         return;
     }
     stopped = true;
     if (_listener != null)
     {
         _listener.Stop();
     }
     if (privoxyRunner != null)
     {
         privoxyRunner.Stop();
     }
     if (_config.enabled)
     {
         SystemProxy.Update(_config, true, null);
     }
     Encryption.RNG.Close();
 }
示例#7
0
        protected void Reload()
        {
            Encryption.RNG.Reload();
            // some logic in configuration updated the config when saving, we need to read it again
            _config = Configuration.Load();

            NLogConfig.LoadConfiguration();

            StatisticsConfiguration = StatisticsStrategyConfiguration.Load();

            privoxyRunner = privoxyRunner ?? new PrivoxyRunner();

            _pacDaemon = _pacDaemon ?? new PACDaemon(_config);
            _pacDaemon.PACFileChanged      += PacDaemon_PACFileChanged;
            _pacDaemon.UserRuleFileChanged += PacDaemon_UserRuleFileChanged;
            _pacServer = _pacServer ?? new PACServer(_pacDaemon);
            _pacServer.UpdatePACURL(_config); // So PACServer works when system proxy disabled.

            GeositeUpdater.ResetEvent();
            GeositeUpdater.UpdateCompleted += PacServer_PACUpdateCompleted;
            GeositeUpdater.Error           += PacServer_PACUpdateError;

            availabilityStatistics.UpdateConfiguration(this);
            _listener?.Stop();
            StopPlugins();

            // don't put PrivoxyRunner.Start() before pacServer.Stop()
            // or bind will fail when switching bind address from 0.0.0.0 to 127.0.0.1
            // though UseShellExecute is set to true now
            // http://stackoverflow.com/questions/10235093/socket-doesnt-close-after-application-exits-if-a-launched-process-is-open
            privoxyRunner.Stop();
            try
            {
                var strategy = GetCurrentStrategy();
                strategy?.ReloadServers();

                StartPlugin();
                privoxyRunner.Start(_config);

                TCPRelay tcpRelay = new TCPRelay(this, _config);
                tcpRelay.OnConnected += UpdateLatency;
                tcpRelay.OnInbound   += UpdateInboundCounter;
                tcpRelay.OnOutbound  += UpdateOutboundCounter;
                tcpRelay.OnFailed    += (o, e) => GetCurrentStrategy()?.SetFailure(e.server);

                UDPRelay udpRelay = new UDPRelay(this);
                List <Listener.IService> services = new List <Listener.IService>
                {
                    tcpRelay,
                    udpRelay,
                    _pacServer,
                    new PortForwarder(privoxyRunner.RunningPort)
                };
                _listener = new Listener(services);
                _listener.Start(_config);
            }
            catch (Exception e)
            {
                // translate Microsoft language into human language
                // i.e. An attempt was made to access a socket in a way forbidden by its access permissions => Port already in use
                if (e is SocketException se)
                {
                    if (se.SocketErrorCode == SocketError.AddressAlreadyInUse)
                    {
                        e = new Exception(I18N.GetString("Port {0} already in use", _config.localPort), e);
                    }
                    else if (se.SocketErrorCode == SocketError.AccessDenied)
                    {
                        e = new Exception(I18N.GetString("Port {0} is reserved by system", _config.localPort), e);
                    }
                }
                logger.LogUsefulException(e);
                ReportError(e);
            }

            ConfigChanged?.Invoke(this, new EventArgs());
            UpdateSystemProxy();
            Utils.ReleaseMemory(true);
        }