diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-03-13 06:26:06 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:25:46 +0200 |
commit | 5a8727e34b938b70623ca865273fd81c7604b461 (patch) | |
tree | a2921e90aa454072dc58fced36b508f67f5d1226 /include/Database.hpp | |
parent | 9ffc25c9d99fe86d4789108d1d8615ecb0388cc6 (diff) |
Expose include dir
Diffstat (limited to 'include/Database.hpp')
-rw-r--r-- | include/Database.hpp | 153 |
1 files changed, 0 insertions, 153 deletions
diff --git a/include/Database.hpp b/include/Database.hpp deleted file mode 100644 index 6bc7bc5..0000000 --- a/include/Database.hpp +++ /dev/null @@ -1,153 +0,0 @@ -#pragma once - -#include "types.hpp" -#include "Key.hpp" -#include "DataView.hpp" -#include "DatabaseStorage.hpp" -#include "Hash.hpp" -#include "utils.hpp" -#include "StagedObject.hpp" -#include "Signature.hpp" -#include "Permission.hpp" -#include "DatabaseNode.hpp" -#include <opendht/dhtrunner.h> -#include <vector> -#include <ntp/NtpClient.hpp> -#include <boost/filesystem/path.hpp> -#include <stdexcept> - -namespace odhtdb -{ - class User; - class LocalUser; - class Group; - - class CommitCreateException : public std::runtime_error - { - public: - CommitCreateException(const std::string &errMsg) : std::runtime_error(errMsg) {} - }; - - class CommitAddException : public std::runtime_error - { - public: - CommitAddException(const std::string &errMsg) : std::runtime_error(errMsg) {} - }; - - class DatabaseCreateException : public std::runtime_error - { - public: - DatabaseCreateException(const std::string &errMsg) : std::runtime_error(errMsg) {} - }; - - class DatabaseAddException : public std::runtime_error - { - public: - DatabaseAddException(const std::string &errMsg) : std::runtime_error(errMsg) {} - }; - - enum class DatabaseOperation : u8 - { - ADD_DATA, - ADD_USER - }; - - struct DatabaseCreateRequest - { - DISABLE_COPY(DatabaseCreateRequest) - - u64 timestamp; // In microseconds - Group *creatorGroup; - std::string name; - - DatabaseCreateRequest(u64 _timestamp, Group *_creatorGroup, std::string &&_name) : - timestamp(_timestamp), - creatorGroup(_creatorGroup), - 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 - { - DISABLE_COPY(DatabaseAddRequest) - - u64 timestamp; // In microseconds - const User *creatorUser; - Decryption decryptedData; - - DatabaseAddRequest(u64 _timestamp, const User *_creatorUser, Decryption &&_decryptedData) : - timestamp(_timestamp), - creatorUser(_creatorUser), - decryptedData(std::move(_decryptedData)) - { - - } - - DatabaseAddRequest(DatabaseAddRequest &&other) - { - timestamp = other.timestamp; - creatorUser = other.creatorUser; - decryptedData = std::move(other.decryptedData); - - other.timestamp = 0; - other.creatorUser = nullptr; - } - }; - - class DatabaseCreateResponse - { - public: - 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; - }; - - class Database - { - public: - Database(const char *bootstrapNodeAddr, u16 port, boost::filesystem::path storageDir); - ~Database(); - - void seed(const std::shared_ptr<Hash> hash, const std::shared_ptr<char*> encryptionKey); - // Throws DatabaseCreateException on failure. - std::unique_ptr<DatabaseCreateResponse> create(const std::string &ownerName, const std::string &nodeName); - // Throws DatabaseAddException on failure - void addData(const DatabaseNode &nodeInfo, LocalUser *userToPerformActionWith, DataView dataToAdd); - // 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(); - 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 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); - private: - dht::DhtRunner node; - std::vector<std::unique_ptr<StagedObject>> stagedCreateObjects; - std::vector<std::unique_ptr<StagedObject>> stagedAddObjects; - DatabaseStorage databaseStorage; - }; -} |