mirror of
https://github.com/fhmq/hmq.git
synced 2026-08-29 14:03:10 +00:00
Fixed pubMsg when WillTopic is null
Previously the broker would run and compile, but would throw a runtime panic if the will was null because of GoLang's inline struct operator. Should REALLY consider adding a unit test
This commit is contained in:
+8
-4
@@ -407,16 +407,20 @@ func (b *Broker) handleConnection(typ int, conn net.Conn) error{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.clients.Store(cid, c)
|
b.clients.Store(cid, c)
|
||||||
|
log.Warn("trying to build publish packet..\n")
|
||||||
|
|
||||||
|
var pubPack = PubPacket{}
|
||||||
|
if willmsg != nil {
|
||||||
|
pubPack.TopicName = info.willMsg.TopicName
|
||||||
|
pubPack.Payload = info.willMsg.Payload
|
||||||
|
}
|
||||||
|
|
||||||
pubInfo := Info{
|
pubInfo := Info{
|
||||||
ClientID: info.clientID,
|
ClientID: info.clientID,
|
||||||
Username: info.username,
|
Username: info.username,
|
||||||
Password: info.password,
|
Password: info.password,
|
||||||
Keepalive: info.keepalive,
|
Keepalive: info.keepalive,
|
||||||
WillMsg: &PubPacket{
|
WillMsg: pubPack,
|
||||||
TopicName: info.willMsg.TopicName,
|
|
||||||
Payload: info.willMsg.Payload,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
b.OnlineOfflineNotification(pubInfo, true, c.lastMsgTime)
|
b.OnlineOfflineNotification(pubInfo, true, c.lastMsgTime)
|
||||||
|
|||||||
+9
-5
@@ -122,7 +122,7 @@ type Info struct {
|
|||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password []byte `json:"password"`
|
Password []byte `json:"password"`
|
||||||
Keepalive uint16 `json:"keepalive"`
|
Keepalive uint16 `json:"keepalive"`
|
||||||
WillMsg *PubPacket `json:"willMsg"`
|
WillMsg PubPacket `json:"willMsg"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type route struct {
|
type route struct {
|
||||||
@@ -859,15 +859,19 @@ func (c *client) Close() {
|
|||||||
|
|
||||||
if c.typ == CLIENT {
|
if c.typ == CLIENT {
|
||||||
b.BroadcastUnSubscribe(unSubTopics)
|
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{
|
pubInfo := Info{
|
||||||
ClientID: c.info.clientID,
|
ClientID: c.info.clientID,
|
||||||
Username: c.info.username,
|
Username: c.info.username,
|
||||||
Password: c.info.password,
|
Password: c.info.password,
|
||||||
Keepalive: c.info.keepalive,
|
Keepalive: c.info.keepalive,
|
||||||
WillMsg: &PubPacket{
|
WillMsg: pubPack,
|
||||||
TopicName: c.info.willMsg.TopicName,
|
|
||||||
Payload: c.info.willMsg.Payload,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
//offline notification
|
//offline notification
|
||||||
b.OnlineOfflineNotification(pubInfo, false, c.lastMsgTime)
|
b.OnlineOfflineNotification(pubInfo, false, c.lastMsgTime)
|
||||||
|
|||||||
+6
-4
@@ -37,6 +37,11 @@ func InitHTTPMoniter(b *Broker) {
|
|||||||
conns := make([]ConnClient, 0)
|
conns := make([]ConnClient, 0)
|
||||||
b.clients.Range(func (k, v interface{}) bool {
|
b.clients.Range(func (k, v interface{}) bool {
|
||||||
cl, _ := v.(*client)
|
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{
|
msg := ConnClient{
|
||||||
Info: Info{
|
Info: Info{
|
||||||
@@ -44,10 +49,7 @@ func InitHTTPMoniter(b *Broker) {
|
|||||||
Username: cl.info.username,
|
Username: cl.info.username,
|
||||||
Password: cl.info.password,
|
Password: cl.info.password,
|
||||||
Keepalive: cl.info.keepalive,
|
Keepalive: cl.info.keepalive,
|
||||||
WillMsg: &PubPacket{
|
WillMsg: pubPack,
|
||||||
TopicName: cl.info.willMsg.TopicName,
|
|
||||||
Payload: cl.info.willMsg.Payload,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
LastMsgTime: cl.lastMsgTime,
|
LastMsgTime: cl.lastMsgTime,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user