2021-05-02 18:22:38 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2023-01-02 19:30:11 +00:00
|
|
|
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
|
2021-05-02 18:22:38 +00:00
|
|
|
|
|
|
|
#include "NetworkManager.h"
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QNetworkProxy>
|
2023-02-11 17:11:21 +00:00
|
|
|
#include <QRegularExpression>
|
|
|
|
#include <QUrl>
|
2021-05-02 18:22:38 +00:00
|
|
|
|
2023-02-11 17:11:21 +00:00
|
|
|
#include "utils/config.h"
|
|
|
|
#include "utils/Utils.h"
|
|
|
|
|
|
|
|
QNetworkAccessManager *g_networkManagerSocks5 = nullptr;
|
2021-05-02 18:22:38 +00:00
|
|
|
QNetworkAccessManager *g_networkManagerClearnet = nullptr;
|
|
|
|
|
2023-02-11 17:11:21 +00:00
|
|
|
QNetworkAccessManager* getNetworkSocks5()
|
2021-05-02 18:22:38 +00:00
|
|
|
{
|
2023-02-11 17:11:21 +00:00
|
|
|
if (!g_networkManagerSocks5) {
|
|
|
|
g_networkManagerSocks5 = new QNetworkAccessManager(QCoreApplication::instance());
|
2021-05-02 18:22:38 +00:00
|
|
|
QNetworkProxy proxy;
|
|
|
|
proxy.setType(QNetworkProxy::Socks5Proxy);
|
|
|
|
proxy.setHostName("127.0.0.1");
|
|
|
|
proxy.setPort(9050);
|
2023-02-11 17:11:21 +00:00
|
|
|
g_networkManagerSocks5->setProxy(proxy);
|
2021-05-02 18:22:38 +00:00
|
|
|
}
|
2023-02-11 17:11:21 +00:00
|
|
|
return g_networkManagerSocks5;
|
2021-05-02 18:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QNetworkAccessManager* getNetworkClearnet()
|
|
|
|
{
|
|
|
|
if (!g_networkManagerClearnet) {
|
|
|
|
g_networkManagerClearnet = new QNetworkAccessManager(QCoreApplication::instance());
|
|
|
|
}
|
|
|
|
return g_networkManagerClearnet;
|
|
|
|
}
|
|
|
|
|
2023-02-11 17:11:21 +00:00
|
|
|
|
|
|
|
QNetworkAccessManager* getNetwork(const QString &address)
|
|
|
|
{
|
|
|
|
if (config()->get(Config::proxy).toInt() == Config::Proxy::None) {
|
|
|
|
return getNetworkClearnet();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore proxy rules for local addresses
|
|
|
|
if (!address.isEmpty() && Utils::isLocalUrl(QUrl(address))) {
|
|
|
|
return getNetworkClearnet();
|
|
|
|
}
|
|
|
|
|
|
|
|
return getNetworkSocks5();
|
|
|
|
}
|