Skip to content

Commit

Permalink
Merge pull request #193 from spit4520/master
Browse files Browse the repository at this point in the history
HOTFIX | Fixed pubMsg when WillTopic is null
  • Loading branch information
chowyu12 authored Dec 12, 2023
2 parents e3fa657 + cdff426 commit 35944d7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
11 changes: 7 additions & 4 deletions broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,19 @@ func (b *Broker) handleConnection(typ int, conn net.Conn) error{
}
}
b.clients.Store(cid, c)

var pubPack = PubPacket{}
if willmsg != nil {
pubPack.TopicName = info.willMsg.TopicName
pubPack.Payload = info.willMsg.Payload
}

pubInfo := Info{
ClientID: info.clientID,
Username: info.username,
Password: info.password,
Keepalive: info.keepalive,
WillMsg: &PubPacket{
TopicName: info.willMsg.TopicName,
Payload: info.willMsg.Payload,
},
WillMsg: pubPack,
}

b.OnlineOfflineNotification(pubInfo, true, c.lastMsgTime)
Expand Down
14 changes: 9 additions & 5 deletions broker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type Info struct {
Username string `json:"username"`
Password []byte `json:"password"`
Keepalive uint16 `json:"keepalive"`
WillMsg *PubPacket `json:"willMsg"`
WillMsg PubPacket `json:"willMsg"`
}

type route struct {
Expand Down Expand Up @@ -859,15 +859,19 @@ func (c *client) Close() {

if c.typ == CLIENT {
b.BroadcastUnSubscribe(unSubTopics)

var pubPack = PubPacket{}
if c.info.willMsg != nil {
pubPack.TopicName = c.info.willMsg.TopicName
pubPack.Payload = c.info.willMsg.Payload
}

pubInfo := Info{
ClientID: c.info.clientID,
Username: c.info.username,
Password: c.info.password,
Keepalive: c.info.keepalive,
WillMsg: &PubPacket{
TopicName: c.info.willMsg.TopicName,
Payload: c.info.willMsg.Payload,
},
WillMsg: pubPack,
}
//offline notification
b.OnlineOfflineNotification(pubInfo, false, c.lastMsgTime)
Expand Down
10 changes: 6 additions & 4 deletions broker/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@ func InitHTTPMoniter(b *Broker) {
conns := make([]ConnClient, 0)
b.clients.Range(func (k, v interface{}) bool {
cl, _ := v.(*client)
var pubPack = PubPacket{}
if cl.info.willMsg != nil {
pubPack.TopicName = cl.info.willMsg.TopicName
pubPack.Payload = cl.info.willMsg.Payload
}

msg := ConnClient{
Info: Info{
ClientID: cl.info.clientID,
Username: cl.info.username,
Password: cl.info.password,
Keepalive: cl.info.keepalive,
WillMsg: &PubPacket{
TopicName: cl.info.willMsg.TopicName,
Payload: cl.info.willMsg.Payload,
},
WillMsg: pubPack,
},
LastMsgTime: cl.lastMsgTime,
}
Expand Down

0 comments on commit 35944d7

Please sign in to comment.