diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-03-13 03:03:11 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:25:46 +0200 |
commit | c7740f0e3cbcd9a7233258f22e6168b1cd8853a8 (patch) | |
tree | 21292e24cb7c534d27d8a0600a033977312cfffc /include/DatabaseStorage.hpp | |
parent | 6099ec04bd0d98b9e75f5b55b1215c94ccf20202 (diff) |
Fix add data operation not working correctly
Reminder: do not get reference to hash map value... duh
Add thread-safe logging (log is in order now!).
Store data immediately to database when WE add it instead of waiting for
response from remote peers.
TODO: Test with multiple peers (not only localhost)
Diffstat (limited to 'include/DatabaseStorage.hpp')
-rw-r--r-- | include/DatabaseStorage.hpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/include/DatabaseStorage.hpp b/include/DatabaseStorage.hpp index ee4d2ad..ad4f70b 100644 --- a/include/DatabaseStorage.hpp +++ b/include/DatabaseStorage.hpp @@ -52,7 +52,7 @@ namespace odhtdb DatabaseStorageNotFound(const std::string &errMsg) : std::runtime_error(errMsg) {} }; - using DatabaseStorageMap = MapHashKey<DatabaseStorageObjectList*>; + using DatabaseStorageMap = MapHash<DatabaseStorageObjectList*>; using DatabaseStorageQuarantineMap = Signature::MapPublicKey<std::vector<DatabaseStorageQuarantineObject*>>; class DatabaseStorage @@ -61,10 +61,12 @@ namespace odhtdb // Throws DatabaseStorageAlreadyExists if data with hash already exists void createStorage(const Hash &hash, Group *creatorGroup, u64 timestamp, const u8 *data, usize dataSize); - // Throws DatabaseStorageNotFound if data with hash does not exist - void appendStorage(const Hash &hash, const User *creatorUser, u64 timestamp, const u8 *data, usize dataSize); + // Throws DatabaseStorageNotFound if data with @nodeHash hash has not been created yet. + // Throws DatabaseStorageAlreadyExists if same data has been added before (hash of @data, in @dataHash) + void appendStorage(const Hash &nodeHash, const Hash &dataHash, const User *creatorUser, u64 timestamp, const u8 *data, usize dataSize); - void addToQuarantine(const Signature::PublicKey &creatorPublicKey, u64 timestamp, const u8 *data, usize dataSize); + // Throws DatabaseStorageAlreadyExists if same data has been added before (hash of @data, in @dataHash) + void addToQuarantine(const Hash &dataHash, const Signature::PublicKey &creatorPublicKey, u64 timestamp, const u8 *data, usize dataSize); void addUser(User *user, const Hash &hash); @@ -85,7 +87,8 @@ namespace odhtdb private: DatabaseStorageMap storageMap; DatabaseStorageQuarantineMap quarantineStorageMap; - Signature::MapPublicKey<Hash> userPublicKeyNodeMap; + SetHash storedDataHash; // Prevent duplicate data from being added + Signature::MapPublicKey<Hash*> userPublicKeyNodeMap; Signature::MapPublicKey<const User*> publicKeyUserMap; DataViewMap<Group*> groupByIdMap; }; |