mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
feat: resolve profile domain
This commit is contained in:
@@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user