Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BandWidthRateLimiter ¶
type BandWidthRateLimiter struct {
*ratelimiter.RateLimiter
}
BandWidthRateLimiter unicast rate limiter that limits the bandwidth that can be sent by a peer per some configured interval.
func NewBandWidthRateLimiter ¶
func NewBandWidthRateLimiter(limit rate.Limit, burst int, lockout time.Duration, opts ...p2p.RateLimiterOpt) *BandWidthRateLimiter
NewBandWidthRateLimiter returns a new BandWidthRateLimiter. The cleanup loop will be started in a separate goroutine and should be stopped by calling Close.
func (*BandWidthRateLimiter) Allow ¶
func (b *BandWidthRateLimiter) Allow(peerID peer.ID, msgSize int) bool
Allow checks the cached limiter for the peer and returns limiter.AllowN(msg.Size()) which will check if a peer is able to send a message of msg.Size(). If a limiter is not cached one is created.
type NoopRateLimiter ¶
func NewNoopRateLimiter ¶
func NewNoopRateLimiter() *NoopRateLimiter
func (*NoopRateLimiter) IsRateLimited ¶
func (n *NoopRateLimiter) IsRateLimited(peer.ID) bool
func (*NoopRateLimiter) Start ¶
func (n *NoopRateLimiter) Start(irrecoverable.SignalerContext)
type OnRateLimitedPeerFunc ¶
type RateLimitReason ¶
type RateLimitReason string
var ( ReasonMessageCount RateLimitReason = "messagecount" ReasonBandwidth RateLimitReason = "bandwidth" )
func (RateLimitReason) String ¶
func (r RateLimitReason) String() string
type RateLimiters ¶
type RateLimiters struct { MessageRateLimiter p2p.RateLimiter BandWidthRateLimiter p2p.RateLimiter // contains filtered or unexported fields }
RateLimiters used to manage stream and bandwidth rate limiters
func NewRateLimiters ¶
func NewRateLimiters(opts ...RateLimitersOption) *RateLimiters
NewRateLimiters returns *RateLimiters
func NoopRateLimiters ¶
func NoopRateLimiters() *RateLimiters
NoopRateLimiters returns noop rate limiters.
func (*RateLimiters) BandwidthAllowed ¶
func (r *RateLimiters) BandwidthAllowed(peerID peer.ID, originRole string, msgSize int, msgType string, msgTopic channels.Topic) bool
BandwidthAllowed will return result from BandWidthRateLimiter.Allow. It will invoke the OnRateLimitedPeerFunc callback each time a peer is not allowed.
func (*RateLimiters) Limiters ¶ added in v0.30.0
func (r *RateLimiters) Limiters() []p2p.RateLimiter
Limiters returns list of all underlying rate limiters.
func (*RateLimiters) MessageAllowed ¶
func (r *RateLimiters) MessageAllowed(peerID peer.ID) bool
MessageAllowed will return result from MessageRateLimiter.Allow. It will invoke the OnRateLimitedPeerFunc callback each time a peer is not allowed.
type RateLimitersOption ¶
type RateLimitersOption func(*RateLimiters)
func WithBandwidthRateLimiter ¶ added in v0.30.0
func WithBandwidthRateLimiter(bandwidthLimiter p2p.RateLimiter) RateLimitersOption
func WithDisabledRateLimiting ¶
func WithDisabledRateLimiting(disabled bool) RateLimitersOption
func WithMessageRateLimiter ¶ added in v0.30.0
func WithMessageRateLimiter(messageLimiter p2p.RateLimiter) RateLimitersOption
func WithNotifier ¶ added in v0.30.0
func WithNotifier(notifier p2p.RateLimiterConsumer) RateLimitersOption
type UnicastRateLimiterDistributor ¶ added in v0.30.0
type UnicastRateLimiterDistributor struct {
// contains filtered or unexported fields
}
UnicastRateLimiterDistributor subscribes to rate limited peer events from RateLimiters.
func NewUnicastRateLimiterDistributor ¶ added in v0.30.0
func NewUnicastRateLimiterDistributor() *UnicastRateLimiterDistributor
NewUnicastRateLimiterDistributor returns a new UnicastRateLimiterDistributor.
func (*UnicastRateLimiterDistributor) AddConsumer ¶ added in v0.30.0
func (r *UnicastRateLimiterDistributor) AddConsumer(consumer p2p.RateLimiterConsumer)
AddConsumer adds a consumer to the consumers list.
func (*UnicastRateLimiterDistributor) OnRateLimitedPeer ¶ added in v0.30.0
func (r *UnicastRateLimiterDistributor) OnRateLimitedPeer(pid peer.ID, role, msgType, topic, reason string)
OnRateLimitedPeer invokes each consumer callback with the rate limited peer info.