From 33f5d20022cdcecd27115f80f14a8478c5e93556 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 3 Oct 2025 17:11:56 +0800 Subject: [PATCH] Update ProfileGroupItem.cs --- v2rayN/ServiceLib/Models/ProfileGroupItem.cs | 45 +++++++++++++++++++ .../CoreConfig/V2ray/V2rayOutboundService.cs | 3 +- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/v2rayN/ServiceLib/Models/ProfileGroupItem.cs b/v2rayN/ServiceLib/Models/ProfileGroupItem.cs index eb6ac49f..bb1615ae 100644 --- a/v2rayN/ServiceLib/Models/ProfileGroupItem.cs +++ b/v2rayN/ServiceLib/Models/ProfileGroupItem.cs @@ -1,4 +1,5 @@ using SQLite; + namespace ServiceLib.Models; [Serializable] @@ -10,4 +11,48 @@ public class ProfileGroupItem public string ChildItems { get; set; } public EMultipleLoad MultipleLoad { get; set; } = EMultipleLoad.LeastPing; + + public bool HasCycle() + { + return HasCycle(new HashSet(), new HashSet()); + } + + public bool HasCycle(HashSet visited, HashSet stack) + { + if (string.IsNullOrEmpty(ParentIndexId)) + return false; + + if (stack.Contains(ParentIndexId)) + return true; + + if (visited.Contains(ParentIndexId)) + return false; + + visited.Add(ParentIndexId); + stack.Add(ParentIndexId); + + if (string.IsNullOrEmpty(ChildItems)) + { + return false; + } + + var childIds = Utils.String2List(ChildItems) + .Where(p => !string.IsNullOrEmpty(p)) + .ToList(); + + var childProfiles = childIds.Select(ProfileGroupItemManager.Instance.GetOrDefault)//这里是内存访问 + .Where(p => p != null) + .ToList(); + + foreach (var child in childProfiles) + { + if (child.HasCycle(visited, stack)) + { + return true; + } + } + + stack.Remove(ParentIndexId); + return false; + } } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs index b16ccac2..2fbf42b5 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs @@ -496,7 +496,8 @@ public partial class CoreConfigV2rayService return -1; } - var hasCycle = await node.HasCycle(new HashSet(), new HashSet()); + var hasCycle = profileGroupItem.HasCycle(); + //var hasCycle = await node.HasCycle(new HashSet(), new HashSet()); if (hasCycle) { return -1;