From 705e08a277e6d5276ca3c18f38007c2155d78a37 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Sun, 4 Jun 2023 14:42:36 +0800 Subject: [PATCH] log: add detail of conn --- internal/msggateway/context.go | 3 +++ internal/msggateway/n_ws_server.go | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/msggateway/context.go b/internal/msggateway/context.go index 5006a01fd..cbb47fdfd 100644 --- a/internal/msggateway/context.go +++ b/internal/msggateway/context.go @@ -56,6 +56,9 @@ func newContext(respWriter http.ResponseWriter, req *http.Request) *UserConnCont ConnID: utils.Md5(req.RemoteAddr + "_" + strconv.Itoa(int(utils.GetCurrentTimestampByMill()))), } } +func (c *UserConnContext) GetRemoteAddr() string { + return c.RemoteAddr +} func (c *UserConnContext) Query(key string) (string, bool) { var value string if value = c.Req.URL.Query().Get(key); value == "" { diff --git a/internal/msggateway/n_ws_server.go b/internal/msggateway/n_ws_server.go index 237c89666..8fab14a1c 100644 --- a/internal/msggateway/n_ws_server.go +++ b/internal/msggateway/n_ws_server.go @@ -132,7 +132,7 @@ func (ws *WsServer) registerClient(client *Client) { if clientOK { //已经有同平台的连接存在 ws.clients.Set(client.userID, client) ws.multiTerminalLoginChecker(cli) - log.ZInfo(client.ctx, "repeat login", "userID", client.userID, "platformID", client.platformID) + log.ZInfo(client.ctx, "repeat login", "userID", client.userID, "platformID", client.platformID, "old remote addr", getRemoteAdders(cli)) atomic.AddInt64(&ws.onlineUserConnNum, 1) } else { ws.clients.Set(client.userID, client) @@ -141,6 +141,17 @@ func (ws *WsServer) registerClient(client *Client) { } log.ZInfo(client.ctx, "user online", "online user Num", ws.onlineUserNum, "online user conn Num", ws.onlineUserConnNum) } +func getRemoteAdders(client []*Client) string { + var ret string + for i, c := range client { + if i == 0 { + ret = c.ctx.GetRemoteAddr() + } else { + ret += "@" + c.ctx.GetRemoteAddr() + } + } + return ret +} func (ws *WsServer) multiTerminalLoginChecker(client []*Client) {