diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Database.cpp | 10 |
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) |