mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	Update comments in handleIn, add switch_getFlowLabelFromCoords helper (in case it is useful if we try to consider flowlabels in multi-link scenarios)
This commit is contained in:
		
							parent
							
								
									382c2e6546
								
							
						
					
					
						commit
						5b054766a2
					
				
					 1 changed files with 25 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -630,6 +630,16 @@ func switch_getPacketStreamID(packet []byte) string {
 | 
			
		|||
	return string(switch_getPacketCoords(packet))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Returns the flowlabel from a given set of coords
 | 
			
		||||
func switch_getFlowLabelFromCoords(in []byte) []byte {
 | 
			
		||||
	for i, v := range in {
 | 
			
		||||
		if v == 0 {
 | 
			
		||||
			return in[i+1:]
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return []byte{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Find the best port for a given set of coords
 | 
			
		||||
func (t *switchTable) bestPortForCoords(coords []byte) switchPort {
 | 
			
		||||
	table := t.getTable()
 | 
			
		||||
| 
						 | 
				
			
			@ -667,20 +677,28 @@ func (t *switchTable) handleIn(packet []byte, idle map[switchPort]time.Time) boo
 | 
			
		|||
		var update bool
 | 
			
		||||
		switch {
 | 
			
		||||
		case to == nil:
 | 
			
		||||
			//nothing
 | 
			
		||||
			// no port was found, ignore it
 | 
			
		||||
		case !isIdle:
 | 
			
		||||
			//nothing
 | 
			
		||||
			// the port is busy, ignore it
 | 
			
		||||
		case best == nil:
 | 
			
		||||
			// this is the first idle port we've found, so select it until we find a
 | 
			
		||||
			// better candidate port to use instead
 | 
			
		||||
			update = true
 | 
			
		||||
		case cinfo.dist < bestDist:
 | 
			
		||||
			// the port takes a shorter path/is more direct than our current
 | 
			
		||||
			// candidate, so select that instead
 | 
			
		||||
			update = true
 | 
			
		||||
		case cinfo.dist > bestDist:
 | 
			
		||||
			//nothing
 | 
			
		||||
			// the port takes a longer path/is less direct than our current candidate,
 | 
			
		||||
			// ignore it
 | 
			
		||||
		case thisTime.After(bestTime):
 | 
			
		||||
			// Pick the one that was used most recently -- at least this should pick the same link consistently in low-traffic scenarios
 | 
			
		||||
			// all else equal, this port was used more recently than our current
 | 
			
		||||
			// candidate, so choose that instead. this should mean that, in low
 | 
			
		||||
			// traffic scenarios, we consistently pick the same link which helps with
 | 
			
		||||
			// packet ordering
 | 
			
		||||
			update = true
 | 
			
		||||
		default:
 | 
			
		||||
			//nothing
 | 
			
		||||
			// the search for a port has finished
 | 
			
		||||
		}
 | 
			
		||||
		if update {
 | 
			
		||||
			best = to
 | 
			
		||||
| 
						 | 
				
			
			@ -693,11 +711,10 @@ func (t *switchTable) handleIn(packet []byte, idle map[switchPort]time.Time) boo
 | 
			
		|||
		delete(idle, best.port)
 | 
			
		||||
		best.sendPacket(packet)
 | 
			
		||||
		return true
 | 
			
		||||
	} else {
 | 
			
		||||
	}
 | 
			
		||||
	// Didn't find anyone idle to send it to
 | 
			
		||||
	return false
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Info about a buffered packet
 | 
			
		||||
type switch_packetInfo struct {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue