aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-14 20:28:33 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commitc820b10adddc7a229cf2de99937d05a5715d2ab0 (patch)
tree49a16be790c44817064826cd53a0947c7c739900
parent080487c961b424c9dd822d38ec8c2c4d79aff24b (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)