CheckAnyShouldUpdate

This commit is contained in:
KusakabeSi 2021-10-14 10:37:09 +00:00
parent 157c218d30
commit fd80661060
12 changed files with 31 additions and 4 deletions

View File

@ -753,10 +753,12 @@ func (device *Device) RoutineRecalculateNhTable() {
}
if device.IsSuperNode {
for {
if device.graph.CheckAnyShouldUpdate() {
changed := device.graph.RecalculateNhTable(true)
if changed {
device.Event_server_NhTable_changed <- struct{}{}
}
}
time.Sleep(device.graph.TimeoutCheckInterval)
}
} else {
@ -765,8 +767,10 @@ func (device *Device) RoutineRecalculateNhTable() {
}
for {
if time.Now().After(device.graph.NhTableExpire) {
if device.graph.CheckAnyShouldUpdate() {
device.graph.RecalculateNhTable(false)
}
}
time.Sleep(device.graph.TimeoutCheckInterval)
}
}

View File

@ -44,6 +44,7 @@ dynamicroute:
jittertolerance: 20
jittertolerancemultiplier: 1.1
nodereporttimeout: 40
timeoutcheckinterval: 5
recalculatecooldown: 5
ntpconfig:
usentp: true

View File

@ -44,6 +44,7 @@ dynamicroute:
jittertolerance: 20
jittertolerancemultiplier: 1.1
nodereporttimeout: 40
timeoutcheckinterval: 5
recalculatecooldown: 5
ntpconfig:
usentp: true

View File

@ -44,6 +44,7 @@ dynamicroute:
jittertolerance: 20
jittertolerancemultiplier: 1.1
nodereporttimeout: 40
timeoutcheckinterval: 5
recalculatecooldown: 5
ntpconfig:
usentp: true

View File

@ -44,6 +44,7 @@ dynamicroute:
jittertolerance: 20
jittertolerancemultiplier: 1.1
nodereporttimeout: 40
timeoutcheckinterval: 5
recalculatecooldown: 5
ntpconfig:
usentp: true

View File

@ -44,6 +44,7 @@ dynamicroute:
jittertolerance: 20
jittertolerancemultiplier: 1.1
nodereporttimeout: 40
timeoutcheckinterval: 5
recalculatecooldown: 5
ntpconfig:
usentp: true

View File

@ -44,6 +44,7 @@ dynamicroute:
jittertolerance: 20
jittertolerancemultiplier: 1.1
nodereporttimeout: 40
timeoutcheckinterval: 5
recalculatecooldown: 5
ntpconfig:
usentp: true

View File

@ -428,6 +428,7 @@ Return value:
1. jittertolerancemultiplier: the same is the jitter tolerance, but high ping allows more errors
https://www.desmos.com/calculator/raoti16r5n
1. nodereporttimeout: The timeout of the received `Pong` packet. Change back to Infinity after timeout.
1. timeoutcheckinterval: The interval to check if there any `Pong` packet timeouted, and recalculate the NhTable
1. nexthoptable: only works in `staticmode==true`, set nexthoptable manually
1. edgetemplate: for `addpeer` API. Refer to this configuration file and show a sample configuration file of the edge to the user
1. usepskforinteredge: Whether to enable pre-share key communication between edges. If enabled, supernode will generate PSKs for edges automatically

View File

@ -431,6 +431,7 @@ curl "http://127.0.0.1:3000/api/peer/del?privkey=IJtpnkm9ytbuCukx4VBMENJKuLngo9K
1. jittertolerancemultiplier: 一樣是抖動容許誤差但是高ping的話允許更多誤差
https://www.desmos.com/calculator/raoti16r5n
1. nodereporttimeout: 收到的`Pong`封包的有效期限。太久沒收到就變回Infinity
1. timeoutcheckinterval: 固定間格檢查有沒有人的Pong封包超過有效期限要重算轉發表
1. nexthoptable: 僅在`staticmode==true` 有效手動設定的nexthoptable
1. edgetemplate: 給`addpeer`API用的。參考這個設定檔顯示一個範例設定檔給edge
1. usepskforinteredge: 是否啟用edge間pre shares key通信。若啟用則幫edge們自動生成PSK

View File

@ -45,6 +45,7 @@ dynamicroute:
jittertolerance: 20
jittertolerancemultiplier: 1.1
nodereporttimeout: 40
timeoutcheckinterval: 5
recalculatecooldown: 5
ntpconfig:
usentp: true

View File

@ -45,6 +45,7 @@ dynamicroute:
jittertolerance: 20
jittertolerancemultiplier: 1.1
nodereporttimeout: 40
timeoutcheckinterval: 5
recalculatecooldown: 5
ntpconfig:
usentp: true

View File

@ -110,6 +110,19 @@ func (g *IG) ShouldUpdate(u config.Vertex, v config.Vertex, newval float64) bool
}
}
func (g *IG) CheckAnyShouldUpdate() bool {
vert := g.Vertices()
for u, _ := range vert {
for v, _ := range vert {
newVal := g.Weight(u, v)
if g.ShouldUpdate(u, v, newVal) {
return true
}
}
}
return false
}
func (g *IG) RecalculateNhTable(checkchange bool) (changed bool) {
if g.StaticMode {
if bytes.Equal(g.NhTableHash[:], make([]byte, 32)) {