mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-11-20 19:42:42 +09:00
* fix: share double-stop guard via VpnProtocol base class * feat: add local proxy core module * feat: local proxy settings api * feat: wire local proxy into app controllers * feat: local proxy settings ui * feat: arbitrate shared xray engine ownership via ipc tokens * fix: remove connection type * chore: add qthttpserver to desktop ci qt modules * fix: local proxy port fallback and active port reporting * fix: keep text field button aligned when error is shown * fix: hide local proxy for free servers and guard device unlink * fix: show local proxy state per server * fix: anchor text field button to content * fix: adapt local proxy pages to design * fix: copy logic and port logic * refactor: move local proxy files to controllers and utils * refactor: merge local proxy into LocalProxyController * refactor: reuse gateway config request and keep local proxy state in memory --------- Co-authored-by: vkamn <vk@amnezia.org>
83 lines
2.6 KiB
C++
83 lines
2.6 KiB
C++
#include <QCoreApplication>
|
|
#include <QFileInfo>
|
|
#include <QProcess>
|
|
#include <QTcpSocket>
|
|
#include <QThread>
|
|
|
|
#include "wireGuardProtocol.h"
|
|
#include "core/utils/networkUtilities.h"
|
|
|
|
#include "mozilla/localsocketcontroller.h"
|
|
|
|
WireguardProtocol::WireguardProtocol(const QJsonObject &configuration, QObject *parent)
|
|
: VpnProtocol(configuration, parent)
|
|
{
|
|
m_impl.reset(new LocalSocketController());
|
|
connect(m_impl.get(), &ControllerImpl::connected, this,
|
|
[this](const QString &pubkey, const QDateTime &connectionTimestamp) {
|
|
setConnectionState(Vpn::ConnectionState::Connected);
|
|
});
|
|
connect(m_impl.get(), &ControllerImpl::statusUpdated, this,
|
|
[this](const QString& serverIpv4Gateway,
|
|
const QString& deviceIpv4Address, uint64_t txBytes,
|
|
uint64_t rxBytes) {
|
|
const QString previousGateway = m_vpnGateway;
|
|
const QString previousLocal = m_vpnLocalAddress;
|
|
|
|
if (!serverIpv4Gateway.isEmpty()) {
|
|
m_vpnGateway = serverIpv4Gateway;
|
|
}
|
|
if (!deviceIpv4Address.isEmpty()) {
|
|
m_vpnLocalAddress = deviceIpv4Address;
|
|
}
|
|
|
|
if ((!m_vpnGateway.isEmpty() && m_vpnGateway != previousGateway) ||
|
|
(!m_vpnLocalAddress.isEmpty() && m_vpnLocalAddress != previousLocal)) {
|
|
emit tunnelAddressesUpdated(m_vpnGateway, m_vpnLocalAddress);
|
|
}
|
|
});
|
|
|
|
connect(m_impl.get(), &ControllerImpl::disconnected, this,
|
|
[this]() { setConnectionState(Vpn::ConnectionState::Disconnected); });
|
|
m_impl->initialize(nullptr, nullptr);
|
|
}
|
|
|
|
WireguardProtocol::~WireguardProtocol()
|
|
{
|
|
WireguardProtocol::stop();
|
|
QThread::msleep(200);
|
|
}
|
|
|
|
void WireguardProtocol::stop()
|
|
{
|
|
if (guardStop()) {
|
|
return;
|
|
}
|
|
stopMzImpl();
|
|
}
|
|
|
|
ErrorCode WireguardProtocol::startMzImpl()
|
|
{
|
|
QString protocolName = m_rawConfig.value("protocol").toString();
|
|
QJsonObject vpnConfigData = m_rawConfig.value(protocolName + "_config_data").toObject();
|
|
vpnConfigData[configKey::hostName] = NetworkUtilities::getIPAddress(vpnConfigData.value(configKey::hostName).toString());
|
|
m_rawConfig.insert(protocolName + "_config_data", vpnConfigData);
|
|
m_rawConfig[configKey::hostName] = NetworkUtilities::getIPAddress(m_rawConfig[configKey::hostName].toString());
|
|
|
|
m_impl->activate(m_rawConfig);
|
|
return ErrorCode::NoError;
|
|
}
|
|
|
|
ErrorCode WireguardProtocol::stopMzImpl()
|
|
{
|
|
m_impl->deactivate();
|
|
return ErrorCode::NoError;
|
|
}
|
|
|
|
|
|
ErrorCode WireguardProtocol::start()
|
|
{
|
|
resetStopGuard();
|
|
return startMzImpl();
|
|
}
|