diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/Database.hpp | 21 | ||||
-rw-r--r-- | include/Group.hpp | 19 | ||||
-rw-r--r-- | include/LocalUser.hpp | 17 | ||||
-rw-r--r-- | include/User.hpp | 21 |
4 files changed, 71 insertions, 7 deletions
diff --git a/include/Database.hpp b/include/Database.hpp index 0b324e8..20d7513 100644 --- a/include/Database.hpp +++ b/include/Database.hpp @@ -5,13 +5,24 @@ #include "DataView.hpp" #include <opendht/dhtrunner.h> #include <vector> +#include <ntp/NtpClient.hpp> namespace odhtdb { - struct StagedObject + class Group; + + struct StagedCreateObject + { + Key key; + Group *primaryAdminGroup; + u64 timestamp; // In microseconds + }; + + struct StagedAddObject { Key key; DataView data; + u64 timestamp; // In microseconds }; class Database @@ -20,12 +31,16 @@ namespace odhtdb Database(const char *bootstrapNodeAddr, u16 port); ~Database(); + void create(const Key &key, Group *primaryAdminGroup); void add(const Key &key, DataView data); void commit(); private: - void commitStagedObject(const StagedObject &stagedObject); + void commitStagedCreateObject(const StagedCreateObject &stagedObject); + void commitStagedAddObject(const StagedAddObject &stagedObject); + ntp::NtpTimestamp getSyncedTimestampUtc() const; private: dht::DhtRunner node; - std::vector<StagedObject> stagedObjects; + std::vector<StagedCreateObject> stagedCreateObjects; + std::vector<StagedAddObject> stagedAddObjects; }; }
\ No newline at end of file diff --git a/include/Group.hpp b/include/Group.hpp index dafc05a..c909728 100644 --- a/include/Group.hpp +++ b/include/Group.hpp @@ -1,19 +1,34 @@ #pragma once -#include <opendht/crypto.h> #include <string> #include <vector> +#include <stdexcept> namespace odhtdb { class User; + class GroupNameTooLongException : public std::runtime_error + { + public: + GroupNameTooLongException(const std::string &groupName) : + std::runtime_error(std::string("The group name ") + groupName + " is longer than 255 bytes") + { + + } + }; + class Group { public: + Group(const std::string &name); ~Group(); + + void addUser(User *user); + + const std::string& getName() const; + const std::vector<User*>& getUsers() const; private: - dht::crypto::PublicKey publicKey; std::string name; std::vector<User*> users; }; diff --git a/include/LocalUser.hpp b/include/LocalUser.hpp new file mode 100644 index 0000000..200f30f --- /dev/null +++ b/include/LocalUser.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include "User.hpp" + +namespace odhtdb +{ + class LocalUser : public User + { + public: + static LocalUser* create(const std::string &name) + { + return new LocalUser(name); + } + private: + LocalUser(const std::string &name) : User(name){} + }; +}
\ No newline at end of file diff --git a/include/User.hpp b/include/User.hpp index 727bbcf..e542434 100644 --- a/include/User.hpp +++ b/include/User.hpp @@ -1,15 +1,32 @@ #pragma once -#include <opendht/crypto.h> #include <string> +#include <stdexcept> namespace odhtdb { + class UserNameTooLongException : public std::runtime_error + { + public: + UserNameTooLongException(const std::string &userName) : + std::runtime_error(std::string("The username ") + userName + " is longer than 255 bytes") + { + + } + }; + class User { public: + const std::string& getName() const { return name; } + protected: + User(const std::string &_name) : name(_name) + { + if(name.size() > 255) + throw UserNameTooLongException(name); + } private: - dht::crypto::PublicKey publicKey; + // TODO: Add public key std::string name; }; }
\ No newline at end of file |