aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <0xdec05eba@gmail.com>2018-05-14 20:28:33 +0200
committerdec05eba <0xdec05eba@gmail.com>2018-05-14 20:28:38 +0200
commit7d675a45023e44cfa03d7fa95e4ec20e3a1c2fb9 (patch)
tree976a0bad4b3da51f654ef71433cad7af9aed124c
parent8daf7b3165c65a932a7d8eae1f0a640199892ca9 (diff)
Ignore our own requests when requesting old packets
-rw-r--r--src/Database.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/Database.cpp b/src/Database.cpp
index fdafab8..ddef6d1 100644
--- a/src/Database.cpp
+++ b/src/Database.cpp
@@ -204,7 +204,8 @@ namespace odhtdb
u8 responseKey[OPENDHT_INFOHASH_LEN];
randombytes_buf(responseKey, OPENDHT_INFOHASH_LEN);
- newSeedInfo.reponseKeyInfoHash = make_shared<InfoHash>(responseKey, OPENDHT_INFOHASH_LEN);
+ shared_ptr<InfoHash> responseKeyShared = make_shared<InfoHash>(responseKey, OPENDHT_INFOHASH_LEN);;
+ newSeedInfo.reponseKeyInfoHash = responseKeyShared;
// TODO: If this response key is spammed, generate a new one.
auto responseKeyFuture = node.listen(*newSeedInfo.reponseKeyInfoHash, [this, nodeToSeed](const shared_ptr<Value> &value)
@@ -219,15 +220,18 @@ namespace odhtdb
// TODO:!!! Before listening on this key, we should check how many remote peers are also providing this data.
// This is to prevent too many peers from responding to a request to get old data.
- auto requestOldDataListenerFuture = node.listen(dhtKey.getRequestOldDataKey(), [this, nodeToSeed](const shared_ptr<Value> &value)
+ auto requestOldDataListenerFuture = node.listen(dhtKey.getRequestOldDataKey(), [this, nodeToSeed, responseKeyShared](const shared_ptr<Value> &value)
{
Log::debug("Request: Got request to send old data");
try
{
+ static_assert(HASH_LEN == OPENDHT_INFOHASH_LEN, "Wrong hashlen size, did it change with opendht upgrade?");
sibs::SafeDeserializer deserializer(value->data.data(), value->data.size());
InfoHash requestResponseInfoHash;
deserializer.extract(requestResponseInfoHash.data(), OPENDHT_INFOHASH_LEN);
- static_assert(HASH_LEN == OPENDHT_INFOHASH_LEN, "Wrong hashlen size, did it change with opendht upgrade?");
+ if(*responseKeyShared == requestResponseInfoHash)
+ return true; // We sent the request, ignore our own requests
+
bool userWantsCreateNode = deserializer.extract<u8>() == 1;
if(userWantsCreateNode)