feat: resolve profile domain

This commit is contained in:
arm64v8a
2022-09-22 22:26:39 +08:00
parent 3f0081b930
commit 0ca3e20824
11 changed files with 101 additions and 8 deletions

View File

@@ -1,4 +1,9 @@
#include "AbstractBean.hpp"
#include "includes.h"
#include <functional>
#include <QApplication>
#include <QHostInfo>
namespace NekoRay::fmt {
AbstractBean::AbstractBean(int version) {
@@ -33,4 +38,38 @@ namespace NekoRay::fmt {
QString AbstractBean::DisplayTypeAndName() {
return QString(" [%1] %2").arg(DisplayType(), DisplayName());
}
}
void AbstractBean::ResolveDomainToIP(const std::function<void()> &onFinished) {
bool noResolve = false;
if (dynamic_cast<ChainBean *>(this) != nullptr) noResolve = true;
if (dynamic_cast<CustomBean *>(this) != nullptr) noResolve = true;
if (dynamic_cast<NaiveBean *>(this) != nullptr) noResolve = true;
if (IsIpAddress(serverAddress)) noResolve = true;
if (noResolve) {
onFinished();
return;
}
QHostInfo::lookupHost(serverAddress, QApplication::instance(), [=](const QHostInfo &host) {
auto addr = host.addresses();
if (!addr.isEmpty()) {
auto domain = serverAddress;
auto stream = GetStreamSettings(this);
// replace serverAddress
serverAddress = addr.first().toString();
// replace ws tls
if (stream != nullptr) {
if (stream->security == "tls" && !stream->sni.isEmpty()) {
stream->sni = domain;
}
if (stream->network == "ws" && !stream->host.isEmpty()) {
stream->host = domain;
}
}
}
onFinished();
});
}
}