add optional Accept function

This commit is contained in:
root 2024-11-09 18:34:47 +00:00
parent 98cb8c734c
commit 754f73fe8a

View file

@ -33,6 +33,7 @@ func NewBlockCipher(key []byte) cipher.Block {
type MQTTClient struct { type MQTTClient struct {
TopicRegex *regexp.Regexp TopicRegex *regexp.Regexp
Accept func(from uint32) bool
BlockCipher cipher.Block BlockCipher cipher.Block
MessageHandler func(from uint32, topic string, portNum generated.PortNum, payload []byte) MessageHandler func(from uint32, topic string, portNum generated.PortNum, payload []byte)
topics []string topics []string
@ -105,6 +106,10 @@ func (c *MQTTClient) handleMessage(_ mqtt.Client, msg mqtt.Message) {
log.Printf("[warn] skipping MeshPacket from unknown on %v", topic) log.Printf("[warn] skipping MeshPacket from unknown on %v", topic)
return return
} }
// check sender
if c.Accept != nil && !c.Accept(from) {
return
}
// get Data, try decoded first // get Data, try decoded first
data := packet.GetDecoded() data := packet.GetDecoded()
if data == nil { if data == nil {