github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/p2p/unicast/ratelimit/noop_rate_limiter.go (about)

     1  package ratelimit
     2  
     3  import (
     4  	"github.com/libp2p/go-libp2p/core/peer"
     5  
     6  	"github.com/onflow/flow-go/module"
     7  	"github.com/onflow/flow-go/module/component"
     8  	"github.com/onflow/flow-go/module/irrecoverable"
     9  )
    10  
    11  type NoopRateLimiter struct {
    12  	component.Component
    13  }
    14  
    15  func (n *NoopRateLimiter) Allow(peer.ID, int) bool {
    16  	return true
    17  }
    18  func (n *NoopRateLimiter) IsRateLimited(peer.ID) bool {
    19  	return false
    20  }
    21  
    22  func (n *NoopRateLimiter) Start(irrecoverable.SignalerContext) {}
    23  
    24  func NewNoopRateLimiter() *NoopRateLimiter {
    25  	return &NoopRateLimiter{
    26  		Component: &module.NoopComponent{},
    27  	}
    28  }
    29  
    30  // NoopRateLimiters returns noop rate limiters.
    31  func NoopRateLimiters() *RateLimiters {
    32  	return &RateLimiters{
    33  		MessageRateLimiter:   NewNoopRateLimiter(),
    34  		BandWidthRateLimiter: NewNoopRateLimiter(),
    35  		disabled:             true,
    36  		notifier:             NewUnicastRateLimiterDistributor(),
    37  	}
    38  }