diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Database.cpp | 26 | ||||
-rw-r--r-- | src/DatabaseStorage.cpp | 8 |
2 files changed, 30 insertions, 4 deletions
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<u64>(); - 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<u64>(); - 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<DatabaseOperation>(); #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); } diff --git a/src/DatabaseStorage.cpp b/src/DatabaseStorage.cpp index 233f7c6..9c64a86 100644 --- a/src/DatabaseStorage.cpp +++ b/src/DatabaseStorage.cpp @@ -822,6 +822,14 @@ namespace odhtdb return localUsers; } + DatabaseStorageObject* DatabaseStorage::getDataById(const Hash &dataHash) + { + auto storageIt = storedDataHash.find(dataHash); + if(storageIt != storedDataHash.end()) + return storageIt->second; + return nullptr; + } + std::pair<bool, std::shared_ptr<OwnedMemory>> DatabaseStorage::getNodeDecryptionKey(const Hash &nodeHash) { auto nodeDecryptionKeyIt = nodeDecryptionKeyMap.find(nodeHash); |