aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <0xdec05eba@gmail.com>2018-05-01 14:57:29 +0200
committerdec05eba <0xdec05eba@gmail.com>2018-05-01 14:57:32 +0200
commitb0cc417bc9289fdd5c98028136e37c6a6ee62944 (patch)
treebb1646b4436d56bc10e103af0c03e157670f32fd /src
parent8da5ba7f057978b224868028679cbda9e11089ab (diff)
Update ntp dependency with bug fix, make error messages better
Diffstat (limited to 'src')
-rw-r--r--src/Database.cpp26
-rw-r--r--src/DatabaseStorage.cpp8
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);