mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-27 12:05:23 +00:00
more search fixes/updates
This commit is contained in:
parent
cd856426e5
commit
7c2cb9a02d
@ -83,7 +83,6 @@ func (sinfo *searchInfo) handleDHTRes(res *dhtRes) {
|
|||||||
if res != nil {
|
if res != nil {
|
||||||
sinfo.recv++
|
sinfo.recv++
|
||||||
if sinfo.checkDHTRes(res) {
|
if sinfo.checkDHTRes(res) {
|
||||||
sinfo.searches.router.core.log.Debugln("Finished search:", sinfo.dest, sinfo.send, sinfo.recv)
|
|
||||||
return // Search finished successfully
|
return // Search finished successfully
|
||||||
}
|
}
|
||||||
// Add results to the search
|
// Add results to the search
|
||||||
@ -97,15 +96,9 @@ func (sinfo *searchInfo) handleDHTRes(res *dhtRes) {
|
|||||||
|
|
||||||
// Adds the information from a dhtRes to an ongoing search.
|
// Adds the information from a dhtRes to an ongoing search.
|
||||||
// Info about a node that has already been visited is not re-added to the search.
|
// Info about a node that has already been visited is not re-added to the search.
|
||||||
// Duplicate information about nodes toVisit is deduplicated (the newest information is kept).
|
|
||||||
func (sinfo *searchInfo) addToSearch(res *dhtRes) {
|
func (sinfo *searchInfo) addToSearch(res *dhtRes) {
|
||||||
|
// Add to search
|
||||||
for _, info := range res.Infos {
|
for _, info := range res.Infos {
|
||||||
if *info.getNodeID() == sinfo.visited {
|
|
||||||
// dht_ordered could return true here, but we want to skip it in this case
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if dht_ordered(&sinfo.dest, info.getNodeID(), &sinfo.visited) && *info.getNodeID() != sinfo.visited {
|
|
||||||
// Response is closer to the destination
|
|
||||||
sinfo.toVisit = append(sinfo.toVisit, info)
|
sinfo.toVisit = append(sinfo.toVisit, info)
|
||||||
}
|
}
|
||||||
// Sort
|
// Sort
|
||||||
@ -113,6 +106,12 @@ func (sinfo *searchInfo) addToSearch(res *dhtRes) {
|
|||||||
// Should return true if i is closer to the destination than j
|
// Should return true if i is closer to the destination than j
|
||||||
return dht_ordered(&sinfo.dest, sinfo.toVisit[i].getNodeID(), sinfo.toVisit[j].getNodeID())
|
return dht_ordered(&sinfo.dest, sinfo.toVisit[i].getNodeID(), sinfo.toVisit[j].getNodeID())
|
||||||
})
|
})
|
||||||
|
// Remove anything too far away
|
||||||
|
for idx, info := range sinfo.toVisit {
|
||||||
|
if *info.getNodeID() == sinfo.visited || !dht_ordered(&sinfo.dest, info.getNodeID(), &sinfo.visited) {
|
||||||
|
sinfo.toVisit = sinfo.toVisit[:idx]
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +173,7 @@ func (s *searches) newIterSearch(dest *crypto.NodeID, mask *crypto.NodeID, callb
|
|||||||
// Otherwise return false.
|
// Otherwise return false.
|
||||||
func (sinfo *searchInfo) checkDHTRes(res *dhtRes) bool {
|
func (sinfo *searchInfo) checkDHTRes(res *dhtRes) bool {
|
||||||
from := dhtInfo{key: res.Key, coords: res.Coords}
|
from := dhtInfo{key: res.Key, coords: res.Coords}
|
||||||
if dht_ordered(&sinfo.dest, from.getNodeID(), &sinfo.visited) {
|
if *from.getNodeID() != sinfo.visited && dht_ordered(&sinfo.dest, from.getNodeID(), &sinfo.visited) {
|
||||||
// Closer to the destination, so update visited
|
// Closer to the destination, so update visited
|
||||||
sinfo.searches.router.core.log.Debugln("Updating search:", sinfo.dest, *from.getNodeID(), sinfo.send, sinfo.recv)
|
sinfo.searches.router.core.log.Debugln("Updating search:", sinfo.dest, *from.getNodeID(), sinfo.send, sinfo.recv)
|
||||||
sinfo.visited = *from.getNodeID()
|
sinfo.visited = *from.getNodeID()
|
||||||
@ -202,8 +201,11 @@ func (sinfo *searchInfo) checkDHTRes(res *dhtRes) bool {
|
|||||||
sinfo.callback(sess, nil)
|
sinfo.callback(sess, nil)
|
||||||
}
|
}
|
||||||
// Cleanup
|
// Cleanup
|
||||||
|
if _, isIn := sinfo.searches.searches[sinfo.dest]; isIn {
|
||||||
|
sinfo.searches.router.core.log.Debugln("Finished search:", sinfo.dest, sinfo.send, sinfo.recv)
|
||||||
delete(sinfo.searches.searches, res.Dest)
|
delete(sinfo.searches.searches, res.Dest)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// They match, so create a session and send a sessionRequest
|
// They match, so create a session and send a sessionRequest
|
||||||
var err error
|
var err error
|
||||||
sess, isIn := sinfo.searches.router.sessions.getByTheirPerm(&res.Key)
|
sess, isIn := sinfo.searches.router.sessions.getByTheirPerm(&res.Key)
|
||||||
|
Loading…
Reference in New Issue
Block a user