Skip to content

Commit

Permalink
Default domain strategy for resolving the outbound domain names -- si…
Browse files Browse the repository at this point in the history
…ngbox
  • Loading branch information
2dust committed Jul 8, 2024
1 parent c2928be commit 7545763
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 9 deletions.
1 change: 1 addition & 0 deletions v2rayN/v2rayN/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ internal class Global

public static readonly List<string> AllowInsecure = new() { "true", "false", "" };
public static readonly List<string> DomainStrategy4Freedoms = new() { "AsIs", "UseIP", "UseIPv4", "UseIPv6", "" };
public static readonly List<string> SingboxDomainStrategy4Out = new() { "ipv4_only", "prefer_ipv4", "prefer_ipv6", "ipv6_only", "" };
public static readonly List<string> Languages = new() { "zh-Hans", "zh-Hant", "en", "fa-Ir", "ru" };
public static readonly List<string> Alpns = new() { "h3", "h2", "http/1.1", "h3,h2,http/1.1", "h3,h2", "h2,http/1.1", "" };
public static readonly List<string> LogLevels = new() { "debug", "info", "warning", "error", "none" };
Expand Down
8 changes: 4 additions & 4 deletions v2rayN/v2rayN/Handler/CoreConfig/CoreConfigSingbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ private int GenDns(ProfileItem node, SingboxConfig singboxConfig)
}
singboxConfig.dns = dns4Sbox;

GenDnsDomains(node, singboxConfig);
GenDnsDomains(node, singboxConfig, item?.domainStrategy4Freedom);
}
catch (Exception ex)
{
Expand All @@ -835,7 +835,7 @@ private int GenDns(ProfileItem node, SingboxConfig singboxConfig)
return 0;
}

private int GenDnsDomains(ProfileItem? node, SingboxConfig singboxConfig)
private int GenDnsDomains(ProfileItem? node, SingboxConfig singboxConfig, string? strategy)
{
var dns4Sbox = singboxConfig.dns ?? new();
dns4Sbox.servers ??= [];
Expand All @@ -847,7 +847,7 @@ private int GenDnsDomains(ProfileItem? node, SingboxConfig singboxConfig)
tag = tag,
address = "223.5.5.5",
detour = Global.DirectTag,
//strategy = strategy
strategy = strategy
});

var lstDomain = singboxConfig.outbounds
Expand Down Expand Up @@ -1144,7 +1144,7 @@ public int GenerateClientSpeedtestConfig(List<ServerTestItem> selecteds, out Sin
singboxConfig.route.rules.Add(rule);
}

GenDnsDomains(null, singboxConfig);
GenDnsDomains(null, singboxConfig, null);
//var dnsServer = singboxConfig.dns?.servers.FirstOrDefault();
//if (dnsServer != null)
//{
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Models/ConfigItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public class TunModeItem
public string stack { get; set; }
public int mtu { get; set; }
public bool enableExInbound { get; set; }
public bool enableIPv6Address { get; set; } = true;
public bool enableIPv6Address { get; set; }
}

[Serializable]
Expand Down
9 changes: 9 additions & 0 deletions v2rayN/v2rayN/Resx/ResUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions v2rayN/v2rayN/Resx/ResUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1297,4 +1297,7 @@
<data name="menuProxiesSelectActivity" xml:space="preserve">
<value>Select active node (Enter)</value>
</data>
<data name="TbSettingsDomainStrategy4Out" xml:space="preserve">
<value>Default domain strategy for outbound</value>
</data>
</root>
3 changes: 3 additions & 0 deletions v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1294,4 +1294,7 @@
<data name="menuProxiesSelectActivity" xml:space="preserve">
<value>设为活动节点 (Enter)</value>
</data>
<data name="TbSettingsDomainStrategy4Out" xml:space="preserve">
<value>Outbound默认解析策略</value>
</data>
</root>
11 changes: 7 additions & 4 deletions v2rayN/v2rayN/ViewModels/DNSSettingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class DNSSettingViewModel : ReactiveObject
[Reactive] public string normalDNS { get; set; }
[Reactive] public string normalDNS2 { get; set; }
[Reactive] public string tunDNS2 { get; set; }
[Reactive] public string domainStrategy4Freedom2 { get; set; }

public ReactiveCommand<Unit, Unit> SaveCmd { get; }
public ReactiveCommand<Unit, Unit> ImportDefConfig4V2rayCmd { get; }
Expand All @@ -34,12 +35,13 @@ public DNSSettingViewModel(Window view)

var item = LazyConfig.Instance.GetDNSItem(ECoreType.Xray);
useSystemHosts = item.useSystemHosts;
domainStrategy4Freedom = item?.domainStrategy4Freedom!;
normalDNS = item?.normalDNS!;
domainStrategy4Freedom = item?.domainStrategy4Freedom ?? string.Empty;
normalDNS = item?.normalDNS ?? string.Empty;

var item2 = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box);
normalDNS2 = item2?.normalDNS!;
tunDNS2 = item2?.tunDNS!;
normalDNS2 = item2?.normalDNS ?? string.Empty;
tunDNS2 = item2?.tunDNS ?? string.Empty;
domainStrategy4Freedom2 = item2?.domainStrategy4Freedom ?? string.Empty;

SaveCmd = ReactiveCommand.Create(() =>
{
Expand Down Expand Up @@ -105,6 +107,7 @@ private void SaveSetting()
var item2 = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box);
item2.normalDNS = JsonUtils.Serialize(JsonUtils.ParseJson(normalDNS2));
item2.tunDNS = JsonUtils.Serialize(JsonUtils.ParseJson(tunDNS2));
item2.domainStrategy4Freedom = domainStrategy4Freedom2;
ConfigHandler.SaveDNSItems(_config, item2);

_noticeHandler?.Enqueue(ResUI.OperationSuccess);
Expand Down
13 changes: 13 additions & 0 deletions v2rayN/v2rayN/Views/DNSSettingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@
Style="{StaticResource DefButton}" />
</StackPanel>

<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal">
<TextBlock
Margin="{StaticResource SettingItemMargin}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbSettingsDomainStrategy4Out}" />
<ComboBox
x:Name="cmbdomainStrategy4Out"
Width="200"
Margin="{StaticResource SettingItemMargin}"
Style="{StaticResource DefComboBox}" />
</StackPanel>

<Grid Margin="{StaticResource SettingItemMargin}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
Expand Down
6 changes: 6 additions & 0 deletions v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ public DNSSettingWindow()
{
cmbdomainStrategy4Freedom.Items.Add(it);
});
Global.SingboxDomainStrategy4Out.ForEach(it =>
{
cmbdomainStrategy4Out.Items.Add(it);
});


this.WhenActivated(disposables =>
{
this.Bind(ViewModel, vm => vm.useSystemHosts, v => v.togUseSystemHosts.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.domainStrategy4Freedom, v => v.cmbdomainStrategy4Freedom.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.normalDNS, v => v.txtnormalDNS.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.domainStrategy4Freedom2, v => v.cmbdomainStrategy4Out.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.normalDNS2, v => v.txtnormalDNS2.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.tunDNS2, v => v.txttunDNS2.Text).DisposeWith(disposables);
Expand Down

0 comments on commit 7545763

Please sign in to comment.