mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-23 02:01:36 +00:00
deduplicate dht responses when adding them to the search, limit the search toVisit size
This commit is contained in:
parent
10a72444e3
commit
ed6c9c2a54
@ -70,17 +70,30 @@ func (s *searches) handleDHTRes(res *dhtRes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *searches) addToSearch(sinfo *searchInfo, res *dhtRes) {
|
func (s *searches) addToSearch(sinfo *searchInfo, res *dhtRes) {
|
||||||
// TODO
|
// Add responses to toVisit if closer to dest than the res node
|
||||||
|
|
||||||
from := dhtInfo{key: res.key, coords: res.coords}
|
from := dhtInfo{key: res.key, coords: res.coords}
|
||||||
for _, info := range res.infos {
|
for _, info := range res.infos {
|
||||||
if dht_firstCloserThanThird(info.getNodeID(), &res.dest, from.getNodeID()) {
|
if dht_firstCloserThanThird(info.getNodeID(), &res.dest, from.getNodeID()) {
|
||||||
sinfo.toVisit = append(sinfo.toVisit, info)
|
sinfo.toVisit = append(sinfo.toVisit, info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Deduplicate
|
||||||
|
vMap := make(map[NodeID]*dhtInfo)
|
||||||
|
for _, info := range sinfo.toVisit {
|
||||||
|
vMap[*info.getNodeID()] = info
|
||||||
|
}
|
||||||
|
sinfo.toVisit = sinfo.toVisit[:0]
|
||||||
|
for _, info := range vMap {
|
||||||
|
sinfo.toVisit = append(sinfo.toVisit, info)
|
||||||
|
}
|
||||||
|
// Sort
|
||||||
sort.SliceStable(sinfo.toVisit, func(i, j int) bool {
|
sort.SliceStable(sinfo.toVisit, func(i, j int) bool {
|
||||||
return dht_firstCloserThanThird(sinfo.toVisit[i].getNodeID(), &res.dest, sinfo.toVisit[j].getNodeID())
|
return dht_firstCloserThanThird(sinfo.toVisit[i].getNodeID(), &res.dest, sinfo.toVisit[j].getNodeID())
|
||||||
})
|
})
|
||||||
|
// Truncate to some maximum size
|
||||||
|
if len(sinfo.toVisit) > 16 {
|
||||||
|
sinfo.toVisit = sinfo.toVisit[:16]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *searches) doSearchStep(sinfo *searchInfo) {
|
func (s *searches) doSearchStep(sinfo *searchInfo) {
|
||||||
|
Loading…
Reference in New Issue
Block a user