github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/validator/target_validator.go (about) 1 package validator 2 3 import ( 4 "github.com/rs/zerolog" 5 6 "github.com/onflow/flow-go/model/flow" 7 "github.com/onflow/flow-go/network" 8 "github.com/onflow/flow-go/utils/logging" 9 ) 10 11 var _ network.MessageValidator = &TargetValidator{} 12 13 // TargetValidator filters out messages by target ID 14 type TargetValidator struct { 15 target flow.Identifier 16 log zerolog.Logger 17 } 18 19 var _ network.MessageValidator = (*TargetValidator)(nil) 20 21 // ValidateTarget returns a new TargetValidator for the given target id 22 func ValidateTarget(log zerolog.Logger, target flow.Identifier) network.MessageValidator { 23 tv := &TargetValidator{ 24 target: target, 25 log: log, 26 } 27 return tv 28 } 29 30 // Validate returns true if the message is intended for the given target ID else it returns false 31 func (tv *TargetValidator) Validate(msg network.IncomingMessageScope) bool { 32 for _, t := range msg.TargetIDs() { 33 if tv.target == t { 34 return true 35 } 36 } 37 tv.log.Debug(). 38 Hex("message_target_id", logging.ID(tv.target)). 39 Hex("local_node_id", logging.ID(tv.target)). 40 Hex("event_id", msg.EventID()). 41 Msg("message not intended for target") 42 return false 43 }