mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-13 11:59:13 +00:00
Fix
This commit is contained in:
parent
ef09be7a26
commit
e2df1bc6cb
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
|
||||
resultOutbounds.AddRange(prevOutbounds);
|
||||
resultOutbounds.AddRange(singboxConfig.outbounds);
|
||||
singboxConfig.outbounds = resultOutbounds;
|
||||
singboxConfig.endpoints ??= new List<Endpoints4Sbox>();
|
||||
resultEndpoints.AddRange(singboxConfig.endpoints);
|
||||
singboxConfig.endpoints = resultEndpoints;
|
||||
var serverList = new List<BaseServer4Sbox>();
|
||||
serverList = serverList.Concat(prevOutbounds)
|
||||
.Concat(resultOutbounds)
|
||||
.Concat(resultEndpoints)
|
||||
.ToList();
|
||||
await AddRangeOutbounds(serverList, singboxConfig, baseTagName == Global.ProxyTag);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -770,12 +770,11 @@ public partial class CoreConfigSingboxService
|
|||
resultOutbounds.Insert(0, outUrltest);
|
||||
resultOutbounds.Insert(0, outSelector);
|
||||
}
|
||||
singboxConfig.outbounds ??= new();
|
||||
resultOutbounds.AddRange(singboxConfig.outbounds);
|
||||
singboxConfig.outbounds = resultOutbounds;
|
||||
singboxConfig.endpoints ??= new();
|
||||
resultEndpoints.AddRange(singboxConfig.endpoints);
|
||||
singboxConfig.endpoints = resultEndpoints;
|
||||
var serverList = new List<BaseServer4Sbox>();
|
||||
serverList = serverList.Concat(resultOutbounds)
|
||||
.Concat(resultEndpoints)
|
||||
.ToList();
|
||||
await AddRangeOutbounds(serverList, singboxConfig, baseTagName == Global.ProxyTag);
|
||||
return await Task.FromResult(0);
|
||||
}
|
||||
|
||||
|
@ -818,14 +817,40 @@ public partial class CoreConfigSingboxService
|
|||
resultOutbounds.Add(outbound);
|
||||
}
|
||||
}
|
||||
singboxConfig.outbounds ??= new();
|
||||
resultOutbounds.AddRange(singboxConfig.outbounds);
|
||||
singboxConfig.outbounds = resultOutbounds;
|
||||
var serverList = new List<BaseServer4Sbox>();
|
||||
serverList = serverList.Concat(resultOutbounds)
|
||||
.Concat(resultEndpoints)
|
||||
.ToList();
|
||||
await AddRangeOutbounds(serverList, singboxConfig, baseTagName == Global.ProxyTag);
|
||||
return await Task.FromResult(0);
|
||||
}
|
||||
|
||||
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();
|
||||
resultEndpoints.AddRange(singboxConfig.endpoints);
|
||||
singboxConfig.endpoints = resultEndpoints;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -376,7 +376,7 @@ public partial class CoreConfigSingboxService
|
|||
return Global.ProxyTag;
|
||||
}
|
||||
|
||||
var tag = Global.ProxyTag + node.IndexId.ToString();
|
||||
var tag = $"{node.IndexId}-{Global.ProxyTag}";
|
||||
if (singboxConfig.outbounds.Any(o => o.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)
|
||||
{
|
||||
var childBaseTagName = $"{Global.ProxyTag}-{node.IndexId}";
|
||||
var ret = await GenGroupOutbound(node, singboxConfig, childBaseTagName);
|
||||
var ret = await GenGroupOutbound(node, singboxConfig, tag);
|
||||
if (ret == 0)
|
||||
{
|
||||
return childBaseTagName;
|
||||
return tag;
|
||||
}
|
||||
return Global.ProxyTag;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using ServiceLib.Models;
|
||||
|
||||
namespace ServiceLib.Services.CoreConfig;
|
||||
|
||||
public partial class CoreConfigV2rayService
|
||||
|
@ -728,10 +730,18 @@ public partial class CoreConfigV2rayService
|
|||
}
|
||||
|
||||
// Merge results: first the main chain outbounds, then other outbounds, and finally utility outbounds
|
||||
if (baseTagName == Global.ProxyTag)
|
||||
{
|
||||
resultOutbounds.AddRange(prevOutbounds);
|
||||
resultOutbounds.AddRange(v2rayConfig.outbounds);
|
||||
v2rayConfig.outbounds = resultOutbounds;
|
||||
}
|
||||
else
|
||||
{
|
||||
v2rayConfig.outbounds.AddRange(prevOutbounds);
|
||||
v2rayConfig.outbounds.AddRange(resultOutbounds);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
|
@ -842,13 +852,19 @@ public partial class CoreConfigV2rayService
|
|||
outbound.tag = baseTagName + (i + 1).ToString();
|
||||
resultOutbounds.Add(outbound);
|
||||
}
|
||||
v2rayConfig.outbounds ??= new();
|
||||
if (baseTagName == Global.ProxyTag)
|
||||
{
|
||||
resultOutbounds.AddRange(v2rayConfig.outbounds);
|
||||
v2rayConfig.outbounds = resultOutbounds;
|
||||
}
|
||||
else
|
||||
{
|
||||
v2rayConfig.outbounds.AddRange(resultOutbounds);
|
||||
}
|
||||
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
|
||||
var nodesReverse = nodes.AsEnumerable().Reverse().ToList();
|
||||
|
@ -889,9 +905,15 @@ public partial class CoreConfigV2rayService
|
|||
|
||||
resultOutbounds.Add(outbound);
|
||||
}
|
||||
v2RayConfig.outbounds ??= new();
|
||||
resultOutbounds.AddRange(v2RayConfig.outbounds);
|
||||
v2RayConfig.outbounds = resultOutbounds;
|
||||
if (baseTagName == Global.ProxyTag)
|
||||
{
|
||||
resultOutbounds.AddRange(v2rayConfig.outbounds);
|
||||
v2rayConfig.outbounds = resultOutbounds;
|
||||
}
|
||||
else
|
||||
{
|
||||
v2rayConfig.outbounds.AddRange(resultOutbounds);
|
||||
}
|
||||
|
||||
return await Task.FromResult(0);
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ public partial class CoreConfigV2rayService
|
|||
return Global.ProxyTag;
|
||||
}
|
||||
|
||||
var tag = Global.ProxyTag + node.IndexId.ToString();
|
||||
var tag = $"{node.IndexId}-{Global.ProxyTag}";
|
||||
if (v2rayConfig.outbounds.Any(p => p.tag == tag))
|
||||
{
|
||||
return tag;
|
||||
|
@ -141,11 +141,10 @@ public partial class CoreConfigV2rayService
|
|||
|
||||
if (node.ConfigType is EConfigType.PolicyGroup or EConfigType.ProxyChain)
|
||||
{
|
||||
var childBaseTagName = $"{Global.ProxyTag}-{node.IndexId}";
|
||||
var ret = await GenGroupOutbound(node, v2rayConfig, childBaseTagName);
|
||||
var ret = await GenGroupOutbound(node, v2rayConfig, tag);
|
||||
if (ret == 0)
|
||||
{
|
||||
return childBaseTagName;
|
||||
return tag;
|
||||
}
|
||||
return Global.ProxyTag;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue