From 1c7e6e074155499155adbbb651db1c66f1762ba2 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 1 Feb 2018 21:15:13 +0100 Subject: Sync time with ntp server, starting with basic operations --- include/Database.hpp | 21 ++++++++++++++++++--- include/Group.hpp | 19 +++++++++++++++++-- include/LocalUser.hpp | 17 +++++++++++++++++ include/User.hpp | 21 +++++++++++++++++++-- 4 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 include/LocalUser.hpp (limited to 'include') 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 #include +#include 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 stagedObjects; + std::vector stagedCreateObjects; + std::vector 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 #include #include +#include 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& getUsers() const; private: - dht::crypto::PublicKey publicKey; std::string name; std::vector 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 #include +#include 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 -- cgit v1.2.3