Browse Source

sip008 controller support

tags/4.2.1.0
Student Main 4 years ago
parent
commit
ca963c638d
No known key found for this signature in database GPG Key ID: AA78519C208C8742
2 changed files with 47 additions and 3 deletions
  1. +36
    -3
      shadowsocks-csharp/Controller/ShadowsocksController.cs
  2. +11
    -0
      shadowsocks-csharp/Model/Configuration.cs

+ 36
- 3
shadowsocks-csharp/Controller/ShadowsocksController.cs View File

@@ -7,6 +7,7 @@ using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Windows.Forms;
using NLog;
@@ -449,7 +450,7 @@ namespace Shadowsocks.Controller
#endregion
#region Misc
public void ToggleVerboseLogging(bool enabled)
{
_config.isVerboseLogging = enabled;
@@ -490,7 +491,7 @@ namespace Shadowsocks.Controller
ConfigChanged?.Invoke(this, new EventArgs());
}
#endregion
#region Statistic
@@ -567,7 +568,7 @@ namespace Shadowsocks.Controller
#endregion
#region SIP003
private void StartPlugin()
{
var server = _config.GetCurrentServer();
@@ -685,5 +686,37 @@ namespace Shadowsocks.Controller
#endregion
#region SIP008
public async Task UpdateOnlineConfig(string url)
{
var selected = GetCurrentServer();
var onlineServer = await OnlineConfigResolver.GetOnline(url, _config.WebProxy);
_config.configs = Configuration.SortByOnlineConfig(
_config.configs
.Where(c => c.group != url)
.Concat(onlineServer)
);
_config.index = _config.configs.IndexOf(selected);
Configuration.Save(_config);
}
public async Task UpdateAllOnlineConfig()
{
var selected = GetCurrentServer();
var r = await Task.WhenAll(
_config.onlineConfigSource.Select(url => OnlineConfigResolver.GetOnline(url, _config.WebProxy))
);
var results = r.SelectMany(s => s);
_config.configs = Configuration.SortByOnlineConfig(
_config.configs
.Where(c => string.IsNullOrEmpty(c.group))
.Concat(r.SelectMany(s => s))
);
_config.index = _config.configs.IndexOf(selected);
Configuration.Save(_config);
}
#endregion
}
}

+ 11
- 0
shadowsocks-csharp/Model/Configuration.cs View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using Newtonsoft.Json;
using NLog;
@@ -197,6 +198,7 @@ namespace Shadowsocks.Model
public static void Save(Configuration config)
{
config.configs = SortByOnlineConfig(config.configs);
config.version = UpdateChecker.Version;
if (config.index >= config.configs.Count)
config.index = config.configs.Count - 1;
@@ -230,6 +232,15 @@ namespace Shadowsocks.Model
}
}
public static List<Server> SortByOnlineConfig(IEnumerable<Server> servers)
{
var groups = servers.GroupBy(s => s.group);
List<Server> ret = new List<Server>();
ret.AddRange(groups.Where(g => string.IsNullOrEmpty(g.Key)).SelectMany(g => g));
ret.AddRange(groups.Where(g => !string.IsNullOrEmpty(g.Key)).SelectMany(g => g));
return ret;
}
public static Server AddDefaultServerOrServer(Configuration config, Server server = null, int? index = null)
{
if (config?.configs != null)


Loading…
Cancel
Save