mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-13 20:09:12 +00:00
Compare commits
26 commits
ea857861d0
...
0d80d0d377
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0d80d0d377 | ||
![]() |
6250810f31 | ||
![]() |
4bf86665b7 | ||
![]() |
ae46b39110 | ||
![]() |
836217266e | ||
![]() |
4e3c2991f9 | ||
![]() |
cdab7a097f | ||
![]() |
1d8b8491ea | ||
![]() |
04dae54654 | ||
![]() |
63bf68376f | ||
![]() |
826f9f833a | ||
![]() |
9317c73084 | ||
![]() |
2d5a5465df | ||
![]() |
af62d9e0f4 | ||
![]() |
2ab044b4fc | ||
![]() |
c76d125ce1 | ||
![]() |
183be53153 | ||
![]() |
52d1eb1e2b | ||
![]() |
521dca33d5 | ||
![]() |
a323484ee3 | ||
![]() |
9a43003c47 | ||
![]() |
e97b98f4bf | ||
![]() |
bd3a733057 | ||
![]() |
0cde086448 | ||
![]() |
8561311a45 | ||
![]() |
57fd56fc05 |
6 changed files with 105 additions and 17 deletions
|
@ -1253,12 +1253,49 @@ public static class ConfigHandler
|
|||
ProfileItem? itemSocks = null;
|
||||
if (node.ConfigType != EConfigType.Custom && coreType != ECoreType.sing_box && config.TunModeItem.EnableTun)
|
||||
{
|
||||
var tun2SocksAddress = node.Address;
|
||||
if (node.ConfigType > EConfigType.Group)
|
||||
{
|
||||
static async Task<List<string>> GetChildNodeAddressesAsync(string parentIndexId)
|
||||
{
|
||||
var childAddresses = new List<string>();
|
||||
if (!ProfileGroupItemManager.Instance.TryGet(parentIndexId, out var groupItem) || groupItem.ChildItems.IsNullOrEmpty())
|
||||
return childAddresses;
|
||||
|
||||
var childIds = Utils.String2List(groupItem.ChildItems);
|
||||
|
||||
foreach (var childId in childIds)
|
||||
{
|
||||
var childNode = await AppManager.Instance.GetProfileItem(childId);
|
||||
if (childNode == null)
|
||||
continue;
|
||||
|
||||
if (!childNode.IsComplex())
|
||||
{
|
||||
childAddresses.Add(childNode.Address);
|
||||
}
|
||||
else if (childNode.ConfigType > EConfigType.Group)
|
||||
{
|
||||
var subAddresses = await GetChildNodeAddressesAsync(childNode.IndexId);
|
||||
childAddresses.AddRange(subAddresses);
|
||||
}
|
||||
}
|
||||
|
||||
return childAddresses;
|
||||
}
|
||||
|
||||
var lstAddresses = await GetChildNodeAddressesAsync(node.IndexId);
|
||||
if (lstAddresses.Count > 0)
|
||||
{
|
||||
tun2SocksAddress = Utils.List2String(lstAddresses);
|
||||
}
|
||||
}
|
||||
itemSocks = new ProfileItem()
|
||||
{
|
||||
CoreType = ECoreType.sing_box,
|
||||
ConfigType = EConfigType.SOCKS,
|
||||
Address = Global.Loopback,
|
||||
SpiderX = node.Address, // Tun2SocksAddress
|
||||
SpiderX = tun2SocksAddress, // Tun2SocksAddress
|
||||
Port = AppManager.Instance.GetLocalPort(EInboundProtocol.socks)
|
||||
};
|
||||
}
|
||||
|
|
|
@ -109,6 +109,42 @@ public class ProfileItem : ReactiveObject
|
|||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> HasCycle(HashSet<string> visited, HashSet<string> stack)
|
||||
{
|
||||
if (ConfigType < EConfigType.Group)
|
||||
return false;
|
||||
|
||||
if (stack.Contains(IndexId))
|
||||
return true;
|
||||
|
||||
if (visited.Contains(IndexId))
|
||||
return false;
|
||||
|
||||
visited.Add(IndexId);
|
||||
stack.Add(IndexId);
|
||||
|
||||
if (ProfileGroupItemManager.Instance.TryGet(IndexId, out var group)
|
||||
&& !group.ChildItems.IsNullOrEmpty())
|
||||
{
|
||||
var childProfiles = (await Task.WhenAll(
|
||||
Utils.String2List(group.ChildItems)
|
||||
.Where(p => !p.IsNullOrEmpty())
|
||||
.Select(AppManager.Instance.GetProfileItem)
|
||||
))
|
||||
.Where(p => p != null)
|
||||
.ToList();
|
||||
|
||||
foreach (var child in childProfiles)
|
||||
{
|
||||
if (await child.HasCycle(visited, stack))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
stack.Remove(IndexId);
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion function
|
||||
|
||||
[PrimaryKey]
|
||||
|
|
|
@ -124,6 +124,13 @@ public class ActionPrecheckService(Config config)
|
|||
return errors;
|
||||
}
|
||||
|
||||
var hasCycle = await item.HasCycle(new HashSet<string>(), new HashSet<string>());
|
||||
if (hasCycle)
|
||||
{
|
||||
errors.Add(string.Format(ResUI.GroupSelfReference, item.Remarks));
|
||||
return errors;
|
||||
}
|
||||
|
||||
foreach (var child in Utils.String2List(group.ChildItems))
|
||||
{
|
||||
var childErrors = new List<string>();
|
||||
|
@ -139,13 +146,6 @@ public class ActionPrecheckService(Config config)
|
|||
continue;
|
||||
}
|
||||
|
||||
// self-reference check
|
||||
if (childItem.IndexId == item.IndexId)
|
||||
{
|
||||
childErrors.Add(string.Format(ResUI.GroupSelfReference, childItem.Remarks));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (childItem.ConfigType is EConfigType.Custom or EConfigType.ProxyChain)
|
||||
{
|
||||
childErrors.Add(string.Format(ResUI.InvalidProperty, childItem.Remarks));
|
||||
|
|
|
@ -414,16 +414,19 @@ public partial class CoreConfigSingboxService
|
|||
return 0;
|
||||
}
|
||||
|
||||
var domain = string.Empty;
|
||||
List<string> domain = new();
|
||||
if (Utils.IsDomain(node.Address)) // normal outbound
|
||||
{
|
||||
domain = node.Address;
|
||||
domain.Add(node.Address);
|
||||
}
|
||||
else if (node.Address == Global.Loopback && node.SpiderX.IsNotEmpty() && Utils.IsDomain(node.SpiderX)) // Tun2SocksAddress
|
||||
if (node.Address == Global.Loopback && node.SpiderX.IsNotEmpty()) // Tun2SocksAddress
|
||||
{
|
||||
domain = node.SpiderX;
|
||||
domain.AddRange(Utils.String2List(node.SpiderX)
|
||||
.Where(Utils.IsDomain)
|
||||
.Distinct()
|
||||
.ToList());
|
||||
}
|
||||
if (domain.IsNullOrEmpty())
|
||||
if (domain.Count == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -432,7 +435,7 @@ public partial class CoreConfigSingboxService
|
|||
singboxConfig.dns.rules.Insert(0, new Rule4Sbox
|
||||
{
|
||||
server = server,
|
||||
domain = [domain],
|
||||
domain = domain,
|
||||
});
|
||||
|
||||
return await Task.FromResult(0);
|
||||
|
|
|
@ -217,9 +217,15 @@ public partial class CoreConfigSingboxService
|
|||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
var hasCycle = await node.HasCycle(new HashSet<string>(), new HashSet<string>());
|
||||
if (hasCycle)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// remove custom nodes
|
||||
// remove group nodes for proxy chain
|
||||
// avoid self-reference
|
||||
var childProfiles = (await Task.WhenAll(
|
||||
Utils.String2List(profileGroupItem.ChildItems)
|
||||
.Where(p => !p.IsNullOrEmpty())
|
||||
|
@ -230,7 +236,6 @@ public partial class CoreConfigSingboxService
|
|||
&& p.IsValid()
|
||||
&& p.ConfigType != EConfigType.Custom
|
||||
&& (node.ConfigType == EConfigType.PolicyGroup || p.ConfigType < EConfigType.Group)
|
||||
&& p.IndexId != node.IndexId
|
||||
)
|
||||
.ToList();
|
||||
|
||||
|
|
|
@ -493,6 +493,13 @@ public partial class CoreConfigV2rayService
|
|||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
var hasCycle = await node.HasCycle(new HashSet<string>(), new HashSet<string>());
|
||||
if (hasCycle)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// remove custom nodes
|
||||
// remove group nodes for proxy chain
|
||||
var childProfiles = (await Task.WhenAll(
|
||||
|
|
Loading…
Reference in a new issue