mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-12-02 01:21:38 +00:00
make sure searches don't end if try to continue (in parallel) with nowhere left to send, but we just sent a search and are still waiting for a response
This commit is contained in:
parent
7a28eb787e
commit
277da1fe60
@ -36,6 +36,7 @@ type searchInfo struct {
|
|||||||
core *Core
|
core *Core
|
||||||
dest crypto.NodeID
|
dest crypto.NodeID
|
||||||
mask crypto.NodeID
|
mask crypto.NodeID
|
||||||
|
time time.Time
|
||||||
toVisit []*dhtInfo
|
toVisit []*dhtInfo
|
||||||
visited map[crypto.NodeID]bool
|
visited map[crypto.NodeID]bool
|
||||||
callback func(*sessionInfo, error)
|
callback func(*sessionInfo, error)
|
||||||
@ -68,6 +69,7 @@ func (s *searches) createSearch(dest *crypto.NodeID, mask *crypto.NodeID, callba
|
|||||||
core: s.core,
|
core: s.core,
|
||||||
dest: *dest,
|
dest: *dest,
|
||||||
mask: *mask,
|
mask: *mask,
|
||||||
|
time: time.Now(),
|
||||||
callback: callback,
|
callback: callback,
|
||||||
}
|
}
|
||||||
s.searches[*dest] = &info
|
s.searches[*dest] = &info
|
||||||
@ -130,9 +132,11 @@ func (sinfo *searchInfo) addToSearch(res *dhtRes) {
|
|||||||
// Otherwise, it pops the closest node to the destination (in keyspace) off of the toVisit list and sends a dht ping.
|
// Otherwise, it pops the closest node to the destination (in keyspace) off of the toVisit list and sends a dht ping.
|
||||||
func (sinfo *searchInfo) doSearchStep() {
|
func (sinfo *searchInfo) doSearchStep() {
|
||||||
if len(sinfo.toVisit) == 0 {
|
if len(sinfo.toVisit) == 0 {
|
||||||
// Dead end, do cleanup
|
if time.Since(sinfo.time) > search_RETRY_TIME {
|
||||||
|
// Dead end and no response in too long, do cleanup
|
||||||
delete(sinfo.core.searches.searches, sinfo.dest)
|
delete(sinfo.core.searches.searches, sinfo.dest)
|
||||||
sinfo.callback(nil, errors.New("search reached dead end"))
|
sinfo.callback(nil, errors.New("search reached dead end"))
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Send to the next search target
|
// Send to the next search target
|
||||||
@ -141,6 +145,7 @@ func (sinfo *searchInfo) doSearchStep() {
|
|||||||
rq := dhtReqKey{next.key, sinfo.dest}
|
rq := dhtReqKey{next.key, sinfo.dest}
|
||||||
sinfo.core.dht.addCallback(&rq, sinfo.handleDHTRes)
|
sinfo.core.dht.addCallback(&rq, sinfo.handleDHTRes)
|
||||||
sinfo.core.dht.ping(next, &sinfo.dest)
|
sinfo.core.dht.ping(next, &sinfo.dest)
|
||||||
|
sinfo.time = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we've recenty sent a ping for this search, do nothing.
|
// If we've recenty sent a ping for this search, do nothing.
|
||||||
|
Loading…
Reference in New Issue
Block a user