ratevalidator

package
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2019 License: Apache-2.0 Imports: 9 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// MyPeerID is the peer ID of the host. Messages where From == MyPeerID will
	// not be rate limited and will not be counted toward the global or per-peer
	// limits.
	MyPeerID peer.ID
	// GlobalLimit is the maximum rate of messages per second across all peers.
	GlobalLimit rate.Limit
	// GlobalBurst is the maximum number of messages that can be received at once
	// from all peers.
	GlobalBurst int
	// PerPeerLimit is the maximum rate of messages for each peer.
	PerPeerLimit rate.Limit
	// PerPeerBurst is the maximum number of messages that can be received at once
	// from each peer.
	PerPeerBurst int
	// MaxMessageSize is the maximum size (in bytes) for a message. Any messages
	// that exceed this size will be considered invalid.
	MaxMessageSize int
}

Config is a set of configuration options for the validator.

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator is a rate limiting pubsub validator that only allows messages to be sent at a certain rate.

func New

func New(ctx context.Context, config Config) (*Validator, error)

New creates and returns a new rate limiting validator. BUG(albrow): New currently leaks goroutines due to a limitation of the caching library used under the hood.

func (*Validator) Validate

func (v *Validator) Validate(ctx context.Context, peerID peer.ID, msg *pubsub.Message) bool

Validate validates a pubsub message based solely on the rate of messages received. If either the global or per-peer limits are exceeded, the message is considered "invalid" and will be dropped.

Notes

Bugs

  • New currently leaks goroutines due to a limitation of the caching library used under the hood.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL