mirror of
https://github.com/2dust/v2rayN.git
synced 2025-04-20 06:02:23 +00:00
WebProxy uses socks5 instead of http
This commit is contained in:
parent
5d55a55754
commit
fbd4557b44
5 changed files with 15 additions and 15 deletions
|
@ -10,7 +10,7 @@ namespace ServiceLib.Common
|
||||||
{
|
{
|
||||||
private static readonly Lazy<HttpClientHelper> _instance = new(() =>
|
private static readonly Lazy<HttpClientHelper> _instance = new(() =>
|
||||||
{
|
{
|
||||||
HttpClientHandler handler = new() { UseCookies = false };
|
SocketsHttpHandler handler = new() { UseCookies = false };
|
||||||
HttpClientHelper helper = new(new HttpClient(handler));
|
HttpClientHelper helper = new(new HttpClient(handler));
|
||||||
return helper;
|
return helper;
|
||||||
});
|
});
|
||||||
|
|
|
@ -122,7 +122,7 @@ namespace ServiceLib.Services.CoreConfig
|
||||||
singboxConfig.inbounds.Clear();
|
singboxConfig.inbounds.Clear();
|
||||||
singboxConfig.outbounds.RemoveAt(0);
|
singboxConfig.outbounds.RemoveAt(0);
|
||||||
|
|
||||||
var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
|
var initPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
|
||||||
|
|
||||||
foreach (var it in selecteds)
|
foreach (var it in selecteds)
|
||||||
{
|
{
|
||||||
|
@ -144,8 +144,8 @@ namespace ServiceLib.Services.CoreConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
//find unused port
|
//find unused port
|
||||||
var port = httpPort;
|
var port = initPort;
|
||||||
for (int k = httpPort; k < Global.MaxPort; k++)
|
for (int k = initPort; k < Global.MaxPort; k++)
|
||||||
{
|
{
|
||||||
if (lstIpEndPoints?.FindIndex(_it => _it.Port == k) >= 0)
|
if (lstIpEndPoints?.FindIndex(_it => _it.Port == k) >= 0)
|
||||||
{
|
{
|
||||||
|
@ -157,7 +157,7 @@ namespace ServiceLib.Services.CoreConfig
|
||||||
}
|
}
|
||||||
//found
|
//found
|
||||||
port = k;
|
port = k;
|
||||||
httpPort = port + 1;
|
initPort = port + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -248,7 +248,7 @@ namespace ServiceLib.Services.CoreConfig
|
||||||
v2rayConfig.outbounds.Clear();
|
v2rayConfig.outbounds.Clear();
|
||||||
v2rayConfig.routing.rules.Clear();
|
v2rayConfig.routing.rules.Clear();
|
||||||
|
|
||||||
var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
|
var initPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
|
||||||
|
|
||||||
foreach (var it in selecteds)
|
foreach (var it in selecteds)
|
||||||
{
|
{
|
||||||
|
@ -270,8 +270,8 @@ namespace ServiceLib.Services.CoreConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
//find unused port
|
//find unused port
|
||||||
var port = httpPort;
|
var port = initPort;
|
||||||
for (var k = httpPort; k < Global.MaxPort; k++)
|
for (var k = initPort; k < Global.MaxPort; k++)
|
||||||
{
|
{
|
||||||
if (lstIpEndPoints?.FindIndex(_it => _it.Port == k) >= 0)
|
if (lstIpEndPoints?.FindIndex(_it => _it.Port == k) >= 0)
|
||||||
{
|
{
|
||||||
|
@ -283,7 +283,7 @@ namespace ServiceLib.Services.CoreConfig
|
||||||
}
|
}
|
||||||
//found
|
//found
|
||||||
port = k;
|
port = k;
|
||||||
httpPort = port + 1;
|
initPort = port + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -280,13 +280,13 @@ namespace ServiceLib.Services
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
|
var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
|
||||||
if (await SocketCheck(Global.Loopback, httpPort) == false)
|
if (await SocketCheck(Global.Loopback, port) == false)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new WebProxy(Global.Loopback, httpPort);
|
return new WebProxy($"socks5://{Global.Loopback}:{port}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> SocketCheck(string ip, int port)
|
private async Task<bool> SocketCheck(string ip, int port)
|
||||||
|
|
|
@ -191,7 +191,7 @@ namespace ServiceLib.Services
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
WebProxy webProxy = new(Global.Loopback, it.Port);
|
var webProxy = new WebProxy($"socks5://{Global.Loopback}:{it.Port}");
|
||||||
var output = await GetRealPingTime(downloadHandle, webProxy);
|
var output = await GetRealPingTime(downloadHandle, webProxy);
|
||||||
|
|
||||||
ProfileExHandler.Instance.SetTestDelay(it.IndexId, output);
|
ProfileExHandler.Instance.SetTestDelay(it.IndexId, output);
|
||||||
|
@ -262,7 +262,7 @@ namespace ServiceLib.Services
|
||||||
var item = await AppHandler.Instance.GetProfileItem(it.IndexId);
|
var item = await AppHandler.Instance.GetProfileItem(it.IndexId);
|
||||||
if (item is null) continue;
|
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) =>
|
await downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) =>
|
||||||
{
|
{
|
||||||
|
@ -324,7 +324,7 @@ namespace ServiceLib.Services
|
||||||
var item = await AppHandler.Instance.GetProfileItem(it.IndexId);
|
var item = await AppHandler.Instance.GetProfileItem(it.IndexId);
|
||||||
if (item is null) continue;
|
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) =>
|
_ = downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) =>
|
||||||
{
|
{
|
||||||
decimal.TryParse(msg, out var dec);
|
decimal.TryParse(msg, out var dec);
|
||||||
|
|
Loading…
Reference in a new issue