mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	fix sim and tune dht to bootstrap a little faster
This commit is contained in:
		
							parent
							
								
									289f1ce7c2
								
							
						
					
					
						commit
						ef6cece720
					
				
					 2 changed files with 12 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -82,10 +82,16 @@ func (t *dht) lookup(nodeID *NodeID, everything bool) []*dhtInfo {
 | 
			
		|||
	for _, info := range t.table {
 | 
			
		||||
		results = append(results, info)
 | 
			
		||||
	}
 | 
			
		||||
	sort.SliceStable(results, func(i, j int) bool {
 | 
			
		||||
		return dht_ordered(nodeID, results[i].getNodeID(), results[j].getNodeID())
 | 
			
		||||
	})
 | 
			
		||||
	if len(results) > dht_lookup_size {
 | 
			
		||||
		// Drop the middle part, so we keep some nodes before and after.
 | 
			
		||||
		// This should help to bootstrap / recover more quickly.
 | 
			
		||||
		sort.SliceStable(results, func(i, j int) bool {
 | 
			
		||||
			return dht_ordered(nodeID, results[i].getNodeID(), results[j].getNodeID())
 | 
			
		||||
		})
 | 
			
		||||
		newRes := make([]*dhtInfo, 0, len(results))
 | 
			
		||||
		newRes = append(newRes, results[len(results)-dht_lookup_size/2:]...)
 | 
			
		||||
		newRes = append(newRes, results[:len(results)-dht_lookup_size/2]...)
 | 
			
		||||
		results = newRes
 | 
			
		||||
		results = results[:dht_lookup_size]
 | 
			
		||||
	}
 | 
			
		||||
	return results
 | 
			
		||||
| 
						 | 
				
			
			@ -168,7 +174,7 @@ func (t *dht) handleReq(req *dhtReq) {
 | 
			
		|||
		coords: req.Coords,
 | 
			
		||||
	}
 | 
			
		||||
	if _, isIn := t.table[*info.getNodeID()]; !isIn && t.isImportant(&info) {
 | 
			
		||||
		t.insert(&info)
 | 
			
		||||
		t.ping(&info, nil)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -276,7 +282,7 @@ func (t *dht) doMaintenance() {
 | 
			
		|||
	}
 | 
			
		||||
	for _, info := range t.getImportant() {
 | 
			
		||||
		if now.Sub(info.recv) > info.throttle {
 | 
			
		||||
			t.ping(info, info.getNodeID())
 | 
			
		||||
			t.ping(info, nil)
 | 
			
		||||
			info.pings++
 | 
			
		||||
			info.throttle += time.Second
 | 
			
		||||
			if info.throttle > 30*time.Second {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue