From 0e62cb8e5ed06d906ad84321cdda22acfcc952c9 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 9 Mar 2018 10:26:55 +0100 Subject: Partially implement 'add' operation --- include/DatabaseStorage.hpp | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'include/DatabaseStorage.hpp') diff --git a/include/DatabaseStorage.hpp b/include/DatabaseStorage.hpp index 6f251d1..fd29050 100644 --- a/include/DatabaseStorage.hpp +++ b/include/DatabaseStorage.hpp @@ -10,27 +10,33 @@ namespace odhtdb { class Group; + class User; struct DatabaseStorageObject { DataView data; - u64 timestamp; // In microseconds + u64 createdTimestamp; // In microseconds Signature::PublicKey creatorPublicKey; - DatabaseStorageObject(DataView &_data, u64 _timestamp, const Signature::PublicKey &_creatorPublicKey) : - data(_data), timestamp(_timestamp), creatorPublicKey(_creatorPublicKey) - { - - } + DatabaseStorageObject(DataView &_data, u64 _timestamp, const Signature::PublicKey &_creatorPublicKey); }; struct DatabaseStorageObjectList { - u64 timestamp; // In microseconds + DataView data; + u64 createdTimestamp; // In microseconds std::vector groups; - std::vector objects; - u8 *createData; - usize createDataSize; + std::vector objects; + }; + + struct DatabaseStorageQuarantineObject + { + DataView data; + u64 createdTimestamp; // In microseconds + u64 storedTimestamp; // In microseconds + Signature::PublicKey creatorPublicKey; + + DatabaseStorageQuarantineObject(DataView &_data, u64 _timestamp, const Signature::PublicKey &_creatorPublicKey); }; class DatabaseStorageAlreadyExists : public std::runtime_error @@ -46,6 +52,7 @@ namespace odhtdb }; using DatabaseStorageMap = MapHashKey; + using DatabaseStorageQuarantineMap = Signature::MapPublicKey>; class DatabaseStorage { @@ -54,11 +61,22 @@ namespace odhtdb 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); + void appendStorage(const Hash &hash, const User *creatorUser, u64 timestamp, const u8 *data, usize dataSize); + + void addToQuarantine(const Signature::PublicKey &creatorPublicKey, u64 timestamp, const u8 *data, usize dataSize); - // Returns nullptr if not storage with provided hash exists + // Returns nullptr if no storage with provided hash exists const DatabaseStorageObjectList* getStorage(const Hash &hash) const; + + // Returns nullptr if no node with the user exists + const Hash* getNodeByUserPublicKey(const Signature::PublicKey &userPublicKey) const; + + // Returns nullptr if no user with public key exists + const User* getUserByPublicKey(const Signature::PublicKey &userPublicKey) const; private: DatabaseStorageMap storageMap; + DatabaseStorageQuarantineMap quarantineStorageMap; + Signature::MapPublicKey userPublicKeyNodeMap; + Signature::MapPublicKey publicKeyUserMap; }; } -- cgit v1.2.3