public ShadowsocksController()
 {
     _config = Configuration.Load();
     StatisticsConfiguration = StatisticsStrategyConfiguration.Load();
     _strategyManager        = new StrategyManager(this);
     StartReleasingMemory();
 }
Ejemplo n.º 2
0
 public bool Set(StatisticsStrategyConfiguration config)
 {
     _config = config;
     try
     {
         if (config.StatisticsEnabled)
         {
             if (_timer?.Change(DelayBeforeStart, Interval) == null)
             {
                 _state = new State();
                 _timer = new Timer(Run, _state, DelayBeforeStart, Interval);
             }
         }
         else
         {
             _timer?.Dispose();
         }
         return(true);
     }
     catch (Exception e)
     {
         Logging.LogUsefulException(e);
         return(false);
     }
 }
 public FuckshadowsController()
 {
     _config = Configuration.Load();
     StatisticsConfiguration = StatisticsStrategyConfiguration.Load();
     _strategyManager        = new StrategyManager(this);
     StartTrafficStatistics(61);
 }
 public ShadowsocksController()
 {
     _config = Configuration.Load();
     StatisticsConfiguration = StatisticsStrategyConfiguration.Load();
     _strategyManager        = new StrategyManager(this);
     StartReleasingMemory();
     StartTrafficStatistics(61);
     GetServerFromInternet();
 }
 public ShadowsocksController()
 {
     _config = Configuration.Load();
     StatisticsConfiguration = StatisticsStrategyConfiguration.Load();
     _strategyManager        = new StrategyManager(this);
     _pluginsByServer        = new ConcurrentDictionary <Server, Sip003Plugin>();
     StartReleasingMemory();
     StartTrafficStatistics(61);
 }
Ejemplo n.º 6
0
        private void LoadConfiguration()
        {
            var configs = _controller.GetCurrentConfiguration().configs;

            _servers       = configs.Select(server => server.FriendlyName()).ToList();
            _configuration = _controller.StatisticsConfiguration
                             ?? new StatisticsStrategyConfiguration();
            if (_configuration.Calculations == null)
            {
                _configuration = new StatisticsStrategyConfiguration();
            }
        }
Ejemplo n.º 7
0
        public ShadowsocksController()
        {
            _config = Configuration.Load();
            StatisticsConfiguration = StatisticsStrategyConfiguration.Load();
            _strategyManager        = new StrategyManager(this);
            _pluginsByServer        = new ConcurrentDictionary <Server, Sip003Plugin>();
            StartReleasingMemory();
            StartTrafficStatistics(61);

            ProgramUpdated += (o, e) =>
            {
                logger.Info($"Updated from {e.OldVersion} to {e.NewVersion}");
            };
        }
Ejemplo n.º 8
0
        public ShadowsocksController()
        {
            logger     = LogManager.GetCurrentClassLogger();
            httpClient = new HttpClient();
            _config    = Configuration.Load();
            Configuration.Process(ref _config);
            StatisticsConfiguration = StatisticsStrategyConfiguration.Load();
            _strategyManager        = new StrategyManager(this);
            _pluginsByServer        = new ConcurrentDictionary <Server, Sip003Plugin>();
            StartTrafficStatistics(61);

            ProgramUpdated += (o, e) =>
            {
                logger.Info($"Updated from {e.OldVersion} to {e.NewVersion}");
            };
        }
Ejemplo n.º 9
0
        public ShadowsocksController()
        {
/***************************************************<Start> add by Ian.May 2016/10/15****************************************************/
// for destructing fogNodes at closing stage, should not be handed from _config;(shallow copy)
/***************************************************<Start> add by Ian.May 2016/10/15****************************************************/
            _configBackup      = Configuration.Load();
            _clientUser        = ClientUser.Load();
            isShadowFogMode    = true;
            isInitialStartup   = true;
            isShadowFogStarted = false;

            SystemProxy.Update(_configBackup, true);// forcedisable = true ,means force _config.enabled = false to update(close) system proxy;
/****************************************************<End> add by Ian.May 2016/10/15*****************************************************/

            _config = Configuration.Load();
            StatisticsConfiguration = StatisticsStrategyConfiguration.Load();
            _strategyManager        = new StrategyManager(this);
            StartReleasingMemory();
            StartTrafficStatistics(61);
        }
        public ShadowsocksController()
        {
            /***************************************************<Start> add by Ian.May 2016/10/15****************************************************/
            // preparing parameters for destructing fogNodes at closing stage, should not be handed from _config;(shallow copy)
            _configBackup      = Configuration.Load();
            _clientUser        = ClientUser.Load();
            isShadowFogMode    = true;
            isInitialStartup   = true;
            isShadowFogStarted = false;

            Sysproxy.SetIEProxy(false, false, "", "");
            //Ends
            /****************************************************<End> add by Ian.May 2016/10/15*****************************************************/

            _config = Configuration.Load();
            StatisticsConfiguration = StatisticsStrategyConfiguration.Load();
            _strategyManager        = new StrategyManager(this);
            StartReleasingMemory();
            StartTrafficStatistics(61);
        }
        protected void Reload()
        {
            Encryption.RNG.Reload();
            // some logic in configuration updated the config when saving, we need to read it again
            _config = Configuration.Load();
            StatisticsConfiguration = StatisticsStrategyConfiguration.Load();

            if (privoxyRunner == null)
            {
                privoxyRunner = new PrivoxyRunner();
            }
            if (_pacServer == null)
            {
                _pacServer = new PACServer();
                _pacServer.PACFileChanged      += pacServer_PACFileChanged;
                _pacServer.UserRuleFileChanged += pacServer_UserRuleFileChanged;
            }
            _pacServer.UpdateConfiguration(_config);
            if (gfwListUpdater == null)
            {
                gfwListUpdater = new GFWListUpdater();
                gfwListUpdater.UpdateCompleted += pacServer_PACUpdateCompleted;
                gfwListUpdater.Error           += pacServer_PACUpdateError;
            }

            availabilityStatistics.UpdateConfiguration(this);

            if (_listener != null)
            {
                _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();
                if (strategy != null)
                {
                    strategy.ReloadServers();
                }

                StartPlugin();
                privoxyRunner.Start(_config);

                TCPRelay tcpRelay = new TCPRelay(this, _config);
                UDPRelay udpRelay = new UDPRelay(this);
                List <Listener.IService> services = new List <Listener.IService>();
                services.Add(tcpRelay);
                services.Add(udpRelay);
                services.Add(_pacServer);
                services.Add(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)
                {
                    SocketException se = (SocketException)e;
                    if (se.SocketErrorCode == SocketError.AccessDenied)
                    {
                        e = new Exception(I18N.GetString("Port already in use"), e);
                    }
                }
                Logging.LogUsefulException(e);
                ReportError(e);
            }

            if (ConfigChanged != null)
            {
                ConfigChanged(this, new EventArgs());
            }

            UpdateSystemProxy();
            Utils.ReleaseMemory(true);
        }
 public void SaveStrategyConfigurations(StatisticsStrategyConfiguration configuration)
 {
     StatisticsConfiguration = configuration;
     StatisticsStrategyConfiguration.Save(configuration);
 }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
 internal void UpdateConfiguration(Configuration config, StatisticsStrategyConfiguration statisticsConfig)
 {
     Set(statisticsConfig);
     _servers = config.configs;
 }
Ejemplo n.º 15
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();
            StatisticsConfiguration = StatisticsStrategyConfiguration.Load();

            if (_pacServer == null)
            {
                _pacServer = new PACServer();
                _pacServer.PACFileChanged      += pacServer_PACFileChanged;
                _pacServer.UserRuleFileChanged += pacServer_UserRuleFileChanged;
            }
            _pacServer.UpdateConfiguration(_config);
            if (gfwListUpdater == null)
            {
                gfwListUpdater = new GFWListUpdater();
                gfwListUpdater.UpdateCompleted += pacServer_PACUpdateCompleted;
                gfwListUpdater.Error           += pacServer_PACUpdateError;
            }

            availabilityStatistics.UpdateConfiguration(this);

            if (_listener != null)
            {
                _listener.Stop();
            }

            try
            {
                var strategy = GetCurrentStrategy();
                if (strategy != null)
                {
                    strategy.ReloadServers();
                }

                TCPRelay tcpRelay = new TCPRelay(this, _config);
                UDPRelay udpRelay = new UDPRelay(this);
                List <Listener.IService> services = new List <Listener.IService>();
                services.Add(_pacServer);
                services.Add(tcpRelay);
                services.Add(udpRelay);
                _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)
                {
                    SocketException se = (SocketException)e;
                    if (se.SocketErrorCode == SocketError.AccessDenied)
                    {
                        e = new Exception(I18N.GetString("Port already in use"), e);
                    }
                }
                Logging.LogUsefulException(e);
                ReportError(e);
            }

            if (ConfigChanged != null)
            {
                ConfigChanged(this, new EventArgs());
            }

            UpdateSystemProxy();
            Utils.ReleaseMemory(true);
        }
        protected void Reload()
        {
            // some logic in configuration updated the config when saving, we need to read it again
            _config = Configuration.Load();
            StatisticsConfiguration = StatisticsStrategyConfiguration.Load();

            if (polipoRunner == null)
            {
                polipoRunner = new PolipoRunner();
            }
            if (_pacServer == null)
            {
                _pacServer = new PACServer();
                _pacServer.PACFileChanged += pacServer_PACFileChanged;
            }
            _pacServer.UpdateConfiguration(_config);
            if (gfwListUpdater == null)
            {
                gfwListUpdater = new GFWListUpdater();
                gfwListUpdater.UpdateCompleted += pacServer_PACUpdateCompleted;
                gfwListUpdater.Error           += pacServer_PACUpdateError;
            }

            if (availabilityStatistics == null)
            {
                availabilityStatistics = new AvailabilityStatistics(_config, StatisticsConfiguration);
            }
            availabilityStatistics.UpdateConfiguration(_config, StatisticsConfiguration);

            if (_listener != null)
            {
                _listener.Stop();
            }
            // don't put polipoRunner.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
            polipoRunner.Stop();
            try
            {
                var strategy = GetCurrentStrategy();
                if (strategy != null)
                {
                    strategy.ReloadServers();
                }

                polipoRunner.Start(_config);

                TCPRelay tcpRelay = new TCPRelay(this);
                UDPRelay udpRelay = new UDPRelay(this);
                List <Listener.Service> services = new List <Listener.Service>();
                services.Add(tcpRelay);   // 开启本地socks5 tcp代理服务
                services.Add(udpRelay);   // 开启本地socks5 udp代理服务
                services.Add(_pacServer); // 开启本地pac服务器

                /*
                 * 这里是shadowsocks-windows能成为http代理的关键之处。:100:
                 * 我们在对ss-windows设置各种代理模式时,实际上只是对系统的internet选项进行的http代理设置。
                 * 我们知道,ss服务器是一个socks协议的代理,为什么对系统的http代理请求也能起作用呢?
                 *
                 * 当ss-windows启动时,同时会启动privoxy.exe(监听8123端口,可配置),privoxy是一个http代理,它收到http请求后,
                 * 转化成socks协议的数据,再转发给ss端口,由ss访问internet,再层层向回发。
                 *
                 *           http请求                     转发给                           封包成socks5协议,转发给
                 * browser-------------> ss socks5 代理 ----------------------> privoxy -----------------------------> ss socks5 代理
                 *       <--------------               <----------------------         <-----------------------------
                 *       转发http响应数据                 封包成http形式数据                 将结果以socks5形式返回
                 *
                 */
                services.Add(new PortForwarder(polipoRunner.RunningPort));  //开启本地http代理服务
                _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)
                {
                    SocketException se = (SocketException)e;
                    if (se.SocketErrorCode == SocketError.AccessDenied)
                    {
                        e = new Exception(I18N.GetString("Port already in use"), e);
                    }
                }
                Logging.LogUsefulException(e);
                ReportError(e);
            }

            if (ConfigChanged != null)
            {
                ConfigChanged(this, new EventArgs());
            }

            UpdateSystemProxy();
            Util.Utils.ReleaseMemory(true);
        }
Ejemplo n.º 17
0
 public AvailabilityStatistics(Configuration config, StatisticsStrategyConfiguration statisticsConfig)
 {
     UpdateConfiguration(config, statisticsConfig);
 }