5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-12-23 08:45:39 +00:00

Merge pull request #649 from Arceliar/switch

Sort search response results before sending requests
This commit is contained in:
Arceliar 2020-02-06 17:48:26 -06:00 committed by GitHub
commit b8bab06f95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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())
})
}
}