mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	sort search response results before sending requests
This commit is contained in:
		
							parent
							
								
									0da433f5d2
								
							
						
					
					
						commit
						70659bfb91
					
				
					 1 changed files with 6 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -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())
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue