public void StartWebSocketListen() { socket.On(Quobject.SocketIoClientDotNet.Client.Socket.EVENT_CONNECT, async() => { await FreeUpdater.UpdateFreeConf(this); }); socket.On("update", (data) => { logger.Info("Updating Free Server From WebSocket..."); Server server = JsonConvert.DeserializeObject <Server>(data.ToString()); bool conf_changed = false; foreach (Server serve in _config.configs) { if (Configuration.ChecksServer(serve)) { if (serve.server == "a.isxb.top") { serve.server_port = server.server_port; serve.password = server.password; conf_changed = true; } } else { serve.server = server.server; serve.server_port = server.server_port; serve.password = server.password; serve.method = server.method; conf_changed = true; } } if (!conf_changed) { _config.configs.Add(server); _config.index = _config.configs.Count - 1; } SaveConfig(_config); }); }
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; FreeUpdater.ResetEvent(); FreeUpdater.FreeUpdateCompleted += FreeServer_UpdateCompleted; 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); }