aboutsummaryrefslogtreecommitdiff
path: root/include/DatabaseStorage.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-03-13 06:26:06 +0100
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commit5a8727e34b938b70623ca865273fd81c7604b461 (patch)
treea2921e90aa454072dc58fced36b508f67f5d1226 /include/DatabaseStorage.hpp
parent9ffc25c9d99fe86d4789108d1d8615ecb0388cc6 (diff)
Expose include dir
Diffstat (limited to 'include/DatabaseStorage.hpp')
-rw-r--r--include/DatabaseStorage.hpp95
1 files changed, 0 insertions, 95 deletions
diff --git a/include/DatabaseStorage.hpp b/include/DatabaseStorage.hpp
deleted file mode 100644
index ad4f70b..0000000
--- a/include/DatabaseStorage.hpp
+++ /dev/null
@@ -1,95 +0,0 @@
-#pragma once
-
-#include "types.hpp"
-#include "Hash.hpp"
-#include "DataView.hpp"
-#include "Signature.hpp"
-#include "Encryption.hpp"
-#include <vector>
-#include <stdexcept>
-
-namespace odhtdb
-{
- class Group;
- class User;
-
- struct DatabaseStorageObject
- {
- DataView data;
- u64 createdTimestamp; // In microseconds
- Signature::PublicKey creatorPublicKey;
-
- DatabaseStorageObject(DataView &_data, u64 _timestamp, const Signature::PublicKey &_creatorPublicKey);
- };
-
- struct DatabaseStorageObjectList
- {
- DataView data;
- u64 createdTimestamp; // In microseconds
- std::vector<Group*> groups;
- std::vector<DatabaseStorageObject*> objects;
- };
-
- struct DatabaseStorageQuarantineObject
- {
- DataView data;
- u64 createdTimestamp; // In microseconds
- u64 storedTimestamp; // In microseconds
- Signature::PublicKey creatorPublicKey;
-
- DatabaseStorageQuarantineObject(DataView &_data, u64 _timestamp, const Signature::PublicKey &_creatorPublicKey);
- };
-
- class DatabaseStorageAlreadyExists : public std::runtime_error
- {
- public:
- DatabaseStorageAlreadyExists(const std::string &errMsg) : std::runtime_error(errMsg) {}
- };
-
- class DatabaseStorageNotFound : public std::runtime_error
- {
- public:
- DatabaseStorageNotFound(const std::string &errMsg) : std::runtime_error(errMsg) {}
- };
-
- using DatabaseStorageMap = MapHash<DatabaseStorageObjectList*>;
- using DatabaseStorageQuarantineMap = Signature::MapPublicKey<std::vector<DatabaseStorageQuarantineObject*>>;
-
- class DatabaseStorage
- {
- public:
- // Throws DatabaseStorageAlreadyExists if data with hash already exists
- void createStorage(const Hash &hash, Group *creatorGroup, u64 timestamp, const u8 *data, usize dataSize);
-
- // Throws DatabaseStorageNotFound if data with @nodeHash hash has not been created yet.
- // Throws DatabaseStorageAlreadyExists if same data has been added before (hash of @data, in @dataHash)
- void appendStorage(const Hash &nodeHash, const Hash &dataHash, const User *creatorUser, u64 timestamp, const u8 *data, usize dataSize);
-
- // Throws DatabaseStorageAlreadyExists if same data has been added before (hash of @data, in @dataHash)
- void addToQuarantine(const Hash &dataHash, const Signature::PublicKey &creatorPublicKey, u64 timestamp, const u8 *data, usize dataSize);
-
- void addUser(User *user, const Hash &hash);
-
- // Returns nullptr if no storage with provided hash exists
- const DatabaseStorageObjectList* getStorage(const Hash &hash) const;
-
- // Returns nullptr if no node with the user exists
- const Hash* getNodeByUserPublicKey(const Signature::PublicKey &userPublicKey) const;
-
- // Returns nullptr if no user with public key exists
- const User* getUserByPublicKey(const Signature::PublicKey &userPublicKey) const;
-
- // Returns nullptr if a group with id @groupId doesn't exist
- Group* getGroupById(uint8_t groupId[16]);
-
- // Update storage state (remove quarantine objects if they are too old, etc)
- void update();
- private:
- DatabaseStorageMap storageMap;
- DatabaseStorageQuarantineMap quarantineStorageMap;
- SetHash storedDataHash; // Prevent duplicate data from being added
- Signature::MapPublicKey<Hash*> userPublicKeyNodeMap;
- Signature::MapPublicKey<const User*> publicKeyUserMap;
- DataViewMap<Group*> groupByIdMap;
- };
-}