aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-21 08:26:02 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commitac626d47ebd49188458d70f98c6d871b1b7e3f50 (patch)
tree0a551e7b87df0561cf30d497cf3a7829d446962d /src
parent24ee6bcc7ef8877ff00bbafc003aac76d756f9bc (diff)
Add methods to allow pinging
Diffstat (limited to 'src')
-rw-r--r--src/Database.cpp20
-rw-r--r--src/DhtKey.cpp6
2 files changed, 22 insertions, 4 deletions
diff --git a/src/Database.cpp b/src/Database.cpp
index 155e8f5..8d32240 100644
--- a/src/Database.cpp
+++ b/src/Database.cpp
@@ -715,12 +715,12 @@ namespace odhtdb
return databaseStorage.getUserGroups(nodeHash, userPublicKey);
}
- void Database::receiveCustomMessage(const dht::InfoHash &receiveMessageKey, ReceiveCustomMessageCallbackFunc callbackFunc)
+ std::future<size_t> Database::receiveCustomMessage(const dht::InfoHash &receiveMessageKey, ReceiveCustomMessageCallbackFunc callbackFunc)
{
dht::InfoHash responseKey = receiveMessageKey;
++responseKey[0];
- node.listen(receiveMessageKey, [callbackFunc, this, responseKey](const shared_ptr<Value> value)
+ return node.listen(receiveMessageKey, [callbackFunc, this, responseKey](const shared_ptr<Value> value)
{
sibs::SafeSerializer serializer = callbackFunc(value->data.data(), value->data.size());
if(!serializer.getBuffer().empty())
@@ -732,18 +732,30 @@ namespace odhtdb
});
}
- void Database::sendCustomMessage(const dht::InfoHash &requestKey, vector<u8> &&data, SendCustomMessageCallbackFunc callbackFunc)
+ void Database::sendCustomMessage(const dht::InfoHash &requestKey, vector<u8> &&data)
+ {
+ shared_ptr<Value> value = make_shared<Value>(move(data));
+ nodePutWithRetry(&node, requestKey, value);
+ }
+
+ std::future<size_t> Database::sendCustomMessage(const dht::InfoHash &requestKey, vector<u8> &&data, SendCustomMessageCallbackFunc callbackFunc)
{
dht::InfoHash responseKey = requestKey;
++responseKey[0];
- node.listen(responseKey, [callbackFunc](const shared_ptr<Value> value)
+ auto listener = node.listen(responseKey, [callbackFunc](const shared_ptr<Value> value)
{
return callbackFunc(true, value->data.data(), value->data.size());
});
shared_ptr<Value> value = make_shared<Value>(move(data));
nodePutWithRetry(&node, requestKey, value);
+ return listener;
+ }
+
+ void Database::cancelNodeListener(const dht::InfoHash &infoHash, std::future<size_t> &nodeListener)
+ {
+ node.cancelListen(infoHash, nodeListener.get());
}
int Database::clearCache()
diff --git a/src/DhtKey.cpp b/src/DhtKey.cpp
index 422b715..1508657 100644
--- a/src/DhtKey.cpp
+++ b/src/DhtKey.cpp
@@ -24,4 +24,10 @@ namespace odhtdb
infoHash[0] = firstByteOriginalValue + 1;
return infoHash;
}
+
+ dht::InfoHash DhtKey::getPingKey()
+ {
+ infoHash[0] = firstByteOriginalValue + 10;
+ return infoHash;
+ }
}