aboutsummaryrefslogtreecommitdiff
path: root/include/DatabaseStorage.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-02-13 00:46:46 +0100
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:12 +0200
commit00a2777fc154537fe9fc9cfac082a29f70bf6b75 (patch)
tree8c8a1489afe9d430cfdb1a19c63341d320f7543e /include/DatabaseStorage.hpp
parenta9a7ecaa25e6bc11062e21affd458e2de78747ff (diff)
Add database storage (in memory), need to store it on disk later
Diffstat (limited to 'include/DatabaseStorage.hpp')
-rw-r--r--include/DatabaseStorage.hpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/include/DatabaseStorage.hpp b/include/DatabaseStorage.hpp
index fee6b72..863c5d9 100644
--- a/include/DatabaseStorage.hpp
+++ b/include/DatabaseStorage.hpp
@@ -1,10 +1,58 @@
#pragma once
+#include "Key.hpp"
+#include "DataView.hpp"
+#include "Signature.hpp"
+#include <vector>
+#include <stdexcept>
+
namespace odhtdb
{
+ class Group;
+
+ struct DatabaseStorageObject
+ {
+ DataView data;
+ u64 timestamp; // In microseconds
+ Signature::PublicKey creatorPublicKey;
+
+ DatabaseStorageObject(DataView &_data, u64 _timestamp, const Signature::PublicKey &_creatorPublicKey) :
+ data(_data), timestamp(_timestamp), creatorPublicKey(_creatorPublicKey)
+ {
+
+ }
+ };
+
+ struct DatabaseStorageObjectList
+ {
+ u64 timestamp; // In microseconds
+ std::vector<Group*> groups;
+ std::vector<DatabaseStorageObject> objects;
+ };
+
+ 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 = KeyMap<DatabaseStorageObjectList*>;
+
class DatabaseStorage
{
public:
+ // Throws DatabaseStorageAlreadyExists if data with key already exists
+ void createStorage(const Key &key, std::vector<Group*> &&groups, u64 timestamp);
+ // Throws DatabaseStorageNotFound if data with key does not exist
+ void appendStorage(const Key &key, DataView &data, u64 timestamp, const Signature::PublicKey &creatorPublicKey);
+ private:
+ DatabaseStorageMap storageMap;
};
}