From c9d6366d75f6b23466464675123daf11a0a0313c Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Fri, 5 Oct 2018 08:22:47 +0200 Subject: [PATCH] lib/connections: Don't info log about LAN if there are no rate limits (#5242) --- lib/connections/limiter.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/connections/limiter.go b/lib/connections/limiter.go index e14e25ae7..8dc17d5f9 100644 --- a/lib/connections/limiter.go +++ b/lib/connections/limiter.go @@ -134,36 +134,38 @@ func (lim *limiter) CommitConfiguration(from, to config.Configuration) bool { return true } + limited := false + sendLimitStr := "is unlimited" + recvLimitStr := "is unlimited" + // The rate variables are in KiB/s in the config (despite the camel casing // of the name). We multiply by 1024 to get bytes/s. if to.Options.MaxRecvKbps <= 0 { lim.read.SetLimit(rate.Inf) } else { lim.read.SetLimit(1024 * rate.Limit(to.Options.MaxRecvKbps)) + recvLimitStr = fmt.Sprintf("limit is %d KiB/s", to.Options.MaxRecvKbps) + limited = true } if to.Options.MaxSendKbps <= 0 { lim.write.SetLimit(rate.Inf) } else { lim.write.SetLimit(1024 * rate.Limit(to.Options.MaxSendKbps)) + sendLimitStr = fmt.Sprintf("limit is %d KiB/s", to.Options.MaxSendKbps) + limited = true } lim.limitsLAN.set(to.Options.LimitBandwidthInLan) - sendLimitStr := "is unlimited" - recvLimitStr := "is unlimited" - if to.Options.MaxSendKbps > 0 { - sendLimitStr = fmt.Sprintf("limit is %d KiB/s", to.Options.MaxSendKbps) - } - if to.Options.MaxRecvKbps > 0 { - recvLimitStr = fmt.Sprintf("limit is %d KiB/s", to.Options.MaxRecvKbps) - } l.Infof("Overall send rate %s, receive rate %s", sendLimitStr, recvLimitStr) - if to.Options.LimitBandwidthInLan { - l.Infoln("Rate limits apply to LAN connections") - } else { - l.Infoln("Rate limits do not apply to LAN connections") + if limited { + if to.Options.LimitBandwidthInLan { + l.Infoln("Rate limits apply to LAN connections") + } else { + l.Infoln("Rate limits do not apply to LAN connections") + } } return true