mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	consistently prioritize which peer to forward to instead of letting it be partly random
This commit is contained in:
		
							parent
							
								
									74ac535d55
								
							
						
					
					
						commit
						21cecf4630
					
				
					 1 changed files with 25 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -645,20 +645,39 @@ func (t *switchTable) handleIn(packet []byte, idle map[switchPort]struct{}) bool
 | 
			
		|||
		ports[0].sendPacket(packet)
 | 
			
		||||
		return true
 | 
			
		||||
	}
 | 
			
		||||
	table := t.getTable()
 | 
			
		||||
	var best *peer
 | 
			
		||||
	var bestDist int
 | 
			
		||||
	var bestCoordLen int
 | 
			
		||||
	for port, dist := range closer {
 | 
			
		||||
		to := ports[port]
 | 
			
		||||
		_, isIdle := idle[port]
 | 
			
		||||
		coordLen := len(table.elems[port].locator.coords)
 | 
			
		||||
		var update bool
 | 
			
		||||
		switch {
 | 
			
		||||
		case to == nil: // skip
 | 
			
		||||
		case !isIdle: // skip
 | 
			
		||||
		case best == nil: // keep
 | 
			
		||||
			fallthrough
 | 
			
		||||
		case dist < bestDist: // keep
 | 
			
		||||
		case to == nil:
 | 
			
		||||
			//nothing
 | 
			
		||||
		case !isIdle:
 | 
			
		||||
			//nothing
 | 
			
		||||
		case best == nil:
 | 
			
		||||
			update = true
 | 
			
		||||
		case dist < bestDist:
 | 
			
		||||
			update = true
 | 
			
		||||
		case dist > bestDist:
 | 
			
		||||
			//nothing
 | 
			
		||||
		case coordLen < bestCoordLen:
 | 
			
		||||
			update = true
 | 
			
		||||
		case coordLen > bestCoordLen:
 | 
			
		||||
			//nothing
 | 
			
		||||
		case port < best.port:
 | 
			
		||||
			update = true
 | 
			
		||||
		default:
 | 
			
		||||
			//nothing
 | 
			
		||||
		}
 | 
			
		||||
		if update {
 | 
			
		||||
			best = to
 | 
			
		||||
			bestDist = dist
 | 
			
		||||
		default: // skip
 | 
			
		||||
			bestCoordLen = coordLen
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if best != nil {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue