Skip to content

Commit

Permalink
update to 5.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Soul Dark committed Aug 11, 2018
1 parent 67fb856 commit bc88ce4
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 35 deletions.
5 changes: 1 addition & 4 deletions shadowsocks-csharp/Controller/ShadowsocksController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ public void Start()

protected void ReportError(Exception e)
{
if (Errored != null)
{
Errored(this, new ErrorEventArgs(e));
}
Errored?.Invoke(this, new ErrorEventArgs(e));
}

public void ReloadIPRange()
Expand Down
15 changes: 3 additions & 12 deletions shadowsocks-csharp/Controller/UpdateChecker.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Shadowsocks.Model;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Windows.Forms;
Expand All @@ -21,7 +18,7 @@ public class UpdateChecker

public const string Name = "ShadowsocksR";
public const string Copyright = "Copyright © BreakWa11 2017. Fork from Shadowsocks by clowwindy";
public const string Version = "5.0.5";
public const string Version = "5.0.7";
#if !_CONSOLE
public const string NetVer = "4.0";
#else
Expand Down Expand Up @@ -194,10 +191,7 @@ private void http_DownloadStringCompleted(object sender, DownloadStringCompleted
SortVersions(versions);
LatestVersionURL = versions[versions.Count - 1];
LatestVersionNumber = ParseVersionFromURL(LatestVersionURL);
if (NewVersionFound != null)
{
NewVersionFound(this, new EventArgs());
}
NewVersionFound?.Invoke(this, new EventArgs());
}
catch (Exception ex)
{
Expand All @@ -206,10 +200,7 @@ private void http_DownloadStringCompleted(object sender, DownloadStringCompleted
Logging.Debug(e.Error.ToString());
}
Logging.Debug(ex.ToString());
if (NewVersionFound != null)
{
NewVersionFound(this, new EventArgs());
}
NewVersionFound?.Invoke(this, new EventArgs());
return;
}
}
Expand Down
51 changes: 48 additions & 3 deletions shadowsocks-csharp/Model/Server.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
#if !_CONSOLE
using SimpleJson;
Expand All @@ -10,7 +9,7 @@
using System.Text.RegularExpressions;
using System.Net;
using System.Net.Sockets;
using Shadowsocks.Encryption;
using System.Linq;

namespace Shadowsocks.Model
{
Expand All @@ -20,7 +19,7 @@ public class DnsBuffer
public DateTime updateTime;
public string host;
public bool force_expired;
public bool isExpired(string host)
public bool isExpired(string host)
{
if (updateTime == null) return true;
if (this.host != host) return true;
Expand Down Expand Up @@ -120,6 +119,13 @@ public class Server
public bool enable;
public bool udp_over_tcp;

public int latency;

public static int LATENCY_ERROR = -2;
public static int LATENCY_PENDING = -1;
public static int LATENCY_TESTING = 0;


private object protocoldata;
private object obfsdata;
private ServerSpeedLog serverSpeedLog = new ServerSpeedLog();
Expand Down Expand Up @@ -296,6 +302,7 @@ public Server()
group = "FreeSSR-public";
udp_over_tcp = false;
enable = true;
latency = LATENCY_PENDING;
byte[] id = new byte[16];
Util.Utils.RandBytes(id, id.Length);
this.id = BitConverter.ToString(id).Replace("-", "");
Expand Down Expand Up @@ -506,5 +513,43 @@ public void setProtocolData(object data)
{
this.protocoldata = data;
}

public void tcpingLatency()
{
var latencies = new List<double>();
var sock = new TcpClient();
var stopwatch = new Stopwatch();
stopwatch.Start();
try
{
Dns.GetHostAddresses(server);
}
catch (Exception)
{
latency = LATENCY_ERROR;
return;
}

var result = sock.BeginConnect(server, server_port, null, null);
if (result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(2)))
{
stopwatch.Stop();
latencies.Add(stopwatch.Elapsed.TotalMilliseconds);
sock.EndConnect(result);
}
else
{
stopwatch.Stop();
}

if (latencies.Count != 0)
{
latency = (int)latencies.Average();
}
else
{
latency = LATENCY_ERROR;
}
}
}
}
2 changes: 1 addition & 1 deletion shadowsocks-csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void Main(string[] args)
{
if (arg == "--setautorun")
{
if (!Controller.AutoStartup.Switch())
if (!AutoStartup.Switch())
{
Environment.ExitCode = 1;
}
Expand Down
72 changes: 58 additions & 14 deletions shadowsocks-csharp/View/MenuViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
using System.Threading;
using System.Text.RegularExpressions;
using Shadowsocks.Util;
using System.Net.Sockets;
using System.Net;
using System.Linq;

namespace Shadowsocks.View
{
Expand All @@ -40,6 +43,8 @@ public class MenuViewController
private UpdateFreeNode updateFreeNodeChecker;
private UpdateSubscribeManager updateSubscribeManager;

private bool isBeingUsed = false;

private NotifyIcon _notifyIcon;
private ContextMenu contextMenu1;

Expand Down Expand Up @@ -67,8 +72,9 @@ public class MenuViewController
private SubscribeForm subScribeForm;
private LogForm logForm;
private string _urlToOpen;
private System.Timers.Timer timerDetect360;
private System.Timers.Timer timerDetectVirus;
private System.Timers.Timer timerDelayCheckUpdate;
private System.Timers.Timer timerUpdateLatency;

private bool configfrom_open = false;
private List<EventParams> eventList = new List<EventParams>();
Expand Down Expand Up @@ -105,16 +111,21 @@ public MenuViewController(ShadowsocksController controller)
updateSubscribeManager = new UpdateSubscribeManager();

LoadCurrentConfiguration();
timerDetect360 = new System.Timers.Timer(1000.0 * 30);
timerDetect360.Elapsed += timerDetect360_Elapsed;
timerDetect360.Start();
timerDetectVirus = new System.Timers.Timer(1000.0 * 30);
timerDetectVirus.Elapsed += timerDetectVirus_Elapsed;
timerDetectVirus.Start();

//this interval will change
timerDelayCheckUpdate = new System.Timers.Timer(1000.0 * 10);
timerDelayCheckUpdate.Elapsed += timerDelayCheckUpdate_Elapsed;
timerDelayCheckUpdate.Start();

timerUpdateLatency = new System.Timers.Timer(1000.0 * 3);
timerUpdateLatency.Elapsed += timerUpdateLatency_Elapsed;
timerUpdateLatency.Start();
}

private void timerDetect360_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
private void timerDetectVirus_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (Utils.isVirusExist())
{
Expand Down Expand Up @@ -144,6 +155,16 @@ private void timerDelayCheckUpdate_Elapsed(object sender, System.Timers.ElapsedE
}
}

private void timerUpdateLatency_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
timerUpdateLatency.Interval = 1000.0 * 60;
Configuration configuration = _controller.GetCurrentConfiguration();
foreach (var server in configuration.configs)
{
server.tcpingLatency();
}
UpdateServersMenu();
}
void controller_Errored(object sender, System.IO.ErrorEventArgs e)
{
MessageBox.Show(e.GetException().ToString(), String.Format(I18N.GetString("Shadowsocks Error: {0}"), e.GetException().Message));
Expand Down Expand Up @@ -659,12 +680,12 @@ void updateChecker_NewVersionFound(object sender, EventArgs e)

void UpdateItem_Clicked(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(updateChecker.LatestVersionURL);
Process.Start(updateChecker.LatestVersionURL);
}

void notifyIcon1_BalloonTipClicked(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(updateChecker.LatestVersionURL);
Process.Start(updateChecker.LatestVersionURL);
_notifyIcon.BalloonTipClicked -= notifyIcon1_BalloonTipClicked;
}

Expand Down Expand Up @@ -717,7 +738,24 @@ private void UpdateServersMenu()
else
group_name = server.group;

MenuItem item = new MenuItem(server.FriendlyName());
string latency;
if (server.latency == Server.LATENCY_TESTING)
{
latency = "[testing]";
}
else if (server.latency == Server.LATENCY_ERROR)
{
latency = "[error]";
}
else if (server.latency == Server.LATENCY_PENDING)
{
latency = "[pending]";
}
else
{
latency = "[" + server.latency.ToString() + "ms]";
}
MenuItem item = new MenuItem(latency + " " + server.FriendlyName());
item.Tag = i;
item.Click += AServerItem_Click;
if (configuration.index == i)
Expand Down Expand Up @@ -900,7 +938,7 @@ void configForm_FormClosed(object sender, FormClosedEventArgs e)
{
configForm = null;
configfrom_open = false;
Util.Utils.ReleaseMemory();
Utils.ReleaseMemory();
if (eventList.Count > 0)
{
foreach (EventParams p in eventList)
Expand All @@ -914,7 +952,7 @@ void configForm_FormClosed(object sender, FormClosedEventArgs e)
void settingsForm_FormClosed(object sender, FormClosedEventArgs e)
{
settingsForm = null;
Util.Utils.ReleaseMemory();
Utils.ReleaseMemory();
}

void serverLogForm_FormClosed(object sender, FormClosedEventArgs e)
Expand Down Expand Up @@ -992,18 +1030,24 @@ private void Quit()
serverLogForm.Close();
serverLogForm = null;
}
if (timerDetect360 != null)
if (timerDetectVirus != null)
{
timerDetect360.Elapsed -= timerDetect360_Elapsed;
timerDetect360.Stop();
timerDetect360 = null;
timerDetectVirus.Elapsed -= timerDetectVirus_Elapsed;
timerDetectVirus.Stop();
timerDetectVirus = null;
}
if (timerDelayCheckUpdate != null)
{
timerDelayCheckUpdate.Elapsed -= timerDelayCheckUpdate_Elapsed;
timerDelayCheckUpdate.Stop();
timerDelayCheckUpdate = null;
}
if (timerUpdateLatency != null)
{
timerUpdateLatency.Elapsed -= timerUpdateLatency_Elapsed;
timerUpdateLatency.Stop();
timerUpdateLatency = null;
}
_notifyIcon.Visible = false;
Application.Exit();
}
Expand Down
2 changes: 1 addition & 1 deletion shadowsocks-csharp/ssr-win-4.0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:files="https://sourceforge.net/api/files.rdf#" xmlns:media="http://video.search.yahoo.com/mrss/" xmlns:doap="http://usefulinc.com/ns/doap#" xmlns:sf="https://sourceforge.net/api/sfelements.rdf#" version="2.0">
<channel xmlns:files="https://sourceforge.net/api/files.rdf#" xmlns:media="http://video.search.yahoo.com/mrss/" xmlns:doap="http://usefulinc.com/ns/doap#" xmlns:sf="https://sourceforge.net/api/sfelements.rdf#">
<item>
<media:content xmlns:media="http://video.search.yahoo.com/mrss/" type="application/zip; charset=binary" url="https://github.com/SoDa-GitHub/shadowsocksrr-csharp/releases/download/5.0.5/ShadowsocksR-win-5.0.5.7z" filesize="828669"></media:content>
<media:content xmlns:media="http://video.search.yahoo.com/mrss/" type="application/zip; charset=binary" url="https://github.com/SoDa-GitHub/shadowsocksrr-csharp/releases/download/5.0.7/ShadowsocksR-win-5.0.7.7z" filesize="828669"></media:content>
</item>
</channel>
</rss>
Expand Down

0 comments on commit bc88ce4

Please sign in to comment.