Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pkg/session/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,29 @@ func stream(ctx context.Context, dir Direction, r, w net.Conn, h Handler, preIc,
switch dir {
case Up:
if err = authorize(ctx, pkt, h); err != nil {
if pub, ok := pkt.(*packets.PublishPacket); ok {
switch pub.Qos {
case 0:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this approach, If authn and authz fails and if QoS is greater than 0 , then MQTT Client will keep on retrying.

Best approach is disconnect the MQTT Client if authn or authz fails

pkt = packets.NewControlPacket(packets.Disconnect).(*packets.DisconnectPacket)
if wErr := pkt.Write(w); wErr != nil {
err = errors.Join(err, wErr)
}
case 1:
puback := packets.NewControlPacket(packets.Puback).(*packets.PubackPacket)
puback.MessageID = pub.MessageID
if wErr := puback.Write(w); wErr != nil {
err = errors.Join(err, wErr)
}

case 2:
pubrec := packets.NewControlPacket(packets.Pubrec).(*packets.PubrecPacket)
pubrec.MessageID = pub.MessageID

if wErr := pubrec.Write(w); wErr != nil {
err = errors.Join(err, wErr)
}
}
}
errs <- wrap(ctx, err, dir)
return
}
Expand Down
Loading