fix(backend): correct speed limit unit conversion from Mbps to Bytes/s

This commit is contained in:
sagit
2026-02-09 06:13:56 +00:00
parent 0c7b7deaf5
commit 67d8f7a381
2 changed files with 9 additions and 1 deletions
@@ -1045,7 +1045,10 @@ func buildForwardServiceConfigs(baseName string, forward *forwardRecord, tunnel
service["metadata"] = map[string]interface{}{"interface": node.InterfaceName}
}
if limiter != nil && *limiter > 0 {
service["limiter"] = strconv.Itoa(*limiter)
// Convert Mbps to Bytes/s
// 1 Mbps = 1,000,000 bits/s = 125,000 Bytes/s
// We use decimal Mbps standard as is common in networking
service["limiter"] = strconv.Itoa(*limiter * 125000)
}
services = append(services, service)
}
@@ -193,6 +193,11 @@ func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
xtraffic.LimitsOption(fmt.Sprintf("%s %d %d", xtraffic.ServiceLimitKey, val, val)),
)
}
if lim == nil {
lim = xtraffic.NewTrafficLimiter(
xtraffic.LimitsOption(fmt.Sprintf("%s %s %s", xtraffic.ServiceLimitKey, cfg.Limiter, cfg.Limiter)),
)
}
}
trafficLimiter = listener.TrafficLimiterOption(
cache_limiter.NewCachedTrafficLimiter(