ignore root tstamp updates if we just updated, to throttle the rate at which updates (and new signatures) can propagate

This commit is contained in:
Arceliar 2018-02-17 23:57:24 -06:00
parent a66a29779a
commit 71150fcb86

View File

@ -11,11 +11,6 @@ package yggdrasil
// TODO? use a pre-computed lookup table (python version had this) // TODO? use a pre-computed lookup table (python version had this)
// A little annoying to do with constant changes from bandwidth estimates // A little annoying to do with constant changes from bandwidth estimates
// FIXME (!) throttle how often root updates are accepted
// If the root starts spaming with new timestamps, it should only affect their neighbors
// The rest of the network should see announcements at a somewhat reasonable rate
// Maybe no faster than 2x the usual update interval
import "time" import "time"
import "sync" import "sync"
import "sync/atomic" import "sync/atomic"
@ -23,6 +18,8 @@ import "sync/atomic"
//import "fmt" //import "fmt"
const switch_timeout = time.Minute const switch_timeout = time.Minute
const switch_updateInterval = switch_timeout / 2
const switch_throttle = switch_updateInterval / 2
// You should be able to provide crypto signatures for this // You should be able to provide crypto signatures for this
// 1 signature per coord, from the *sender* to that coord // 1 signature per coord, from the *sender* to that coord
@ -219,7 +216,7 @@ func (t *switchTable) cleanRoot() {
} }
// Or, if we are the root, possibly update our timestamp // Or, if we are the root, possibly update our timestamp
if t.data.locator.root == t.key && if t.data.locator.root == t.key &&
now.Sub(t.time) > switch_timeout/2 { now.Sub(t.time) > switch_updateInterval {
//fmt.Println("root is self and old, updating", t.data.locator.Root) //fmt.Println("root is self and old, updating", t.data.locator.Root)
doUpdate = true doUpdate = true
} }
@ -343,9 +340,11 @@ func (t *switchTable) handleMessage(msg *switchMessage, fromPort switchPort, sig
updateRoot = true updateRoot = true
case cost < pCost: case cost < pCost:
updateRoot = true updateRoot = true
case sender.port == t.parent && case sender.port != t.parent: // do nothing
(msg.locator.tstamp > t.data.locator.tstamp || case !equiv(&msg.locator, &t.data.locator):
!equiv(&msg.locator, &t.data.locator)): updateRoot = true
case now.Sub(t.time) < switch_throttle: // do nothing
case msg.locator.tstamp > t.data.locator.tstamp:
updateRoot = true updateRoot = true
} }
if updateRoot { if updateRoot {