WebProxy uses socks5 instead of http

This commit is contained in:
2dust 2024-12-06 14:01:11 +08:00
parent 5d55a55754
commit fbd4557b44
5 changed files with 15 additions and 15 deletions

View file

@ -10,7 +10,7 @@ namespace ServiceLib.Common
{
private static readonly Lazy<HttpClientHelper> _instance = new(() =>
{
HttpClientHandler handler = new() { UseCookies = false };
SocketsHttpHandler handler = new() { UseCookies = false };
HttpClientHelper helper = new(new HttpClient(handler));
return helper;
});

View file

@ -122,7 +122,7 @@ namespace ServiceLib.Services.CoreConfig
singboxConfig.inbounds.Clear();
singboxConfig.outbounds.RemoveAt(0);
var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
var initPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
foreach (var it in selecteds)
{
@ -144,8 +144,8 @@ namespace ServiceLib.Services.CoreConfig
}
//find unused port
var port = httpPort;
for (int k = httpPort; k < Global.MaxPort; k++)
var port = initPort;
for (int k = initPort; k < Global.MaxPort; k++)
{
if (lstIpEndPoints?.FindIndex(_it => _it.Port == k) >= 0)
{
@ -157,7 +157,7 @@ namespace ServiceLib.Services.CoreConfig
}
//found
port = k;
httpPort = port + 1;
initPort = port + 1;
break;
}

View file

@ -248,7 +248,7 @@ namespace ServiceLib.Services.CoreConfig
v2rayConfig.outbounds.Clear();
v2rayConfig.routing.rules.Clear();
var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
var initPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
foreach (var it in selecteds)
{
@ -270,8 +270,8 @@ namespace ServiceLib.Services.CoreConfig
}
//find unused port
var port = httpPort;
for (var k = httpPort; k < Global.MaxPort; k++)
var port = initPort;
for (var k = initPort; k < Global.MaxPort; k++)
{
if (lstIpEndPoints?.FindIndex(_it => _it.Port == k) >= 0)
{
@ -283,7 +283,7 @@ namespace ServiceLib.Services.CoreConfig
}
//found
port = k;
httpPort = port + 1;
initPort = port + 1;
break;
}

View file

@ -280,13 +280,13 @@ namespace ServiceLib.Services
{
return null;
}
var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
if (await SocketCheck(Global.Loopback, httpPort) == false)
var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
if (await SocketCheck(Global.Loopback, port) == false)
{
return null;
}
return new WebProxy(Global.Loopback, httpPort);
return new WebProxy($"socks5://{Global.Loopback}:{port}");
}
private async Task<bool> SocketCheck(string ip, int port)

View file

@ -191,7 +191,7 @@ namespace ServiceLib.Services
{
try
{
WebProxy webProxy = new(Global.Loopback, it.Port);
var webProxy = new WebProxy($"socks5://{Global.Loopback}:{it.Port}");
var output = await GetRealPingTime(downloadHandle, webProxy);
ProfileExHandler.Instance.SetTestDelay(it.IndexId, output);
@ -262,7 +262,7 @@ namespace ServiceLib.Services
var item = await AppHandler.Instance.GetProfileItem(it.IndexId);
if (item is null) continue;
WebProxy webProxy = new(Global.Loopback, it.Port);
var webProxy = new WebProxy($"socks5://{Global.Loopback}:{it.Port}");
await downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) =>
{
@ -324,7 +324,7 @@ namespace ServiceLib.Services
var item = await AppHandler.Instance.GetProfileItem(it.IndexId);
if (item is null) continue;
WebProxy webProxy = new(Global.Loopback, it.Port);
var webProxy = new WebProxy($"socks5://{Global.Loopback}:{it.Port}");
_ = downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) =>
{
decimal.TryParse(msg, out var dec);