Use networkchecker for all protocols
This commit is contained in:
parent
9b41ed66bb
commit
4b86425992
7 changed files with 45 additions and 16 deletions
|
|
@ -50,14 +50,7 @@ LocalSocketController::LocalSocketController() {
|
||||||
connect(&m_initializingTimer, &QTimer::timeout, this,
|
connect(&m_initializingTimer, &QTimer::timeout, this,
|
||||||
&LocalSocketController::initializeInternal);
|
&LocalSocketController::initializeInternal);
|
||||||
|
|
||||||
connect(IpcClient::Interface().data(), &IpcInterfaceReplica::connectionLose,
|
|
||||||
this, [this]() {
|
|
||||||
logger.debug() << "Connection Lose";
|
|
||||||
auto result = IpcClient::Interface()->stopNetworkCheck();
|
|
||||||
result.waitForFinished(3000);
|
|
||||||
this->deactivate();
|
|
||||||
this->activate(m_RawConfig);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,8 +119,6 @@ void LocalSocketController::daemonConnected() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalSocketController::activate(const QJsonObject &rawConfig) {
|
void LocalSocketController::activate(const QJsonObject &rawConfig) {
|
||||||
m_RawConfig = rawConfig;
|
|
||||||
|
|
||||||
QString protocolName = rawConfig.value("protocol").toString();
|
QString protocolName = rawConfig.value("protocol").toString();
|
||||||
|
|
||||||
int splitTunnelType = rawConfig.value("splitTunnelType").toInt();
|
int splitTunnelType = rawConfig.value("splitTunnelType").toInt();
|
||||||
|
|
@ -143,6 +134,7 @@ void LocalSocketController::activate(const QJsonObject &rawConfig) {
|
||||||
// json.insert("hopindex", QJsonValue((double)hop.m_hopindex));
|
// json.insert("hopindex", QJsonValue((double)hop.m_hopindex));
|
||||||
json.insert("privateKey", wgConfig.value(amnezia::config_key::client_priv_key));
|
json.insert("privateKey", wgConfig.value(amnezia::config_key::client_priv_key));
|
||||||
json.insert("deviceIpv4Address", wgConfig.value(amnezia::config_key::client_ip));
|
json.insert("deviceIpv4Address", wgConfig.value(amnezia::config_key::client_ip));
|
||||||
|
m_deviceIpv4 = wgConfig.value(amnezia::config_key::client_ip).toString();
|
||||||
|
|
||||||
// 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
|
// this will be default IPv6 gateway, OS recognizes that IPv6 link
|
||||||
|
|
@ -435,9 +427,6 @@ void LocalSocketController::parseCommand(const QByteArray& command) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IpcClient::Interface()->startNetworkCheck(serverIpv4Gateway.toString(),
|
|
||||||
deviceIpv4Address.toString());
|
|
||||||
|
|
||||||
QJsonValue txBytes = obj.value("txBytes");
|
QJsonValue txBytes = obj.value("txBytes");
|
||||||
if (!txBytes.isDouble()) {
|
if (!txBytes.isDouble()) {
|
||||||
logger.error() << "Unexpected txBytes value";
|
logger.error() << "Unexpected txBytes value";
|
||||||
|
|
@ -470,8 +459,14 @@ void LocalSocketController::parseCommand(const QByteArray& command) {
|
||||||
|
|
||||||
logger.debug() << "Handshake completed with:"
|
logger.debug() << "Handshake completed with:"
|
||||||
<< pubkey.toString();
|
<< pubkey.toString();
|
||||||
emit connected(pubkey.toString());
|
|
||||||
checkStatus();
|
checkStatus();
|
||||||
|
|
||||||
|
emit statusUpdated("",
|
||||||
|
m_deviceIpv4, 0,
|
||||||
|
0);
|
||||||
|
|
||||||
|
emit connected(pubkey.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,10 +60,9 @@ class LocalSocketController final : public ControllerImpl {
|
||||||
|
|
||||||
QByteArray m_buffer;
|
QByteArray m_buffer;
|
||||||
|
|
||||||
|
QString m_deviceIpv4;
|
||||||
std::function<void(const QString&)> m_logCallback = nullptr;
|
std::function<void(const QString&)> m_logCallback = nullptr;
|
||||||
|
|
||||||
QJsonObject m_RawConfig;
|
|
||||||
|
|
||||||
QTimer m_initializingTimer;
|
QTimer m_initializingTimer;
|
||||||
uint32_t m_initializingRetry = 0;
|
uint32_t m_initializingRetry = 0;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,11 @@ QString VpnProtocol::vpnGateway() const
|
||||||
return m_vpnGateway;
|
return m_vpnGateway;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString VpnProtocol::vpnLocalAddress() const
|
||||||
|
{
|
||||||
|
return m_vpnLocalAddress;
|
||||||
|
}
|
||||||
|
|
||||||
VpnProtocol *VpnProtocol::factory(DockerContainer container, const QJsonObject &configuration)
|
VpnProtocol *VpnProtocol::factory(DockerContainer container, const QJsonObject &configuration)
|
||||||
{
|
{
|
||||||
switch (container) {
|
switch (container) {
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ public:
|
||||||
|
|
||||||
QString routeGateway() const;
|
QString routeGateway() const;
|
||||||
QString vpnGateway() const;
|
QString vpnGateway() const;
|
||||||
|
QString vpnLocalAddress() const;
|
||||||
|
|
||||||
static VpnProtocol* factory(amnezia::DockerContainer container, const QJsonObject &configuration);
|
static VpnProtocol* factory(amnezia::DockerContainer container, const QJsonObject &configuration);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,13 @@ WireguardProtocol::WireguardProtocol(const QJsonObject &configuration, QObject *
|
||||||
[this](const QString &pubkey, const QDateTime &connectionTimestamp) {
|
[this](const QString &pubkey, const QDateTime &connectionTimestamp) {
|
||||||
emit connectionStateChanged(Vpn::ConnectionState::Connected);
|
emit connectionStateChanged(Vpn::ConnectionState::Connected);
|
||||||
});
|
});
|
||||||
|
connect(m_impl.get(), &ControllerImpl::statusUpdated, this,
|
||||||
|
[this](const QString& serverIpv4Gateway,
|
||||||
|
const QString& deviceIpv4Address, uint64_t txBytes,
|
||||||
|
uint64_t rxBytes) {
|
||||||
|
m_vpnLocalAddress = deviceIpv4Address;
|
||||||
|
});
|
||||||
|
|
||||||
connect(m_impl.get(), &ControllerImpl::disconnected, this,
|
connect(m_impl.get(), &ControllerImpl::disconnected, this,
|
||||||
[this]() { emit connectionStateChanged(Vpn::ConnectionState::Disconnected); });
|
[this]() { emit connectionStateChanged(Vpn::ConnectionState::Disconnected); });
|
||||||
m_impl->initialize(nullptr, nullptr);
|
m_impl->initialize(nullptr, nullptr);
|
||||||
|
|
|
||||||
|
|
@ -86,8 +86,13 @@ void VpnConnection::onConnectionStateChanged(Vpn::ConnectionState state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (container != DockerContainer::Ipsec) {
|
||||||
|
IpcClient::Interface()->startNetworkCheck(remoteAddress(), m_vpnProtocol->vpnLocalAddress());
|
||||||
|
}
|
||||||
|
|
||||||
} else if (state == Vpn::ConnectionState::Error) {
|
} else if (state == Vpn::ConnectionState::Error) {
|
||||||
IpcClient::Interface()->flushDns();
|
IpcClient::Interface()->flushDns();
|
||||||
|
IpcClient::Interface()->stopNetworkCheck();
|
||||||
|
|
||||||
if (m_settings->isSitesSplitTunnelingEnabled()) {
|
if (m_settings->isSitesSplitTunnelingEnabled()) {
|
||||||
if (m_settings->routeMode() == Settings::VpnOnlyForwardSites) {
|
if (m_settings->routeMode() == Settings::VpnOnlyForwardSites) {
|
||||||
|
|
@ -97,6 +102,7 @@ void VpnConnection::onConnectionStateChanged(Vpn::ConnectionState state)
|
||||||
} else if (state == Vpn::ConnectionState::Connecting) {
|
} else if (state == Vpn::ConnectionState::Connecting) {
|
||||||
|
|
||||||
} else if (state == Vpn::ConnectionState::Disconnected) {
|
} else if (state == Vpn::ConnectionState::Disconnected) {
|
||||||
|
IpcClient::Interface()->stopNetworkCheck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -237,6 +243,9 @@ void VpnConnection::connectToVpn(int serverIndex, const ServerCredentials &crede
|
||||||
emit connectionStateChanged(Vpn::ConnectionState::Connecting);
|
emit connectionStateChanged(Vpn::ConnectionState::Connecting);
|
||||||
|
|
||||||
m_vpnConfiguration = vpnConfiguration;
|
m_vpnConfiguration = vpnConfiguration;
|
||||||
|
m_serverIndex = serverIndex;
|
||||||
|
m_serverCredentials = credentials;
|
||||||
|
m_dockerContainer = container;
|
||||||
|
|
||||||
#ifdef AMNEZIA_DESKTOP
|
#ifdef AMNEZIA_DESKTOP
|
||||||
if (m_vpnProtocol) {
|
if (m_vpnProtocol) {
|
||||||
|
|
@ -281,6 +290,15 @@ void VpnConnection::createProtocolConnections()
|
||||||
connect(m_vpnProtocol.data(), SIGNAL(connectionStateChanged(Vpn::ConnectionState)), this,
|
connect(m_vpnProtocol.data(), SIGNAL(connectionStateChanged(Vpn::ConnectionState)), this,
|
||||||
SLOT(onConnectionStateChanged(Vpn::ConnectionState)));
|
SLOT(onConnectionStateChanged(Vpn::ConnectionState)));
|
||||||
connect(m_vpnProtocol.data(), SIGNAL(bytesChanged(quint64, quint64)), this, SLOT(onBytesChanged(quint64, quint64)));
|
connect(m_vpnProtocol.data(), SIGNAL(bytesChanged(quint64, quint64)), this, SLOT(onBytesChanged(quint64, quint64)));
|
||||||
|
|
||||||
|
connect(IpcClient::Interface().data(), &IpcInterfaceReplica::connectionLose,
|
||||||
|
this, [this]() {
|
||||||
|
qDebug() << "Connection Lose";
|
||||||
|
auto result = IpcClient::Interface()->stopNetworkCheck();
|
||||||
|
result.waitForFinished(3000);
|
||||||
|
this->disconnectFromVpn();
|
||||||
|
this->connectToVpn(m_serverIndex, m_serverCredentials, m_dockerContainer, m_vpnConfiguration);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void VpnConnection::appendKillSwitchConfig()
|
void VpnConnection::appendKillSwitchConfig()
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,10 @@ private:
|
||||||
QJsonObject m_routeMode;
|
QJsonObject m_routeMode;
|
||||||
QString m_remoteAddress;
|
QString m_remoteAddress;
|
||||||
|
|
||||||
|
ServerCredentials m_serverCredentials;
|
||||||
|
int m_serverIndex;
|
||||||
|
DockerContainer m_dockerContainer;
|
||||||
|
|
||||||
// Only for iOS for now, check counters
|
// Only for iOS for now, check counters
|
||||||
QTimer m_checkTimer;
|
QTimer m_checkTimer;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue