moved the function of checking the availability of wireguard config to ipc client
This commit is contained in:
parent
caad670dbf
commit
8f18933713
4 changed files with 33 additions and 19 deletions
|
|
@ -8,8 +8,7 @@
|
||||||
#include "wireguardprotocol.h"
|
#include "wireguardprotocol.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
|
||||||
WireguardProtocol::WireguardProtocol(const QJsonObject &configuration, QObject* parent) :
|
WireguardProtocol::WireguardProtocol(const QJsonObject &configuration, QObject* parent) : VpnProtocol(configuration, parent)
|
||||||
VpnProtocol(configuration, parent)
|
|
||||||
{
|
{
|
||||||
m_configFile.setFileName(QDir::tempPath() + QDir::separator() + serviceName() + ".conf");
|
m_configFile.setFileName(QDir::tempPath() + QDir::separator() + serviceName() + ".conf");
|
||||||
writeWireguardConfiguration(configuration);
|
writeWireguardConfiguration(configuration);
|
||||||
|
|
@ -145,10 +144,17 @@ ErrorCode WireguardProtocol::start()
|
||||||
return lastError();
|
return lastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (!QFileInfo::exists(configPath())) {
|
if (IpcClient::Interface()) {
|
||||||
// setLastError(ErrorCode::ConfigMissing);
|
QRemoteObjectPendingReply<bool> result = IpcClient::Interface()->isWireguardConfigExists(configPath());
|
||||||
// return lastError();
|
if (result.returnValue()) {
|
||||||
// }
|
setLastError(ErrorCode::ConfigMissing);
|
||||||
|
return lastError();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qCritical() << "IPC client not initialized";
|
||||||
|
setLastError(ErrorCode::InternalError);
|
||||||
|
return lastError();
|
||||||
|
}
|
||||||
|
|
||||||
setConnectionState(VpnConnectionState::Connecting);
|
setConnectionState(VpnConnectionState::Connecting);
|
||||||
|
|
||||||
|
|
@ -198,7 +204,7 @@ ErrorCode WireguardProtocol::start()
|
||||||
|
|
||||||
connect(m_wireguardStartProcess.data(), &PrivilegedProcess::readyReadStandardError, this, [this]() {
|
connect(m_wireguardStartProcess.data(), &PrivilegedProcess::readyReadStandardError, this, [this]() {
|
||||||
QRemoteObjectPendingReply<QByteArray> reply = m_wireguardStartProcess->readAllStandardError();
|
QRemoteObjectPendingReply<QByteArray> reply = m_wireguardStartProcess->readAllStandardError();
|
||||||
reply.waitForFinished(1000);
|
reply.waitForFinished(10);
|
||||||
qDebug() << "WireguardProtocol::WireguardProtocol readAllStandardError" << reply.returnValue();
|
qDebug() << "WireguardProtocol::WireguardProtocol readAllStandardError" << reply.returnValue();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -213,20 +219,20 @@ ErrorCode WireguardProtocol::start()
|
||||||
|
|
||||||
void WireguardProtocol::updateVpnGateway(const QString &line)
|
void WireguardProtocol::updateVpnGateway(const QString &line)
|
||||||
{
|
{
|
||||||
// // line looks like
|
// // line looks like
|
||||||
// // PUSH: Received control message: 'PUSH_REPLY,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5,peer-id 0,cipher AES-256-GCM'
|
// // PUSH: Received control message: 'PUSH_REPLY,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5,peer-id 0,cipher AES-256-GCM'
|
||||||
|
|
||||||
// QStringList params = line.split(",");
|
// QStringList params = line.split(",");
|
||||||
// for (const QString &l : params) {
|
// for (const QString &l : params) {
|
||||||
// if (l.contains("ifconfig")) {
|
// if (l.contains("ifconfig")) {
|
||||||
// if (l.split(" ").size() == 3) {
|
// if (l.split(" ").size() == 3) {
|
||||||
// m_vpnLocalAddress = l.split(" ").at(1);
|
// m_vpnLocalAddress = l.split(" ").at(1);
|
||||||
// m_vpnGateway = l.split(" ").at(2);
|
// m_vpnGateway = l.split(" ").at(2);
|
||||||
|
|
||||||
// qDebug() << QString("Set vpn local address %1, gw %2").arg(m_vpnLocalAddress).arg(vpnGateway());
|
// qDebug() << QString("Set vpn local address %1, gw %2").arg(m_vpnLocalAddress).arg(vpnGateway());
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
QString WireguardProtocol::serviceName() const
|
QString WireguardProtocol::serviceName() const
|
||||||
|
|
|
||||||
|
|
@ -21,5 +21,6 @@ class IpcInterface
|
||||||
|
|
||||||
SLOT( bool copyWireguardConfig(const QString &sourcePath) );
|
SLOT( bool copyWireguardConfig(const QString &sourcePath) );
|
||||||
SLOT( bool isWireguardRunning() );
|
SLOT( bool isWireguardRunning() );
|
||||||
|
SLOT( bool isWireguardConfigExists(const QString &configPath) );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QLocalSocket>
|
#include <QLocalSocket>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
#include "router.h"
|
#include "router.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
@ -169,3 +170,8 @@ bool IpcServer::isWireguardRunning()
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IpcServer::isWireguardConfigExists(const QString &configPath)
|
||||||
|
{
|
||||||
|
return QFileInfo::exists(configPath);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ public:
|
||||||
virtual void setLogsEnabled(bool enabled) override;
|
virtual void setLogsEnabled(bool enabled) override;
|
||||||
virtual bool copyWireguardConfig(const QString &sourcePath) override;
|
virtual bool copyWireguardConfig(const QString &sourcePath) override;
|
||||||
virtual bool isWireguardRunning() override;
|
virtual bool isWireguardRunning() override;
|
||||||
|
virtual bool isWireguardConfigExists(const QString &configPath) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_localpid = 0;
|
int m_localpid = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue