mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-27 12:05:23 +00:00
make searches more parallel
This commit is contained in:
parent
5bd9391c61
commit
9fac5355eb
@ -16,7 +16,6 @@ package yggdrasil
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"sort"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
|
"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
|
||||||
@ -104,24 +103,6 @@ func (sinfo *searchInfo) addToSearch(res *dhtRes) {
|
|||||||
sinfo.toVisit = append(sinfo.toVisit, info)
|
sinfo.toVisit = append(sinfo.toVisit, info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Deduplicate
|
|
||||||
vMap := make(map[crypto.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 {
|
|
||||||
// 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())
|
|
||||||
})
|
|
||||||
// Truncate to some maximum size
|
|
||||||
if len(sinfo.toVisit) > search_MAX_SEARCH_SIZE {
|
|
||||||
sinfo.toVisit = sinfo.toVisit[:search_MAX_SEARCH_SIZE]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are no nodes left toVisit, then this cleans up the search.
|
// If there are no nodes left toVisit, then this cleans up the search.
|
||||||
@ -136,12 +117,13 @@ func (sinfo *searchInfo) doSearchStep() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Send to the next search target
|
// Send to the next search target
|
||||||
var next *dhtInfo
|
for _, next := range sinfo.toVisit {
|
||||||
next, sinfo.toVisit = sinfo.toVisit[0], sinfo.toVisit[1:]
|
|
||||||
rq := dhtReqKey{next.key, sinfo.dest}
|
rq := dhtReqKey{next.key, sinfo.dest}
|
||||||
sinfo.searches.router.dht.addCallback(&rq, sinfo.handleDHTRes)
|
sinfo.searches.router.dht.addCallback(&rq, sinfo.handleDHTRes)
|
||||||
sinfo.searches.router.dht.ping(next, &sinfo.dest)
|
sinfo.searches.router.dht.ping(next, &sinfo.dest)
|
||||||
sinfo.time = time.Now()
|
sinfo.time = time.Now()
|
||||||
|
}
|
||||||
|
sinfo.toVisit = sinfo.toVisit[:0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we've recently sent a ping for this search, do nothing.
|
// If we've recently sent a ping for this search, do nothing.
|
||||||
|
Loading…
Reference in New Issue
Block a user