From 7d675a45023e44cfa03d7fa95e4ec20e3a1c2fb9 Mon Sep 17 00:00:00 2001 From: dec05eba <0xdec05eba@gmail.com> 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(-) (limited to 'src') 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