From 3faa0b28545bdf5fbc384a18ad23e79230288695 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Thu, 6 Feb 2020 20:47:53 -0600 Subject: [PATCH] deduplicate the list of nodes to visit in a search (keeping newest rumors) --- src/yggdrasil/search.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/yggdrasil/search.go b/src/yggdrasil/search.go index ede4547..7df3bdd 100644 --- a/src/yggdrasil/search.go +++ b/src/yggdrasil/search.go @@ -97,8 +97,19 @@ func (sinfo *searchInfo) handleDHTRes(res *dhtRes) { // Adds the information from a dhtRes to an ongoing search. // Info about a node that has already been visited is not re-added to the search. func (sinfo *searchInfo) addToSearch(res *dhtRes) { - // Add to search + // Get a (deduplicated) list of known nodes to check + temp := make(map[crypto.NodeID]*dhtInfo, len(sinfo.toVisit)+len(res.Infos)) + for _, info := range sinfo.toVisit { + temp[*info.getNodeID()] = info + } + // Add new results to the list for _, info := range res.Infos { + temp[*info.getNodeID()] = info + } + // Move list to toVisit + delete(temp, sinfo.visited) + sinfo.toVisit = sinfo.toVisit[:0] + for _, info := range temp { sinfo.toVisit = append(sinfo.toVisit, info) } // Sort @@ -106,9 +117,9 @@ func (sinfo *searchInfo) addToSearch(res *dhtRes) { // Should return true if i is closer to the destination than j return dht_ordered(&sinfo.dest, sinfo.toVisit[i].getNodeID(), sinfo.toVisit[j].getNodeID()) }) - // Remove anything too far away + // Remove anything too far away to be useful for idx, info := range sinfo.toVisit { - if *info.getNodeID() == sinfo.visited || !dht_ordered(&sinfo.dest, info.getNodeID(), &sinfo.visited) { + if !dht_ordered(&sinfo.dest, info.getNodeID(), &sinfo.visited) { sinfo.toVisit = sinfo.toVisit[:idx] break }