diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-03-09 10:26:55 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:25:46 +0200 |
commit | 0e62cb8e5ed06d906ad84321cdda22acfcc952c9 (patch) | |
tree | 9ba0cc8e20febb4bf07d4d065e3d653ed651bdda /include/Database.hpp | |
parent | eda9a7bbefc5587bf1ff895a9214f450e64575fa (diff) |
Partially implement 'add' operation
Diffstat (limited to 'include/Database.hpp')
-rw-r--r-- | include/Database.hpp | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/include/Database.hpp b/include/Database.hpp index d160133..1024fe0 100644 --- a/include/Database.hpp +++ b/include/Database.hpp @@ -16,6 +16,7 @@ namespace odhtdb { + class User; class LocalUser; class Group; @@ -74,35 +75,39 @@ namespace odhtdb { DISABLE_COPY(DatabaseAddRequest) - u16 packetStructureVersion; u64 timestamp; // In microseconds - Signature::PublicKey creatorPublicKey; - DataView data; + const User *creatorUser; + Decryption decryptedData; - DatabaseAddRequest(u16 _packetStructureVersion, u64 _timestamp, Signature::PublicKey &&_creatorPublicKey, DataView &_data) : - packetStructureVersion(_packetStructureVersion), + DatabaseAddRequest(u64 _timestamp, const User *_creatorUser, Decryption &&_decryptedData) : timestamp(_timestamp), - creatorPublicKey(std::move(_creatorPublicKey)), - data(_data) + creatorUser(_creatorUser), + decryptedData(std::move(_decryptedData)) { } - ~DatabaseAddRequest() + DatabaseAddRequest(DatabaseAddRequest &&other) { - free(data.data); - data = DataView(); + timestamp = other.timestamp; + creatorUser = other.creatorUser; + decryptedData = std::move(other.decryptedData); + + other.timestamp = 0; + other.creatorUser = nullptr; } }; class DatabaseCreateResponse { public: - DatabaseCreateResponse(const std::shared_ptr<char*> &key, const std::shared_ptr<Hash> &hash); + DatabaseCreateResponse(LocalUser *nodeAdminUser, const std::shared_ptr<char*> &key, const std::shared_ptr<Hash> &hash); + const LocalUser* getNodeAdminUser() const; const std::shared_ptr<char*> getNodeEncryptionKey() const; const std::shared_ptr<Hash> getRequestHash() const; private: + LocalUser *nodeAdminUser; std::shared_ptr<char*> key; std::shared_ptr<Hash> hash; }; @@ -115,15 +120,15 @@ namespace odhtdb void seed(const std::shared_ptr<Hash> hash, const std::shared_ptr<char*> encryptionKey); // Throws DatabaseCreateException on failure. - std::unique_ptr<DatabaseCreateResponse> create(const LocalUser *owner, const std::string &name); + std::unique_ptr<DatabaseCreateResponse> create(const std::string &ownerName, const std::string &nodeName); // Throws DatabaseAddException on failure - void add(const LocalUser *owner, const Key &key, DataView data); + void add(const std::unique_ptr<DatabaseCreateResponse> &nodeInfo, DataView dataToAdd); void commit(); private: // Throws CommitCreateException on failure - void commitStagedCreateObject(const std::unique_ptr<StagedCreateObject> &stagedObject); + void commitStagedCreateObject(const std::unique_ptr<StagedObject> &stagedObject); // Throws CommitAddException on failure - void commitStagedAddObject(const DataView &stagedObject); + 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); DatabaseAddRequest deserializeAddRequest(const std::shared_ptr<dht::Value> &value, const Hash &hash, const std::shared_ptr<char*> encryptionKey); @@ -131,8 +136,8 @@ namespace odhtdb bool listenAddData(std::shared_ptr<dht::Value> value, const Hash &hash, const std::shared_ptr<char*> encryptionKey); private: dht::DhtRunner node; - std::vector<std::unique_ptr<StagedCreateObject>> stagedCreateObjects; - std::vector<std::unique_ptr<DataView>> stagedAddObjects; + std::vector<std::unique_ptr<StagedObject>> stagedCreateObjects; + std::vector<std::unique_ptr<StagedObject>> stagedAddObjects; DatabaseStorage databaseStorage; }; } |