From 00a2777fc154537fe9fc9cfac082a29f70bf6b75 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 13 Feb 2018 00:46:46 +0100 Subject: Add database storage (in memory), need to store it on disk later --- include/DatabaseStorage.hpp | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'include/DatabaseStorage.hpp') 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 +#include + 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 groups; + std::vector 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; + class DatabaseStorage { public: + // Throws DatabaseStorageAlreadyExists if data with key already exists + void createStorage(const Key &key, std::vector &&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; }; } -- cgit v1.2.3