Use service for PingSender
This commit is contained in:
parent
e792117be1
commit
8bb4fa3f35
7 changed files with 46 additions and 47 deletions
|
@ -33,14 +33,9 @@ set(HEADERS ${HEADERS}
|
||||||
# Mozilla headres
|
# Mozilla headres
|
||||||
set(HEADERS ${HEADERS}
|
set(HEADERS ${HEADERS}
|
||||||
${CLIENT_ROOT_DIR}/mozilla/models/server.h
|
${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/ipaddress.h
|
||||||
${CLIENT_ROOT_DIR}/mozilla/shared/leakdetector.h
|
${CLIENT_ROOT_DIR}/mozilla/shared/leakdetector.h
|
||||||
${CLIENT_ROOT_DIR}/mozilla/controllerimpl.h
|
${CLIENT_ROOT_DIR}/mozilla/controllerimpl.h
|
||||||
${CLIENT_ROOT_DIR}/mozilla/localsocketcontroller.h
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(NOT IOS)
|
if(NOT IOS)
|
||||||
|
@ -88,13 +83,8 @@ set(SOURCES ${SOURCES}
|
||||||
# Mozilla sources
|
# Mozilla sources
|
||||||
set(SOURCES ${SOURCES}
|
set(SOURCES ${SOURCES}
|
||||||
${CLIENT_ROOT_DIR}/mozilla/models/server.cpp
|
${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/ipaddress.cpp
|
||||||
${CLIENT_ROOT_DIR}/mozilla/shared/leakdetector.cpp
|
${CLIENT_ROOT_DIR}/mozilla/shared/leakdetector.cpp
|
||||||
${CLIENT_ROOT_DIR}/mozilla/localsocketcontroller.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(NOT IOS)
|
if(NOT IOS)
|
||||||
|
@ -155,25 +145,13 @@ set(SOURCES ${SOURCES}
|
||||||
${UI_CONTROLLERS_CPP}
|
${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)
|
if(WIN32)
|
||||||
set(HEADERS ${HEADERS}
|
set(HEADERS ${HEADERS}
|
||||||
${CLIENT_ROOT_DIR}/protocols/ikev2_vpn_protocol_windows.h
|
${CLIENT_ROOT_DIR}/protocols/ikev2_vpn_protocol_windows.h
|
||||||
${CLIENT_ROOT_DIR}/platforms/windows/windowspingsender.h
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SOURCES ${SOURCES}
|
set(SOURCES ${SOURCES}
|
||||||
${CLIENT_ROOT_DIR}/protocols/ikev2_vpn_protocol_windows.cpp
|
${CLIENT_ROOT_DIR}/protocols/ikev2_vpn_protocol_windows.cpp
|
||||||
${CLIENT_ROOT_DIR}/platforms/windows/windowspingsender.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(RESOURCES ${RESOURCES}
|
set(RESOURCES ${RESOURCES}
|
||||||
|
@ -181,16 +159,6 @@ if(WIN32)
|
||||||
)
|
)
|
||||||
endif()
|
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))
|
if(WIN32 OR (APPLE AND NOT IOS) OR (LINUX AND NOT ANDROID))
|
||||||
message("Client desktop build")
|
message("Client desktop build")
|
||||||
add_compile_definitions(AMNEZIA_DESKTOP)
|
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/wireguardprotocol.h
|
||||||
${CLIENT_ROOT_DIR}/protocols/xrayprotocol.h
|
${CLIENT_ROOT_DIR}/protocols/xrayprotocol.h
|
||||||
${CLIENT_ROOT_DIR}/protocols/awgprotocol.h
|
${CLIENT_ROOT_DIR}/protocols/awgprotocol.h
|
||||||
|
${CLIENT_ROOT_DIR}/mozilla/localsocketcontroller.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SOURCES ${SOURCES}
|
set(SOURCES ${SOURCES}
|
||||||
${CLIENT_ROOT_DIR}/core/ipcclient.cpp
|
${CLIENT_ROOT_DIR}/core/ipcclient.cpp
|
||||||
${CLIENT_ROOT_DIR}/core/privileged_process.cpp
|
${CLIENT_ROOT_DIR}/core/privileged_process.cpp
|
||||||
|
${CLIENT_ROOT_DIR}/mozilla/localsocketcontroller.cpp
|
||||||
${CLIENT_ROOT_DIR}/ui/systemtray_notificationhandler.cpp
|
${CLIENT_ROOT_DIR}/ui/systemtray_notificationhandler.cpp
|
||||||
${CLIENT_ROOT_DIR}/protocols/openvpnprotocol.cpp
|
${CLIENT_ROOT_DIR}/protocols/openvpnprotocol.cpp
|
||||||
${CLIENT_ROOT_DIR}/protocols/openvpnovercloakprotocol.cpp
|
${CLIENT_ROOT_DIR}/protocols/openvpnovercloakprotocol.cpp
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "models/server.h"
|
#include "models/server.h"
|
||||||
#include "daemon/daemonerrors.h"
|
#include "daemon/daemonerrors.h"
|
||||||
|
|
||||||
|
#include "core/ipcclient.h"
|
||||||
|
|
||||||
#include "protocols/protocols_defs.h"
|
#include "protocols/protocols_defs.h"
|
||||||
|
|
||||||
// How many times do we try to reconnect.
|
// How many times do we try to reconnect.
|
||||||
|
@ -50,11 +52,12 @@ LocalSocketController::LocalSocketController() {
|
||||||
connect(&m_initializingTimer, &QTimer::timeout, this,
|
connect(&m_initializingTimer, &QTimer::timeout, this,
|
||||||
&LocalSocketController::initializeInternal);
|
&LocalSocketController::initializeInternal);
|
||||||
|
|
||||||
connect(&m_pingHelper, &PingHelper::connectionLose, this, [this]() {
|
connect(IpcClient::Interface().data(), &IpcInterfaceReplica::connectionLose,
|
||||||
|
this, [this]() {
|
||||||
logger.debug() << "Connection Lose";
|
logger.debug() << "Connection Lose";
|
||||||
m_pingHelper.stop();
|
auto result = IpcClient::Interface()->stopNetworkCheck();
|
||||||
|
result.waitForFinished(3000);
|
||||||
this->deactivate();
|
this->deactivate();
|
||||||
QThread::msleep(3000);
|
|
||||||
this->activate(m_RawConfig);
|
this->activate(m_RawConfig);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -145,11 +148,14 @@ void LocalSocketController::activate(const QJsonObject &rawConfig) {
|
||||||
json.insert("deviceIpv4Address", wgConfig.value(amnezia::config_key::client_ip));
|
json.insert("deviceIpv4Address", wgConfig.value(amnezia::config_key::client_ip));
|
||||||
|
|
||||||
// set up IPv6 unique-local-address, ULA, with "fd00::/8" prefix, not globally routable.
|
// 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.
|
// 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.
|
// Otherwise some OSes (Linux) try IPv6 forever and hang.
|
||||||
// https://en.wikipedia.org/wiki/Unique_local_address (RFC 4193)
|
// https://en.wikipedia.org/wiki/Unique_local_address (RFC 4193)
|
||||||
// https://man7.org/linux/man-pages/man5/gai.conf.5.html
|
// 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("serverPublicKey", wgConfig.value(amnezia::config_key::server_pub_key));
|
||||||
json.insert("serverPskKey", wgConfig.value(amnezia::config_key::psk_key));
|
json.insert("serverPskKey", wgConfig.value(amnezia::config_key::psk_key));
|
||||||
|
@ -286,6 +292,8 @@ void LocalSocketController::deactivate() {
|
||||||
QJsonObject json;
|
QJsonObject json;
|
||||||
json.insert("type", "deactivate");
|
json.insert("type", "deactivate");
|
||||||
write(json);
|
write(json);
|
||||||
|
auto result = IpcClient::Interface()->stopNetworkCheck();
|
||||||
|
result.waitForFinished(3000);
|
||||||
emit disconnected();
|
emit disconnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,8 +383,6 @@ void LocalSocketController::parseCommand(const QByteArray& command) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << command;
|
|
||||||
|
|
||||||
QJsonObject obj = json.object();
|
QJsonObject obj = json.object();
|
||||||
QJsonValue typeValue = obj.value("type");
|
QJsonValue typeValue = obj.value("type");
|
||||||
if (!typeValue.isString()) {
|
if (!typeValue.isString()) {
|
||||||
|
@ -434,7 +440,8 @@ void LocalSocketController::parseCommand(const QByteArray& command) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pingHelper.start(serverIpv4Gateway.toString(), deviceIpv4Address.toString());
|
IpcClient::Interface()->startNetworkCheck(serverIpv4Gateway.toString(),
|
||||||
|
deviceIpv4Address.toString());
|
||||||
|
|
||||||
QJsonValue txBytes = obj.value("txBytes");
|
QJsonValue txBytes = obj.value("txBytes");
|
||||||
if (!txBytes.isDouble()) {
|
if (!txBytes.isDouble()) {
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "controllerimpl.h"
|
#include "controllerimpl.h"
|
||||||
#include "mozilla/pinghelper.h"
|
|
||||||
#include "qjsonobject.h"
|
#include "qjsonobject.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,7 +63,6 @@ class LocalSocketController final : public ControllerImpl {
|
||||||
std::function<void(const QString&)> m_logCallback = nullptr;
|
std::function<void(const QString&)> m_logCallback = nullptr;
|
||||||
|
|
||||||
QJsonObject m_RawConfig;
|
QJsonObject m_RawConfig;
|
||||||
PingHelper m_pingHelper;
|
|
||||||
|
|
||||||
QTimer m_initializingTimer;
|
QTimer m_initializingTimer;
|
||||||
QTimer m_statusTimer;
|
QTimer m_statusTimer;
|
||||||
|
|
|
@ -32,5 +32,9 @@ class IpcInterface
|
||||||
SLOT( bool enablePeerTraffic( const QJsonObject &configStr) );
|
SLOT( bool enablePeerTraffic( const QJsonObject &configStr) );
|
||||||
SLOT( bool enableKillSwitch( const QJsonObject &excludeAddr, int vpnAdapterIndex) );
|
SLOT( bool enableKillSwitch( const QJsonObject &excludeAddr, int vpnAdapterIndex) );
|
||||||
SLOT( bool updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers) );
|
SLOT( bool updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers) );
|
||||||
|
SLOT( bool startNetworkCheck(const QString& serverIpv4Gateway, const QString& deviceIpv4Address) );
|
||||||
|
SLOT( bool stopNetworkCheck() );
|
||||||
|
|
||||||
|
SIGNAL( connectionLose() );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
IpcServer::IpcServer(QObject *parent) : IpcInterfaceSource(parent)
|
IpcServer::IpcServer(QObject *parent) : IpcInterfaceSource(parent)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
connect(&m_pingHelper, &PingHelper::connectionLose, this, &IpcServer::connectionLose);
|
||||||
}
|
}
|
||||||
|
|
||||||
int IpcServer::createPrivilegedProcess()
|
int IpcServer::createPrivilegedProcess()
|
||||||
|
@ -188,6 +188,20 @@ void IpcServer::setLogsEnabled(bool enabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IpcServer::startNetworkCheck(const QString& serverIpv4Gateway, const QString& deviceIpv4Address)
|
||||||
|
{
|
||||||
|
m_pingHelper.start(serverIpv4Gateway, deviceIpv4Address);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IpcServer::stopNetworkCheck()
|
||||||
|
{
|
||||||
|
|
||||||
|
qDebug() << "stopNetworkCheck";
|
||||||
|
m_pingHelper.stop();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool IpcServer::enableKillSwitch(const QJsonObject &configStr, int vpnAdapterIndex)
|
bool IpcServer::enableKillSwitch(const QJsonObject &configStr, int vpnAdapterIndex)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QRemoteObjectNode>
|
#include <QRemoteObjectNode>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include "../client/daemon/interfaceconfig.h"
|
#include "../client/daemon/interfaceconfig.h"
|
||||||
|
#include "../client/mozilla/pinghelper.h"
|
||||||
|
|
||||||
#include "ipc.h"
|
#include "ipc.h"
|
||||||
#include "ipcserverprocess.h"
|
#include "ipcserverprocess.h"
|
||||||
|
@ -38,6 +39,11 @@ public:
|
||||||
virtual bool enableKillSwitch(const QJsonObject &excludeAddr, int vpnAdapterIndex) override;
|
virtual bool enableKillSwitch(const QJsonObject &excludeAddr, int vpnAdapterIndex) override;
|
||||||
virtual bool disableKillSwitch() override;
|
virtual bool disableKillSwitch() override;
|
||||||
virtual bool updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers) override;
|
virtual bool updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers) override;
|
||||||
|
virtual bool startNetworkCheck(const QString& serverIpv4Gateway, const QString& deviceIpv4Address) override;
|
||||||
|
virtual bool stopNetworkCheck() override;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void ConnectionLose();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_localpid = 0;
|
int m_localpid = 0;
|
||||||
|
@ -57,6 +63,8 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
QMap<int, ProcessDescriptor> m_processes;
|
QMap<int, ProcessDescriptor> m_processes;
|
||||||
|
PingHelper m_pingHelper;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // IPCSERVER_H
|
#endif // IPCSERVER_H
|
||||||
|
|
|
@ -56,7 +56,6 @@ set(HEADERS ${HEADERS}
|
||||||
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/controllerimpl.h
|
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/controllerimpl.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/dnspingsender.h
|
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/dnspingsender.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/localsocketcontroller.h
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/networkwatcher.h
|
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/networkwatcher.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/networkwatcherimpl.h
|
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/networkwatcherimpl.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/pinghelper.h
|
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/pinghelper.h
|
||||||
|
@ -80,7 +79,6 @@ set(SOURCES ${SOURCES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/shared/leakdetector.cpp
|
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/shared/leakdetector.cpp
|
||||||
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/dnspingsender.cpp
|
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/dnspingsender.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/localsocketcontroller.cpp
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/networkwatcher.cpp
|
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/networkwatcher.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/pinghelper.cpp
|
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/pinghelper.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/pingsender.cpp
|
${CMAKE_CURRENT_LIST_DIR}/../../client/mozilla/pingsender.cpp
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue