mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-08 03:35:35 +08:00
Ref T295, fix for the "no network config" issue
* details: https://stackoverflow.com/questions/51686943/no-qnetworkconfiguration-although-i-can-connect-to-wifi * network accessibility check can be disabled if network config looks suspicious * using QNetworkConfigurationManager
This commit is contained in:
@@ -34,16 +34,12 @@ namespace BlackCore
|
||||
|
||||
CNetworkWatchdog::CNetworkWatchdog(bool networkAccessible, QObject *parent) : CContinuousWorker(parent, "swift DB watchdog")
|
||||
{
|
||||
Q_ASSERT_X(sApp, Q_FUNC_INFO, "Need sApp");
|
||||
Q_ASSERT_X(parent, Q_FUNC_INFO, "Need parent (normally sApp)");
|
||||
|
||||
m_networkAccessible = networkAccessible;
|
||||
m_internetAccessible = networkAccessible;
|
||||
m_dbAccessible = networkAccessible && m_checkDbAccessibility;
|
||||
|
||||
if (networkAccessible)
|
||||
{
|
||||
this->initWorkingSharedUrlFromSetup();
|
||||
}
|
||||
|
||||
m_updateTimer.setInterval(10 * 1000);
|
||||
connect(&m_updateTimer, &QTimer::timeout, this, &CNetworkWatchdog::doWork);
|
||||
}
|
||||
@@ -51,7 +47,7 @@ namespace BlackCore
|
||||
void CNetworkWatchdog::setDbAccessibility(bool accessible)
|
||||
{
|
||||
m_dbAccessible = accessible;
|
||||
m_internetAccessible = m_internetAccessible && m_networkAccessible;
|
||||
m_internetAccessible = m_internetAccessible && this->isNetworkkAccessibleOrCheckDisabled();
|
||||
|
||||
// restart timer
|
||||
QPointer<CNetworkWatchdog> myself(this);
|
||||
@@ -64,13 +60,13 @@ namespace BlackCore
|
||||
|
||||
bool CNetworkWatchdog::hasWorkingSharedUrl() const
|
||||
{
|
||||
if (!m_networkAccessible) { return false; }
|
||||
if (!this->isNetworkkAccessibleOrCheckDisabled()) { return false; }
|
||||
return !this->getWorkingSharedUrl().isEmpty();
|
||||
}
|
||||
|
||||
CUrl CNetworkWatchdog::getWorkingSharedUrl() const
|
||||
{
|
||||
if (!m_networkAccessible) { return CUrl(); }
|
||||
if (!this->isNetworkkAccessibleOrCheckDisabled()) { return CUrl(); }
|
||||
QReadLocker l(&m_lockUrl);
|
||||
return m_workingSharedUrl;
|
||||
}
|
||||
@@ -125,11 +121,18 @@ namespace BlackCore
|
||||
if (m_checkInProgress) { return; }
|
||||
m_checkInProgress = true;
|
||||
|
||||
// lazy init
|
||||
if (!this->hasWorkingSharedUrl())
|
||||
{
|
||||
this->initWorkingSharedUrlFromSetup();
|
||||
}
|
||||
|
||||
// checks
|
||||
do
|
||||
{
|
||||
const bool wasDbAvailable = m_dbAccessible;
|
||||
const bool wasInternetAvailable = m_internetAccessible;
|
||||
const bool networkAccessible = m_networkAccessible;
|
||||
const bool networkAccessible = this->isNetworkkAccessibleOrCheckDisabled();
|
||||
const CUrl testUrl(CNetworkWatchdog::dbTestUrl());
|
||||
bool canConnectDb = m_checkDbAccessibility && networkAccessible &&
|
||||
CNetworkUtils::canConnect(testUrl, CanConnectTimeMs); // running here in background worker
|
||||
@@ -260,6 +263,16 @@ namespace BlackCore
|
||||
emit this->changedNetworkAccessible(accessibility);
|
||||
}
|
||||
|
||||
void CNetworkWatchdog::networkConfigurationsUpdateCompleted()
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
void CNetworkWatchdog::setOnline(bool online)
|
||||
{
|
||||
m_online = online;
|
||||
}
|
||||
|
||||
void CNetworkWatchdog::gracefulShutdown()
|
||||
{
|
||||
this->pingDbClientService(CGlobalSetup::PingCompleteShutdown);
|
||||
@@ -276,6 +289,13 @@ namespace BlackCore
|
||||
sApp->getFromNetwork(pingUrl, { this, &CNetworkWatchdog::replyPingClientService });
|
||||
}
|
||||
|
||||
bool CNetworkWatchdog::disableNetworkAccessibilityCheck(bool disable)
|
||||
{
|
||||
if (disable == m_disableNetworkCheck) { return false; }
|
||||
m_disableNetworkCheck = disable;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CNetworkWatchdog::replyPingClientService(QNetworkReply *nwReply)
|
||||
{
|
||||
// init and clean up
|
||||
|
||||
@@ -42,6 +42,13 @@ namespace BlackCore
|
||||
//! \threadsafe
|
||||
void setNetworkAccessibility(QNetworkAccessManager::NetworkAccessibility accessibility);
|
||||
|
||||
//! Configuration updates completed as reported by QNetworkConfigurationManager::updateCompleted
|
||||
void networkConfigurationsUpdateCompleted();
|
||||
|
||||
//! Set online as reported by QNetworkConfigurationManager::onlineStateChanged
|
||||
//! \threadsafe
|
||||
void setOnline(bool online);
|
||||
|
||||
//! DB available?
|
||||
//! \threadsafe
|
||||
bool isSwiftDbAccessible() const { return m_dbAccessible; }
|
||||
@@ -75,6 +82,9 @@ namespace BlackCore
|
||||
//! \threadsafe
|
||||
bool isInternetAccessible() const { return m_internetAccessible; }
|
||||
|
||||
//! Accesible or check disabled?
|
||||
bool isNetworkkAccessibleOrCheckDisabled() const { return m_networkAccessible || m_disableNetworkCheck; }
|
||||
|
||||
//! Has working shared URL?
|
||||
//! \threadsafe
|
||||
bool hasWorkingSharedUrl() const;
|
||||
@@ -111,6 +121,15 @@ namespace BlackCore
|
||||
//! Ping the DB server, fire and forget (no feedback etc)
|
||||
void pingDbClientService(Data::CGlobalSetup::PingType type = Data::CGlobalSetup::PingUnspecific, bool force = false);
|
||||
|
||||
//! Disable the network check
|
||||
//! \remark if disabled network reports always accessible
|
||||
//! \threadsafe
|
||||
bool disableNetworkAccessibilityCheck(bool disable);
|
||||
|
||||
//! Has network check been disabled?
|
||||
//! \threadsafe
|
||||
bool isNetworkAccessibilityCheckDisabled() const { return m_disableNetworkCheck; }
|
||||
|
||||
//! URL referring to the DB
|
||||
//! \remark depends on BlackCore::Application::getGlobalSetup()
|
||||
static bool isDbUrl(const BlackMisc::Network::CUrl &url);
|
||||
@@ -160,6 +179,8 @@ namespace BlackCore
|
||||
std::atomic_bool m_logOwnMessages { true };
|
||||
std::atomic_bool m_doDetailedCheck { true };
|
||||
std::atomic_bool m_networkAccessible { true };
|
||||
std::atomic_bool m_disableNetworkCheck { false }; //!< if this is true, network accessible always reports true/accessible
|
||||
std::atomic_bool m_online { true };
|
||||
std::atomic_bool m_internetAccessible { true };
|
||||
std::atomic_bool m_dbAccessible { true };
|
||||
std::atomic_bool m_lastClientPingSuccess { true };
|
||||
@@ -171,7 +192,7 @@ namespace BlackCore
|
||||
std::atomic_int m_totalBadCountDb { 0 }; //!< Total number of DB failing counts (only real responses when tried)
|
||||
std::atomic_int m_totalBadCountInternet { 0 }; //!< Total number of Internet failing count (only when network is accessible)
|
||||
std::atomic_int m_totalGoodCountDb { 0 };
|
||||
std::atomic_int m_totalGoodCountInternet { 0 };
|
||||
std::atomic_int m_totalGoodCountInternet { 0 };
|
||||
std::atomic_int m_consecutivePingBadCount { 0 }; //!< Bad count of ping until a godd state is received
|
||||
QString m_lastPingUrl;
|
||||
BlackMisc::Network::CUrl m_workingSharedUrl;
|
||||
|
||||
Reference in New Issue
Block a user