mirror of
https://github.com/2dust/v2rayN.git
synced 2026-11-03 02:55:01 +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 tag = Global.ProxyTag + inbound.port.ToString();
|
||||||
var isBalancer = false;
|
var isBalancer = false;
|
||||||
//outbound
|
//outbound
|
||||||
var proxyOutbounds =
|
var service = new CoreConfigV2rayService(context with { Node = item });
|
||||||
new CoreConfigV2rayService(context with { Node = item }).BuildAllProxyOutbounds(tag);
|
var proxyOutbounds = service.BuildAllProxyOutbounds(tag);
|
||||||
_coreConfig.outbounds.AddRange(proxyOutbounds);
|
_coreConfig.outbounds.AddRange(proxyOutbounds);
|
||||||
if (proxyOutbounds.Count(n => n.tag.StartsWith(tag)) > 1)
|
if (proxyOutbounds.Count(n => n.tag.StartsWith(tag)) > 1)
|
||||||
{
|
{
|
||||||
isBalancer = true;
|
isBalancer = true;
|
||||||
var multipleLoad = _node.GetProtocolExtra().MultipleLoad ?? EMultipleLoad.LeastPing;
|
var multipleLoad = service.FindFirstPolicyGroupMultipleLoad() ?? EMultipleLoad.LeastPing;
|
||||||
GenObservatory(multipleLoad, tag);
|
GenObservatory(multipleLoad, tag);
|
||||||
GenBalancer(multipleLoad, tag);
|
GenBalancer(multipleLoad, tag);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public partial class CoreConfigV2rayService
|
|||||||
_coreConfig.outbounds.InsertRange(0, proxyOutboundList);
|
_coreConfig.outbounds.InsertRange(0, proxyOutboundList);
|
||||||
if (proxyOutboundList.Count(n => n.tag.StartsWith(Global.ProxyTag)) > 1)
|
if (proxyOutboundList.Count(n => n.tag.StartsWith(Global.ProxyTag)) > 1)
|
||||||
{
|
{
|
||||||
var multipleLoad = _node.GetProtocolExtra().MultipleLoad ?? EMultipleLoad.LeastPing;
|
var multipleLoad = FindFirstPolicyGroupMultipleLoad() ?? EMultipleLoad.LeastPing;
|
||||||
GenObservatory(multipleLoad);
|
GenObservatory(multipleLoad);
|
||||||
GenBalancer(multipleLoad);
|
GenBalancer(multipleLoad);
|
||||||
}
|
}
|
||||||
@@ -914,4 +914,32 @@ public partial class CoreConfigV2rayService
|
|||||||
}
|
}
|
||||||
return clonedOutbounds;
|
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;
|
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);
|
_coreConfig.outbounds.AddRange(proxyOutbounds);
|
||||||
if (proxyOutbounds.Count(n => n.tag.StartsWith(tag)) > 1)
|
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);
|
GenObservatory(multipleLoad, tag);
|
||||||
GenBalancer(multipleLoad, tag);
|
GenBalancer(multipleLoad, tag);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user