validator

package
v0.27.6-block-uploads-... Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: AGPL-3.0 Imports: 11 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSenderEjected      = errors.New("validation failed: sender is an ejected node")
	ErrIdentityUnverified = errors.New("validation failed: could not verify identity of sender")
)

Functions

func NewAnyValidator added in v0.21.1

func NewAnyValidator(validators ...network.MessageValidator) network.MessageValidator

func NewNotValidator added in v0.21.0

func NewNotValidator(validator network.MessageValidator) network.MessageValidator

func NewOriginValidator added in v0.21.1

func NewOriginValidator(provider id.IdentifierProvider) network.MessageValidator

func ValidateNotSender added in v0.21.0

func ValidateNotSender(sender flow.Identifier) network.MessageValidator

ValidateNotSender creates and returns a validator which validates that the message origin id is different from sender id

func ValidateSender added in v0.21.0

func ValidateSender(sender flow.Identifier) network.MessageValidator

ValidateSender creates and returns a new SenderValidator for the given sender ID

func ValidateTarget added in v0.21.0

func ValidateTarget(log zerolog.Logger, target flow.Identifier) network.MessageValidator

ValidateTarget returns a new TargetValidator for the given target id

Types

type AnyValidator added in v0.21.1

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

AnyValidator returns true if any of the given validators returns true

func (AnyValidator) Validate added in v0.21.1

func (v AnyValidator) Validate(msg message.Message) bool

type GetIdentityFunc added in v0.27.3

type GetIdentityFunc func(peer.ID) (*flow.Identity, bool)

type MessageValidator added in v0.27.3

type MessageValidator func(from peer.ID, msg interface{}) (string, error)

MessageValidator validates the given message with original sender `from` and returns an error if validation fails else upon successful validation it should return the decoded message type string. Note: contrarily to pubsub.ValidatorEx, the peerID parameter does not represent the bearer of the message, but its source.

func AuthorizedSenderValidator added in v0.27.3

func AuthorizedSenderValidator(log zerolog.Logger, slashingViolationsConsumer slashing.ViolationsConsumer, channel channels.Channel, isUnicast bool, getIdentity GetIdentityFunc) MessageValidator

AuthorizedSenderValidator returns a MessageValidator that will check if the sender of a message is authorized to send the message. The MessageValidator returned will use the getIdentity to get the flow identity for the sender, asserting that the sender is a staked node and not ejected. Otherwise, the message is rejected. The message is also authorized by checking that the sender is allowed to send the message on the channel. If validation fails the message is rejected, and if the validation error is an expected error, slashing data is also collected. Authorization config is defined in message.MsgAuthConfig.

type NotValidator added in v0.21.0

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

NotValidator returns the opposite result of the given validator for the Validate call

func (NotValidator) Validate added in v0.21.0

func (n NotValidator) Validate(msg message.Message) bool

type OriginValidator added in v0.21.1

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

OriginValidator returns true if the sender of the message is among the set of identifiers returned by the given IdentifierProvider

func (OriginValidator) Validate added in v0.21.1

func (v OriginValidator) Validate(msg message.Message) bool

type PubSubMessageValidator added in v0.27.3

type PubSubMessageValidator func(from peer.ID, msg interface{}) pubsub.ValidationResult

PubSubMessageValidator validates the given message with original sender `from` and returns pubsub.ValidationResult. Note: contrarily to pubsub.ValidatorEx, the peerID parameter does not represent the bearer of the message, but its source.

func AuthorizedSenderMessageValidator added in v0.27.3

func AuthorizedSenderMessageValidator(log zerolog.Logger, slashingViolationsConsumer slashing.ViolationsConsumer, channel channels.Channel, getIdentity GetIdentityFunc) PubSubMessageValidator

AuthorizedSenderMessageValidator wraps the callback returned by AuthorizedSenderValidator and returns MessageValidator callback that returns pubsub.ValidationReject if validation fails and pubsub.ValidationAccept if validation passes.

type SenderValidator

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

SenderValidator validates messages by sender ID

func (*SenderValidator) Validate

func (sv *SenderValidator) Validate(msg message.Message) bool

Validate returns true if the message origin id is the same as the sender ID.

type TargetValidator

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

TargetValidator filters out messages by target ID

func (*TargetValidator) Validate

func (tv *TargetValidator) Validate(msg message.Message) bool

Validate returns true if the message is intended for the given target ID else it returns false

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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