mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-25 23:01:38 +00:00
consistently prioritize which peer to forward to instead of letting it be partly random
This commit is contained in:
parent
74ac535d55
commit
21cecf4630
@ -645,20 +645,39 @@ func (t *switchTable) handleIn(packet []byte, idle map[switchPort]struct{}) bool
|
|||||||
ports[0].sendPacket(packet)
|
ports[0].sendPacket(packet)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
table := t.getTable()
|
||||||
var best *peer
|
var best *peer
|
||||||
var bestDist int
|
var bestDist int
|
||||||
|
var bestCoordLen int
|
||||||
for port, dist := range closer {
|
for port, dist := range closer {
|
||||||
to := ports[port]
|
to := ports[port]
|
||||||
_, isIdle := idle[port]
|
_, isIdle := idle[port]
|
||||||
|
coordLen := len(table.elems[port].locator.coords)
|
||||||
|
var update bool
|
||||||
switch {
|
switch {
|
||||||
case to == nil: // skip
|
case to == nil:
|
||||||
case !isIdle: // skip
|
//nothing
|
||||||
case best == nil: // keep
|
case !isIdle:
|
||||||
fallthrough
|
//nothing
|
||||||
case dist < bestDist: // keep
|
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
|
best = to
|
||||||
bestDist = dist
|
bestDist = dist
|
||||||
default: // skip
|
bestCoordLen = coordLen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if best != nil {
|
if best != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user