platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
46
selective-vpn-api/app/transport_health_refresh_compare.go
Normal file
46
selective-vpn-api/app/transport_health_refresh_compare.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func transportShouldPersistHealthSnapshot(prev, next TransportClient, now time.Time) bool {
|
||||
if transportHealthChanged(prev, next) {
|
||||
return true
|
||||
}
|
||||
prevTS, ok := parseTransportHealthLastCheck(prev)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
return now.Sub(prevTS) >= transportHealthPersistMinAge
|
||||
}
|
||||
|
||||
func transportHealthChanged(prev, next TransportClient) bool {
|
||||
if normalizeTransportStatus(prev.Status) != normalizeTransportStatus(next.Status) {
|
||||
return true
|
||||
}
|
||||
if strings.TrimSpace(prev.Health.LastError) != strings.TrimSpace(next.Health.LastError) {
|
||||
return true
|
||||
}
|
||||
if transportHealthLatencyBucket(prev.Health.LatencyMS) != transportHealthLatencyBucket(next.Health.LatencyMS) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func transportHealthLatencyBucket(ms int) string {
|
||||
if ms <= 0 {
|
||||
return "none"
|
||||
}
|
||||
switch {
|
||||
case ms < 100:
|
||||
return "lt100"
|
||||
case ms < 300:
|
||||
return "100-299"
|
||||
case ms < 800:
|
||||
return "300-799"
|
||||
default:
|
||||
return "ge800"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user