From 1e4dac83952e1f707cdb837f647e6c80c3414154 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 28 Apr 2018 15:30:21 +0200 Subject: Add stop seeding function --- include/odhtdb/Database.hpp | 24 +++++++++++++++++++++++- include/odhtdb/DatabaseStorage.hpp | 9 +++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/odhtdb/Database.hpp b/include/odhtdb/Database.hpp index e78bc6e..ecdf70c 100644 --- a/include/odhtdb/Database.hpp +++ b/include/odhtdb/Database.hpp @@ -125,6 +125,24 @@ namespace odhtdb std::shared_ptr key; std::shared_ptr hash; }; + + struct DatabaseSeedInfo + { + std::shared_ptr> newDataListenerFuture; + std::shared_ptr> responseKeyFuture; + std::shared_ptr> requestOldDataListenerFuture; + + std::shared_ptr reponseKeyInfoHash; + + DatabaseSeedInfo(){} + DatabaseSeedInfo(const DatabaseSeedInfo &other) + { + newDataListenerFuture = other.newDataListenerFuture; + responseKeyFuture = other.responseKeyFuture; + requestOldDataListenerFuture = other.requestOldDataListenerFuture; + reponseKeyInfoHash = other.reponseKeyInfoHash; + } + }; class Database { @@ -133,13 +151,16 @@ namespace odhtdb Database(const char *bootstrapNodeAddr, u16 port, const boost::filesystem::path &storageDir); ~Database(); + // Safe to call multiple times with same node hash, will be ignored if the node is already beeing seeded void seed(const DatabaseNode &nodeToSeed); + void stopSeeding(const Hash &nodeHash); + // Throws DatabaseCreateException on failure. std::unique_ptr create(const std::string &ownerName, const std::string &nodeName); // Throws DatabaseCreateException on failure. std::unique_ptr create(const std::string &ownerName, const Signature::KeyPair &keyPair, const std::string &nodeName); // Throws PermissionDeniedException if user @userToPerformActionWith is not allowed to add data to node - void addData(const DatabaseNode &nodeInfo, LocalUser *userToPerformActionWith, DataView dataToAdd); + void addData(const DatabaseNode &nodeInfo, const LocalUser *userToPerformActionWith, DataView dataToAdd); // Throws PermissionDeniedException if user @userToPerformActionWith is not allowed to add user @userToAdd to group @groupToAddUserTo void addUser(const DatabaseNode &nodeInfo, LocalUser *userToPerformActionWith, const std::string &userToAddName, const Signature::PublicKey &userToAddPublicKey, Group *groupToAddUserTo); void commit(); @@ -167,5 +188,6 @@ namespace odhtdb std::function onCreateNodeCallbackFunc; std::function onAddNodeCallbackFunc; std::function onAddUserCallbackFunc; + MapHash seedInfoMap; }; } diff --git a/include/odhtdb/DatabaseStorage.hpp b/include/odhtdb/DatabaseStorage.hpp index 85a61eb..9cfe12d 100644 --- a/include/odhtdb/DatabaseStorage.hpp +++ b/include/odhtdb/DatabaseStorage.hpp @@ -140,9 +140,15 @@ namespace odhtdb // Returns nullptr if no storage with provided hash exists const DatabaseStorageObjectList* getStorage(const Hash &hash) const; + // Returns nullptr if node @nodeHash doesn't exist + const DataViewMap* getNodeGroups(const Hash &nodeHash); + // Returns nullptr if a group with id @groupId doesn't exist in node @nodeHash or if no node with id @nodeHash exists Group* getGroupById(const Hash &nodeHash, uint8_t groupId[GROUP_ID_LENGTH]) const; + // Returns nullptr if node @nodeHash doesn't exist + const Signature::MapPublicKey* getNodeUsers(const Hash &nodeHash); + // Returns nullptr if a user with public key @publicKey doesn't exist in node @nodeHash or if no node with id @nodeHash exists User* getUserByPublicKey(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const; @@ -159,6 +165,9 @@ namespace odhtdb // Safe to call multiple times. std::vector getLocalNodeUsers(const Signature::KeyPair &keyPair); + // Returns true and node decryption key if node exists and we have the decryption key, + // otherwise return false and OwnedMemory with data set to nullptr + std::pair> getNodeDecryptionKey(const Hash &nodeHash); void setNodeDecryptionKey(const Hash &nodeHash, const DataView &decryptionKey); const dht::crypto::Identity& getIdentity() const; -- cgit v1.2.3