From e24b595191e37d34817075b5c6fae1c9aaea5ce8 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 8 Feb 2019 08:42:12 -0500 Subject: [PATCH] more dht fixing, only pick the most up to date entity for reply --- llarp/dht/localserviceaddresslookup.cpp | 2 +- llarp/dht/recursiverouterlookup.cpp | 11 +++++++++++ llarp/dht/serviceaddresslookup.cpp | 4 ++-- llarp/router_contact.hpp | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/llarp/dht/localserviceaddresslookup.cpp b/llarp/dht/localserviceaddresslookup.cpp index 0c3dcd19c..def38fc67 100644 --- a/llarp/dht/localserviceaddresslookup.cpp +++ b/llarp/dht/localserviceaddresslookup.cpp @@ -32,7 +32,7 @@ namespace llarp return; } // pick newest if we have more than 1 result - if(valuesFound.size() > 1) + if(valuesFound.size()) { service::IntroSet found; for(const auto &introset : valuesFound) diff --git a/llarp/dht/recursiverouterlookup.cpp b/llarp/dht/recursiverouterlookup.cpp index 0bcab6951..43d09b1f1 100644 --- a/llarp/dht/recursiverouterlookup.cpp +++ b/llarp/dht/recursiverouterlookup.cpp @@ -40,6 +40,17 @@ namespace llarp void RecursiveRouterLookup::SendReply() { + if(valuesFound.size()) + { + RouterContact found; + for(const auto &rc : valuesFound) + { + if(found.OtherIsNewer(rc)) + found = rc; + } + valuesFound.clear(); + valuesFound.emplace_back(found); + } if(resultHandler) { resultHandler(valuesFound); diff --git a/llarp/dht/serviceaddresslookup.cpp b/llarp/dht/serviceaddresslookup.cpp index b64e86bf7..fa2fa02f9 100644 --- a/llarp/dht/serviceaddresslookup.cpp +++ b/llarp/dht/serviceaddresslookup.cpp @@ -81,10 +81,10 @@ namespace llarp handleResult(valuesFound); } // get newest introset - if(valuesFound.size() > 1) + if(valuesFound.size()) { llarp::service::IntroSet found; - for(const auto & introset : valuesFound) + for(const auto &introset : valuesFound) if(found.OtherIsNewer(introset)) found = introset; valuesFound.clear(); diff --git a/llarp/router_contact.hpp b/llarp/router_contact.hpp index 397550e96..e813acc14 100644 --- a/llarp/router_contact.hpp +++ b/llarp/router_contact.hpp @@ -96,7 +96,7 @@ namespace llarp /// node nickname, yw kee llarp::AlignedBuffer< NICKLEN > nickname; - uint64_t last_updated; + uint64_t last_updated = 0; bool BEncode(llarp_buffer_t *buf) const override;