2021-06-12 11:59:36 +03:00
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QProcess>
|
|
|
|
|
#include <QTcpSocket>
|
|
|
|
|
#include <QThread>
|
|
|
|
|
|
2022-12-28 13:41:45 +03:00
|
|
|
#include "logger.h"
|
2022-08-29 12:21:09 +04:30
|
|
|
#include "utilities.h"
|
2023-07-24 16:31:04 +09:00
|
|
|
#include "wireguardprotocol.h"
|
2021-06-12 11:59:36 +03:00
|
|
|
|
2023-07-15 14:19:48 -07:00
|
|
|
#include "mozilla/localsocketcontroller.h"
|
|
|
|
|
|
2023-07-24 16:31:04 +09:00
|
|
|
WireguardProtocol::WireguardProtocol(const QJsonObject &configuration, QObject *parent)
|
|
|
|
|
: VpnProtocol(configuration, parent)
|
2021-06-12 11:59:36 +03:00
|
|
|
{
|
2023-07-15 14:19:48 -07:00
|
|
|
m_impl.reset(new LocalSocketController());
|
2023-07-24 16:31:04 +09:00
|
|
|
connect(m_impl.get(), &ControllerImpl::connected, this,
|
|
|
|
|
[this](const QString &pubkey, const QDateTime &connectionTimestamp) {
|
|
|
|
|
emit connectionStateChanged(Vpn::ConnectionState::Connected);
|
|
|
|
|
});
|
|
|
|
|
connect(m_impl.get(), &ControllerImpl::disconnected, this,
|
|
|
|
|
[this]() { emit connectionStateChanged(Vpn::ConnectionState::Disconnected); });
|
2023-07-15 14:19:48 -07:00
|
|
|
m_impl->initialize(nullptr, nullptr);
|
2021-06-12 11:59:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WireguardProtocol::~WireguardProtocol()
|
|
|
|
|
{
|
|
|
|
|
WireguardProtocol::stop();
|
|
|
|
|
QThread::msleep(200);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WireguardProtocol::stop()
|
|
|
|
|
{
|
2023-07-15 14:19:48 -07:00
|
|
|
stopMzImpl();
|
|
|
|
|
return;
|
2021-06-12 11:59:36 +03:00
|
|
|
}
|
|
|
|
|
|
2023-07-15 14:19:48 -07:00
|
|
|
ErrorCode WireguardProtocol::startMzImpl()
|
|
|
|
|
{
|
|
|
|
|
m_impl->activate(m_rawConfig);
|
|
|
|
|
return ErrorCode::NoError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ErrorCode WireguardProtocol::stopMzImpl()
|
|
|
|
|
{
|
|
|
|
|
m_impl->deactivate();
|
|
|
|
|
return ErrorCode::NoError;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-12 11:59:36 +03:00
|
|
|
|
|
|
|
|
ErrorCode WireguardProtocol::start()
|
|
|
|
|
{
|
2023-07-15 14:19:48 -07:00
|
|
|
return startMzImpl();
|
2021-06-12 11:59:36 +03:00
|
|
|
}
|
|
|
|
|
|