コード例 #1
0
        public void Reload()
        {
            StopPortMap();
            // some logic in configuration updated the config when saving, we need to read it again
            Global.GuiConfig = MergeGetConfiguration(Global.GuiConfig);
            Global.GuiConfig.FlushPortMapCache();
            Logging.SaveToFile = Global.GuiConfig.LogEnable;
            Logging.OpenLogFile();

            ReloadProxyRule();

            if (_privoxyRunner == null)
            {
                _privoxyRunner = new HttpProxyRunner();
            }
            ReloadPacServer();
            if (_gfwListUpdater == null)
            {
                _gfwListUpdater = new GfwListUpdater();
                _gfwListUpdater.UpdateCompleted += (o, args) => UpdatePACFromGFWListCompleted?.Invoke(o, args);
                _gfwListUpdater.Error           += (o, args) => UpdatePACFromGFWListError?.Invoke(o, args);
            }

            _listener?.Stop();

            _privoxyRunner.Stop();
            // 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
            try
            {
                _privoxyRunner.Start(Global.GuiConfig);

                var local    = new Local(Global.GuiConfig, _transfer, _chnRangeSet);
                var services = new List <Listener.IService>
                {
                    local,
                    _pacServer,
                    new HttpPortForwarder(_privoxyRunner.RunningPort, Global.GuiConfig)
                };
                _listener = new Listener(services);
                _listener.Start(Global.GuiConfig, 0);
            }
            catch (Exception e)
            {
                ThrowSocketException(ref e);
                Logging.LogUsefulException(e);
                ReportError(e);
            }

            LoadPortMap();

            Application.Current.Dispatcher?.InvokeAsync(() => { ConfigChanged?.Invoke(this, new EventArgs()); });

            UpdateSystemProxy();
            Utils.ReleaseMemory();
        }
コード例 #2
0
        public void Reload()
        {
            StopPortMap();
            // some logic in configuration updated the config when saving, we need to read it again
            Global.GuiConfig = MergeGetConfiguration(Global.GuiConfig);
            Global.GuiConfig.FlushPortMapCache();
            Logging.SaveToFile = Global.GuiConfig.LogEnable;
            Logging.OpenLogFile();

            ReloadProxyRule();

            _httpProxyRunner ??= new HttpProxyRunner();
            ReloadPacServer();
            if (_gfwListUpdater == null)
            {
                _gfwListUpdater = new GfwListUpdater();
                _gfwListUpdater.UpdateCompleted += (o, args) => UpdatePACFromGFWListCompleted?.Invoke(o, args);
                _gfwListUpdater.Error           += (o, args) => UpdatePACFromGFWListError?.Invoke(o, args);
            }

            _listener?.Stop();
            _httpProxyRunner.Stop();
            try
            {
                _httpProxyRunner.Start(Global.GuiConfig);

                var local    = new Local(Global.GuiConfig, _transfer, _chnRangeSet);
                var services = new List <Listener.IService>
                {
                    local,
                    _pacServer,
                    new HttpPortForwarder(_httpProxyRunner.RunningPort, Global.GuiConfig)
                };
                _listener = new Listener(services);
                _listener.Start(Global.GuiConfig, 0);
            }
            catch (Exception e)
            {
                ThrowSocketException(ref e);
                Logging.LogUsefulException(e);
                ReportError(e);
            }

            LoadPortMap();

            Application.Current.Dispatcher?.InvokeAsync(() => { ConfigChanged?.Invoke(this, new EventArgs()); });

            UpdateSystemProxy();
        }
コード例 #3
0
        private void PacDaemon_UserRuleFileChanged(object sender, EventArgs e)
        {
            if (!Utils.IsGFWListPAC(PACDaemon.PAC_FILE))
            {
                return;
            }
            if (!File.Exists(Utils.GetTempPath(PACServer.gfwlist_FILE)))
            {
                UpdatePACFromGFWList();
            }
            else
            {
                GfwListUpdater.MergeAndWritePacFile(FileManager.NonExclusiveReadAllText(Utils.GetTempPath(PACServer.gfwlist_FILE)));
            }

            UpdateSystemProxy();
        }
コード例 #4
0
        public void Reload()
        {
            if (_port_map_listener != null)
            {
                foreach (var l in _port_map_listener)
                {
                    l.Stop();
                }
                _port_map_listener = null;
            }
            // some logic in configuration updated the config when saving, we need to read it again
            _config = MergeGetConfiguration(_config);
            _config.FlushPortMapCache();
            Logging.SaveToFile = _config.logEnable;
            Logging.OpenLogFile();

            if (_hostDaemon == null)
            {
                _hostDaemon = new HostDaemon();
                _hostDaemon.ChnIpChanged    += (o, args) => ReloadIPRange();
                _hostDaemon.UserRuleChanged += (o, args) => HostMap.Reload();
            }
            ReloadIPRange();
            HostMap.Reload();

            GlobalConfiguration.OSSupportsLocalIPv6 = Socket.OSSupportsIPv6;

            if (privoxyRunner == null)
            {
                privoxyRunner = new HttpProxyRunner();
            }
            if (_pacDaemon == null)
            {
                _pacDaemon = new PACDaemon();
                _pacDaemon.PACFileChanged      += (o, args) => UpdateSystemProxy();
                _pacDaemon.UserRuleFileChanged += PacDaemon_UserRuleFileChanged;
            }
            if (_pacServer == null)
            {
                _pacServer = new PACServer(_pacDaemon);
            }
            _pacServer.UpdatePacUrl(_config);
            if (gfwListUpdater == null)
            {
                gfwListUpdater = new GfwListUpdater();
                gfwListUpdater.UpdateCompleted += (o, args) => UpdatePACFromGFWListCompleted?.Invoke(o, args);
                gfwListUpdater.Error           += (o, args) => UpdatePACFromGFWListError?.Invoke(o, args);
            }

            _listener?.Stop();

            privoxyRunner.Stop();
            // 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
            try
            {
                privoxyRunner.Start(_config);

                var local    = new Local(_config, _transfer, _chnRangeSet);
                var services = new List <Listener.IService>
                {
                    local,
                    _pacServer,
                    new HttpPortForwarder(privoxyRunner.RunningPort, _config)
                };
                _listener = new Listener(services);
                _listener.Start(_config, 0);
            }
            catch (Exception e)
            {
                ThrowSocketException(ref e);
                Logging.LogUsefulException(e);
                ReportError(e);
            }

            _port_map_listener = new List <Listener>();
            foreach (var pair in _config.GetPortMapCache())
            {
                try
                {
                    var local    = new Local(_config, _transfer, _chnRangeSet);
                    var services = new List <Listener.IService> {
                        local
                    };
                    var listener = new Listener(services);
                    listener.Start(_config, pair.Key);
                    _port_map_listener.Add(listener);
                }
                catch (Exception e)
                {
                    ThrowSocketException(ref e);
                    Logging.LogUsefulException(e);
                    ReportError(e);
                }
            }

            Application.Current.Dispatcher?.Invoke(() => { ConfigChanged?.Invoke(this, new EventArgs()); });

            UpdateSystemProxy();
            Utils.ReleaseMemory();
        }