From 7e1a6236beea0e402f6630d35c311d5447d0a4d8 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 7 Feb 2020 14:35:57 -0500 Subject: [PATCH 1/7] if relayed try closer router if we don't have an intro --- llarp/dht/messages/findintro.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/llarp/dht/messages/findintro.cpp b/llarp/dht/messages/findintro.cpp index 715242471..a024cf78d 100644 --- a/llarp/dht/messages/findintro.cpp +++ b/llarp/dht/messages/findintro.cpp @@ -128,10 +128,23 @@ namespace llarp if((us ^ location) < (peer ^ location) || peer == us) { - // we are not closer than our peer to the target so don't - // recurse farther - replies.emplace_back(new GotIntroMessage({}, txID)); - return true; + // think we are the closeset + if(relayed) + { + // ask second closest as we are relayed + if(not dht.Nodes()->FindClosest(location, peer)) + { + // no second closeset + replies.emplace_back(new GotIntroMessage({}, txID)); + return true; + } + } + else + { + // non relayed request tell them we don't have it + replies.emplace_back(new GotIntroMessage({}, txID)); + return true; + } } if(relayed) { From 3bea7327cb58147a46791d6a9e321539d3271591 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 7 Feb 2020 14:46:12 -0500 Subject: [PATCH 2/7] handle end case by telling requester that it's not there --- llarp/dht/messages/findintro.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/llarp/dht/messages/findintro.cpp b/llarp/dht/messages/findintro.cpp index a024cf78d..6d9fe80b4 100644 --- a/llarp/dht/messages/findintro.cpp +++ b/llarp/dht/messages/findintro.cpp @@ -112,12 +112,7 @@ namespace llarp if(recursionDepth == 0) { // we don't have it - - Key_t closer; - // find closer peer - if(!dht.Nodes()->FindClosest(location, closer)) - return false; - replies.emplace_back(new GotIntroMessage(From, closer, txID)); + replies.emplace_back(new GotIntroMessage({}, txID)); return true; } From 19d91a440f94b1e2dd61ac076c80850f1b16b957 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 7 Feb 2020 14:50:02 -0500 Subject: [PATCH 3/7] move declaration of peer --- llarp/dht/messages/findintro.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llarp/dht/messages/findintro.cpp b/llarp/dht/messages/findintro.cpp index 6d9fe80b4..8ca258e58 100644 --- a/llarp/dht/messages/findintro.cpp +++ b/llarp/dht/messages/findintro.cpp @@ -89,7 +89,7 @@ namespace llarp llarp::LogWarn("duplicate FIM from ", From, " txid=", txID); return false; } - Key_t peer; + std::set< Key_t > exclude = {dht.OurKey(), From}; if(not tagName.Empty()) return false; @@ -119,7 +119,7 @@ namespace llarp // we are recursive const auto rc = dht.GetRouter()->nodedb()->FindClosestTo(location); - peer = Key_t(rc.pubkey); + Key_t peer = Key_t(rc.pubkey); if((us ^ location) < (peer ^ location) || peer == us) { From 5b87a9419e2bca9bda0110fddd4053323c5e52f5 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 7 Feb 2020 14:55:08 -0500 Subject: [PATCH 4/7] default recursion depth to 2 not 12 --- llarp/service/hidden_service_address_lookup.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llarp/service/hidden_service_address_lookup.cpp b/llarp/service/hidden_service_address_lookup.cpp index 5b791bc30..49a63ff38 100644 --- a/llarp/service/hidden_service_address_lookup.cpp +++ b/llarp/service/hidden_service_address_lookup.cpp @@ -46,8 +46,8 @@ namespace llarp HiddenServiceAddressLookup::BuildRequestMessage() { auto msg = std::make_shared< routing::DHTMessage >(); - msg->M.emplace_back(std::make_unique< dht::FindIntroMessage >( - txid, location, dht::FindIntroMessage::MaxRecursionDepth)); + msg->M.emplace_back( + std::make_unique< dht::FindIntroMessage >(txid, location, 2)); return msg; } From b211450cc82b7b87af16ebe43823ac5e735ad1a9 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 7 Feb 2020 15:20:47 -0500 Subject: [PATCH 5/7] always recurse to second closest if we don't have it --- llarp/dht/messages/findintro.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/llarp/dht/messages/findintro.cpp b/llarp/dht/messages/findintro.cpp index 8ca258e58..2491581e2 100644 --- a/llarp/dht/messages/findintro.cpp +++ b/llarp/dht/messages/findintro.cpp @@ -123,20 +123,10 @@ namespace llarp if((us ^ location) < (peer ^ location) || peer == us) { - // think we are the closeset - if(relayed) + // ask second closest as we are relayed + if(not dht.Nodes()->FindCloseExcluding(location, peer, exclude)) { - // ask second closest as we are relayed - if(not dht.Nodes()->FindClosest(location, peer)) - { - // no second closeset - replies.emplace_back(new GotIntroMessage({}, txID)); - return true; - } - } - else - { - // non relayed request tell them we don't have it + // no second closeset replies.emplace_back(new GotIntroMessage({}, txID)); return true; } From e4a16dfdd563b01e5e4ca08a888def19a9e32b93 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 7 Feb 2020 15:22:58 -0500 Subject: [PATCH 6/7] fix comment --- llarp/dht/messages/findintro.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llarp/dht/messages/findintro.cpp b/llarp/dht/messages/findintro.cpp index 2491581e2..b250c7cc5 100644 --- a/llarp/dht/messages/findintro.cpp +++ b/llarp/dht/messages/findintro.cpp @@ -123,7 +123,7 @@ namespace llarp if((us ^ location) < (peer ^ location) || peer == us) { - // ask second closest as we are relayed + // ask second closest as we are recursive if(not dht.Nodes()->FindCloseExcluding(location, peer, exclude)) { // no second closeset From 00260555bd40eef75762a1802d0fdac66ef22e19 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 7 Feb 2020 15:28:13 -0500 Subject: [PATCH 7/7] logic simplification --- llarp/dht/messages/findintro.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llarp/dht/messages/findintro.cpp b/llarp/dht/messages/findintro.cpp index b250c7cc5..e3a9a7ea3 100644 --- a/llarp/dht/messages/findintro.cpp +++ b/llarp/dht/messages/findintro.cpp @@ -121,7 +121,7 @@ namespace llarp Key_t peer = Key_t(rc.pubkey); - if((us ^ location) < (peer ^ location) || peer == us) + if((us ^ location) <= (peer ^ location)) { // ask second closest as we are recursive if(not dht.Nodes()->FindCloseExcluding(location, peer, exclude))