Skip to content

Commit

Permalink
🎂 ForwardProxyView + HotkeysView + OnlineConfigView + VersionUpdatePr…
Browse files Browse the repository at this point in the history
…omptView

- Infrastructure: use one HttpClient instance throughout the lifecycle
- Version update: rewrite the update service and add update prompt window
- Server sharing: add copy link button
- Dependencies: add ReactiveUI.Events.WPF, ReactiveUI.Fody, ReactiveUI.Validation, WPFLocalizeExtension, MdXaml
  • Loading branch information
database64128 committed Oct 17, 2020
1 parent a05a782 commit d376002
Show file tree
Hide file tree
Showing 47 changed files with 3,391 additions and 2,322 deletions.
34 changes: 2 additions & 32 deletions shadowsocks-csharp/Controller/Service/GeositeUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public static class GeositeUpdater

private static readonly string DATABASE_PATH = Utils.GetTempPath("dlc.dat");

private static HttpClientHandler httpClientHandler;
private static HttpClient httpClient;
private static readonly string GEOSITE_URL = "https://github.com/v2fly/domain-list-community/raw/release/dlc.dat";
private static readonly string GEOSITE_SHA256SUM_URL = "https://github.com/v2fly/domain-list-community/raw/release/dlc.dat.sha256sum";
private static byte[] geositeDB;
Expand Down Expand Up @@ -82,30 +80,15 @@ public static async Task UpdatePACFromGeosite()
SHA256 mySHA256 = SHA256.Create();
var config = Program.MainController.GetCurrentConfiguration();
bool blacklist = config.geositePreferDirect;

var httpClient = Program.MainController.GetHttpClient();

if (!string.IsNullOrWhiteSpace(config.geositeUrl))
{
logger.Info("Found custom Geosite URL in config file");
geositeUrl = config.geositeUrl;
}
logger.Info($"Checking Geosite from {geositeUrl}");

// use System.Net.Http.HttpClient to download GeoSite db.
// NASTY workaround: new HttpClient every update
// because we can't change proxy on existing socketsHttpHandler instance
httpClientHandler = new HttpClientHandler();
httpClient = new HttpClient(httpClientHandler);
if (!string.IsNullOrWhiteSpace(config.userAgentString))
httpClient.DefaultRequestHeaders.Add("User-Agent", config.userAgentString);
if (config.enabled)
{
httpClientHandler.Proxy = new WebProxy(
config.isIPv6Enabled
? $"[{IPAddress.IPv6Loopback}]"
: IPAddress.Loopback.ToString(),
config.localPort);
}

try
{
// download checksum first
Expand Down Expand Up @@ -154,19 +137,6 @@ public static async Task UpdatePACFromGeosite()
{
Error?.Invoke(null, new ErrorEventArgs(ex));
}
finally
{
if (httpClientHandler != null)
{
httpClientHandler.Dispose();
httpClientHandler = null;
}
if (httpClient != null)
{
httpClient.Dispose();
httpClient = null;
}
}
}

/// <summary>
Expand Down
17 changes: 2 additions & 15 deletions shadowsocks-csharp/Controller/Service/OnlineConfigResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,15 @@ namespace Shadowsocks.Controller.Service
{
public class OnlineConfigResolver
{
public static async Task<List<Server>> GetOnline(string url, string userAgentString, IWebProxy proxy = null)
public static async Task<List<Server>> GetOnline(string url)
{
var httpClientHandler = new HttpClientHandler()
{
Proxy = proxy
};
var httpClient = new HttpClient(httpClientHandler)
{
Timeout = TimeSpan.FromSeconds(15)
};
if (!string.IsNullOrWhiteSpace(userAgentString))
httpClient.DefaultRequestHeaders.Add("User-Agent", userAgentString);

var httpClient = Program.MainController.GetHttpClient();
string server_json = await httpClient.GetStringAsync(url);

var servers = server_json.GetServers();

foreach (var server in servers)
{
server.group = url;
}

return servers.ToList();
}
}
Expand Down
6 changes: 3 additions & 3 deletions shadowsocks-csharp/Controller/Service/TCPRelay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public AsyncSession(AsyncSession session, T state) : base(session.Remote)
public DateTime lastActivity;

private readonly ShadowsocksController _controller;
private readonly ProxyConfig _config;
private readonly ForwardProxyConfig _config;
private readonly Socket _connection;

private IEncryptor _encryptor;
Expand Down Expand Up @@ -665,10 +665,10 @@ private void StartConnect()
{
switch (_config.proxyType)
{
case ProxyConfig.PROXY_SOCKS5:
case ForwardProxyConfig.PROXY_SOCKS5:
remote = new Socks5Proxy();
break;
case ProxyConfig.PROXY_HTTP:
case ForwardProxyConfig.PROXY_HTTP:
remote = new HttpProxy();
break;
default:
Expand Down
Loading

0 comments on commit d376002

Please sign in to comment.