aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/odhtdb/DatabaseStorage.hpp4
-rw-r--r--src/Database.cpp6
-rw-r--r--src/DatabaseStorage.cpp26
3 files changed, 36 insertions, 0 deletions
diff --git a/include/odhtdb/DatabaseStorage.hpp b/include/odhtdb/DatabaseStorage.hpp
index 9f1a992..11e243a 100644
--- a/include/odhtdb/DatabaseStorage.hpp
+++ b/include/odhtdb/DatabaseStorage.hpp
@@ -137,6 +137,10 @@ namespace odhtdb
// Return false if user public key already exists, otherwise return true
bool addUser(const Hash &nodeHash, User *user);
+ // Increase user action counter, returning the new value. If user has not performed any action yet, then 0 is returned.
+ // Returns DatabaseStorageException if no node with id @nodeHash exists or if user with public key @userPublicKey doesn't exist in node @nodeHash
+ //u64 increaseUserActionCounter(const Hash &nodeHash, const Signature::PublicKey &userPublicKey);
+
// Returns nullptr if no storage with provided hash exists
const DatabaseStorageObjectList* getStorage(const Hash &hash) const;
diff --git a/src/Database.cpp b/src/Database.cpp
index 85e56d3..ee18b87 100644
--- a/src/Database.cpp
+++ b/src/Database.cpp
@@ -350,6 +350,8 @@ namespace odhtdb
throw PermissionDeniedException(errMsg);
}
+ //u64 actionCounter = databaseStorage.increaseUserActionCounter(userToPerformActionWith->getPublicKey());
+
sibs::SafeSerializer serializer;
serializer.add(DATABASE_ADD_PACKET_STRUCTURE_VERSION);
u64 timestampCombined = getSyncedTimestampUtc().getCombined();
@@ -521,6 +523,7 @@ namespace odhtdb
}
u64 creationDate = deserializer.extract<u64>();
+ /* // TODO: This doesn't seem to work right now, fix it
auto currentTimestamp = getSyncedTimestampUtc();
if(creationDate > currentTimestamp.getCombined())
{
@@ -531,6 +534,7 @@ namespace odhtdb
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);
@@ -571,6 +575,7 @@ namespace odhtdb
u64 creationDate = deserializerUnsigned.extract<u64>();
auto currentTimestamp = getSyncedTimestampUtc();
+ /* // TODO: This doesn't seem to work right now, fix it
if(creationDate > currentTimestamp.getCombined())
{
auto creationDateTimestamp = ntp::NtpTimestamp::fromCombined(creationDate);
@@ -580,6 +585,7 @@ namespace odhtdb
errMsg += to_string((double)currentTimestamp.seconds + currentTimestamp.getFractionAsSeconds());
throw sibs::DeserializeException(errMsg);
}
+ */
DatabaseOperation operation = deserializerUnsigned.extract<DatabaseOperation>();
#if 0
diff --git a/src/DatabaseStorage.cpp b/src/DatabaseStorage.cpp
index 9c64a86..0e7a1a8 100644
--- a/src/DatabaseStorage.cpp
+++ b/src/DatabaseStorage.cpp
@@ -684,6 +684,32 @@ namespace odhtdb
return true;
}
+ /*
+ u64 DatabaseStorage::increaseUserActionCounter(const Hash &nodeHash, const Signature::PublicKey &userPublicKey)
+ {
+ auto publicKeyUserDataMapIt = nodePublicKeyUserDataMap.find(nodeHash);
+ if(publicKeyUserDataMapIt != nodePublicKeyUserDataMap.end())
+ {
+ auto it = publicKeyUserDataMapIt->second->find(userPublicKey);
+ if(it != publicKeyUserDataMapIt->second->end())
+ {
+ return ++it->second->actionCounter;
+ }
+
+ string errMsg = "User with id ";
+ errMsg += userPublicKey.toString();
+ errMsg += " doesn't exist in node ";
+ errMsg += nodeHash.toString();
+ throw DatabaseStorageException(errMsg);
+ }
+
+ string errMsg = "Node with id ";
+ errMsg += nodeHash.toString();
+ errMsg += " doesn't exist";
+ throw DatabaseStorageException(errMsg);
+ }
+ */
+
const DatabaseStorageObjectList* DatabaseStorage::getStorage(const Hash &hash) const
{
auto it = storageMap.find(hash);