add check of time offset

This commit is contained in:
ondra 2020-12-28 11:58:06 +01:00
parent b031741b88
commit 14e0e421ba
2 changed files with 22 additions and 3 deletions

View File

@ -153,7 +153,7 @@ void DatabaseAPI::reupdateDeleted(const QList<QString>& ids)
{
auto query = mDbMan->createQuery();
for (const auto &id : ids){
query.prepare("UPDATE colnod_token SET last_update = CURRENT_TIMESTAMP() WHERE id = :id");
query.prepare("UPDATE colnod_token SET last_update = now() WHERE id = :id");
// query.bindValue(":last_update", QDateTime::fromMSecsSinceEpoch(getNow()).toString("yyyy-MM-dd hh:mm:ss.zzz"));
// QString tempId = "'" + id + "'";
query.bindValue(":id", id);

View File

@ -107,9 +107,11 @@ void SyncManager::init() {
return;
}
Timestamp time;
time.setTimestamp(syncBegin - 100 * 1000);
qint64 offset = 5 * 1000;
time.setTimestamp(syncBegin - offset);
auto tokensRequest = colnod->getTokensUpdated(time);
auto timeCompare = QDateTime::currentDateTime();
// updated data are ready
@ -122,6 +124,23 @@ void SyncManager::init() {
emit end();
return;
}
// check time offset
if (!preparedData->databaseData->updatedTokens.isEmpty() && uploadedData->updatedTokens.isEmpty()) {
qCritical(syncmanager) << "Offset with colnod time is greater than 5 seconds";
emit end();
return;
}
if (!uploadedData->updatedTokens.isEmpty()) {
auto diff = uploadedData->updatedTokens[0]->lastUpdate().secsTo(timeCompare);
if ( diff > 1 || diff < -1) {
qCritical(syncmanager) << "Offset with colnod time is:" << diff << "seconds";
emit end();
return;
}
}
if (!database->uploadTokens(uploadedData->updatedTokens, {"lastModified"})) {
qCritical(syncmanager) << "Not possible to upload data to database";
emit end();
@ -164,7 +183,7 @@ bool SyncManager::startSynchronization()
emit end();
return false;
}
qint64 offset = 75 * 1000;
qint64 offset = 0 * 1000;
qInfo(syncmanager) << tab << "Begin sync ( previous sync" << mlastSync.toDateString() << ")";
colnod->downloadData(mlastSync.timestamp() - offset);