diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-03-17 14:18:14 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:25:46 +0200 |
commit | 53a1850ce2a253c574113684ac38c8ed31b1d0ae (patch) | |
tree | 00d73cd00217e2c64b08377f146862d644cef55c /include | |
parent | 89d9a70f8bc284970138d0fb824b5fcbf13d0b3c (diff) |
Add callback functions for operations
Diffstat (limited to 'include')
-rw-r--r-- | include/odhtdb/Database.hpp | 75 |
1 files changed, 46 insertions, 29 deletions
diff --git a/include/odhtdb/Database.hpp b/include/odhtdb/Database.hpp index 5114d28..926437a 100644 --- a/include/odhtdb/Database.hpp +++ b/include/odhtdb/Database.hpp @@ -15,6 +15,7 @@ #include <ntp/NtpClient.hpp> #include <boost/filesystem/path.hpp> #include <stdexcept> +#include <functional> namespace odhtdb { @@ -52,57 +53,64 @@ namespace odhtdb ADD_USER }; - struct DatabaseCreateRequest + struct DatabaseCreateNodeRequest { - DISABLE_COPY(DatabaseCreateRequest) + DISABLE_COPY(DatabaseCreateNodeRequest) + const Hash *nodeHash; u64 timestamp; // In microseconds - Group *creatorGroup; + const User *creatorUser; std::string name; - DatabaseCreateRequest(u64 _timestamp, Group *_creatorGroup, std::string &&_name) : + DatabaseCreateNodeRequest(const Hash *_nodeHash, u64 _timestamp, const User *_creatorUser, std::string &&_name) : + nodeHash(_nodeHash), timestamp(_timestamp), - creatorGroup(_creatorGroup), + creatorUser(_creatorUser), name(std::move(_name)) { } - - DatabaseCreateRequest(DatabaseCreateRequest &&other) - { - timestamp = other.timestamp; - creatorGroup = other.creatorGroup; - name = std::move(other.name); - - other.timestamp = 0; - other.creatorGroup = nullptr; - } }; - struct DatabaseAddRequest + struct DatabaseAddNodeRequest { - DISABLE_COPY(DatabaseAddRequest) + DISABLE_COPY(DatabaseAddNodeRequest) + const Hash *nodeHash; + const Hash *requestHash; u64 timestamp; // In microseconds const User *creatorUser; - Decryption decryptedData; + const DataView decryptedData; - DatabaseAddRequest(u64 _timestamp, const User *_creatorUser, Decryption &&_decryptedData) : + DatabaseAddNodeRequest(const Hash *_nodeHash, const Hash *_requestHash, u64 _timestamp, const User *_creatorUser, const DataView &_decryptedData) : + nodeHash(_nodeHash), + requestHash(_requestHash), timestamp(_timestamp), creatorUser(_creatorUser), - decryptedData(std::move(_decryptedData)) + decryptedData(_decryptedData) { } - - DatabaseAddRequest(DatabaseAddRequest &&other) + }; + + struct DatabaseAddUserRequest + { + DISABLE_COPY(DatabaseAddUserRequest) + + const Hash *nodeHash; + const Hash *requestHash; + u64 timestamp; // In microseconds + const User *creatorUser; + const User *userToAdd; + const Group *groupToAddUserTo; + + DatabaseAddUserRequest(const Hash *_nodeHash, const Hash *_requestHash, u64 _timestamp, const User *_creatorUser, const User *_userToAdd, const Group *_groupToAddUserTo) : + timestamp(_timestamp), + creatorUser(_creatorUser), + userToAdd(_userToAdd), + groupToAddUserTo(_groupToAddUserTo) { - timestamp = other.timestamp; - creatorUser = other.creatorUser; - decryptedData = std::move(other.decryptedData); - - other.timestamp = 0; - other.creatorUser = nullptr; + } }; @@ -135,13 +143,19 @@ namespace odhtdb // Throws PermissionDeniedException if user @userToPerformActionWith is not allowed to add user @userToAdd to group @groupToAddUserTo void addUserToGroup(const DatabaseNode &nodeInfo, LocalUser *userToPerformActionWith, const std::string &userToAddName, const Signature::PublicKey &userToAddPublicKey, Group *groupToAddUserTo); void commit(); + + void setOnCreateNodeCallback(std::function<void(const DatabaseCreateNodeRequest&)> callbackFunc); + void setOnAddNodeCallback(std::function<void(const DatabaseAddNodeRequest&)> callbackFunc); + void setOnAddUserCallback(std::function<void(const DatabaseAddUserRequest&)> callbackFunc); + + DatabaseStorage& getStorage(); private: // Throws CommitCreateException on failure void commitStagedCreateObject(const std::unique_ptr<StagedObject> &stagedObject); // Throws CommitAddException on failure void commitStagedAddObject(const std::unique_ptr<StagedObject> &stagedObject); ntp::NtpTimestamp getSyncedTimestampUtc() const; - DatabaseCreateRequest deserializeCreateRequest(const std::shared_ptr<dht::Value> &value, const Hash &hash, const std::shared_ptr<char*> encryptionKey); + void deserializeCreateRequest(const std::shared_ptr<dht::Value> &value, const Hash &hash, const std::shared_ptr<char*> encryptionKey); void deserializeAddRequest(const std::shared_ptr<dht::Value> &value, const Hash &requestDataHash, const std::shared_ptr<char*> encryptionKey); bool listenCreateData(std::shared_ptr<dht::Value> value, const Hash &hash, const std::shared_ptr<char*> encryptionKey); bool listenAddData(std::shared_ptr<dht::Value> value, const Hash &requestDataHash, const std::shared_ptr<char*> encryptionKey); @@ -150,5 +164,8 @@ namespace odhtdb std::vector<std::unique_ptr<StagedObject>> stagedCreateObjects; std::vector<std::unique_ptr<StagedObject>> stagedAddObjects; DatabaseStorage databaseStorage; + std::function<void(const DatabaseCreateNodeRequest&)> onCreateNodeCallbackFunc; + std::function<void(const DatabaseAddNodeRequest&)> onAddNodeCallbackFunc; + std::function<void(const DatabaseAddUserRequest&)> onAddUserCallbackFunc; }; } |