diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index 4aace2e9c..90c05fefe 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -53,7 +53,6 @@ AccountState::AccountState(AccountPtr account) this, &AccountState::slotCredentialsFetched); connect(account.data(), &Account::credentialsAsked, this, &AccountState::slotCredentialsAsked); - _timeSinceLastETagCheck.invalidate(); connect(this, &AccountState::isConnectedChanged, [=]{ // Get the Apps available on the server if we're now connected. @@ -181,9 +180,9 @@ bool AccountState::isConnected() const return _state == Connected; } -void AccountState::tagLastSuccessfullETagRequest() +void AccountState::tagLastSuccessfullETagRequest(const QDateTime &tp) { - _timeSinceLastETagCheck.start(); + _timeOfLastETagCheck = tp; } QByteArray AccountState::notificationsEtagResponseHeader() const @@ -227,12 +226,11 @@ void AccountState::checkConnectivity() // IF the account is connected the connection check can be skipped // if the last successful etag check job is not so long ago. - ConfigFile cfg; - std::chrono::milliseconds polltime = cfg.remotePollInterval(); - - if (isConnected() && _timeSinceLastETagCheck.isValid() - && !_timeSinceLastETagCheck.hasExpired(polltime.count())) { - qCDebug(lcAccountState) << account()->displayName() << "The last ETag check succeeded within the last " << polltime.count() / 1000 << " secs. No connection check needed!"; + const auto polltime = std::chrono::duration_cast(ConfigFile().remotePollInterval()); + const auto elapsed = _timeOfLastETagCheck.secsTo(QDateTime::currentDateTimeUtc()); + if (isConnected() && _timeOfLastETagCheck.isValid() + && elapsed <= polltime.count()) { + qCDebug(lcAccountState) << account()->displayName() << "The last ETag check succeeded within the last " << polltime.count() << "s (" << elapsed << "s). No connection check needed!"; return; } diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h index d4b158b65..4c6bba62d 100644 --- a/src/gui/accountstate.h +++ b/src/gui/accountstate.h @@ -136,7 +136,7 @@ public: * the server to validate the connection if the last successful etag job * was not so long ago. */ - void tagLastSuccessfullETagRequest(); + void tagLastSuccessfullETagRequest(const QDateTime &tp); /** Saves the ETag Response header from the last Notifications api * request with statusCode 200. @@ -195,7 +195,7 @@ private: ConnectionStatus _connectionStatus; QStringList _connectionErrors; bool _waitingForNewCredentials; - QElapsedTimer _timeSinceLastETagCheck; + QDateTime _timeOfLastETagCheck; QPointer _connectionValidator; QByteArray _notificationsEtagResponseHeader; QByteArray _navigationAppsEtagResponseHeader; diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index c542de947..7aef17696 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -343,7 +343,7 @@ void Folder::slotRunEtagJob() // The _requestEtagJob is auto deleting itself on finish. Our guard pointer _requestEtagJob will then be null. } -void Folder::etagRetrieved(const QString &etag) +void Folder::etagRetrieved(const QString &etag, const QDateTime &tp) { // re-enable sync if it was disabled because network was down FolderMan::instance()->setSyncEnabled(true); @@ -354,13 +354,13 @@ void Folder::etagRetrieved(const QString &etag) slotScheduleThisFolder(); } - _accountState->tagLastSuccessfullETagRequest(); + _accountState->tagLastSuccessfullETagRequest(tp); } -void Folder::etagRetrievedFromSyncEngine(const QString &etag) +void Folder::etagRetrievedFromSyncEngine(const QString &etag, const QDateTime &time) { qCInfo(lcFolder) << "Root etag from during sync:" << etag; - accountState()->tagLastSuccessfullETagRequest(); + accountState()->tagLastSuccessfullETagRequest(time); _lastEtag = etag; } diff --git a/src/gui/folder.h b/src/gui/folder.h index 91e4ce8d4..5150d3ac0 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -372,8 +372,8 @@ private slots: void slotItemCompleted(const SyncFileItemPtr &); void slotRunEtagJob(); - void etagRetrieved(const QString &); - void etagRetrievedFromSyncEngine(const QString &); + void etagRetrieved(const QString &, const QDateTime &tp); + void etagRetrievedFromSyncEngine(const QString &, const QDateTime &time); void slotEmitFinishedDelayed(); diff --git a/src/libsync/abstractnetworkjob.cpp b/src/libsync/abstractnetworkjob.cpp index 7482d7b46..be9c01c93 100644 --- a/src/libsync/abstractnetworkjob.cpp +++ b/src/libsync/abstractnetworkjob.cpp @@ -282,6 +282,7 @@ void AbstractNetworkJob::slotFinished() QByteArray AbstractNetworkJob::responseTimestamp() { + ASSERT(!_responseTimestamp.isEmpty()); return _responseTimestamp; } diff --git a/src/libsync/discovery.h b/src/libsync/discovery.h index a45050827..2d036b9a9 100644 --- a/src/libsync/discovery.h +++ b/src/libsync/discovery.h @@ -277,6 +277,6 @@ private: signals: void finished(); // The root etag of this directory was fetched - void etag(const QString &); + void etag(const QString &, const QDateTime &time); }; } diff --git a/src/libsync/discoveryphase.cpp b/src/libsync/discoveryphase.cpp index d79497df9..bbe6280f3 100644 --- a/src/libsync/discoveryphase.cpp +++ b/src/libsync/discoveryphase.cpp @@ -499,10 +499,11 @@ void DiscoverySingleDirectoryJob::lsJobFinishedWithoutErrorSlot() deleteLater(); return; } else if (_isE2eEncrypted) { + emit etag(_firstEtag, QDateTime::fromString(QString::fromUtf8(_lsColJob->responseTimestamp()), Qt::RFC2822Date)); fetchE2eMetadata(); return; } - emit etag(_firstEtag); + emit etag(_firstEtag, QDateTime::fromString(QString::fromUtf8(_lsColJob->responseTimestamp()), Qt::RFC2822Date)); emit finished(_results); deleteLater(); } @@ -561,7 +562,6 @@ void DiscoverySingleDirectoryJob::metadataReceived(const QJsonDocument &json, in return result; }); - emit etag(_firstEtag); emit finished(_results); deleteLater(); } @@ -569,7 +569,6 @@ void DiscoverySingleDirectoryJob::metadataReceived(const QJsonDocument &json, in void DiscoverySingleDirectoryJob::metadataError(const QByteArray &fileId, int httpReturnCode) { qCWarning(lcDiscovery) << "E2EE Metadata job error. Trying to proceed without it." << fileId << httpReturnCode; - emit etag(_firstEtag); emit finished(_results); deleteLater(); } diff --git a/src/libsync/discoveryphase.h b/src/libsync/discoveryphase.h index 748d57537..20aab7311 100644 --- a/src/libsync/discoveryphase.h +++ b/src/libsync/discoveryphase.h @@ -126,7 +126,7 @@ public: // This is not actually a network job, it is just a job signals: void firstDirectoryPermissions(RemotePermissions); - void etag(const QString &); + void etag(const QString &, const QDateTime &time); void finished(const HttpResult> &result); private slots: diff --git a/src/libsync/networkjobs.cpp b/src/libsync/networkjobs.cpp index ee47446a2..d70d28a44 100644 --- a/src/libsync/networkjobs.cpp +++ b/src/libsync/networkjobs.cpp @@ -129,7 +129,7 @@ bool RequestEtagJob::finished() } } } - emit etagRetrieved(etag); + emit etagRetrieved(etag, QDateTime::fromString(QString::fromUtf8(_responseTimestamp), Qt::RFC2822Date)); emit finishedWithResult(etag); } else { emit finishedWithResult(HttpError{ httpCode, errorString() }); diff --git a/src/libsync/networkjobs.h b/src/libsync/networkjobs.h index 82e56fa0a..03635a964 100644 --- a/src/libsync/networkjobs.h +++ b/src/libsync/networkjobs.h @@ -348,7 +348,7 @@ public: void start() override; signals: - void etagRetrieved(const QString &etag); + void etagRetrieved(const QString &etag, const QDateTime &time); void finishedWithResult(const HttpResult &etag); private slots: diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index e058e2693..834bfe74d 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -607,12 +607,12 @@ void SyncEngine::slotFolderDiscovered(bool local, const QString &folder) emit transmissionProgress(*_progressInfo); } -void SyncEngine::slotRootEtagReceived(const QString &e) +void SyncEngine::slotRootEtagReceived(const QString &e, const QDateTime &time) { if (_remoteRootEtag.isEmpty()) { qCDebug(lcEngine) << "Root etag:" << e; _remoteRootEtag = e; - emit rootEtag(_remoteRootEtag); + emit rootEtag(_remoteRootEtag, time); } } diff --git a/src/libsync/syncengine.h b/src/libsync/syncengine.h index 783ff060b..70f3db888 100644 --- a/src/libsync/syncengine.h +++ b/src/libsync/syncengine.h @@ -138,7 +138,7 @@ public: signals: // During update, before reconcile - void rootEtag(QString); + void rootEtag(const QString &, const QDateTime &); // after the above signals. with the items that actually need propagating void aboutToPropagate(SyncFileItemVector &); @@ -172,7 +172,7 @@ signals: private slots: void slotFolderDiscovered(bool local, const QString &folder); - void slotRootEtagReceived(const QString &); + void slotRootEtagReceived(const QString &, const QDateTime &time); /** When the discovery phase discovers an item */ void slotItemDiscovered(const SyncFileItemPtr &item);