From 4b656c5600a28f05665e849715af3d08f29dff2f Mon Sep 17 00:00:00 2001 From: dec05eba <0xdec05eba@gmail.com> Date: Tue, 15 May 2018 06:06:02 +0200 Subject: Store known remote nodes and connect to them next time --- include/odhtdb/Database.hpp | 2 ++ include/odhtdb/DatabaseStorage.hpp | 8 ++++++++ include/odhtdb/FileUtils.hpp | 4 ++++ 3 files changed, 14 insertions(+) (limited to 'include') diff --git a/include/odhtdb/Database.hpp b/include/odhtdb/Database.hpp index 11a6cd4..5ebe9c5 100644 --- a/include/odhtdb/Database.hpp +++ b/include/odhtdb/Database.hpp @@ -187,5 +187,7 @@ namespace odhtdb std::function onAddNodeCallbackFunc; std::function onAddUserCallbackFunc; MapHash seedInfoMap; + std::thread remoteNodesSaveThread; + bool shuttingDown; }; } diff --git a/include/odhtdb/DatabaseStorage.hpp b/include/odhtdb/DatabaseStorage.hpp index a004619..886412c 100644 --- a/include/odhtdb/DatabaseStorage.hpp +++ b/include/odhtdb/DatabaseStorage.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include class sqlite3; @@ -121,6 +122,9 @@ namespace odhtdb std::pair> getNodeDecryptionKey(const Hash &nodeHash); void setNodeDecryptionKey(const Hash &nodeHash, const DataView &decryptionKey); + const std::vector& getRemoteNodes() const; + void setRemoteNodes(const std::vector &remoteNodes); + const dht::crypto::Identity& getIdentity() const; // Update storage state (remove quarantine objects if they are too old, etc) @@ -131,6 +135,7 @@ namespace odhtdb void bindCheckError(int sqliteBindResult); void loadMetadataFromFile(); + void loadRemoteNodesFromFile(); bool decryptNodeData(const Hash &nodeHash, const std::shared_ptr decryptionKey); bool decryptNodeData(const Hash &nodeHash, const std::shared_ptr decryptionKey, const Signature::PublicKey *creatorPublicKey, const DataView &adminGroupId, u64 timestamp); bool decryptNodeAddData(i64 rowId, const Hash &nodeHash, const Hash &dataHash, u64 timestamp, const Signature::PublicKey *creatorPublicKey, const DataView &encryptedData, const std::shared_ptr decryptionKey); @@ -168,7 +173,10 @@ namespace odhtdb sqlite3_stmt *setNodeAddDataAdditionalDataStmt; boost::filesystem::path metadataFilePath; + boost::filesystem::path remoteNodesFilePath; + u8 passwordSalt[PASSWORD_SALT_LEN]; std::pair, std::shared_ptr> identity; + std::vector remoteNodes; }; } diff --git a/include/odhtdb/FileUtils.hpp b/include/odhtdb/FileUtils.hpp index 7bfbe3e..88721ed 100644 --- a/include/odhtdb/FileUtils.hpp +++ b/include/odhtdb/FileUtils.hpp @@ -19,4 +19,8 @@ namespace odhtdb // Creates file if it doesn't exist. // Throws FileException on error void fileAppend(const boost::filesystem::path &filepath, const DataView &data); + + // Creates a file if it doesn'te xist. + // Throws FileException on error. + void fileOverwrite(const boost::filesystem::path &filepath, const DataView &data); } -- cgit v1.2.3