mirror of
https://github.com/2dust/v2rayN.git
synced 2026-11-04 19:45:00 +03:00
Refactor core config gen (#8768)
* Refactor core config gen * Update tag naming * Support sing-box 1.11 DNS * Fix * Optimize ProfileItem acquisition speed * Fix * Fix
This commit is contained in:
@@ -79,7 +79,7 @@ public class GroupProfileManager
|
||||
{
|
||||
if (protocolExtra == null)
|
||||
{
|
||||
return new();
|
||||
return [];
|
||||
}
|
||||
|
||||
var items = new List<ProfileItem>();
|
||||
@@ -93,27 +93,44 @@ public class GroupProfileManager
|
||||
{
|
||||
if (extra == null || extra.ChildItems.IsNullOrEmpty())
|
||||
{
|
||||
return new();
|
||||
return [];
|
||||
}
|
||||
var childProfiles = (await Task.WhenAll(
|
||||
(Utils.String2List(extra.ChildItems) ?? new())
|
||||
.Where(p => !p.IsNullOrEmpty())
|
||||
.Select(AppManager.Instance.GetProfileItem)
|
||||
))
|
||||
.Where(p =>
|
||||
p != null &&
|
||||
p.IsValid() &&
|
||||
p.ConfigType != EConfigType.Custom
|
||||
)
|
||||
.ToList();
|
||||
return childProfiles ?? new();
|
||||
var childProfileIds = Utils.String2List(extra.ChildItems)
|
||||
?.Where(p => !string.IsNullOrEmpty(p))
|
||||
.ToList() ?? [];
|
||||
if (childProfileIds.Count == 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
var childProfiles = await AppManager.Instance.GetProfileItemsByIndexIds(childProfileIds);
|
||||
if (childProfiles == null || childProfiles.Count == 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
var profileMap = childProfiles
|
||||
.Where(p => p != null && !p.IndexId.IsNullOrEmpty())
|
||||
.GroupBy(p => p!.IndexId!)
|
||||
.ToDictionary(g => g.Key, g => g.First());
|
||||
|
||||
var ordered = new List<ProfileItem>(childProfileIds.Count);
|
||||
foreach (var id in childProfileIds)
|
||||
{
|
||||
if (id != null && profileMap.TryGetValue(id, out var item) && item != null)
|
||||
{
|
||||
ordered.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return ordered;
|
||||
}
|
||||
|
||||
private static async Task<List<ProfileItem>> GetSubChildProfileItems(ProtocolExtraItem? extra)
|
||||
{
|
||||
if (extra == null || extra.SubChildItems.IsNullOrEmpty())
|
||||
{
|
||||
return new();
|
||||
return [];
|
||||
}
|
||||
var childProfiles = await AppManager.Instance.ProfileItems(extra.SubChildItems ?? string.Empty);
|
||||
|
||||
@@ -123,59 +140,30 @@ public class GroupProfileManager
|
||||
!p.ConfigType.IsComplexType() &&
|
||||
(extra.Filter.IsNullOrEmpty() || Regex.IsMatch(p.Remarks, extra.Filter))
|
||||
)
|
||||
.ToList() ?? new();
|
||||
.ToList() ?? [];
|
||||
}
|
||||
|
||||
public static async Task<HashSet<string>> GetAllChildDomainAddresses(ProfileItem profileItem)
|
||||
public static async Task<List<ProfileItem>> GetAllChildProfileItems(ProfileItem profileItem)
|
||||
{
|
||||
var childAddresses = new HashSet<string>();
|
||||
var (childItems, _) = await GetChildProfileItems(profileItem);
|
||||
foreach (var child in childItems)
|
||||
{
|
||||
if (!child.IsComplex())
|
||||
{
|
||||
childAddresses.Add(child.Address);
|
||||
}
|
||||
else if (child.ConfigType.IsGroupType())
|
||||
{
|
||||
var subAddresses = await GetAllChildDomainAddresses(child);
|
||||
foreach (var addr in subAddresses)
|
||||
{
|
||||
childAddresses.Add(addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
return childAddresses;
|
||||
var allChildItems = new List<ProfileItem>();
|
||||
var visited = new HashSet<string>();
|
||||
|
||||
await CollectChildItems(profileItem, allChildItems, visited);
|
||||
|
||||
return allChildItems;
|
||||
}
|
||||
|
||||
public static async Task<HashSet<string>> GetAllChildEchQuerySni(ProfileItem profileItem)
|
||||
private static async Task CollectChildItems(ProfileItem profileItem, List<ProfileItem> allChildItems, HashSet<string> visited)
|
||||
{
|
||||
var childAddresses = new HashSet<string>();
|
||||
var (childItems, _) = await GetChildProfileItems(profileItem);
|
||||
foreach (var childNode in childItems)
|
||||
foreach (var child in childItems.Where(child => visited.Add(child.IndexId)))
|
||||
{
|
||||
if (!childNode.IsComplex() && !childNode.EchConfigList.IsNullOrEmpty())
|
||||
allChildItems.Add(child);
|
||||
|
||||
if (child.ConfigType.IsGroupType())
|
||||
{
|
||||
if (childNode.StreamSecurity == Global.StreamSecurity
|
||||
&& childNode.EchConfigList?.Contains("://") == true)
|
||||
{
|
||||
var idx = childNode.EchConfigList.IndexOf('+');
|
||||
childAddresses.Add(idx > 0 ? childNode.EchConfigList[..idx] : childNode.Sni);
|
||||
}
|
||||
else
|
||||
{
|
||||
childAddresses.Add(childNode.Sni);
|
||||
}
|
||||
}
|
||||
else if (childNode.ConfigType.IsGroupType())
|
||||
{
|
||||
var subAddresses = await GetAllChildDomainAddresses(childNode);
|
||||
foreach (var addr in subAddresses)
|
||||
{
|
||||
childAddresses.Add(addr);
|
||||
}
|
||||
await CollectChildItems(child, allChildItems, visited);
|
||||
}
|
||||
}
|
||||
return childAddresses;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user