mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-13 20:09:12 +00:00
Compare commits
24 commits
0d80d0d377
...
ea857861d0
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ea857861d0 | ||
![]() |
11924b545f | ||
![]() |
ab1dc45ed4 | ||
![]() |
2d41272659 | ||
![]() |
e7f75010d3 | ||
![]() |
aa1ccdd01b | ||
![]() |
b17323c982 | ||
![]() |
71dcd8d1de | ||
![]() |
dace865e6c | ||
![]() |
fad94e68d2 | ||
![]() |
c116aae242 | ||
![]() |
ff1c9093a2 | ||
![]() |
8bb20c0ab8 | ||
![]() |
17a3a516c7 | ||
![]() |
8f0d7e54d8 | ||
![]() |
2ab79afa02 | ||
![]() |
e29d292732 | ||
![]() |
9ef228db1e | ||
![]() |
34327532e6 | ||
![]() |
8af6eda165 | ||
![]() |
f979d13109 | ||
![]() |
6166b6c0e3 | ||
![]() |
8c094dd976 | ||
![]() |
5c4f485471 |
6 changed files with 17 additions and 105 deletions
|
@ -1253,49 +1253,12 @@ 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 = tun2SocksAddress, // Tun2SocksAddress
|
||||
SpiderX = node.Address, // Tun2SocksAddress
|
||||
Port = AppManager.Instance.GetLocalPort(EInboundProtocol.socks)
|
||||
};
|
||||
}
|
||||
|
|
|
@ -109,42 +109,6 @@ 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,13 +124,6 @@ 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>();
|
||||
|
@ -146,6 +139,13 @@ 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,19 +414,16 @@ public partial class CoreConfigSingboxService
|
|||
return 0;
|
||||
}
|
||||
|
||||
List<string> domain = new();
|
||||
var domain = string.Empty;
|
||||
if (Utils.IsDomain(node.Address)) // normal outbound
|
||||
{
|
||||
domain.Add(node.Address);
|
||||
domain = node.Address;
|
||||
}
|
||||
if (node.Address == Global.Loopback && node.SpiderX.IsNotEmpty()) // Tun2SocksAddress
|
||||
else if (node.Address == Global.Loopback && node.SpiderX.IsNotEmpty() && Utils.IsDomain(node.SpiderX)) // Tun2SocksAddress
|
||||
{
|
||||
domain.AddRange(Utils.String2List(node.SpiderX)
|
||||
.Where(Utils.IsDomain)
|
||||
.Distinct()
|
||||
.ToList());
|
||||
domain = node.SpiderX;
|
||||
}
|
||||
if (domain.Count == 0)
|
||||
if (domain.IsNullOrEmpty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -435,7 +432,7 @@ public partial class CoreConfigSingboxService
|
|||
singboxConfig.dns.rules.Insert(0, new Rule4Sbox
|
||||
{
|
||||
server = server,
|
||||
domain = domain,
|
||||
domain = [domain],
|
||||
});
|
||||
|
||||
return await Task.FromResult(0);
|
||||
|
|
|
@ -217,15 +217,9 @@ 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())
|
||||
|
@ -236,6 +230,7 @@ public partial class CoreConfigSingboxService
|
|||
&& p.IsValid()
|
||||
&& p.ConfigType != EConfigType.Custom
|
||||
&& (node.ConfigType == EConfigType.PolicyGroup || p.ConfigType < EConfigType.Group)
|
||||
&& p.IndexId != node.IndexId
|
||||
)
|
||||
.ToList();
|
||||
|
||||
|
|
|
@ -493,13 +493,6 @@ 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