blob: 6f251d14fb53160745b95bd7155987bb199dc251 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#pragma once
#include "Hash.hpp"
#include "DataView.hpp"
#include "Signature.hpp"
#include "Encryption.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;
u8 *createData;
usize createDataSize;
};
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 = MapHashKey<DatabaseStorageObjectList*>;
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 hash does not exist
void appendStorage(const Hash &hash, DataView &data, u64 timestamp, const Signature::PublicKey &creatorPublicKey);
// Returns nullptr if not storage with provided hash exists
const DatabaseStorageObjectList* getStorage(const Hash &hash) const;
private:
DatabaseStorageMap storageMap;
};
}
|