From df30e067b22f5077266ddb22f17a06a8e2c15ce2 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 17 Nov 2018 20:57:50 -0600 Subject: [PATCH] limit how much switch cost can be changed by any 1 message --- src/yggdrasil/switch.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index a14d65d6..da29b8d8 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -372,19 +372,33 @@ func (t *switchTable) unlockedHandleMsg(msg *switchMsg, fromPort switchPort, rep // Reset the cost sender.cost = 0 } else if sender.locator.tstamp > oldSender.locator.tstamp { + var lag time.Duration if sender.locator.tstamp > t.data.locator.tstamp { // Latency based on how early the last message arrived before the parent's - sender.cost += oldSender.time.Sub(t.time) + lag = oldSender.time.Sub(t.time) } else { // Waiting this long cost us something - sender.cost += now.Sub(t.time) + lag = now.Sub(t.time) } + // Limit how much lag can affect things from a single packet + if lag > switch_parent_threshold/8 { + lag = switch_parent_threshold / 8 + } + if lag < -switch_parent_threshold/8 { + lag = -switch_parent_threshold / 8 + } + sender.cost += lag + // Limit how much the cost can move in total if sender.cost < -switch_parent_threshold { sender.cost = -switch_parent_threshold } if sender.cost > switch_parent_threshold { sender.cost = switch_parent_threshold } + if sender.port == t.parent { + // But always reset the parent's cost to 0, by definition + sender.cost = 0 + } } if !equiv(&sender.locator, &oldSender.locator) { doUpdate = true