mirror of
https://github.com/fhmq/hmq.git
synced 2026-08-29 14:03:10 +00:00
修复和优化日志字段的获取逻辑,确保在不同连接类型下正确获取远程地址。同时,调整注释格式以提高代码可读性。
This commit is contained in:
+10
-10
@@ -81,10 +81,16 @@ func getAdditionalLogFields(clientIdentifier string, conn net.Conn, additionalFi
|
||||
result = append(result, zap.String("clientID", clientIdentifier))
|
||||
|
||||
// add remote connection address
|
||||
if !wsEnabled && conn != nil && conn.RemoteAddr() != nil {
|
||||
result = append(result, zap.Stringer("addr", conn.RemoteAddr()))
|
||||
} else if wsEnabled && wsConn != nil && wsConn.Request() != nil {
|
||||
if !wsEnabled && conn != nil {
|
||||
if conn.RemoteAddr() != nil {
|
||||
result = append(result, zap.String("addr", conn.RemoteAddr().String()))
|
||||
}
|
||||
} else if wsEnabled && wsConn != nil {
|
||||
if wsConn.Request() != nil {
|
||||
result = append(result, zap.String("addr", wsConn.Request().RemoteAddr))
|
||||
} else {
|
||||
result = append(result, zap.String("addr", wsConn.RemoteAddr().String()))
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
@@ -143,7 +149,6 @@ func (b *Broker) SubmitWork(clientId string, msg *Message) {
|
||||
ProcessMessage(msg)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (b *Broker) Start() {
|
||||
@@ -190,7 +195,6 @@ func (b *Broker) Start() {
|
||||
go b.processClusterInfo()
|
||||
b.ConnectToDiscovery()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (b *Broker) StartWebsocketListening() {
|
||||
@@ -473,7 +477,7 @@ func (b *Broker) handleConnection(typ int, conn net.Conn) error {
|
||||
}
|
||||
b.clients.Store(cid, c)
|
||||
|
||||
var pubPack = PubPacket{}
|
||||
pubPack := PubPacket{}
|
||||
if willmsg != nil {
|
||||
pubPack.TopicName = info.willMsg.TopicName
|
||||
pubPack.Payload = info.willMsg.Payload
|
||||
@@ -568,7 +572,6 @@ func (b *Broker) processClusterInfo() {
|
||||
}
|
||||
ProcessMessage(msg)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (b *Broker) connectRouter(id, addr string) {
|
||||
@@ -633,7 +636,6 @@ func (b *Broker) connectRouter(id, addr string) {
|
||||
|
||||
go c.readLoop()
|
||||
go c.StartPing()
|
||||
|
||||
}
|
||||
|
||||
func (b *Broker) checkNodeExist(id, url string) bool {
|
||||
@@ -713,7 +715,6 @@ func (b *Broker) BroadcastInfoMessage(remoteID string, msg *packets.PublishPacke
|
||||
}
|
||||
|
||||
func (b *Broker) BroadcastSubOrUnsubMessage(packet packets.ControlPacket) {
|
||||
|
||||
b.routes.Range(func(key, value interface{}) bool {
|
||||
if r, ok := value.(*client); ok {
|
||||
r.WriterPacket(packet)
|
||||
@@ -818,5 +819,4 @@ func FileExist(name string) bool {
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user