aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <0xdec05eba@gmail.com>2018-05-16 07:25:22 +0200
committerdec05eba <0xdec05eba@gmail.com>2018-05-16 07:25:25 +0200
commitba8631c5f75df45fb07726e0aab3bb0834d6a5b6 (patch)
treefa9270cfb2c774ef9448f2d398b1fa24ac5ecf87 /include
parent16a9b3e33cd4e377417dcc785be7e19bf71e18b9 (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;