Skip to content

Commit

Permalink
CNSL-124 Generate random UUID if the client id is missing when connec…
Browse files Browse the repository at this point in the history
…ting in MQTT
  • Loading branch information
kostasbalampekos committed May 1, 2024
1 parent 9b461cc commit f647e08
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/session/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net"

"github.com/eclipse/paho.mqtt.golang/packets"
"github.com/google/uuid"
)

type Direction int
Expand Down Expand Up @@ -103,6 +104,15 @@ func authorize(ctx context.Context, pkt packets.ControlPacket, h Handler) error
s.Password = p.Password
}

// If the client ID is empty, generate a random one.
if s.ID == "" {
id, err := uuid.NewUUID()
if err != nil {
return err
}
s.ID = id.String()
}

ctx = NewContext(ctx, s)
if err := h.AuthConnect(ctx); err != nil {
return err
Expand Down

0 comments on commit f647e08

Please sign in to comment.