validation

package
v0.30.3 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultNumberOfWorkers default number of workers for the inspector component.
	DefaultNumberOfWorkers = 5
	// DefaultControlMsgValidationInspectorQueueCacheSize is the default size of the inspect message queue.
	DefaultControlMsgValidationInspectorQueueCacheSize = 100
)
View Source
const (
	// DiscardThresholdMapKey key used to set the  discard threshold config limit.
	DiscardThresholdMapKey = "discardthreshold"
	// SafetyThresholdMapKey key used to set the safety threshold config limit.
	SafetyThresholdMapKey = "safetythreshold"
	// RateLimitMapKey key used to set the rate limit config limit.
	RateLimitMapKey = "ratelimit"

	// DefaultGraftDiscardThreshold upper bound for graft messages, RPC control messages with a count
	// above the discard threshold are automatically discarded.
	DefaultGraftDiscardThreshold = 30
	// DefaultGraftSafetyThreshold a lower bound for graft messages, RPC control messages with a message count
	// lower than the safety threshold bypass validation.
	DefaultGraftSafetyThreshold = .5 * DefaultGraftDiscardThreshold
	// DefaultGraftRateLimit the rate limit for graft control messages.
	// Currently, the default rate limit is equal to the discard threshold amount.
	// This will result in a rate limit of 30 grafts/sec.
	DefaultGraftRateLimit = DefaultGraftDiscardThreshold

	// DefaultPruneDiscardThreshold upper bound for prune messages, RPC control messages with a count
	// above the discard threshold are automatically discarded.
	DefaultPruneDiscardThreshold = 30
	// DefaultPruneSafetyThreshold a lower bound for prune messages, RPC control messages with a message count
	// lower than the safety threshold bypass validation.
	DefaultPruneSafetyThreshold = .5 * DefaultPruneDiscardThreshold
	// DefaultPruneRateLimit the rate limit for prune control messages.
	// Currently, the default rate limit is equal to the discard threshold amount.
	// This will result in a rate limit of 30 prunes/sec.
	DefaultPruneRateLimit = DefaultPruneDiscardThreshold
)

Variables

This section is empty.

Functions

func IsErrDiscardThreshold

func IsErrDiscardThreshold(err error) bool

IsErrDiscardThreshold returns true if an error is ErrDiscardThreshold

func IsErrDuplicateTopic

func IsErrDuplicateTopic(err error) bool

IsErrDuplicateTopic returns true if an error is ErrDuplicateTopic

func IsErrInvalidLimitConfig

func IsErrInvalidLimitConfig(err error) bool

IsErrInvalidLimitConfig returns whether an error is ErrInvalidLimitConfig

func IsErrInvalidTopic

func IsErrInvalidTopic(err error) bool

IsErrInvalidTopic returns true if an error is ErrInvalidTopic

func IsErrRateLimitedControlMsg

func IsErrRateLimitedControlMsg(err error) bool

IsErrRateLimitedControlMsg returns whether an error is ErrRateLimitedControlMsg

Types

type ControlMsgValidationInspector

type ControlMsgValidationInspector struct {
	component.Component
	// contains filtered or unexported fields
}

ControlMsgValidationInspector RPC message inspector that inspects control messages and performs some validation on them, when some validation rule is broken feedback is given via the Peer scoring notifier.

func NewControlMsgValidationInspector

func NewControlMsgValidationInspector(
	logger zerolog.Logger,
	sporkID flow.Identifier,
	config *ControlMsgValidationInspectorConfig,
	distributor p2p.GossipSubInspectorNotificationDistributor,
) *ControlMsgValidationInspector

NewControlMsgValidationInspector returns new ControlMsgValidationInspector

func (*ControlMsgValidationInspector) Inspect

func (c *ControlMsgValidationInspector) Inspect(from peer.ID, rpc *pubsub.RPC) error

Inspect inspects the rpc received and returns an error if any validation rule is broken. For each control message type an initial inspection is done synchronously to check the amount of messages in the control message. Further inspection is done asynchronously to check rate limits and validate topic IDS each control message if initial validation is passed. All errors returned from this function can be considered benign. errors returned:

ErrDiscardThreshold - if the message count for the control message type exceeds the discard threshold.

func (*ControlMsgValidationInspector) Name

Name returns the name of the rpc inspector.

type ControlMsgValidationInspectorConfig

type ControlMsgValidationInspectorConfig struct {
	// NumberOfWorkers number of component workers to start for processing RPC messages.
	NumberOfWorkers int
	// InspectMsgStoreOpts options used to configure the underlying herocache message store.
	InspectMsgStoreOpts []queue.HeroStoreConfigOption
	// GraftValidationCfg validation configuration for GRAFT control messages.
	GraftValidationCfg *CtrlMsgValidationConfig
	// PruneValidationCfg validation configuration for PRUNE control messages.
	PruneValidationCfg *CtrlMsgValidationConfig
}

ControlMsgValidationInspectorConfig validation configuration for each type of RPC control message.

type CtrlMsgValidationConfig

type CtrlMsgValidationConfig struct {
	// ControlMsg the type of RPC control message.
	ControlMsg p2p.ControlMessageType
	// DiscardThreshold indicates the hard limit for size of the RPC control message
	// any RPC messages with size > DiscardThreshold should be dropped.
	DiscardThreshold uint64
	// SafetyThreshold lower limit for the size of the RPC control message, any RPC messages
	// with a size < SafetyThreshold can skip validation step to avoid resource wasting.
	SafetyThreshold uint64

	// RateLimiter basic limiter without lockout duration.
	RateLimiter p2p.BasicRateLimiter
}

CtrlMsgValidationConfig configuration values for upper, lower threshold and rate limit.

func NewCtrlMsgValidationConfig

func NewCtrlMsgValidationConfig(controlMsg p2p.ControlMessageType, cfgLimitValues CtrlMsgValidationLimits) (*CtrlMsgValidationConfig, error)

NewCtrlMsgValidationConfig ensures each config limit value is greater than 0 before returning a new CtrlMsgValidationConfig. errors returned:

ErrValidationLimit - if any of the validation limits provided are less than 0. This error is non-recoverable
and the node should crash if this error is encountered.

type CtrlMsgValidationConfigs

type CtrlMsgValidationConfigs []*CtrlMsgValidationConfig

CtrlMsgValidationConfigs list of *CtrlMsgValidationConfig

type CtrlMsgValidationLimits

type CtrlMsgValidationLimits map[string]int

CtrlMsgValidationLimits limits used to construct control message validation configuration.

func (CtrlMsgValidationLimits) DiscardThreshold

func (c CtrlMsgValidationLimits) DiscardThreshold() uint64

func (CtrlMsgValidationLimits) RateLimit

func (c CtrlMsgValidationLimits) RateLimit() int

func (CtrlMsgValidationLimits) SafetyThreshold

func (c CtrlMsgValidationLimits) SafetyThreshold() uint64

type ErrDiscardThreshold

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

ErrDiscardThreshold indicates that the amount of RPC messages received exceeds discard threshold.

func NewDiscardThresholdErr

func NewDiscardThresholdErr(controlMsg p2p.ControlMessageType, amount, discardThreshold uint64) ErrDiscardThreshold

NewDiscardThresholdErr returns a new ErrDiscardThreshold.

func (ErrDiscardThreshold) Error

func (e ErrDiscardThreshold) Error() string

type ErrDuplicateTopic

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

ErrDuplicateTopic error that indicates a duplicate topic in control message has been detected.

func NewIDuplicateTopicErr

func NewIDuplicateTopicErr(topic channels.Topic) ErrDuplicateTopic

NewIDuplicateTopicErr returns a new ErrDuplicateTopic

func (ErrDuplicateTopic) Error

func (e ErrDuplicateTopic) Error() string

type ErrInvalidLimitConfig

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

ErrInvalidLimitConfig indicates the validation limit is < 0.

func NewInvalidLimitConfigErr

func NewInvalidLimitConfigErr(controlMsg p2p.ControlMessageType, limitStr string, limit uint64) ErrInvalidLimitConfig

NewInvalidLimitConfigErr returns a new ErrValidationLimit.

func (ErrInvalidLimitConfig) Error

func (e ErrInvalidLimitConfig) Error() string

type ErrInvalidTopic

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

ErrInvalidTopic error wrapper that indicates an error when checking if a Topic is a valid Flow Topic.

func NewInvalidTopicErr

func NewInvalidTopicErr(topic channels.Topic, err error) ErrInvalidTopic

NewInvalidTopicErr returns a new ErrMalformedTopic

func (ErrInvalidTopic) Error

func (e ErrInvalidTopic) Error() string

type ErrRateLimitedControlMsg

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

ErrRateLimitedControlMsg indicates the specified RPC control message is rate limited for the specified peer.

func NewRateLimitedControlMsgErr

func NewRateLimitedControlMsgErr(controlMsg p2p.ControlMessageType) ErrRateLimitedControlMsg

NewRateLimitedControlMsgErr returns a new ErrValidationLimit.

func (ErrRateLimitedControlMsg) Error

func (e ErrRateLimitedControlMsg) Error() string

type InspectMsgRequest

type InspectMsgRequest struct {
	// Nonce adds random value so that when msg req is stored on hero store a unique ID can be created from the struct fields.
	Nonce []byte
	// Peer sender of the message.
	Peer peer.ID
	// contains filtered or unexported fields
}

InspectMsgRequest represents a short digest of an RPC control message. It is used for further message inspection by component workers.

func NewInspectMsgRequest

func NewInspectMsgRequest(from peer.ID, validationConfig *CtrlMsgValidationConfig, ctrlMsg *pubsub_pb.ControlMessage) (*InspectMsgRequest, error)

NewInspectMsgRequest returns a new *InspectMsgRequest.

Jump to

Keyboard shortcuts

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