mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 14:45:07 +03:00
switch parents if the peer's path to the root is both lower latency and shorter in number of hops
This commit is contained in:
parent
0b273d9dd8
commit
be513d8670
1 changed files with 8 additions and 5 deletions
|
@ -380,7 +380,7 @@ func (t *switchTable) unlockedHandleMsg(msg *switchMsg, fromPort switchPort, rep
|
||||||
lag = now.Sub(t.time)
|
lag = now.Sub(t.time)
|
||||||
}
|
}
|
||||||
// Exponentially weighted average latency from last 8 updates
|
// Exponentially weighted average latency from last 8 updates
|
||||||
sender.cost -= sender.cost / 8
|
sender.cost *= 7 / 8
|
||||||
sender.cost += lag / 8
|
sender.cost += lag / 8
|
||||||
}
|
}
|
||||||
if !equiv(&sender.locator, &oldSender.locator) {
|
if !equiv(&sender.locator, &oldSender.locator) {
|
||||||
|
@ -417,8 +417,6 @@ func (t *switchTable) unlockedHandleMsg(msg *switchMsg, fromPort switchPort, rep
|
||||||
// This is not the same root, and it's apparently not better (from the above), so we should ignore it.
|
// This is not the same root, and it's apparently not better (from the above), so we should ignore it.
|
||||||
case t.data.locator.tstamp > sender.locator.tstamp:
|
case t.data.locator.tstamp > sender.locator.tstamp:
|
||||||
// This timetsamp is older than the most recently seen one from this root, so we should ignore it.
|
// This timetsamp is older than the most recently seen one from this root, so we should ignore it.
|
||||||
case now.Sub(t.time) < switch_throttle:
|
|
||||||
// We've already gotten an update from this root recently, so ignore this one to avoid flooding.
|
|
||||||
case noParent:
|
case noParent:
|
||||||
// We currently have no working parent, so update.
|
// We currently have no working parent, so update.
|
||||||
updateRoot = true
|
updateRoot = true
|
||||||
|
@ -429,7 +427,7 @@ func (t *switchTable) unlockedHandleMsg(msg *switchMsg, fromPort switchPort, rep
|
||||||
updateRoot = true
|
updateRoot = true
|
||||||
case sender.port != t.parent:
|
case sender.port != t.parent:
|
||||||
// Ignore further cases if the sender isn't our parent.
|
// Ignore further cases if the sender isn't our parent.
|
||||||
case !equiv(&sender.locator, &t.data.locator):
|
case sender.port == t.parent && !equiv(&sender.locator, &t.data.locator):
|
||||||
// Special case
|
// Special case
|
||||||
// If coords changed, then this may now be a worse parent than before
|
// If coords changed, then this may now be a worse parent than before
|
||||||
// Re-parent the node (de-parent and reprocess the message)
|
// Re-parent the node (de-parent and reprocess the message)
|
||||||
|
@ -440,7 +438,12 @@ func (t *switchTable) unlockedHandleMsg(msg *switchMsg, fromPort switchPort, rep
|
||||||
for _, info := range t.data.peers {
|
for _, info := range t.data.peers {
|
||||||
t.unlockedHandleMsg(&info.msg, info.port, true)
|
t.unlockedHandleMsg(&info.msg, info.port, true)
|
||||||
}
|
}
|
||||||
case sender.locator.tstamp > t.data.locator.tstamp:
|
case now.Sub(t.time) < switch_throttle:
|
||||||
|
// We've already gotten an update from this root recently, so ignore this one to avoid flooding.
|
||||||
|
case sender.cost <= oldParent.cost && len(sender.locator.coords) < len(oldParent.locator.coords):
|
||||||
|
// The latency is at least as good and the sender's path is shorter.
|
||||||
|
updateRoot = true
|
||||||
|
case sender.port == t.parent && sender.locator.tstamp > t.data.locator.tstamp:
|
||||||
// The timestamp was updated, so we need to update locally and send to our peers.
|
// The timestamp was updated, so we need to update locally and send to our peers.
|
||||||
updateRoot = true
|
updateRoot = true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue