diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-05-15 06:06:02 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:25:46 +0200 |
commit | 8a030b5e77031c8b3347170d28758097bca1f15e (patch) | |
tree | 780631de9700a37e862b4aa8f946a71cd163c633 /include | |
parent | 54f53857279644914e0c2a2aed24060f31ed2575 (diff) |
Store known remote nodes and connect to them next time
Diffstat (limited to 'include')
-rw-r--r-- | include/odhtdb/Database.hpp | 2 | ||||
-rw-r--r-- | include/odhtdb/DatabaseStorage.hpp | 8 | ||||
-rw-r--r-- | include/odhtdb/FileUtils.hpp | 4 |
3 files changed, 14 insertions, 0 deletions
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<void(const DatabaseAddNodeRequest&)> onAddNodeCallbackFunc; std::function<void(const DatabaseAddUserRequest&)> onAddUserCallbackFunc; MapHash<DatabaseSeedInfo> 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 <boost/filesystem/path.hpp> #include <sibs/SafeDeserializer.hpp> #include <opendht/crypto.h> +#include <opendht/dhtrunner.h> #include <functional> class sqlite3; @@ -121,6 +122,9 @@ namespace odhtdb std::pair<bool, std::shared_ptr<OwnedMemory>> getNodeDecryptionKey(const Hash &nodeHash); void setNodeDecryptionKey(const Hash &nodeHash, const DataView &decryptionKey); + const std::vector<dht::NodeExport>& getRemoteNodes() const; + void setRemoteNodes(const std::vector<dht::NodeExport> &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<OwnedMemory> decryptionKey); bool decryptNodeData(const Hash &nodeHash, const std::shared_ptr<OwnedMemory> 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<OwnedMemory> 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<dht::crypto::PrivateKey>, std::shared_ptr<dht::crypto::Certificate>> identity; + std::vector<dht::NodeExport> 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); } |