Skip to content

Commit

Permalink
fix update subscribe, bump
Browse files Browse the repository at this point in the history
  • Loading branch information
breakwa11 committed Jun 6, 2017
1 parent 1adf65a commit 34933ce
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 145 deletions.
12 changes: 1 addition & 11 deletions shadowsocks-csharp/Controller/ShadowsocksController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,7 @@ private int FindFirstMatchServer(Server server, List<Server> servers)
{
for (int i = 0; i < servers.Count; ++i)
{
if (servers[i].server == server.server
&& servers[i].server_port == server.server_port
&& servers[i].server_udp_port == server.server_udp_port
&& servers[i].method == server.method
&& servers[i].protocol == server.protocol
&& servers[i].protocolparam == server.protocolparam
&& servers[i].obfs == server.obfs
&& servers[i].obfsparam == server.obfsparam
&& servers[i].password == server.password
&& servers[i].udp_over_tcp == server.udp_over_tcp
)
if (server.isMatchServer(servers[i]))
{
return i;
}
Expand Down
4 changes: 2 additions & 2 deletions shadowsocks-csharp/Controller/SystemProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ public static void Update(Configuration config, bool forceDisable)
bool global = sysProxyMode == (int)ProxyMode.Global;
bool enabled = sysProxyMode != (int)ProxyMode.Direct;
Version win8 = new Version("6.2");
if (Environment.OSVersion.Version.CompareTo(win8) < 0)
//if (Environment.OSVersion.Version.CompareTo(win8) < 0)
{
using (RegistryKey registry = OpenUserRegKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true))
{
Expand Down Expand Up @@ -569,7 +569,7 @@ public static void Update(Configuration config, bool forceDisable)
}
}
}
else
if (Environment.OSVersion.Version.CompareTo(win8) >= 0)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion shadowsocks-csharp/Controller/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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 = "4.4.2";
public const string Version = "4.4.5";
#if !_DOTNET_4_0
public const string NetVer = "2.0";
#elif !_CONSOLE
Expand Down
2 changes: 1 addition & 1 deletion shadowsocks-csharp/Controller/UpdateFreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Shadowsocks.Controller
{
public class UpdateFreeNode
{
private const string UpdateURL = "https://raw.githubusercontent.com/breakwa11/breakwa11.github.io/master/free/freenode.txt";
private const string UpdateURL = "https://raw.githubusercontent.com/breakwa11/breakwa11.github.io/master/free/freenodeplain.txt";

public event EventHandler NewFreeNodeFound;
public string FreeNodeResult;
Expand Down
4 changes: 2 additions & 2 deletions shadowsocks-csharp/Data/cn.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Disable bypass=全局
Servers=服务器
Edit servers...=编辑服务器...
Import servers from file...=从文件导入服务器...
Subscribe setting=SSR服务器订阅设置
Subscribe setting...=SSR服务器订阅设置...
Update subscribe SSR node=更新SSR服务器订阅
Update subscribe SSR node(bypass proxy)=更新SSR服务器订阅(不通过代理)
Global settings...=选项设置...
Expand Down Expand Up @@ -123,7 +123,7 @@ Clear &MaxSpeed=重置历史最高(&M)
&Clear=清空(&C)
Clear &Selected Total=清空选中节点历史流量(&S)
Clear &Total=清空所有历史流量(&T)
C&opy=复制(&O)
Port &out=导出(&O)
Copy current link=复制选中链接
Copy current group links=复制选中组链接
Copy all enable links=复制所有开启节点链接
Expand Down
4 changes: 2 additions & 2 deletions shadowsocks-csharp/Data/zh-tw.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Disable bypass=全局
Servers=伺服器
Edit servers...=編輯伺服器...
Import servers from file...=從文件導入伺服器...
Subscribe setting=SSR伺服器訂閱設置
Subscribe setting...=SSR伺服器訂閱設置...
Update subscribe SSR node=更新SSR伺服器訂閱
Update subscribe SSR node(bypass proxy)=更新SSR伺服器訂閱(不通過代理)
Global settings...=選項設置...
Expand Down Expand Up @@ -123,7 +123,7 @@ Clear &MaxSpeed=重置歷史最高(&M)
&Clear=清空(&C)
Clear &Selected Total=清空選中節點歷史流量(&S)
Clear &Total=清空所有歷史流量(&T)
C&opy=複製(&O)
Port &out=導出(&O)
Copy current link=複製選中連結
Copy current group links=複製選中組連結
Copy all enable links=複製所有開啟節點連結
Expand Down
11 changes: 7 additions & 4 deletions shadowsocks-csharp/Model/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public class Configuration

public string nodeFeedURL;
public string nodeFeedGroup;
public string nodeFeedDecodePass;
public bool nodeFeedAutoUpdate;

public Dictionary<string, string> token = new Dictionary<string, string>();
Expand All @@ -121,6 +120,8 @@ public class Configuration

private static string CONFIG_FILE = "gui-config.json";
private static string DEFAULT_SERVER = "ssr://bm9naWNhdC5uZXQ6NDQzOmF1dGhfYWVzMTI4X21kNTpyYzQtbWQ1LTY6dGxzMS4yX3RpY2tldF9hdXRoOlJHMHRhMWg3SzJ3Lz9vYmZzcGFyYW09Ym05bmFXTmhkQzV1WlhRJnByb3RvcGFyYW09TWpBd01EQXhPaXR0TkRoaU1XdEImcmVtYXJrcz1ibTluYVdOaGRDNXVaWFEmZ3JvdXA9Um5KbFpWTlRVaTF3ZFdKc2FXTQ";
private static string DEFAULT_FEED_URL = "https://raw.githubusercontent.com/breakwa11/breakwa11.github.io/master/free/freenodeplain.txt";
private static string OLD_DEFAULT_FEED_URL = "https://raw.githubusercontent.com/breakwa11/breakwa11.github.io/master/free/freenode.txt";

public static void SetPassword(string password)
{
Expand Down Expand Up @@ -381,9 +382,8 @@ public Configuration()
sysProxyMode = (int)ProxyMode.Global;
proxyRuleMode = (int)ProxyRuleMode.BypassLanAndChina;

nodeFeedURL = "https://raw.githubusercontent.com/breakwa11/breakwa11.github.io/master/free/freenode.txt";
nodeFeedURL = DEFAULT_FEED_URL;
nodeFeedGroup = "";
nodeFeedDecodePass = "ShadowsocksR";
nodeFeedAutoUpdate = true;

configs = new List<Server>()
Expand Down Expand Up @@ -422,7 +422,6 @@ public void CopyFrom(Configuration config)
isHideTips = config.isHideTips;
nodeFeedURL = config.nodeFeedURL;
nodeFeedGroup = config.nodeFeedGroup;
nodeFeedDecodePass = config.nodeFeedDecodePass;
nodeFeedAutoUpdate = config.nodeFeedAutoUpdate;
}

Expand Down Expand Up @@ -455,6 +454,10 @@ public void FixConfiguration()
{
localAuthPassword = randString(20);
}
if (nodeFeedURL == OLD_DEFAULT_FEED_URL)
{
nodeFeedURL = DEFAULT_FEED_URL;
}

Dictionary<string, int> id = new Dictionary<string, int>();
if (index < 0 || index >= configs.Count) index = 0;
Expand Down
23 changes: 21 additions & 2 deletions shadowsocks-csharp/Model/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public Server(string ssURL, string force_group) : this()
{
if (ssURL.StartsWith("ss://", StringComparison.OrdinalIgnoreCase))
{
ServerFromSS(ssURL);
ServerFromSS(ssURL, force_group);
}
else if (ssURL.StartsWith("ssr://", StringComparison.OrdinalIgnoreCase))
{
Expand All @@ -332,6 +332,23 @@ public Server(string ssURL, string force_group) : this()
}
}

public bool isMatchServer(Server server)
{
if (this.server == server.server
&& server_port == server.server_port
&& server_udp_port == server.server_udp_port
&& method == server.method
&& protocol == server.protocol
&& protocolparam == server.protocolparam
&& obfs == server.obfs
&& obfsparam == server.obfsparam
&& password == server.password
&& udp_over_tcp == server.udp_over_tcp
)
return true;
return false;
}

private Dictionary<string, string> ParseParam(string param_str)
{
Dictionary<string, string> params_dict = new Dictionary<string, string>();
Expand Down Expand Up @@ -424,7 +441,7 @@ public void ServerFromSSR(string ssrURL, string force_group)
group = force_group;
}

public void ServerFromSS(string ssURL)
public void ServerFromSS(string ssURL, string force_group)
{
Regex UrlFinder = new Regex("^(?i)ss://([A-Za-z0-9+-/=_]+)(#(.+))?", RegexOptions.IgnoreCase),
DetailsParser = new Regex("^((?<method>.+):(?<password>.*)@(?<hostname>.+?)" +
Expand All @@ -442,6 +459,8 @@ public void ServerFromSS(string ssURL)
password = match.Groups["password"].Value;
server = match.Groups["hostname"].Value;
server_port = int.Parse(match.Groups["port"].Value);
if (!String.IsNullOrEmpty(force_group))
group = force_group;
}

public string GetSSLinkForServer()
Expand Down
4 changes: 2 additions & 2 deletions shadowsocks-csharp/Model/ServerSelectStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private double Algorithm2(ServerSpeedLog serverSpeedLog) // perfer less delay
return MAX_CHANCE;
else
{
long avgConnectTime = serverSpeedLog.AvgConnectTime <= 0 ? 1 : serverSpeedLog.AvgConnectTime;
long avgConnectTime = serverSpeedLog.AvgConnectTime <= 0 ? 1 : serverSpeedLog.AvgConnectTime / 1000;
if (serverSpeedLog.TotalConnectTimes >= 1 && serverSpeedLog.AvgConnectTime < 0)
avgConnectTime = 5000;
long connections = serverSpeedLog.TotalConnectTimes - serverSpeedLog.TotalDisconnectTimes;
Expand All @@ -88,7 +88,7 @@ private double Algorithm3(ServerSpeedLog serverSpeedLog) // perfer less error
return MAX_CHANCE;
else
{
long avgConnectTime = serverSpeedLog.AvgConnectTime <= 0 ? 1 : serverSpeedLog.AvgConnectTime;
long avgConnectTime = serverSpeedLog.AvgConnectTime <= 0 ? 1 : serverSpeedLog.AvgConnectTime / 1000;
if (serverSpeedLog.TotalConnectTimes >= 1 && serverSpeedLog.AvgConnectTime < 0)
avgConnectTime = 5000;
long connections = serverSpeedLog.TotalConnectTimes - serverSpeedLog.TotalDisconnectTimes;
Expand Down
52 changes: 17 additions & 35 deletions shadowsocks-csharp/Model/ServerSpeedLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class ServerSpeedLogShow
public long totalUploadBytes;
public long totalDownloadBytes;
public long totalDownloadRawBytes;
public int sumConnectTime;
public long avgConnectTime;
public long avgDownloadBytes;
public long maxDownloadBytes;
Expand All @@ -69,8 +68,7 @@ public class ServerSpeedLog
private List<TransLog> upTransLog = new List<TransLog>();
private long maxTransDownload = 0;
private long maxTransUpload = 0;
private List<int> connectTime = null;
private int sumConnectTime = 0;
private int avgConnectTime = -1;
//private List<TransLog> speedLog = null;
private LinkedList<ErrorLog> errList = new LinkedList<ErrorLog>();

Expand Down Expand Up @@ -121,7 +119,6 @@ public ServerSpeedLogShow Translate()
ret.totalUploadBytes = transUpload;
ret.totalDownloadBytes = transDownload;
ret.totalDownloadRawBytes = transDownloadRaw;
ret.sumConnectTime = sumConnectTime;
}
return ret;
}
Expand Down Expand Up @@ -282,30 +279,7 @@ public long AvgConnectTime
{
get
{
lock (this)
{
if (connectTime != null)
{
if (connectTime.Count > 4)
{
List<int> sTime = new List<int>();
foreach (int t in connectTime)
{
sTime.Add(t);
}
sTime.Sort();
int sum = 0;
for (int i = 0; i < connectTime.Count / 2; ++i)
{
sum += sTime[i];
}
return sum / (connectTime.Count / 2);
}
if (connectTime.Count > 0)
return sumConnectTime / connectTime.Count;
}
return -1;
}
return avgConnectTime;
}
}
public void ClearError()
Expand Down Expand Up @@ -579,14 +553,22 @@ public void AddConnectTime(int millisecond)
{
lock (this)
{
if (connectTime == null)
connectTime = new List<int>();
connectTime.Add(millisecond);
sumConnectTime += millisecond;
while (connectTime.Count > 20)
if (millisecond == 0)
{
millisecond = 10;
}
else
{
millisecond *= 1000;
}
if (avgConnectTime == -1)
{
avgConnectTime = millisecond;
}
else
{
sumConnectTime -= connectTime[0];
connectTime.RemoveAt(0);
double a = 2.0 / (1 + 16);
avgConnectTime = (int)(0.5 + avgConnectTime * (1 - a) + a * millisecond);
}
}
}
Expand Down
Loading

0 comments on commit 34933ce

Please sign in to comment.