From c820b10adddc7a229cf2de99937d05a5715d2ab0 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 14 May 2018 20:28:33 +0200 Subject: Ignore our own requests when requesting old packets --- src/Database.cpp | 10 +++++++--- 1 file 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(responseKey, OPENDHT_INFOHASH_LEN); + shared_ptr responseKeyShared = make_shared(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) @@ -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) + auto requestOldDataListenerFuture = node.listen(dhtKey.getRequestOldDataKey(), [this, nodeToSeed, responseKeyShared](const shared_ptr &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() == 1; if(userWantsCreateNode) -- cgit v1.2.3