@@ -23,7 +23,7 @@ namespace Shadowsocks.Controller | |||
public string LatestVersionLocalName; | |||
public event EventHandler CheckUpdateCompleted; | |||
public const string Version = "2.5.8.1"; | |||
public const string Version = "2.5.8.2"; | |||
private class CheckUpdateTimer : System.Timers.Timer | |||
{ | |||
@@ -63,6 +63,8 @@ namespace Shadowsocks.Controller | |||
public ShadowsocksController() | |||
{ | |||
_config = Configuration.Load(); | |||
inboundCounter = _config.bandwidthIn; | |||
outboundCounter = _config.bandwidthOut; | |||
StatisticsConfiguration = StatisticsStrategyConfiguration.Load(); | |||
_strategyManager = new StrategyManager(this); | |||
StartReleasingMemory(); | |||
@@ -253,7 +255,7 @@ namespace Shadowsocks.Controller | |||
public static string GetQRCode(Server server) | |||
{ | |||
string parts = server.method + ":" + server.password + "@" + server.server + ":" + server.server_port; | |||
string base64 = System.Convert.ToBase64String(Encoding.UTF8.GetBytes(parts)); | |||
string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(parts)); | |||
return "ss://" + base64; | |||
} | |||
@@ -310,17 +312,21 @@ namespace Shadowsocks.Controller | |||
public void UpdateInboundCounter(long n) | |||
{ | |||
Interlocked.Add(ref inboundCounter, n); | |||
_config.bandwidthIn = inboundCounter; | |||
} | |||
public void UpdateOutboundCounter(long n) | |||
{ | |||
Interlocked.Add(ref outboundCounter, n); | |||
_config.bandwidthOut = outboundCounter; | |||
} | |||
protected void Reload() | |||
{ | |||
// some logic in configuration updated the config when saving, we need to read it again | |||
_config = Configuration.Load(); | |||
inboundCounter = _config.bandwidthIn; | |||
outboundCounter = _config.bandwidthOut; | |||
StatisticsConfiguration = StatisticsStrategyConfiguration.Load(); | |||
if (polipoRunner == null) | |||
@@ -25,19 +25,17 @@ namespace Shadowsocks.Model | |||
public bool availabilityStatistics; | |||
public bool autoCheckUpdate; | |||
public LogViewerConfig logViewer; | |||
public long bandwidthIn; | |||
public long bandwidthOut; | |||
private static string CONFIG_FILE = "gui-config.json"; | |||
public Server GetCurrentServer() | |||
{ | |||
if (index >= 0 && index < configs.Count) | |||
{ | |||
return configs[index]; | |||
} | |||
else | |||
{ | |||
return GetDefaultServer(); | |||
} | |||
} | |||
public static void CheckServer(Server server) | |||
@@ -55,24 +53,15 @@ namespace Shadowsocks.Model | |||
Configuration config = JsonConvert.DeserializeObject<Configuration>(configContent); | |||
config.isDefault = false; | |||
if (config.localPort == 0) | |||
{ | |||
config.localPort = 1080; | |||
} | |||
if (config.index == -1) | |||
{ | |||
if (config.strategy == null) | |||
{ | |||
config.index = 0; | |||
} | |||
} | |||
if (config.index == -1 && config.strategy == null) | |||
config.index = 0; | |||
return config; | |||
} | |||
catch (Exception e) | |||
{ | |||
if (!(e is FileNotFoundException)) | |||
{ | |||
Logging.LogUsefulException(e); | |||
} | |||
return new Configuration | |||
{ | |||
index = 0, | |||
@@ -90,20 +79,11 @@ namespace Shadowsocks.Model | |||
public static void Save(Configuration config) | |||
{ | |||
if (config.index >= config.configs.Count) | |||
{ | |||
config.index = config.configs.Count - 1; | |||
} | |||
if (config.index < -1) | |||
{ | |||
config.index = -1; | |||
} | |||
if (config.index == -1) | |||
{ | |||
if (config.strategy == null) | |||
{ | |||
config.index = 0; | |||
} | |||
} | |||
if (config.index == -1 && config.strategy == null) | |||
config.index = 0; | |||
config.isDefault = false; | |||
try | |||
{ | |||
@@ -128,42 +108,32 @@ namespace Shadowsocks.Model | |||
private static void Assert(bool condition) | |||
{ | |||
if (!condition) | |||
{ | |||
throw new Exception(I18N.GetString("assertion failure")); | |||
} | |||
} | |||
public static void CheckPort(int port) | |||
{ | |||
if (port <= 0 || port > 65535) | |||
{ | |||
throw new ArgumentException(I18N.GetString("Port out of range")); | |||
} | |||
} | |||
public static void CheckLocalPort(int port) | |||
{ | |||
CheckPort(port); | |||
if (port == 8123) | |||
{ | |||
throw new ArgumentException(I18N.GetString("Port can't be 8123")); | |||
} | |||
} | |||
private static void CheckPassword(string password) | |||
{ | |||
if (string.IsNullOrEmpty(password)) | |||
{ | |||
throw new ArgumentException(I18N.GetString("Password can not be blank")); | |||
} | |||
} | |||
private static void CheckServer(string server) | |||
{ | |||
if (string.IsNullOrEmpty(server)) | |||
{ | |||
throw new ArgumentException(I18N.GetString("Server IP can not be blank")); | |||
} | |||
} | |||
} | |||
} |
@@ -24,7 +24,7 @@ namespace Shadowsocks.Model | |||
public override bool Equals(object obj) | |||
{ | |||
Server o2 = (Server)obj; | |||
return this.server == o2.server && this.server_port == o2.server_port; | |||
return server == o2.server && server_port == o2.server_port; | |||
} | |||
public string FriendlyName() | |||
@@ -45,12 +45,12 @@ namespace Shadowsocks.Model | |||
public Server() | |||
{ | |||
this.server = ""; | |||
this.server_port = 8388; | |||
this.method = "aes-256-cfb"; | |||
this.password = ""; | |||
this.remarks = ""; | |||
this.auth = false; | |||
server = ""; | |||
server_port = 8388; | |||
method = "aes-256-cfb"; | |||
password = ""; | |||
remarks = ""; | |||
auth = false; | |||
} | |||
public Server(string ssURL) : this() | |||
@@ -62,7 +62,7 @@ namespace Shadowsocks.Model | |||
{ | |||
try | |||
{ | |||
bytes = System.Convert.FromBase64String(base64); | |||
bytes = Convert.FromBase64String(base64); | |||
} | |||
catch (FormatException) | |||
{ | |||
@@ -80,16 +80,15 @@ namespace Shadowsocks.Model | |||
string afterAt = data.Substring(indexLastAt + 1); | |||
int indexLastColon = afterAt.LastIndexOf(':'); | |||
this.server_port = int.Parse(afterAt.Substring(indexLastColon + 1)); | |||
this.server = afterAt.Substring(0, indexLastColon); | |||
server_port = int.Parse(afterAt.Substring(indexLastColon + 1)); | |||
server = afterAt.Substring(0, indexLastColon); | |||
string beforeAt = data.Substring(0, indexLastAt); | |||
string[] parts = beforeAt.Split(new[] { ':' }); | |||
this.method = parts[0]; | |||
this.password = parts[1]; | |||
method = parts[0]; | |||
password = parts[1]; | |||
//TODO: read one_time_auth | |||
} | |||
catch (IndexOutOfRangeException) | |||
{ | |||