Merge branch 'master' of https://github.com/shadowsocks/shadowsocks-windows.git into dev_proxy
# Conflicts: # shadowsocks-csharp/Controller/Service/TCPRelay.cs # shadowsocks-csharp/Controller/ShadowsocksController.cs # shadowsocks-csharp/View/MenuViewController.cs
This commit is contained in:
Executable → Regular
+71
-4
@@ -5,7 +5,6 @@ using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using Shadowsocks.Controller.Strategy;
|
||||
@@ -23,6 +22,7 @@ namespace Shadowsocks.Controller
|
||||
// interacts with low level logic
|
||||
|
||||
private Thread _ramThread;
|
||||
private Thread _trafficThread;
|
||||
|
||||
private Listener _listener;
|
||||
private PACServer _pacServer;
|
||||
@@ -35,6 +35,7 @@ namespace Shadowsocks.Controller
|
||||
|
||||
public long inboundCounter = 0;
|
||||
public long outboundCounter = 0;
|
||||
public QueueLast<TrafficPerSecond> traffic;
|
||||
|
||||
private bool stopped = false;
|
||||
|
||||
@@ -45,10 +46,30 @@ namespace Shadowsocks.Controller
|
||||
public string Path;
|
||||
}
|
||||
|
||||
public class QueueLast<T> : Queue<T>
|
||||
{
|
||||
public T Last { get; private set; }
|
||||
public new void Enqueue(T item)
|
||||
{
|
||||
Last = item;
|
||||
base.Enqueue(item);
|
||||
}
|
||||
}
|
||||
|
||||
public class TrafficPerSecond
|
||||
{
|
||||
public long inboundCounter;
|
||||
public long outboundCounter;
|
||||
public long inboundIncreasement;
|
||||
public long outboundIncreasement;
|
||||
}
|
||||
|
||||
public event EventHandler ConfigChanged;
|
||||
public event EventHandler EnableStatusChanged;
|
||||
public event EventHandler EnableGlobalChanged;
|
||||
public event EventHandler ShareOverLANStatusChanged;
|
||||
public event EventHandler VerboseLoggingStatusChanged;
|
||||
public event EventHandler TrafficChanged;
|
||||
|
||||
// when user clicked Edit PAC, and PAC file has already created
|
||||
public event EventHandler<PathEventArgs> PACFileReadyToOpen;
|
||||
@@ -66,6 +87,7 @@ namespace Shadowsocks.Controller
|
||||
StatisticsConfiguration = StatisticsStrategyConfiguration.Load();
|
||||
_strategyManager = new StrategyManager(this);
|
||||
StartReleasingMemory();
|
||||
StartTrafficStatistics(60);
|
||||
}
|
||||
|
||||
public void Start()
|
||||
@@ -205,6 +227,15 @@ namespace Shadowsocks.Controller
|
||||
SaveConfig(_config);
|
||||
}
|
||||
|
||||
public void ToggleVerboseLogging(bool enabled)
|
||||
{
|
||||
_config.isVerboseLogging = enabled;
|
||||
SaveConfig(_config);
|
||||
if ( VerboseLoggingStatusChanged != null ) {
|
||||
VerboseLoggingStatusChanged(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectServerIndex(int index)
|
||||
{
|
||||
_config.index = index;
|
||||
@@ -327,7 +358,7 @@ namespace Shadowsocks.Controller
|
||||
{
|
||||
if (_config.availabilityStatistics)
|
||||
{
|
||||
new Task(() => availabilityStatistics.UpdateLatency(server, (int) latency.TotalMilliseconds)).Start();
|
||||
availabilityStatistics.UpdateLatency(server, (int)latency.TotalMilliseconds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,7 +367,7 @@ namespace Shadowsocks.Controller
|
||||
Interlocked.Add(ref inboundCounter, n);
|
||||
if (_config.availabilityStatistics)
|
||||
{
|
||||
new Task(() => availabilityStatistics.UpdateInboundCounter(server, n)).Start();
|
||||
availabilityStatistics.UpdateInboundCounter(server, n);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,7 +376,7 @@ namespace Shadowsocks.Controller
|
||||
Interlocked.Add(ref outboundCounter, n);
|
||||
if (_config.availabilityStatistics)
|
||||
{
|
||||
new Task(() => availabilityStatistics.UpdateOutboundCounter(server, n)).Start();
|
||||
availabilityStatistics.UpdateOutboundCounter(server, n);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -530,5 +561,41 @@ namespace Shadowsocks.Controller
|
||||
}
|
||||
}
|
||||
|
||||
private void StartTrafficStatistics(int queueMaxSize)
|
||||
{
|
||||
traffic = new QueueLast<TrafficPerSecond>();
|
||||
for (int i = 0; i < queueMaxSize; i++)
|
||||
{
|
||||
traffic.Enqueue(new TrafficPerSecond());
|
||||
}
|
||||
_trafficThread = new Thread(new ThreadStart(() => TrafficStatistics(queueMaxSize)));
|
||||
_trafficThread.IsBackground = true;
|
||||
_trafficThread.Start();
|
||||
}
|
||||
|
||||
private void TrafficStatistics(int queueMaxSize)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
TrafficPerSecond previous = traffic.Last;
|
||||
TrafficPerSecond current = new TrafficPerSecond();
|
||||
current.inboundCounter = inboundCounter;
|
||||
current.outboundCounter = outboundCounter;
|
||||
current.inboundIncreasement = inboundCounter - previous.inboundCounter;
|
||||
current.outboundIncreasement = outboundCounter - previous.outboundCounter;
|
||||
|
||||
traffic.Enqueue(current);
|
||||
if (traffic.Count > queueMaxSize)
|
||||
traffic.Dequeue();
|
||||
|
||||
if (TrafficChanged != null)
|
||||
{
|
||||
TrafficChanged(this, new EventArgs());
|
||||
}
|
||||
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user