feat: dns query strategy

This commit is contained in:
arm64v8a
2023-02-14 17:16:31 +09:00
parent fbffd4e606
commit c9aa8b2328
8 changed files with 77 additions and 1 deletions

View File

@@ -247,6 +247,7 @@ namespace NekoRay {
QJsonObject dnsServerRemote; QJsonObject dnsServerRemote;
dnsServerRemote["address"] = dataStore->fake_dns ? "fakedns" : dataStore->remote_dns; dnsServerRemote["address"] = dataStore->fake_dns ? "fakedns" : dataStore->remote_dns;
dnsServerRemote["domains"] = QList2QJsonArray<QString>(status->domainListDNSRemote); dnsServerRemote["domains"] = QList2QJsonArray<QString>(status->domainListDNSRemote);
dnsServerRemote["queryStrategy"] = dataStore->remote_dns_strategy;
if (!status->forTest) dnsServers += dnsServerRemote; if (!status->forTest) dnsServers += dnsServerRemote;
// Direct // Direct
@@ -276,6 +277,7 @@ namespace NekoRay {
dnsServers += QJsonObject{ dnsServers += QJsonObject{
{"address", directDnsAddress.replace("https://", "https+local://")}, {"address", directDnsAddress.replace("https://", "https+local://")},
{"fallbackStrategy", "disabled"}, {"fallbackStrategy", "disabled"},
{"queryStrategy", dataStore->direct_dns_strategy},
{"domains", QList2QJsonArray<QString>(status->domainListDNSDirect)}, {"domains", QList2QJsonArray<QString>(status->domainListDNSDirect)},
}; };
@@ -754,6 +756,7 @@ namespace NekoRay {
dnsServers += QJsonObject{ dnsServers += QJsonObject{
{"tag", "dns-remote"}, {"tag", "dns-remote"},
{"address_resolver", "dns-underlying"}, {"address_resolver", "dns-underlying"},
{"strategy", dataStore->remote_dns_strategy},
{"address", dataStore->remote_dns}, {"address", dataStore->remote_dns},
{"detour", tagProxy}, {"detour", tagProxy},
}; };
@@ -768,6 +771,7 @@ namespace NekoRay {
dnsServers += QJsonObject{ dnsServers += QJsonObject{
{"tag", "dns-direct"}, {"tag", "dns-direct"},
{"address_resolver", "dns-underlying"}, {"address_resolver", "dns-underlying"},
{"strategy", dataStore->direct_dns_strategy},
{"address", directDNSAddress.replace("+local://", "://")}, {"address", directDNSAddress.replace("+local://", "://")},
{"detour", "direct"}, {"detour", "direct"},
}; };

View File

@@ -27,7 +27,9 @@ namespace NekoRay {
_add(new configItem("inbound_http_port", &inbound_http_port, itemType::integer)); _add(new configItem("inbound_http_port", &inbound_http_port, itemType::integer));
_add(new configItem("log_level", &log_level, itemType::string)); _add(new configItem("log_level", &log_level, itemType::string));
_add(new configItem("remote_dns", &remote_dns, itemType::string)); _add(new configItem("remote_dns", &remote_dns, itemType::string));
_add(new configItem("remote_dns_strategy", &remote_dns_strategy, itemType::string));
_add(new configItem("direct_dns", &direct_dns, itemType::string)); _add(new configItem("direct_dns", &direct_dns, itemType::string));
_add(new configItem("direct_dns_strategy", &direct_dns_strategy, itemType::string));
_add(new configItem("domain_matcher", &domain_matcher, itemType::integer)); _add(new configItem("domain_matcher", &domain_matcher, itemType::integer));
_add(new configItem("domain_strategy", &domain_strategy, itemType::string)); _add(new configItem("domain_strategy", &domain_strategy, itemType::string));
_add(new configItem("outbound_domain_strategy", &outbound_domain_strategy, itemType::string)); _add(new configItem("outbound_domain_strategy", &outbound_domain_strategy, itemType::string));

View File

@@ -115,7 +115,9 @@ namespace NekoRay {
// DNS // DNS
QString remote_dns = "https://8.8.8.8/dns-query"; QString remote_dns = "https://8.8.8.8/dns-query";
QString remote_dns_strategy = "";
QString direct_dns = "localhost"; QString direct_dns = "localhost";
QString direct_dns_strategy = "";
bool dns_routing = true; bool dns_routing = true;
// Routing // Routing

View File

@@ -560,6 +560,14 @@
<source>Default Outbound</source> <source>Default Outbound</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Query Strategy</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Remote</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>DialogVPNSettings</name> <name>DialogVPNSettings</name>

View File

@@ -225,7 +225,7 @@
</message> </message>
<message> <message>
<source>Maybe useful for HiDPI screens.</source> <source>Maybe useful for HiDPI screens.</source>
<translation type="unfinished"></translation> <translation> HiDPI </translation>
</message> </message>
<message> <message>
<source>Skip TLS certificate authentication by default (allowInsecure)</source> <source>Skip TLS certificate authentication by default (allowInsecure)</source>
@@ -566,6 +566,14 @@
<source>Default Outbound</source> <source>Default Outbound</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>Query Strategy</source>
<translation>DNS </translation>
</message>
<message>
<source>Remote</source>
<translation></translation>
</message>
</context> </context>
<context> <context>
<name>DialogVPNSettings</name> <name>DialogVPNSettings</name>

View File

@@ -210,3 +210,46 @@ void DialogManageRoutes::on_load_save_clicked() {
w->exec(); w->exec();
w->deleteLater(); w->deleteLater();
} }
void DialogManageRoutes::on_queryStrategy_clicked() {
auto w = new QDialog(this);
w->setWindowTitle("DNS Query Strategy");
auto layout = new QGridLayout;
w->setLayout(layout);
//
QStringList qsValue{""};
if (IS_NEKO_BOX) {
qsValue += QString("prefer_ipv4 prefer_ipv6 ipv4_only ipv6_only").split(" ");
} else {
qsValue += QString("use_ip use_ip4 use_ip6").split(" ");
}
//
auto remote_l = new QLabel(tr("Remote"));
auto direct_l = new QLabel(tr("Direct"));
auto remote = new QComboBox;
auto direct = new QComboBox;
remote->setEditable(true);
remote->addItems(qsValue);
remote->setCurrentText(NekoRay::dataStore->remote_dns_strategy);
direct->setEditable(true);
direct->addItems(qsValue);
direct->setCurrentText(NekoRay::dataStore->direct_dns_strategy);
//
layout->addWidget(remote_l, 0, 0);
layout->addWidget(remote, 0, 1);
layout->addWidget(direct_l, 1, 0);
layout->addWidget(direct, 1, 1);
auto box = new QDialogButtonBox;
box->setOrientation(Qt::Horizontal);
box->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
connect(box, &QDialogButtonBox::accepted, w, [=] {
NekoRay::dataStore->remote_dns_strategy = remote->currentText();
NekoRay::dataStore->direct_dns_strategy = direct->currentText();
NekoRay::dataStore->Save();
w->accept();
});
connect(box, &QDialogButtonBox::rejected, w, &QDialog::reject);
layout->addWidget(box, 2, 1);
//
w->exec();
w->deleteLater();
}

View File

@@ -54,4 +54,6 @@ public slots:
void SetRouteConfig(const NekoRay::Routing &conf); void SetRouteConfig(const NekoRay::Routing &conf);
void on_load_save_clicked(); void on_load_save_clicked();
void on_queryStrategy_clicked();
}; };

View File

@@ -132,6 +132,13 @@
<item> <item>
<widget class="QLineEdit" name="dns_direct"/> <widget class="QLineEdit" name="dns_direct"/>
</item> </item>
<item>
<widget class="QPushButton" name="queryStrategy">
<property name="text">
<string>Query Strategy</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>