mirror of
https://github.com/2dust/v2rayN.git
synced 2026-11-02 18:45:00 +03:00
Fix policy group (#10495)
This commit is contained in:
@@ -176,13 +176,13 @@ public partial class CoreConfigV2rayService(CoreConfigContext context)
|
||||
var tag = Global.ProxyTag + inbound.port.ToString();
|
||||
var isBalancer = false;
|
||||
//outbound
|
||||
var proxyOutbounds =
|
||||
new CoreConfigV2rayService(context with { Node = item }).BuildAllProxyOutbounds(tag);
|
||||
var service = new CoreConfigV2rayService(context with { Node = item });
|
||||
var proxyOutbounds = service.BuildAllProxyOutbounds(tag);
|
||||
_coreConfig.outbounds.AddRange(proxyOutbounds);
|
||||
if (proxyOutbounds.Count(n => n.tag.StartsWith(tag)) > 1)
|
||||
{
|
||||
isBalancer = true;
|
||||
var multipleLoad = _node.GetProtocolExtra().MultipleLoad ?? EMultipleLoad.LeastPing;
|
||||
var multipleLoad = service.FindFirstPolicyGroupMultipleLoad() ?? EMultipleLoad.LeastPing;
|
||||
GenObservatory(multipleLoad, tag);
|
||||
GenBalancer(multipleLoad, tag);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public partial class CoreConfigV2rayService
|
||||
_coreConfig.outbounds.InsertRange(0, proxyOutboundList);
|
||||
if (proxyOutboundList.Count(n => n.tag.StartsWith(Global.ProxyTag)) > 1)
|
||||
{
|
||||
var multipleLoad = _node.GetProtocolExtra().MultipleLoad ?? EMultipleLoad.LeastPing;
|
||||
var multipleLoad = FindFirstPolicyGroupMultipleLoad() ?? EMultipleLoad.LeastPing;
|
||||
GenObservatory(multipleLoad);
|
||||
GenBalancer(multipleLoad);
|
||||
}
|
||||
@@ -914,4 +914,32 @@ public partial class CoreConfigV2rayService
|
||||
}
|
||||
return clonedOutbounds;
|
||||
}
|
||||
|
||||
private EMultipleLoad? FindFirstPolicyGroupMultipleLoad()
|
||||
{
|
||||
if (!_node.ConfigType.IsGroupType())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// BFS: the nearest policy group in the group tree decides the multiple load strategy.
|
||||
var queue = new Queue<ProfileItem>([_node]);
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
var node = queue.Dequeue();
|
||||
if (node.ConfigType == EConfigType.PolicyGroup)
|
||||
{
|
||||
return node.GetProtocolExtra().MultipleLoad;
|
||||
}
|
||||
foreach (var childId in Utils.String2List(node.GetProtocolExtra().ChildItems) ?? [])
|
||||
{
|
||||
if (context.AllProxiesMap.TryGetValue(childId, out var childNode)
|
||||
&& childNode.ConfigType.IsGroupType())
|
||||
{
|
||||
queue.Enqueue(childNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,11 +200,12 @@ public partial class CoreConfigV2rayService
|
||||
return tag;
|
||||
}
|
||||
|
||||
var proxyOutbounds = new CoreConfigV2rayService(context with { Node = node, }).BuildAllProxyOutbounds(tag);
|
||||
var service = new CoreConfigV2rayService(context with { Node = node, });
|
||||
var proxyOutbounds = service.BuildAllProxyOutbounds(tag);
|
||||
_coreConfig.outbounds.AddRange(proxyOutbounds);
|
||||
if (proxyOutbounds.Count(n => n.tag.StartsWith(tag)) > 1)
|
||||
{
|
||||
var multipleLoad = node.GetProtocolExtra().MultipleLoad ?? EMultipleLoad.LeastPing;
|
||||
var multipleLoad = service.FindFirstPolicyGroupMultipleLoad() ?? EMultipleLoad.LeastPing;
|
||||
GenObservatory(multipleLoad, tag);
|
||||
GenBalancer(multipleLoad, tag);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user