aboutsummaryrefslogtreecommitdiff
path: root/include/Database.hpp
blob: bfc30215fedcb16fa60f015b0664043ddf70b5af (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
#pragma once

#include "types.hpp"
#include "Key.hpp"
#include "StagedObject.hpp"
#include "DataView.hpp"
#include <opendht/dhtrunner.h>
#include <vector>
#include <ntp/NtpClient.hpp>
#include <boost/filesystem/path.hpp>

namespace odhtdb
{
    class Group;

    class Database
    {
    public:
        Database(const char *bootstrapNodeAddr, u16 port, boost::filesystem::path storageDir);
        ~Database();

        void seed();
        void create(const Key &key, Group *primaryAdminGroup);
        void add(const Key &key, DataView data);
        void commit();
    private:
        void commitStagedCreateObject(const StagedCreateObject &stagedObject);
        void commitStagedAddObject(const StagedAddObject &stagedObject);
        ntp::NtpTimestamp getSyncedTimestampUtc() const;
        StagedCreateObject deserializeCreateRequest(const std::shared_ptr<dht::Value> &value);
        StagedAddObject deserializeAddRequest(const std::shared_ptr<dht::Value> &value);
        bool listenCreateData(std::shared_ptr<dht::Value> value);
        bool listenAddData(std::shared_ptr<dht::Value> value);
    private:
        dht::DhtRunner node;
        std::vector<StagedCreateObject> stagedCreateObjects;
        std::vector<StagedAddObject> stagedAddObjects;
    };
}