From 92d6393a34dac4b3d623a5169e2b50a9518b4976 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 16 May 2018 07:25:22 +0200 Subject: Add functions to send/receive custom messages --- include/odhtdb/Database.hpp | 11 +++++++++++ include/odhtdb/DhtKey.hpp | 5 +++-- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/odhtdb/Database.hpp b/include/odhtdb/Database.hpp index a68c601..bd7b3f5 100644 --- a/include/odhtdb/Database.hpp +++ b/include/odhtdb/Database.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -146,6 +147,9 @@ namespace odhtdb using CreateNodeCallbackFunc = std::function; using AddNodeCallbackFunc = std::function; using AddUserCallbackFunc = std::function; + + using ReceiveCustomMessageCallbackFunc = std::function; + using SendCustomMessageCallbackFunc = std::function; struct DatabaseCallbackFuncs { @@ -191,6 +195,13 @@ namespace odhtdb std::vector getStoredUserNodeDataDecrypted(const std::string &username, const std::string &password); std::vector getUserGroups(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const; + + void receiveCustomMessage(const dht::InfoHash &requestKey, ReceiveCustomMessageCallbackFunc callbackFunc); + + // Return true in @callbackFunc if you want to continue listening for responses, otherwise return false + void sendCustomMessage(const dht::InfoHash &key, std::vector &&data, SendCustomMessageCallbackFunc callbackFunc); + + static dht::InfoHash getInfoHash(const void *data, usize size); private: void deserializeCreateRequest(const std::shared_ptr &value, const Hash &hash, const std::shared_ptr encryptionKey); void deserializeAddRequest(const std::shared_ptr &value, const Hash &requestDataHash, const std::shared_ptr &nodeHash, const std::shared_ptr encryptionKey); diff --git a/include/odhtdb/DhtKey.hpp b/include/odhtdb/DhtKey.hpp index 7c30ee3..c3398bf 100644 --- a/include/odhtdb/DhtKey.hpp +++ b/include/odhtdb/DhtKey.hpp @@ -9,9 +9,10 @@ namespace odhtdb { public: DhtKey(const Hash &key); + DhtKey(const dht::InfoHash &infoHash); - const dht::InfoHash& getNewDataListenerKey(); - const dht::InfoHash& getRequestOldDataKey(); + dht::InfoHash getNewDataListenerKey(); + dht::InfoHash getRequestOldDataKey(); private: dht::InfoHash infoHash; unsigned char firstByteOriginalValue; -- cgit v1.2.3