From 22abf1aa83b2668f918556491a55947be798f89f Mon Sep 17 00:00:00 2001 From: dec05eba <0xdec05eba@gmail.com> Date: Sun, 21 Oct 2018 14:31:28 +0200 Subject: Async connect --- include/odhtdb/Database.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/odhtdb/Database.hpp b/include/odhtdb/Database.hpp index a326398..61365a0 100644 --- a/include/odhtdb/Database.hpp +++ b/include/odhtdb/Database.hpp @@ -162,7 +162,7 @@ namespace odhtdb DISABLE_COPY(Database) friend class DatabaseStorage; public: - Database(const char *bootstrapNodeAddr, u16 port, const boost::filesystem::path &storageDir, DatabaseCallbackFuncs callbackFuncs); + static std::future> connect(const char *bootstrapNodeAddr, u16 port, const boost::filesystem::path &storageDir, DatabaseCallbackFuncs callbackFuncs); ~Database(); // Safe to call multiple times with same node hash, will be ignored if the node is already beeing seeded @@ -212,13 +212,15 @@ namespace odhtdb static InfoHash getInfoHash(const void *data, usize size); private: + Database(const sibs::Ipv4 &bootstrapNodeAddr, const boost::filesystem::path &storageDir, DatabaseCallbackFuncs callbackFuncs); + bool sendOldDataToPeer(const DatabaseNode nodeToSeed, const void *data, const usize size); void deserializeCreateRequest(const void *data, const usize size, const Hash &hash, const std::shared_ptr encryptionKey); void deserializeAddRequest(const void *data, const usize size, const Hash &requestDataHash, const std::shared_ptr &nodeHash, const std::shared_ptr encryptionKey); bool listenCreateData(const void *data, const usize size, const Hash &hash, const std::shared_ptr encryptionKey); bool listenAddData(const void *data, const usize size, const Hash &requestDataHash, const std::shared_ptr nodeHash, const std::shared_ptr encryptionKey); private: - sibs::BootstrapConnection bootstrapConnection; + std::unique_ptr bootstrapConnection; DatabaseStorage databaseStorage; std::function onCreateNodeCallbackFunc; std::function onAddNodeCallbackFunc; -- cgit v1.2.3