From 768d5cce27c64434dbc45924caac9c4e4302279f Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:11:57 +0800 Subject: [PATCH] Add Sing-box domain strategy --- v2rayN/v2rayN/Global.cs | 1 + v2rayN/v2rayN/Handler/CoreConfigSingbox.cs | 1 + v2rayN/v2rayN/Mode/ConfigItems.cs | 1 + v2rayN/v2rayN/Mode/SingboxConfig.cs | 2 +- v2rayN/v2rayN/Resx/ResUI.Designer.cs | 9 +++++++++ v2rayN/v2rayN/Resx/ResUI.resx | 3 +++ v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx | 5 ++++- .../ViewModels/RoutingSettingViewModel.cs | 5 +++++ v2rayN/v2rayN/Views/MainWindow.xaml | 2 +- v2rayN/v2rayN/Views/RoutingSettingWindow.xaml | 19 ++++++++++++++++--- .../v2rayN/Views/RoutingSettingWindow.xaml.cs | 14 ++++++++++++-- 11 files changed, 54 insertions(+), 8 deletions(-) diff --git a/v2rayN/v2rayN/Global.cs b/v2rayN/v2rayN/Global.cs index 514eb343..7e0d45df 100644 --- a/v2rayN/v2rayN/Global.cs +++ b/v2rayN/v2rayN/Global.cs @@ -141,6 +141,7 @@ public static readonly List coreTypes = new() { "v2fly", "SagerNet", "Xray", "v2fly_v5", "sing_box" }; public static readonly List coreTypes4VLESS = new() { "Xray", "sing_box" }; public static readonly List domainStrategys = new() { "AsIs", "IPIfNonMatch", "IPOnDemand" }; + public static readonly List domainStrategys4Singbox = new() { "", "ipv4_only", "ipv6_only", "prefer_ipv4", "prefer_ipv6" }; public static readonly List domainMatchers = new() { "linear", "mph", "" }; public static readonly List fingerprints = new() { "chrome", "firefox", "safari", "ios", "android", "edge", "360", "qq", "random", "randomized", "" }; public static readonly List userAgent = new() { "chrome", "firefox", "safari", "edge", "none" }; diff --git a/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs b/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs index e348a98b..5ccc68f4 100644 --- a/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs +++ b/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs @@ -133,6 +133,7 @@ namespace v2rayN.Handler inbound.listen_port = LazyConfig.Instance.GetLocalPort(Global.InboundSocks); inbound.sniff = _config.inbound[0].sniffingEnabled; inbound.sniff_override_destination = _config.inbound[0].routeOnly ? false : _config.inbound[0].sniffingEnabled; + inbound.domain_strategy = Utils.IsNullOrEmpty(_config.routingBasicItem.domainStrategy4Singbox) ? null: _config.routingBasicItem.domainStrategy4Singbox; //http var inbound2 = GetInbound(inbound, Global.InboundHttp, 1, false); diff --git a/v2rayN/v2rayN/Mode/ConfigItems.cs b/v2rayN/v2rayN/Mode/ConfigItems.cs index a8ff86e0..4ab9d3ce 100644 --- a/v2rayN/v2rayN/Mode/ConfigItems.cs +++ b/v2rayN/v2rayN/Mode/ConfigItems.cs @@ -191,6 +191,7 @@ namespace v2rayN.Mode /// 域名解析策略 /// public string domainStrategy { get; set; } + public string domainStrategy4Singbox { get; set; } public string domainMatcher { get; set; } public string routingIndexId { get; set; } diff --git a/v2rayN/v2rayN/Mode/SingboxConfig.cs b/v2rayN/v2rayN/Mode/SingboxConfig.cs index a873fb2c..fc8a09df 100644 --- a/v2rayN/v2rayN/Mode/SingboxConfig.cs +++ b/v2rayN/v2rayN/Mode/SingboxConfig.cs @@ -62,7 +62,7 @@ public string tag { get; set; } public string listen { get; set; } public int? listen_port { get; set; } - public string domain_strategy { get; set; } + public string? domain_strategy { get; set; } public string interface_name { get; set; } public string inet4_address { get; set; } public string inet6_address { get; set; } diff --git a/v2rayN/v2rayN/Resx/ResUI.Designer.cs b/v2rayN/v2rayN/Resx/ResUI.Designer.cs index c45a4765..beae407e 100644 --- a/v2rayN/v2rayN/Resx/ResUI.Designer.cs +++ b/v2rayN/v2rayN/Resx/ResUI.Designer.cs @@ -1960,6 +1960,15 @@ namespace v2rayN.Resx { } } + /// + /// 查找类似 Sing-box domain strategy 的本地化字符串。 + /// + public static string TbdomainStrategy4Singbox { + get { + return ResourceManager.GetString("TbdomainStrategy4Singbox", resourceCulture); + } + } + /// /// 查找类似 Edit 的本地化字符串。 /// diff --git a/v2rayN/v2rayN/Resx/ResUI.resx b/v2rayN/v2rayN/Resx/ResUI.resx index ed1aa3c2..6e1dcdc7 100644 --- a/v2rayN/v2rayN/Resx/ResUI.resx +++ b/v2rayN/v2rayN/Resx/ResUI.resx @@ -1126,4 +1126,7 @@ Click to import default DNS config + + Sing-box domain strategy + \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx index e44180bf..f820b5e8 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx @@ -896,7 +896,7 @@ 域名解析策略 - 启用路由高级功能 + 启用高级功能 3.阻止的Domain或IP @@ -1123,4 +1123,7 @@ 点击导入默认DNS配置 + + Sing-box域名解析策略 + \ No newline at end of file diff --git a/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs index 27a43629..a445e705 100644 --- a/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs @@ -42,6 +42,9 @@ namespace v2rayN.ViewModels [Reactive] public string domainMatcher { get; set; } + [Reactive] + public string domainStrategy4Singbox { get; set; } + [Reactive] public string ProxyDomain { get; set; } @@ -83,6 +86,7 @@ namespace v2rayN.ViewModels enableRoutingAdvanced = _config.routingBasicItem.enableRoutingAdvanced; domainStrategy = _config.routingBasicItem.domainStrategy; domainMatcher = _config.routingBasicItem.domainMatcher; + domainStrategy4Singbox = _config.routingBasicItem.domainStrategy4Singbox; RefreshRoutingItems(); @@ -200,6 +204,7 @@ namespace v2rayN.ViewModels _config.routingBasicItem.domainStrategy = domainStrategy; _config.routingBasicItem.enableRoutingAdvanced = enableRoutingAdvanced; _config.routingBasicItem.domainMatcher = domainMatcher; + _config.routingBasicItem.domainStrategy4Singbox = domainStrategy4Singbox; EndBindingLockedData(); diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml b/v2rayN/v2rayN/Views/MainWindow.xaml index 0b540ccc..0f2ed7f0 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml +++ b/v2rayN/v2rayN/Views/MainWindow.xaml @@ -235,7 +235,7 @@ + Header="Sing-box Core" /> - @@ -106,7 +105,21 @@ Text="{x:Static resx:ResUI.TbdomainMatcher}" /> + + + + + + + diff --git a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs index e8a14368..60254194 100644 --- a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs @@ -28,6 +28,10 @@ namespace v2rayN.Views { cmbdomainMatcher.Items.Add(it); }); + Global.domainStrategys4Singbox.ForEach(it => + { + cmbdomainStrategy4Singbox.Items.Add(it); + }); this.WhenActivated(disposables => { @@ -37,6 +41,7 @@ namespace v2rayN.Views this.Bind(ViewModel, vm => vm.enableRoutingAdvanced, v => v.togenableRoutingAdvanced.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.domainStrategy, v => v.cmbdomainStrategy.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.domainMatcher, v => v.cmbdomainMatcher.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.domainStrategy4Singbox, v => v.cmbdomainStrategy4Singbox.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.ProxyDomain, v => v.txtProxyDomain.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.ProxyIP, v => v.txtProxyIP.Text).DisposeWith(disposables); @@ -45,8 +50,8 @@ namespace v2rayN.Views this.Bind(ViewModel, vm => vm.BlockDomain, v => v.txtBlockDomain.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.BlockIP, v => v.txtBlockIP.Text).DisposeWith(disposables); - this.OneWayBind(ViewModel, vm => vm.enableRoutingBasic, v => v.menuRoutingBasic.IsEnabled).DisposeWith(disposables); - this.OneWayBind(ViewModel, vm => vm.enableRoutingAdvanced, v => v.menuRoutingAdvanced.IsEnabled).DisposeWith(disposables); + this.OneWayBind(ViewModel, vm => vm.enableRoutingBasic, v => v.menuRoutingBasic.Visibility).DisposeWith(disposables); + this.OneWayBind(ViewModel, vm => vm.enableRoutingAdvanced, v => v.menuRoutingAdvanced.Visibility).DisposeWith(disposables); this.OneWayBind(ViewModel, vm => vm.enableRoutingBasic, v => v.tabBasic.Visibility).DisposeWith(disposables); this.OneWayBind(ViewModel, vm => vm.enableRoutingAdvanced, v => v.tabAdvanced.Visibility).DisposeWith(disposables); @@ -101,6 +106,11 @@ namespace v2rayN.Views Utils.ProcessStart("https://www.v2fly.org/config/routing.html"); } + private void linkdomainStrategy4Singbox_Click(object sender, RoutedEventArgs e) + { + Utils.ProcessStart("https://sing-box.sagernet.org/zh/configuration/shared/listen/#domain_strategy"); + } + private void btnCancel_Click(object sender, System.Windows.RoutedEventArgs e) { if (ViewModel?.IsModified == true)