github.com/koko1123/flow-go-1@v0.29.6/network/validator/sender_validator.go (about) 1 package validator 2 3 import ( 4 "github.com/koko1123/flow-go-1/model/flow" 5 "github.com/koko1123/flow-go-1/network" 6 ) 7 8 var _ network.MessageValidator = &SenderValidator{} 9 10 // SenderValidator validates messages by sender ID 11 type SenderValidator struct { 12 sender flow.Identifier 13 } 14 15 var _ network.MessageValidator = (*SenderValidator)(nil) 16 17 // ValidateSender creates and returns a new SenderValidator for the given sender ID 18 func ValidateSender(sender flow.Identifier) network.MessageValidator { 19 sv := &SenderValidator{} 20 sv.sender = sender 21 return sv 22 } 23 24 // Validate returns true if the message origin id is the same as the sender ID. 25 func (sv *SenderValidator) Validate(msg network.IncomingMessageScope) bool { 26 return sv.sender == msg.OriginId() 27 } 28 29 // ValidateNotSender creates and returns a validator which validates that the message origin id is different from 30 // sender id 31 func ValidateNotSender(sender flow.Identifier) network.MessageValidator { 32 return NewNotValidator(ValidateSender(sender)) 33 }