From b0cc417bc9289fdd5c98028136e37c6a6ee62944 Mon Sep 17 00:00:00 2001 From: dec05eba <0xdec05eba@gmail.com> Date: Tue, 1 May 2018 14:57:29 +0200 Subject: Update ntp dependency with bug fix, make error messages better --- src/Database.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/Database.cpp') diff --git a/src/Database.cpp b/src/Database.cpp index 8cca298..85e56d3 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -521,8 +521,16 @@ namespace odhtdb } u64 creationDate = deserializer.extract(); - if(creationDate > getSyncedTimestampUtc().getCombined()) - throw sibs::DeserializeException("Packet is from the future"); + auto currentTimestamp = getSyncedTimestampUtc(); + if(creationDate > currentTimestamp.getCombined()) + { + auto creationDateTimestamp = ntp::NtpTimestamp::fromCombined(creationDate); + string errMsg = "Packet is from the future. Packet creation time: "; + errMsg += to_string((double)creationDateTimestamp.seconds + creationDateTimestamp.getFractionAsSeconds()); + errMsg += ", current time: "; + errMsg += to_string((double)currentTimestamp.seconds + currentTimestamp.getFractionAsSeconds()); + throw sibs::DeserializeException(errMsg); + } char creatorPublicKeyRaw[PUBLIC_KEY_NUM_BYTES]; deserializer.extract((u8*)creatorPublicKeyRaw, PUBLIC_KEY_NUM_BYTES); @@ -562,8 +570,16 @@ namespace odhtdb } u64 creationDate = deserializerUnsigned.extract(); - if(creationDate > getSyncedTimestampUtc().getCombined()) - throw sibs::DeserializeException("Packet is from the future"); + auto currentTimestamp = getSyncedTimestampUtc(); + if(creationDate > currentTimestamp.getCombined()) + { + auto creationDateTimestamp = ntp::NtpTimestamp::fromCombined(creationDate); + string errMsg = "Packet is from the future. Packet creation time: "; + errMsg += to_string((double)creationDateTimestamp.seconds + creationDateTimestamp.getFractionAsSeconds()); + errMsg += ", current time: "; + errMsg += to_string((double)currentTimestamp.seconds + currentTimestamp.getFractionAsSeconds()); + throw sibs::DeserializeException(errMsg); + } DatabaseOperation operation = deserializerUnsigned.extract(); #if 0 @@ -691,6 +707,8 @@ namespace odhtdb Log::debug("Got add data"); try { + if(databaseStorage.getDataById(requestDataHash)) + throw DatabaseStorageAlreadyExists("Add data request hash is equal to hash already in storage (duplicate data?)"); deserializeAddRequest(value, requestDataHash, nodeHash, encryptionKey); //Log::debug("Got add object, timestamp: %zu", addObject.timestamp); } -- cgit v1.2.3