use cl.ID instead of pk.Connect.ClientIdentifier when looking for existing clients in inheritClientSession (#417)

* use cl.id instead of pk.Connect.ClientIdentifier which is client-supplied, when looking for existing clients in inheritClientSession

* look for assigned client id explicitly

* simpler implementation using just cl.ID

---------

Co-authored-by: JB <28275108+mochi-co@users.noreply.github.com>
This commit is contained in:
Simon
2024-07-30 15:09:16 -03:00
committed by GitHub
parent dc272d2c36
commit 34f9370f8c

View File

@@ -560,7 +560,7 @@ func (s *Server) validateConnect(cl *Client, pk packets.Packet) packets.Code {
// connection ID. If clean is true, the state of any previously existing client
// session is abandoned.
func (s *Server) inheritClientSession(pk packets.Packet, cl *Client) bool {
if existing, ok := s.Clients.Get(pk.Connect.ClientIdentifier); ok {
if existing, ok := s.Clients.Get(cl.ID); ok {
_ = s.DisconnectClient(existing, packets.ErrSessionTakenOver) // [MQTT-3.1.4-3]
if pk.Connect.Clean || (existing.Properties.Clean && existing.Properties.ProtocolVersion < 5) { // [MQTT-3.1.2-4] [MQTT-3.1.4-4]
s.UnsubscribeClient(existing)