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 {
TopicRegex *regexp.Regexp
Accept func(from uint32) bool
BlockCipher cipher.Block
MessageHandler func(from uint32, topic string, portNum generated.PortNum, payload []byte)
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)
return
}
// check sender
if c.Accept != nil && !c.Accept(from) {
return
}
// get Data, try decoded first
data := packet.GetDecoded()
if data == nil {