diff options
author | Aleksi Lindeman <aleksi_888@hotmail.com> | 2018-02-03 19:33:05 +0100 |
---|---|---|
committer | Aleksi Lindeman <aleksi_888@hotmail.com> | 2018-02-03 19:33:11 +0100 |
commit | 28efc0068f47ec787791a07a63d720710068c095 (patch) | |
tree | bb831558de90002c8c774cd58220dbc0baeb7a12 /include | |
parent | 6f1089db78f14b52b869f5aaa979e52ff5e4c2d7 (diff) |
Add seed function, not yet finished
Diffstat (limited to 'include')
-rw-r--r-- | include/Database.hpp | 20 | ||||
-rw-r--r-- | include/Key.hpp | 1 | ||||
-rw-r--r-- | include/StagedObject.hpp | 38 |
3 files changed, 45 insertions, 14 deletions
diff --git a/include/Database.hpp b/include/Database.hpp index 20d7513..68fff62 100644 --- a/include/Database.hpp +++ b/include/Database.hpp @@ -2,6 +2,7 @@ #include "types.hpp" #include "Key.hpp" +#include "StagedObject.hpp" #include "DataView.hpp" #include <opendht/dhtrunner.h> #include <vector> @@ -11,26 +12,13 @@ namespace odhtdb { class Group; - struct StagedCreateObject - { - Key key; - Group *primaryAdminGroup; - u64 timestamp; // In microseconds - }; - - struct StagedAddObject - { - Key key; - DataView data; - u64 timestamp; // In microseconds - }; - class Database { public: Database(const char *bootstrapNodeAddr, u16 port); ~Database(); + void seed(); void create(const Key &key, Group *primaryAdminGroup); void add(const Key &key, DataView data); void commit(); @@ -38,6 +26,10 @@ namespace odhtdb 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(const std::vector<std::shared_ptr<dht::Value>> &values); + bool listenAddData(const std::vector<std::shared_ptr<dht::Value>> &values); private: dht::DhtRunner node; std::vector<StagedCreateObject> stagedCreateObjects; diff --git a/include/Key.hpp b/include/Key.hpp index e9f0591..505050d 100644 --- a/include/Key.hpp +++ b/include/Key.hpp @@ -7,6 +7,7 @@ namespace odhtdb class Key { public: + Key() {} Key(const char *key) : hashedKey(dht::InfoHash::get(key)) {} dht::InfoHash hashedKey; diff --git a/include/StagedObject.hpp b/include/StagedObject.hpp new file mode 100644 index 0000000..61e1073 --- /dev/null +++ b/include/StagedObject.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include "Key.hpp" +#include "types.hpp" +#include "DataView.hpp" + +namespace odhtdb +{ + class Group; + + struct StagedCreateObject + { + Key key; + Group *primaryAdminGroup; + u64 timestamp; // In microseconds + + StagedCreateObject() : key(), primaryAdminGroup(nullptr), timestamp(0) {} + StagedCreateObject(const Key &_key, Group *_primaryAdminGroup, u64 _timestamp) : + key(_key), primaryAdminGroup(_primaryAdminGroup), timestamp(_timestamp) + { + + } + }; + + struct StagedAddObject + { + Key key; + DataView data; + u64 timestamp; // In microseconds + + StagedAddObject() : key(), data(), timestamp(0) {} + StagedAddObject(const Key &_key, const DataView &_data, u64 _timestamp) : + key(_key), data(_data), timestamp(_timestamp) + { + + } + }; +}
\ No newline at end of file |