github.com/koko1123/flow-go-1@v0.29.6/network/validator/target_validator.go (about) 1 package validator 2 3 import ( 4 "github.com/rs/zerolog" 5 6 "github.com/koko1123/flow-go-1/model/flow" 7 "github.com/koko1123/flow-go-1/network" 8 "github.com/koko1123/flow-go-1/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("target", logging.ID(tv.target)). 39 Hex("event_id", msg.EventID()). 40 Msg("message not intended for target") 41 return false 42 }