Skip to content

Commit

Permalink
Fix bug #6022
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Litvinov <[email protected]>
  • Loading branch information
Zensey committed Sep 5, 2024
1 parent ac0db4e commit f113c91
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions services/wireguard/endpoint/netstack-provider/shaper_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@
package netstack_provider

import (
"time"

"github.com/mysteriumnetwork/node/config"
"github.com/mysteriumnetwork/node/eventbus"
"github.com/rs/zerolog/log"
"golang.org/x/time/rate"
)

const AppTopicConfigShaper = "config:shaper"
const (
AppTopicConfigShaper = "config:shaper"
BurstLimit = 1000 * 1000 * 1000
)

var rateLimiter *rate.Limiter

Expand All @@ -33,7 +38,7 @@ func getRateLimitter() *rate.Limiter {
}

func InitUserspaceShaper(eventBus eventbus.EventBus) {
applyLimits := func(e interface{}) {
applyLimits := func(_ interface{}) {
bandwidthBytes := config.GetUInt64(config.FlagShaperBandwidth) * 1024
bandwidth := rate.Limit(bandwidthBytes)
if !config.GetBool(config.FlagShaperEnabled) {
Expand All @@ -43,9 +48,14 @@ func InitUserspaceShaper(eventBus eventbus.EventBus) {
rateLimiter.SetLimit(bandwidth)
}

rateLimiter = rate.NewLimiter(rate.Inf, 0)
rateLimiter = rate.NewLimiter(rate.Inf, BurstLimit)
rateLimiter.AllowN(time.Now(), BurstLimit) // spend initial burst

applyLimits(nil)

if eventBus == nil {
return
}
err := eventBus.SubscribeAsync(AppTopicConfigShaper, applyLimits)
if err != nil {
log.Error().Msgf("could not subscribe to topic: %v", err)
Expand Down

0 comments on commit f113c91

Please sign in to comment.