Skip to content

Commit

Permalink
save bandwidth in config file per shadowsocks server
Browse files Browse the repository at this point in the history
  • Loading branch information
kimw committed Jan 10, 2016
1 parent f9bd1c9 commit 1ee07d1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion shadowsocks-csharp/Controller/Service/PACServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
16 changes: 8 additions & 8 deletions shadowsocks-csharp/Controller/ShadowsocksController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -404,7 +404,7 @@ protected void Reload()
}

UpdateSystemProxy();
Util.Utils.ReleaseMemory(true);
Utils.ReleaseMemory(true);
}

protected void SaveConfig(Configuration newConfig)
Expand Down Expand Up @@ -500,7 +500,7 @@ private void ReleaseMemory()
{
while (true)
{
Util.Utils.ReleaseMemory(false);
Utils.ReleaseMemory(false);
Thread.Sleep(30 * 1000);
}
}
Expand Down
2 changes: 0 additions & 2 deletions shadowsocks-csharp/Model/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 2 additions & 0 deletions shadowsocks-csharp/Model/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
3 changes: 2 additions & 1 deletion shadowsocks-csharp/View/MenuViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Shadowsocks.Controller;
using Shadowsocks.Model;
using Shadowsocks.Properties;
using Shadowsocks.Util;

namespace Shadowsocks.View
{
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 1ee07d1

Please sign in to comment.