mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-13 11:59:13 +00:00
Fix
This commit is contained in:
parent
7c68e8aece
commit
8d61d6caaf
4 changed files with 82 additions and 37 deletions
|
@ -640,12 +640,12 @@ public partial class CoreConfigSingboxService
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge results: first the selector/urltest/proxies, then other outbounds, and finally prev outbounds
|
// Merge results: first the selector/urltest/proxies, then other outbounds, and finally prev outbounds
|
||||||
resultOutbounds.AddRange(prevOutbounds);
|
var serverList = new List<BaseServer4Sbox>();
|
||||||
resultOutbounds.AddRange(singboxConfig.outbounds);
|
serverList = serverList.Concat(prevOutbounds)
|
||||||
singboxConfig.outbounds = resultOutbounds;
|
.Concat(resultOutbounds)
|
||||||
singboxConfig.endpoints ??= new List<Endpoints4Sbox>();
|
.Concat(resultEndpoints)
|
||||||
resultEndpoints.AddRange(singboxConfig.endpoints);
|
.ToList();
|
||||||
singboxConfig.endpoints = resultEndpoints;
|
await AddRangeOutbounds(serverList, singboxConfig, baseTagName == Global.ProxyTag);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -770,12 +770,11 @@ public partial class CoreConfigSingboxService
|
||||||
resultOutbounds.Insert(0, outUrltest);
|
resultOutbounds.Insert(0, outUrltest);
|
||||||
resultOutbounds.Insert(0, outSelector);
|
resultOutbounds.Insert(0, outSelector);
|
||||||
}
|
}
|
||||||
singboxConfig.outbounds ??= new();
|
var serverList = new List<BaseServer4Sbox>();
|
||||||
resultOutbounds.AddRange(singboxConfig.outbounds);
|
serverList = serverList.Concat(resultOutbounds)
|
||||||
singboxConfig.outbounds = resultOutbounds;
|
.Concat(resultEndpoints)
|
||||||
singboxConfig.endpoints ??= new();
|
.ToList();
|
||||||
resultEndpoints.AddRange(singboxConfig.endpoints);
|
await AddRangeOutbounds(serverList, singboxConfig, baseTagName == Global.ProxyTag);
|
||||||
singboxConfig.endpoints = resultEndpoints;
|
|
||||||
return await Task.FromResult(0);
|
return await Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -818,14 +817,40 @@ public partial class CoreConfigSingboxService
|
||||||
resultOutbounds.Add(outbound);
|
resultOutbounds.Add(outbound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
singboxConfig.outbounds ??= new();
|
var serverList = new List<BaseServer4Sbox>();
|
||||||
resultOutbounds.AddRange(singboxConfig.outbounds);
|
serverList = serverList.Concat(resultOutbounds)
|
||||||
singboxConfig.outbounds = resultOutbounds;
|
.Concat(resultEndpoints)
|
||||||
|
.ToList();
|
||||||
singboxConfig.endpoints ??= new();
|
await AddRangeOutbounds(serverList, singboxConfig, baseTagName == Global.ProxyTag);
|
||||||
resultEndpoints.AddRange(singboxConfig.endpoints);
|
return await Task.FromResult(0);
|
||||||
singboxConfig.endpoints = resultEndpoints;
|
}
|
||||||
|
|
||||||
|
private async Task<int> AddRangeOutbounds(List<BaseServer4Sbox> servers, SingboxConfig singboxConfig, bool prepend = true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (servers is null || servers.Count <= 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
var outbounds = servers.Where(s => s is Outbound4Sbox).Cast<Outbound4Sbox>().ToList();
|
||||||
|
var endpoints = servers.Where(s => s is Endpoints4Sbox).Cast<Endpoints4Sbox>().ToList();
|
||||||
|
singboxConfig.endpoints ??= new();
|
||||||
|
if (prepend)
|
||||||
|
{
|
||||||
|
singboxConfig.outbounds.InsertRange(0, outbounds);
|
||||||
|
singboxConfig.endpoints.InsertRange(0, endpoints);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
singboxConfig.outbounds.AddRange(outbounds);
|
||||||
|
singboxConfig.endpoints.AddRange(endpoints);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
}
|
||||||
return await Task.FromResult(0);
|
return await Task.FromResult(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -376,7 +376,7 @@ public partial class CoreConfigSingboxService
|
||||||
return Global.ProxyTag;
|
return Global.ProxyTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tag = Global.ProxyTag + node.IndexId.ToString();
|
var tag = $"{node.IndexId}-{Global.ProxyTag}";
|
||||||
if (singboxConfig.outbounds.Any(o => o.tag == tag)
|
if (singboxConfig.outbounds.Any(o => o.tag == tag)
|
||||||
|| (singboxConfig.endpoints != null && singboxConfig.endpoints.Any(e => e.tag == tag)))
|
|| (singboxConfig.endpoints != null && singboxConfig.endpoints.Any(e => e.tag == tag)))
|
||||||
{
|
{
|
||||||
|
@ -385,11 +385,10 @@ public partial class CoreConfigSingboxService
|
||||||
|
|
||||||
if (node.ConfigType is EConfigType.PolicyGroup or EConfigType.ProxyChain)
|
if (node.ConfigType is EConfigType.PolicyGroup or EConfigType.ProxyChain)
|
||||||
{
|
{
|
||||||
var childBaseTagName = $"{Global.ProxyTag}-{node.IndexId}";
|
var ret = await GenGroupOutbound(node, singboxConfig, tag);
|
||||||
var ret = await GenGroupOutbound(node, singboxConfig, childBaseTagName);
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
return childBaseTagName;
|
return tag;
|
||||||
}
|
}
|
||||||
return Global.ProxyTag;
|
return Global.ProxyTag;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
using ServiceLib.Models;
|
||||||
|
|
||||||
namespace ServiceLib.Services.CoreConfig;
|
namespace ServiceLib.Services.CoreConfig;
|
||||||
|
|
||||||
public partial class CoreConfigV2rayService
|
public partial class CoreConfigV2rayService
|
||||||
|
@ -728,9 +730,17 @@ public partial class CoreConfigV2rayService
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge results: first the main chain outbounds, then other outbounds, and finally utility outbounds
|
// Merge results: first the main chain outbounds, then other outbounds, and finally utility outbounds
|
||||||
resultOutbounds.AddRange(prevOutbounds);
|
if (baseTagName == Global.ProxyTag)
|
||||||
resultOutbounds.AddRange(v2rayConfig.outbounds);
|
{
|
||||||
v2rayConfig.outbounds = resultOutbounds;
|
resultOutbounds.AddRange(prevOutbounds);
|
||||||
|
resultOutbounds.AddRange(v2rayConfig.outbounds);
|
||||||
|
v2rayConfig.outbounds = resultOutbounds;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
v2rayConfig.outbounds.AddRange(prevOutbounds);
|
||||||
|
v2rayConfig.outbounds.AddRange(resultOutbounds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -842,13 +852,19 @@ public partial class CoreConfigV2rayService
|
||||||
outbound.tag = baseTagName + (i + 1).ToString();
|
outbound.tag = baseTagName + (i + 1).ToString();
|
||||||
resultOutbounds.Add(outbound);
|
resultOutbounds.Add(outbound);
|
||||||
}
|
}
|
||||||
v2rayConfig.outbounds ??= new();
|
if (baseTagName == Global.ProxyTag)
|
||||||
resultOutbounds.AddRange(v2rayConfig.outbounds);
|
{
|
||||||
v2rayConfig.outbounds = resultOutbounds;
|
resultOutbounds.AddRange(v2rayConfig.outbounds);
|
||||||
|
v2rayConfig.outbounds = resultOutbounds;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
v2rayConfig.outbounds.AddRange(resultOutbounds);
|
||||||
|
}
|
||||||
return await Task.FromResult(0);
|
return await Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<int> GenChainOutboundsList(List<ProfileItem> nodes, V2rayConfig v2RayConfig, string baseTagName = Global.ProxyTag)
|
private async Task<int> GenChainOutboundsList(List<ProfileItem> nodes, V2rayConfig v2rayConfig, string baseTagName = Global.ProxyTag)
|
||||||
{
|
{
|
||||||
// Based on actual network flow instead of data packets
|
// Based on actual network flow instead of data packets
|
||||||
var nodesReverse = nodes.AsEnumerable().Reverse().ToList();
|
var nodesReverse = nodes.AsEnumerable().Reverse().ToList();
|
||||||
|
@ -889,9 +905,15 @@ public partial class CoreConfigV2rayService
|
||||||
|
|
||||||
resultOutbounds.Add(outbound);
|
resultOutbounds.Add(outbound);
|
||||||
}
|
}
|
||||||
v2RayConfig.outbounds ??= new();
|
if (baseTagName == Global.ProxyTag)
|
||||||
resultOutbounds.AddRange(v2RayConfig.outbounds);
|
{
|
||||||
v2RayConfig.outbounds = resultOutbounds;
|
resultOutbounds.AddRange(v2rayConfig.outbounds);
|
||||||
|
v2rayConfig.outbounds = resultOutbounds;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
v2rayConfig.outbounds.AddRange(resultOutbounds);
|
||||||
|
}
|
||||||
|
|
||||||
return await Task.FromResult(0);
|
return await Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ public partial class CoreConfigV2rayService
|
||||||
return Global.ProxyTag;
|
return Global.ProxyTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tag = Global.ProxyTag + node.IndexId.ToString();
|
var tag = $"{node.IndexId}-{Global.ProxyTag}";
|
||||||
if (v2rayConfig.outbounds.Any(p => p.tag == tag))
|
if (v2rayConfig.outbounds.Any(p => p.tag == tag))
|
||||||
{
|
{
|
||||||
return tag;
|
return tag;
|
||||||
|
@ -141,11 +141,10 @@ public partial class CoreConfigV2rayService
|
||||||
|
|
||||||
if (node.ConfigType is EConfigType.PolicyGroup or EConfigType.ProxyChain)
|
if (node.ConfigType is EConfigType.PolicyGroup or EConfigType.ProxyChain)
|
||||||
{
|
{
|
||||||
var childBaseTagName = $"{Global.ProxyTag}-{node.IndexId}";
|
var ret = await GenGroupOutbound(node, v2rayConfig, tag);
|
||||||
var ret = await GenGroupOutbound(node, v2rayConfig, childBaseTagName);
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
return childBaseTagName;
|
return tag;
|
||||||
}
|
}
|
||||||
return Global.ProxyTag;
|
return Global.ProxyTag;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue