Compare commits

...
6 Commits
Author SHA1 Message Date
clowwindy 60dc9e7d71 bump 2.5.1 2015-07-26 12:32:35 +08:00
clowwindy 02f75f899f update CHANGES 2015-07-26 12:32:17 +08:00
clowwindy eda92b80e1 refine logs 2015-07-26 12:27:34 +08:00
clowwindy ccec6be210 prevent jittering and fix server settings update in HA 2015-07-26 12:08:28 +08:00
clowwindy 01c059c4e3 fix server index problem 2015-07-26 11:37:09 +08:00
clowwindy a0e79f37bc fix #235 2015-07-26 10:44:44 +08:00
7 changed files with 55 additions and 12 deletions
+7 -1
View File
@@ -1,4 +1,10 @@
2.5 2015-07-11 2.5.1 2015-07-26
- Prevent HA from switching servers too frequently
- Fix a problem that server settings can not be updated when using HA
- Fix server port can't be 8123
- Other minor fixes
2.5 2015-07-25
- Support load balance - Support load balance
- Support high availability - Support high availability
@@ -83,6 +83,10 @@ namespace Shadowsocks.Controller
public void CreateRemote() public void CreateRemote()
{ {
Server server = controller.GetAServer(IStrategyCallerType.TCP, (IPEndPoint)connection.RemoteEndPoint); Server server = controller.GetAServer(IStrategyCallerType.TCP, (IPEndPoint)connection.RemoteEndPoint);
if (server == null || server.server == "")
{
throw new ArgumentException("No server configured");
}
this.encryptor = EncryptorFactory.GetEncryptor(server.method, server.password); this.encryptor = EncryptorFactory.GetEncryptor(server.method, server.password);
this.server = server; this.server = server;
} }
@@ -310,6 +314,7 @@ namespace Shadowsocks.Controller
StartConnect(); StartConnect();
} }
catch (Exception e) catch (Exception e)
{ {
Logging.LogUsefulException(e); Logging.LogUsefulException(e);
@@ -18,7 +18,7 @@ namespace Shadowsocks.Controller
public string LatestVersionURL; public string LatestVersionURL;
public event EventHandler NewVersionFound; public event EventHandler NewVersionFound;
public const string Version = "2.5"; public const string Version = "2.5.1";
public void CheckUpdate(Configuration config) public void CheckUpdate(Configuration config)
{ {
@@ -154,7 +154,7 @@ namespace Shadowsocks.Controller
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine(ex.ToString()); Logging.Debug(ex.ToString());
return; return;
} }
} }
@@ -109,6 +109,10 @@ namespace Shadowsocks.Controller
{ {
return strategy.GetAServer(type, localIPEndPoint); return strategy.GetAServer(type, localIPEndPoint);
} }
if (_config.index < 0)
{
_config.index = 0;
}
return GetCurrentServer(); return GetCurrentServer();
} }
@@ -293,7 +297,8 @@ namespace Shadowsocks.Controller
polipoRunner.Stop(); polipoRunner.Stop();
try try
{ {
foreach (var strategy in GetStrategies()) var strategy = GetCurrentStrategy();
if (strategy != null)
{ {
strategy.ReloadServers(); strategy.ReloadServers();
} }
@@ -7,7 +7,7 @@ namespace Shadowsocks.Controller.Strategy
{ {
class HighAvailabilityStrategy : IStrategy class HighAvailabilityStrategy : IStrategy
{ {
protected Server _currentServer; protected ServerStatus _currentServer;
protected Dictionary<Server, ServerStatus> _serverStatus; protected Dictionary<Server, ServerStatus> _serverStatus;
ShadowsocksController _controller; ShadowsocksController _controller;
Random _random; Random _random;
@@ -67,6 +67,11 @@ namespace Shadowsocks.Controller.Strategy
status.lastTimeDetectLatency = DateTime.Now; status.lastTimeDetectLatency = DateTime.Now;
newServerStatus[server] = status; newServerStatus[server] = status;
} }
else
{
// update settings for existing server
newServerStatus[server].server = server;
}
} }
_serverStatus = newServerStatus; _serverStatus = newServerStatus;
@@ -79,7 +84,11 @@ namespace Shadowsocks.Controller.Strategy
{ {
ChooseNewServer(); ChooseNewServer();
} }
return _currentServer; if (_currentServer == null)
{
return null;
}
return _currentServer.server;
} }
/** /**
@@ -90,7 +99,7 @@ namespace Shadowsocks.Controller.Strategy
*/ */
public void ChooseNewServer() public void ChooseNewServer()
{ {
Server oldServer = _currentServer; ServerStatus oldServer = _currentServer;
List<ServerStatus> servers = new List<ServerStatus>(_serverStatus.Values); List<ServerStatus> servers = new List<ServerStatus>(_serverStatus.Values);
DateTime now = DateTime.Now; DateTime now = DateTime.Now;
foreach (var status in servers) foreach (var status in servers)
@@ -120,12 +129,11 @@ namespace Shadowsocks.Controller.Strategy
} }
if (max != null) if (max != null)
{ {
_currentServer = max.server; if (_currentServer == null || max.score - _currentServer.score > 200)
if (_currentServer != oldServer)
{ {
Console.WriteLine("HA switching to server: {0}", _currentServer.FriendlyName()); _currentServer = max;
Console.WriteLine("HA switching to server: {0}", _currentServer.server.FriendlyName());
} }
Logging.Debug(String.Format("choosing server: {0}", _currentServer.FriendlyName()));
} }
} }
+19
View File
@@ -55,6 +55,13 @@ namespace Shadowsocks.Model
{ {
config.localPort = 1080; config.localPort = 1080;
} }
if (config.index == -1)
{
if (config.strategy == null)
{
config.index = 0;
}
}
return config; return config;
} }
catch (Exception e) catch (Exception e)
@@ -86,6 +93,13 @@ namespace Shadowsocks.Model
{ {
config.index = -1; config.index = -1;
} }
if (config.index == -1)
{
if (config.strategy == null)
{
config.index = 0;
}
}
config.isDefault = false; config.isDefault = false;
try try
{ {
@@ -121,6 +135,11 @@ namespace Shadowsocks.Model
{ {
throw new ArgumentException(I18N.GetString("Port out of range")); throw new ArgumentException(I18N.GetString("Port out of range"));
} }
}
public static void CheckLocalPort(int port)
{
CheckPort(port);
if (port == 8123) if (port == 8123)
{ {
throw new ArgumentException(I18N.GetString("Port can't be 8123")); throw new ArgumentException(I18N.GetString("Port can't be 8123"));
+1 -1
View File
@@ -84,7 +84,7 @@ namespace Shadowsocks.View
}; };
int localPort = int.Parse(ProxyPortTextBox.Text); int localPort = int.Parse(ProxyPortTextBox.Text);
Configuration.CheckServer(server); Configuration.CheckServer(server);
Configuration.CheckPort(localPort); Configuration.CheckLocalPort(localPort);
_modifiedConfiguration.configs[_oldSelectedIndex] = server; _modifiedConfiguration.configs[_oldSelectedIndex] = server;
_modifiedConfiguration.localPort = localPort; _modifiedConfiguration.localPort = localPort;