diff options
author | dec05eba <0xdec05eba@gmail.com> | 2018-04-28 15:30:21 +0200 |
---|---|---|
committer | dec05eba <0xdec05eba@gmail.com> | 2018-04-28 15:30:26 +0200 |
commit | 97fd90f4c3319e3e789416155c1a462ab179875c (patch) | |
tree | 21891c028cf1e3de584686e534e7274b3f6da6e2 /include | |
parent | 54d8ae4c335c21290dc41e5ba4701b3c19bba601 (diff) |
Add stop seeding function
Diffstat (limited to 'include')
-rw-r--r-- | include/odhtdb/Database.hpp | 24 | ||||
-rw-r--r-- | include/odhtdb/DatabaseStorage.hpp | 9 |
2 files changed, 32 insertions, 1 deletions
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<OwnedMemory> key; std::shared_ptr<Hash> hash; }; + + struct DatabaseSeedInfo + { + std::shared_ptr<std::future<size_t>> newDataListenerFuture; + std::shared_ptr<std::future<size_t>> responseKeyFuture; + std::shared_ptr<std::future<size_t>> requestOldDataListenerFuture; + + std::shared_ptr<dht::InfoHash> 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<DatabaseCreateResponse> create(const std::string &ownerName, const std::string &nodeName); // Throws DatabaseCreateException on failure. std::unique_ptr<DatabaseCreateResponse> 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<void(const DatabaseCreateNodeRequest&)> onCreateNodeCallbackFunc; std::function<void(const DatabaseAddNodeRequest&)> onAddNodeCallbackFunc; std::function<void(const DatabaseAddUserRequest&)> onAddUserCallbackFunc; + MapHash<DatabaseSeedInfo> 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<Group*>* 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<User*>* 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<NodeLocalUser> 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<bool, std::shared_ptr<OwnedMemory>> getNodeDecryptionKey(const Hash &nodeHash); void setNodeDecryptionKey(const Hash &nodeHash, const DataView &decryptionKey); const dht::crypto::Identity& getIdentity() const; |