From 70659bfb91032de2c9647677800dbd32dc307f1e Mon Sep 17 00:00:00 2001 From: Arceliar Date: Thu, 6 Feb 2020 17:38:42 -0600 Subject: [PATCH] sort search response results before sending requests --- src/yggdrasil/search.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/yggdrasil/search.go b/src/yggdrasil/search.go index 913b40a..6bd53c6 100644 --- a/src/yggdrasil/search.go +++ b/src/yggdrasil/search.go @@ -16,6 +16,7 @@ package yggdrasil import ( "errors" + "sort" "time" "github.com/yggdrasil-network/yggdrasil-go/src/crypto" @@ -100,6 +101,11 @@ func (sinfo *searchInfo) addToSearch(res *dhtRes) { // Response is closer to the destination sinfo.toVisit = append(sinfo.toVisit, info) } + // Sort + sort.SliceStable(sinfo.toVisit, func(i, j int) bool { + // Should return true if i is closer to the destination than j + return dht_ordered(&res.Dest, sinfo.toVisit[i].getNodeID(), sinfo.toVisit[j].getNodeID()) + }) } }