mirror of
https://github.com/2dust/v2rayN.git
synced 2026-04-16 12:35:46 +00:00
Compare commits
7 commits
07c709e3d6
...
afd5006de4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
afd5006de4 | ||
|
|
0c2114d2e1 | ||
|
|
4af528f8e2 | ||
|
|
588e82f0d9 | ||
|
|
0c13488410 | ||
|
|
a88396c11d | ||
|
|
daa09fc0bf |
8 changed files with 99 additions and 44 deletions
|
|
@ -227,7 +227,7 @@ public class CoreConfigContextBuilder
|
|||
{
|
||||
var result = NodeValidatorResult.Empty();
|
||||
|
||||
if (node.Subid.IsNullOrEmpty())
|
||||
if (node.Subid.IsNullOrEmpty() || node.ConfigType == EConfigType.Custom)
|
||||
{
|
||||
return (null, result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -723,8 +723,6 @@ public static class ConfigHandler
|
|||
profileItem.SetProtocolExtra(profileItem.GetProtocolExtra() with
|
||||
{
|
||||
SalamanderPass = profileItem.GetProtocolExtra().SalamanderPass?.TrimEx(),
|
||||
UpMbps = profileItem.GetProtocolExtra().UpMbps is null or < 0 ? config.HysteriaItem.UpMbps : profileItem.GetProtocolExtra().UpMbps,
|
||||
DownMbps = profileItem.GetProtocolExtra().DownMbps is null or < 0 ? config.HysteriaItem.DownMbps : profileItem.GetProtocolExtra().DownMbps,
|
||||
HopInterval = profileItem.GetProtocolExtra().HopInterval?.TrimEx(),
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -360,6 +360,7 @@ public class TlsSettings4Ray
|
|||
public bool? disableSystemRoot { get; set; }
|
||||
public string? echConfigList { get; set; }
|
||||
public string? echForceQuery { get; set; }
|
||||
public Sockopt4Ray? echSockopt { get; set; }
|
||||
}
|
||||
|
||||
public class CertificateSettings4Ray
|
||||
|
|
|
|||
|
|
@ -727,13 +727,12 @@ public partial class CoreConfigSingboxService
|
|||
}, null);
|
||||
}
|
||||
var idx = echConfig.IndexOf('+');
|
||||
// NOTE: query_server_name, since sing-box 1.13.0
|
||||
//var queryServerName = idx > 0 ? echConfig[..idx] : null;
|
||||
var queryServerName = idx > 0 ? echConfig[..idx] : null;
|
||||
var echDnsServer = idx > 0 ? echConfig[(idx + 1)..] : echConfig;
|
||||
return (new Ech4Sbox()
|
||||
{
|
||||
enabled = true,
|
||||
query_server_name = null,
|
||||
query_server_name = queryServerName,
|
||||
}, ParseDnsAddress(echDnsServer));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -316,16 +316,24 @@ public partial class CoreConfigV2rayService(CoreConfigContext context)
|
|||
SsMethod = Global.None,
|
||||
});
|
||||
|
||||
foreach (var outbound in _coreConfig.outbounds.Where(outbound => outbound.streamSettings?.sockopt?.dialerProxy?.IsNullOrEmpty() ?? true))
|
||||
foreach (var outbound in _coreConfig.outbounds
|
||||
.Where(o => o.streamSettings?.sockopt?.dialerProxy?.IsNullOrEmpty() ?? true))
|
||||
{
|
||||
outbound.streamSettings ??= new StreamSettings4Ray();
|
||||
outbound.streamSettings.sockopt ??= new Sockopt4Ray();
|
||||
outbound.streamSettings.sockopt.dialerProxy = "tun-project-ss";
|
||||
outbound.streamSettings ??= new();
|
||||
outbound.streamSettings.sockopt ??= new();
|
||||
outbound.streamSettings.sockopt.dialerProxy = "tun-protect-ss";
|
||||
}
|
||||
// ech protected
|
||||
foreach (var outbound in _coreConfig.outbounds
|
||||
.Where(outbound => outbound.streamSettings?.tlsSettings?.echConfigList?.IsNullOrEmpty() == false))
|
||||
{
|
||||
outbound.streamSettings!.tlsSettings!.echSockopt ??= new();
|
||||
outbound.streamSettings.tlsSettings.echSockopt.dialerProxy = "tun-protect-ss";
|
||||
}
|
||||
_coreConfig.outbounds.Add(new CoreConfigV2rayService(context with
|
||||
{
|
||||
Node = protectNode,
|
||||
}).BuildProxyOutbound("tun-project-ss"));
|
||||
}).BuildProxyOutbound("tun-protect-ss"));
|
||||
|
||||
_coreConfig.routing.rules ??= [];
|
||||
var hasBalancer = _coreConfig.routing.balancers is { Count: > 0 };
|
||||
|
|
|
|||
|
|
@ -363,44 +363,36 @@ public class UpdateService(Config config, Func<bool, string, Task> updateFunc)
|
|||
var geoipFiles = new List<string>();
|
||||
var geoSiteFiles = new List<string>();
|
||||
|
||||
//Collect used files list
|
||||
// Collect from routing rules
|
||||
var routingItems = await AppManager.Instance.RoutingItems();
|
||||
foreach (var routing in routingItems)
|
||||
{
|
||||
var rules = JsonUtils.Deserialize<List<RulesItem>>(routing.RuleSet);
|
||||
foreach (var item in rules ?? [])
|
||||
{
|
||||
foreach (var ip in item.Ip ?? [])
|
||||
{
|
||||
var prefix = "geoip:";
|
||||
if (ip.StartsWith(prefix))
|
||||
{
|
||||
geoipFiles.Add(ip.Substring(prefix.Length));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var domain in item.Domain ?? [])
|
||||
{
|
||||
var prefix = "geosite:";
|
||||
if (domain.StartsWith(prefix))
|
||||
{
|
||||
geoSiteFiles.Add(domain.Substring(prefix.Length));
|
||||
}
|
||||
}
|
||||
AddPrefixedItems(item.Ip, "geoip:", geoipFiles);
|
||||
AddPrefixedItems(item.Domain, "geosite:", geoSiteFiles);
|
||||
}
|
||||
}
|
||||
|
||||
//append dns items TODO
|
||||
geoSiteFiles.Add("google");
|
||||
geoSiteFiles.Add("cn");
|
||||
geoSiteFiles.Add("geolocation-cn");
|
||||
geoSiteFiles.Add("category-ads-all");
|
||||
// Collect from DNS configuration
|
||||
var dnsItem = await AppManager.Instance.GetDNSItem(ECoreType.sing_box);
|
||||
if (dnsItem != null)
|
||||
{
|
||||
ExtractDnsRuleSets(dnsItem.NormalDNS, geoipFiles, geoSiteFiles);
|
||||
ExtractDnsRuleSets(dnsItem.TunDNS, geoipFiles, geoSiteFiles);
|
||||
}
|
||||
|
||||
// Append default items
|
||||
geoSiteFiles.AddRange(["google", "cn", "geolocation-cn", "category-ads-all"]);
|
||||
|
||||
// Download files
|
||||
var path = Utils.GetBinPath("srss");
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
foreach (var item in geoipFiles.Distinct())
|
||||
{
|
||||
await UpdateSrsFile("geoip", item);
|
||||
|
|
@ -412,6 +404,63 @@ public class UpdateService(Config config, Func<bool, string, Task> updateFunc)
|
|||
}
|
||||
}
|
||||
|
||||
private void AddPrefixedItems(List<string>? items, string prefix, List<string> output)
|
||||
{
|
||||
if (items == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item.StartsWith(prefix))
|
||||
{
|
||||
output.Add(item.Substring(prefix.Length));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ExtractDnsRuleSets(string? dnsJson, List<string> geoipFiles, List<string> geoSiteFiles)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dnsJson))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var dns = JsonUtils.Deserialize<Dns4Sbox>(dnsJson);
|
||||
if (dns?.rules != null)
|
||||
{
|
||||
foreach (var rule in dns.rules)
|
||||
{
|
||||
ExtractSrsRuleSets(rule, geoipFiles, geoSiteFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void ExtractSrsRuleSets(Rule4Sbox? rule, List<string> geoipFiles, List<string> geoSiteFiles)
|
||||
{
|
||||
if (rule == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AddPrefixedItems(rule.rule_set, "geosite-", geoSiteFiles);
|
||||
AddPrefixedItems(rule.rule_set, "geoip-", geoipFiles);
|
||||
|
||||
// Handle nested rules recursively
|
||||
if (rule.rules != null)
|
||||
{
|
||||
foreach (var nestedRule in rule.rules)
|
||||
{
|
||||
ExtractSrsRuleSets(nestedRule, geoipFiles, geoSiteFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateSrsFile(string type, string srsName)
|
||||
{
|
||||
var srsUrl = string.IsNullOrEmpty(_config.ConstItem.SrsSourceUrl)
|
||||
|
|
|
|||
|
|
@ -27,10 +27,10 @@ public class AddServerViewModel : MyReactiveObject
|
|||
public string Ports { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public int UpMbps { get; set; }
|
||||
public int? UpMbps { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public int DownMbps { get; set; }
|
||||
public int? DownMbps { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string HopInterval { get; set; }
|
||||
|
|
@ -113,8 +113,8 @@ public class AddServerViewModel : MyReactiveObject
|
|||
AlterId = int.TryParse(protocolExtra?.AlterId, out var result) ? result : 0;
|
||||
Flow = protocolExtra?.Flow ?? string.Empty;
|
||||
SalamanderPass = protocolExtra?.SalamanderPass ?? string.Empty;
|
||||
UpMbps = protocolExtra?.UpMbps ?? _config.HysteriaItem.UpMbps;
|
||||
DownMbps = protocolExtra?.DownMbps ?? _config.HysteriaItem.DownMbps;
|
||||
UpMbps = protocolExtra?.UpMbps;
|
||||
DownMbps = protocolExtra?.DownMbps;
|
||||
HopInterval = protocolExtra?.HopInterval.IsNullOrEmpty() ?? true ? Global.Hysteria2DefaultHopInt.ToString() : protocolExtra.HopInterval;
|
||||
VmessSecurity = protocolExtra?.VmessSecurity?.IsNullOrEmpty() == false ? protocolExtra.VmessSecurity : Global.DefaultSecurity;
|
||||
VlessEncryption = protocolExtra?.VlessEncryption.IsNullOrEmpty() == false ? protocolExtra.VlessEncryption : Global.None;
|
||||
|
|
@ -175,8 +175,8 @@ public class AddServerViewModel : MyReactiveObject
|
|||
AlterId = AlterId > 0 ? AlterId.ToString() : null,
|
||||
Flow = Flow.NullIfEmpty(),
|
||||
SalamanderPass = SalamanderPass.NullIfEmpty(),
|
||||
UpMbps = UpMbps >= 0 ? UpMbps : null,
|
||||
DownMbps = DownMbps >= 0 ? DownMbps : null,
|
||||
UpMbps = UpMbps,
|
||||
DownMbps = DownMbps,
|
||||
HopInterval = HopInterval.NullIfEmpty(),
|
||||
VmessSecurity = VmessSecurity.NullIfEmpty(),
|
||||
VlessEncryption = VlessEncryption.NullIfEmpty(),
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ public class OptionSettingViewModel : MyReactiveObject
|
|||
[Reactive] public string defUserAgent { get; set; }
|
||||
[Reactive] public string mux4SboxProtocol { get; set; }
|
||||
[Reactive] public bool enableCacheFile4Sbox { get; set; }
|
||||
[Reactive] public int hyUpMbps { get; set; }
|
||||
[Reactive] public int hyDownMbps { get; set; }
|
||||
[Reactive] public int? hyUpMbps { get; set; }
|
||||
[Reactive] public int? hyDownMbps { get; set; }
|
||||
[Reactive] public bool enableFragment { get; set; }
|
||||
|
||||
#endregion Core
|
||||
|
|
@ -336,8 +336,8 @@ public class OptionSettingViewModel : MyReactiveObject
|
|||
_config.CoreBasicItem.DefUserAgent = defUserAgent;
|
||||
_config.Mux4SboxItem.Protocol = mux4SboxProtocol;
|
||||
_config.CoreBasicItem.EnableCacheFile4Sbox = enableCacheFile4Sbox;
|
||||
_config.HysteriaItem.UpMbps = hyUpMbps;
|
||||
_config.HysteriaItem.DownMbps = hyDownMbps;
|
||||
_config.HysteriaItem.UpMbps = hyUpMbps ?? 0;
|
||||
_config.HysteriaItem.DownMbps = hyDownMbps ?? 0;
|
||||
_config.CoreBasicItem.EnableFragment = enableFragment;
|
||||
|
||||
_config.GuiItem.AutoRun = AutoRun;
|
||||
|
|
|
|||
Loading…
Reference in a new issue