Use service for PingSender

This commit is contained in:
Mykola Baibuz 2025-03-13 17:43:13 +02:00
parent e792117be1
commit 8bb4fa3f35
7 changed files with 46 additions and 47 deletions

View file

@ -33,14 +33,9 @@ set(HEADERS ${HEADERS}
# Mozilla headres
set(HEADERS ${HEADERS}
${CLIENT_ROOT_DIR}/mozilla/models/server.h
${CLIENT_ROOT_DIR}/mozilla/dnspingsender.h
${CLIENT_ROOT_DIR}/mozilla/pinghelper.h
${CLIENT_ROOT_DIR}/mozilla/pingsender.h
${CLIENT_ROOT_DIR}/mozilla/pingsenderfactory.h
${CLIENT_ROOT_DIR}/mozilla/shared/ipaddress.h
${CLIENT_ROOT_DIR}/mozilla/shared/leakdetector.h
${CLIENT_ROOT_DIR}/mozilla/controllerimpl.h
${CLIENT_ROOT_DIR}/mozilla/localsocketcontroller.h
)
if(NOT IOS)
@ -88,13 +83,8 @@ set(SOURCES ${SOURCES}
# Mozilla sources
set(SOURCES ${SOURCES}
${CLIENT_ROOT_DIR}/mozilla/models/server.cpp
${CLIENT_ROOT_DIR}/mozilla/dnspingsender.cpp
${CLIENT_ROOT_DIR}/mozilla/pinghelper.cpp
${CLIENT_ROOT_DIR}/mozilla/pingsender.cpp
${CLIENT_ROOT_DIR}/mozilla/pingsenderfactory.cpp
${CLIENT_ROOT_DIR}/mozilla/shared/ipaddress.cpp
${CLIENT_ROOT_DIR}/mozilla/shared/leakdetector.cpp
${CLIENT_ROOT_DIR}/mozilla/localsocketcontroller.cpp
)
if(NOT IOS)
@ -155,25 +145,13 @@ set(SOURCES ${SOURCES}
${UI_CONTROLLERS_CPP}
)
if (LINUX)
set(HEADERS ${HEADERS}
${CLIENT_ROOT_DIR}/platforms/linux/linuxpingsender.h
)
set(SOURCES ${SOURCES}
${CLIENT_ROOT_DIR}/platforms/linux/linuxpingsender.cpp
)
endif()
if(WIN32)
set(HEADERS ${HEADERS}
${CLIENT_ROOT_DIR}/protocols/ikev2_vpn_protocol_windows.h
${CLIENT_ROOT_DIR}/platforms/windows/windowspingsender.h
)
set(SOURCES ${SOURCES}
${CLIENT_ROOT_DIR}/protocols/ikev2_vpn_protocol_windows.cpp
${CLIENT_ROOT_DIR}/platforms/windows/windowspingsender.cpp
)
set(RESOURCES ${RESOURCES}
@ -181,16 +159,6 @@ if(WIN32)
)
endif()
if (APPLE AND NOT IOS AND NOT MACOS_NE)
set(HEADERS ${HEADERS}
${CLIENT_ROOT_DIR}/platforms/macos/macospingsender.h
)
set(SOURCES ${SOURCES}
${CLIENT_ROOT_DIR}/platforms/macos/macosspingsender.cpp
)
endif()
if(WIN32 OR (APPLE AND NOT IOS) OR (LINUX AND NOT ANDROID))
message("Client desktop build")
add_compile_definitions(AMNEZIA_DESKTOP)
@ -205,11 +173,13 @@ if(WIN32 OR (APPLE AND NOT IOS) OR (LINUX AND NOT ANDROID))
${CLIENT_ROOT_DIR}/protocols/wireguardprotocol.h
${CLIENT_ROOT_DIR}/protocols/xrayprotocol.h
${CLIENT_ROOT_DIR}/protocols/awgprotocol.h
${CLIENT_ROOT_DIR}/mozilla/localsocketcontroller.h
)
set(SOURCES ${SOURCES}
${CLIENT_ROOT_DIR}/core/ipcclient.cpp
${CLIENT_ROOT_DIR}/core/privileged_process.cpp
${CLIENT_ROOT_DIR}/mozilla/localsocketcontroller.cpp
${CLIENT_ROOT_DIR}/ui/systemtray_notificationhandler.cpp
${CLIENT_ROOT_DIR}/protocols/openvpnprotocol.cpp
${CLIENT_ROOT_DIR}/protocols/openvpnovercloakprotocol.cpp

View file

@ -21,6 +21,8 @@
#include "models/server.h"
#include "daemon/daemonerrors.h"
#include "core/ipcclient.h"
#include "protocols/protocols_defs.h"
// How many times do we try to reconnect.
@ -39,7 +41,7 @@ LocalSocketController::LocalSocketController() {
m_socket = new QLocalSocket(this);
connect(m_socket, &QLocalSocket::connected, this,
&LocalSocketController::daemonConnected);
connect(m_socket, &QLocalSocket::disconnected, this,
connect(m_socket, &QLocalSocket::disconnected, this,
[&] { errorOccurred(QLocalSocket::PeerClosedError); });
connect(m_socket, &QLocalSocket::errorOccurred, this,
&LocalSocketController::errorOccurred);
@ -50,11 +52,12 @@ LocalSocketController::LocalSocketController() {
connect(&m_initializingTimer, &QTimer::timeout, this,
&LocalSocketController::initializeInternal);
connect(&m_pingHelper, &PingHelper::connectionLose, this, [this]() {
connect(IpcClient::Interface().data(), &IpcInterfaceReplica::connectionLose,
this, [this]() {
logger.debug() << "Connection Lose";
m_pingHelper.stop();
auto result = IpcClient::Interface()->stopNetworkCheck();
result.waitForFinished(3000);
this->deactivate();
QThread::msleep(3000);
this->activate(m_RawConfig);
});
@ -145,11 +148,14 @@ void LocalSocketController::activate(const QJsonObject &rawConfig) {
json.insert("deviceIpv4Address", wgConfig.value(amnezia::config_key::client_ip));
// set up IPv6 unique-local-address, ULA, with "fd00::/8" prefix, not globally routable.
// this will be default IPv6 gateway, OS recognizes that IPv6 link is local and switches to IPv4.
// Otherwise some OSes (Linux) try IPv6 forever and hang.
// this will be default IPv6 gateway, OS recognizes that IPv6 link
// is local and switches to IPv4.
// Otherwise some OSes (Linux) try IPv6 forever and hang.
// https://en.wikipedia.org/wiki/Unique_local_address (RFC 4193)
// https://man7.org/linux/man-pages/man5/gai.conf.5.html
json.insert("deviceIpv6Address", "fd58:baa6:dead::1"); // simply "dead::1" is globally-routable, don't use it
// simply "dead::1" is globally-routable, don't use it
json.insert("deviceIpv6Address", "fd58:baa6:dead::1");
json.insert("serverPublicKey", wgConfig.value(amnezia::config_key::server_pub_key));
json.insert("serverPskKey", wgConfig.value(amnezia::config_key::psk_key));
@ -286,6 +292,8 @@ void LocalSocketController::deactivate() {
QJsonObject json;
json.insert("type", "deactivate");
write(json);
auto result = IpcClient::Interface()->stopNetworkCheck();
result.waitForFinished(3000);
emit disconnected();
}
@ -375,8 +383,6 @@ void LocalSocketController::parseCommand(const QByteArray& command) {
return;
}
qDebug() << command;
QJsonObject obj = json.object();
QJsonValue typeValue = obj.value("type");
if (!typeValue.isString()) {
@ -434,7 +440,8 @@ void LocalSocketController::parseCommand(const QByteArray& command) {
return;
}
m_pingHelper.start(serverIpv4Gateway.toString(), deviceIpv4Address.toString());
IpcClient::Interface()->startNetworkCheck(serverIpv4Gateway.toString(),
deviceIpv4Address.toString());
QJsonValue txBytes = obj.value("txBytes");
if (!txBytes.isDouble()) {

View file

@ -11,7 +11,6 @@
#include <functional>
#include "controllerimpl.h"
#include "mozilla/pinghelper.h"
#include "qjsonobject.h"
@ -64,7 +63,6 @@ class LocalSocketController final : public ControllerImpl {
std::function<void(const QString&)> m_logCallback = nullptr;
QJsonObject m_RawConfig;
PingHelper m_pingHelper;
QTimer m_initializingTimer;
QTimer m_statusTimer;