aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-16 07:25:22 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commit92d6393a34dac4b3d623a5169e2b50a9518b4976 (patch)
treea318cc84e3837f61c03cd4a0533c3380bb5fdbde /include
parentc0574f16ca7960a3301230ba36ba96148818e229 (diff)
Add functions to send/receive custom messages
Diffstat (limited to 'include')
-rw-r--r--include/odhtdb/Database.hpp11
-rw-r--r--include/odhtdb/DhtKey.hpp5
2 files changed, 14 insertions, 2 deletions
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 <vector>
#include <ntp/NtpClient.hpp>
#include <boost/filesystem/path.hpp>
+#include <sibs/SafeSerializer.hpp>
#include <stdexcept>
#include <functional>
@@ -146,6 +147,9 @@ namespace odhtdb
using CreateNodeCallbackFunc = std::function<void(const DatabaseCreateNodeRequest&)>;
using AddNodeCallbackFunc = std::function<void(const DatabaseAddNodeRequest&)>;
using AddUserCallbackFunc = std::function<void(const DatabaseAddUserRequest&)>;
+
+ using ReceiveCustomMessageCallbackFunc = std::function<sibs::SafeSerializer(const void *data, usize size)>;
+ using SendCustomMessageCallbackFunc = std::function<bool(bool gotResponse, const void *data, usize size)>;
struct DatabaseCallbackFuncs
{
@@ -191,6 +195,13 @@ namespace odhtdb
std::vector<NodeUserKeyPair> getStoredUserNodeDataDecrypted(const std::string &username, const std::string &password);
std::vector<OwnedMemory> 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<u8> &&data, SendCustomMessageCallbackFunc callbackFunc);
+
+ static dht::InfoHash getInfoHash(const void *data, usize size);
private:
void deserializeCreateRequest(const std::shared_ptr<dht::Value> &value, const Hash &hash, const std::shared_ptr<OwnedMemory> encryptionKey);
void deserializeAddRequest(const std::shared_ptr<dht::Value> &value, const Hash &requestDataHash, const std::shared_ptr<Hash> &nodeHash, const std::shared_ptr<OwnedMemory> 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;