mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-13 20:09:12 +00:00
Add helper function
This commit is contained in:
parent
71dcd8d1de
commit
b17323c982
2 changed files with 86 additions and 0 deletions
|
@ -64,6 +64,51 @@ public class ProfileItem : ReactiveObject
|
|||
return Network.TrimEx();
|
||||
}
|
||||
|
||||
public bool IsComplex()
|
||||
{
|
||||
return ConfigType is EConfigType.Custom or > EConfigType.Group;
|
||||
}
|
||||
|
||||
public bool IsValid()
|
||||
{
|
||||
if (IsComplex())
|
||||
return true;
|
||||
|
||||
if (Address.IsNullOrEmpty() || Port is <= 0 or >= 65536)
|
||||
return false;
|
||||
|
||||
switch (ConfigType)
|
||||
{
|
||||
case EConfigType.VMess:
|
||||
if (Id.IsNullOrEmpty() || !Utils.IsGuidByParse(Id))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case EConfigType.VLESS:
|
||||
if (Id.IsNullOrEmpty() || (!Utils.IsGuidByParse(Id) && Id.Length > 30))
|
||||
return false;
|
||||
if (!Global.Flows.Contains(Flow))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case EConfigType.Shadowsocks:
|
||||
if (Id.IsNullOrEmpty())
|
||||
return false;
|
||||
if (string.IsNullOrEmpty(Security) || !Global.SsSecuritiesInSingbox.Contains(Security))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((ConfigType is EConfigType.VLESS or EConfigType.Trojan)
|
||||
&& StreamSecurity == Global.StreamSecurityReality
|
||||
&& PublicKey.IsNullOrEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion function
|
||||
|
||||
[PrimaryKey]
|
||||
|
|
|
@ -204,6 +204,47 @@ public partial class CoreConfigSingboxService
|
|||
return await Task.FromResult<BaseServer4Sbox?>(null);
|
||||
}
|
||||
|
||||
private async Task<int> GenGroupOutbound(ProfileItem node, SingboxConfig singboxConfig, string baseTagName = Global.ProxyTag)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (node.ConfigType is not (EConfigType.PolicyGroup or EConfigType.ProxyChain))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
ProfileGroupItemManager.Instance.TryGet(node.IndexId, out var profileGroupItem);
|
||||
if (profileGroupItem is null || profileGroupItem.ChildItems.IsNullOrEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var childProfiles = (await Task.WhenAll(
|
||||
Utils.String2List(profileGroupItem.ChildItems)
|
||||
.Where(p => !p.IsNullOrEmpty())
|
||||
.Select(AppManager.Instance.GetProfileItem)
|
||||
)).Where(p => p != null && p.IsValid()).ToList();
|
||||
if (childProfiles.Count <= 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
switch (node.ConfigType)
|
||||
{
|
||||
case EConfigType.PolicyGroup:
|
||||
await GenOutboundsListWithChain(childProfiles, singboxConfig, profileGroupItem.MultipleLoad, baseTagName);
|
||||
break;
|
||||
case EConfigType.ProxyChain:
|
||||
await GenChainOutboundsList(childProfiles, singboxConfig, baseTagName);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
return await Task.FromResult(0);
|
||||
}
|
||||
|
||||
private async Task<int> GenOutboundMux(ProfileItem node, Outbound4Sbox outbound)
|
||||
{
|
||||
try
|
||||
|
|
Loading…
Reference in a new issue