aboutsummaryrefslogtreecommitdiff
path: root/src/Database.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-01 14:57:29 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commit9197a6118d810356263e92cbb48c406f8e3d3a05 (patch)
tree394460d2e84cd4972af745aecf110228168427d1 /src/Database.cpp
parent98544090819faf40ff56eca83cd24bad3d386caa (diff)
Update ntp dependency with bug fix, make error messages better
Diffstat (limited to 'src/Database.cpp')
-rw-r--r--src/Database.cpp26
1 files changed, 22 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);
}