From 1ee07d196ae7244309917db34454e7d3dc977a84 Mon Sep 17 00:00:00 2001 From: kimw Date: Sun, 10 Jan 2016 10:23:58 +0800 Subject: [PATCH] save bandwidth in config file per shadowsocks server --- .../Controller/Service/PACServer.cs | 2 +- .../Controller/ShadowsocksController.cs | 16 ++++++++-------- shadowsocks-csharp/Model/Configuration.cs | 2 -- shadowsocks-csharp/Model/Server.cs | 2 ++ shadowsocks-csharp/View/MenuViewController.cs | 3 ++- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/shadowsocks-csharp/Controller/Service/PACServer.cs b/shadowsocks-csharp/Controller/Service/PACServer.cs index 5db8b64ab..c6853331c 100644 --- a/shadowsocks-csharp/Controller/Service/PACServer.cs +++ b/shadowsocks-csharp/Controller/Service/PACServer.cs @@ -147,7 +147,7 @@ public void SendResponse(byte[] firstPacket, int length, Socket socket, bool use ", Encoding.UTF8.GetBytes(pac).Length) + pac; byte[] response = Encoding.UTF8.GetBytes(text); socket.BeginSend(response, 0, response.Length, 0, new AsyncCallback(SendCallback), socket); - Util.Utils.ReleaseMemory(true); + Utils.ReleaseMemory(true); } catch (Exception e) { diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 9ddce8ca9..356f58cb3 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -63,8 +63,8 @@ public class PathEventArgs : EventArgs public ShadowsocksController() { _config = Configuration.Load(); - inboundCounter = _config.bandwidthIn; - outboundCounter = _config.bandwidthOut; + inboundCounter = _config.GetCurrentServer().bandwidthIn; + outboundCounter = _config.GetCurrentServer().bandwidthOut; StatisticsConfiguration = StatisticsStrategyConfiguration.Load(); _strategyManager = new StrategyManager(this); StartReleasingMemory(); @@ -312,21 +312,21 @@ public void SaveLogViewerConfig(LogViewerConfig newConfig) public void UpdateInboundCounter(long n) { Interlocked.Add(ref inboundCounter, n); - _config.bandwidthIn = inboundCounter; + _config.GetCurrentServer().bandwidthIn = inboundCounter; } public void UpdateOutboundCounter(long n) { Interlocked.Add(ref outboundCounter, n); - _config.bandwidthOut = outboundCounter; + _config.GetCurrentServer().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; + inboundCounter = _config.GetCurrentServer().bandwidthIn; + outboundCounter = _config.GetCurrentServer().bandwidthOut; StatisticsConfiguration = StatisticsStrategyConfiguration.Load(); if (polipoRunner == null) @@ -404,7 +404,7 @@ protected void Reload() } UpdateSystemProxy(); - Util.Utils.ReleaseMemory(true); + Utils.ReleaseMemory(true); } protected void SaveConfig(Configuration newConfig) @@ -500,7 +500,7 @@ private void ReleaseMemory() { while (true) { - Util.Utils.ReleaseMemory(false); + Utils.ReleaseMemory(false); Thread.Sleep(30 * 1000); } } diff --git a/shadowsocks-csharp/Model/Configuration.cs b/shadowsocks-csharp/Model/Configuration.cs index b97cad030..d65c23a99 100755 --- a/shadowsocks-csharp/Model/Configuration.cs +++ b/shadowsocks-csharp/Model/Configuration.cs @@ -25,8 +25,6 @@ public class Configuration public bool availabilityStatistics; public bool autoCheckUpdate; public LogViewerConfig logViewer; - public long bandwidthIn; - public long bandwidthOut; private static string CONFIG_FILE = "gui-config.json"; diff --git a/shadowsocks-csharp/Model/Server.cs b/shadowsocks-csharp/Model/Server.cs index 8306d9e32..4ae22fde8 100755 --- a/shadowsocks-csharp/Model/Server.cs +++ b/shadowsocks-csharp/Model/Server.cs @@ -15,6 +15,8 @@ public class Server public string method; public string remarks; public bool auth; + public long bandwidthIn; + public long bandwidthOut; public override int GetHashCode() { diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 435f55ca0..32eb992da 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -11,6 +11,7 @@ using Shadowsocks.Controller; using Shadowsocks.Model; using Shadowsocks.Properties; +using Shadowsocks.Util; namespace Shadowsocks.View { @@ -387,7 +388,7 @@ void logForm_FormClosed(object sender, FormClosedEventArgs e) void configForm_FormClosed(object sender, FormClosedEventArgs e) { configForm = null; - Util.Utils.ReleaseMemory(true); + Utils.ReleaseMemory(true); ShowFirstTimeBalloon(); }