mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
add log
This commit is contained in:
parent
f63aa33082
commit
2b03e7aea8
@ -93,20 +93,20 @@ func (ws *WServer) writeMsg(conn *UserConn, a int, msg []byte) error {
|
|||||||
return conn.WriteMessage(a, msg)
|
return conn.WriteMessage(a, msg)
|
||||||
|
|
||||||
}
|
}
|
||||||
func (ws *WServer) MultiTerminalLoginChecker(uid string, platformID int32, newConn *UserConn, token string) {
|
func (ws *WServer) MultiTerminalLoginChecker(uid string, platformID int32, newConn *UserConn, token string, operationID string) {
|
||||||
switch config.Config.MultiLoginPolicy {
|
switch config.Config.MultiLoginPolicy {
|
||||||
case constant.AllLoginButSameTermKick:
|
case constant.AllLoginButSameTermKick:
|
||||||
if oldConnMap, ok := ws.wsUserToConn[uid]; ok {
|
if oldConnMap, ok := ws.wsUserToConn[uid]; ok { // user->map[platform->conn]
|
||||||
if oldConn, ok := oldConnMap[constant.PlatformIDToName(platformID)]; ok {
|
if oldConn, ok := oldConnMap[constant.PlatformIDToName(platformID)]; ok {
|
||||||
log.NewDebug("", uid, platformID, "kick old conn")
|
log.NewDebug(operationID, uid, platformID, "kick old conn")
|
||||||
ws.sendKickMsg(oldConn, newConn)
|
ws.sendKickMsg(oldConn, newConn)
|
||||||
m, err := db.DB.GetTokenMapByUidPid(uid, constant.PlatformIDToName(platformID))
|
m, err := db.DB.GetTokenMapByUidPid(uid, constant.PlatformIDToName(platformID))
|
||||||
if err != nil && err != redis.ErrNil {
|
if err != nil && err != redis.ErrNil {
|
||||||
log.NewError("", "get token from redis err", err.Error())
|
log.NewError(operationID, "get token from redis err", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if m == nil {
|
if m == nil {
|
||||||
log.NewError("", "get token from redis err", "m is nil")
|
log.NewError(operationID, "get token from redis err", "m is nil")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for k, _ := range m {
|
for k, _ := range m {
|
||||||
@ -114,10 +114,10 @@ func (ws *WServer) MultiTerminalLoginChecker(uid string, platformID int32, newCo
|
|||||||
m[k] = constant.KickedToken
|
m[k] = constant.KickedToken
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.NewDebug("get map is ", m)
|
log.NewDebug(operationID, "get map is ", m)
|
||||||
err = db.DB.SetTokenMapByUidPid(uid, platformID, m)
|
err = db.DB.SetTokenMapByUidPid(uid, platformID, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError("", "SetTokenMapByUidPid err", err.Error())
|
log.NewError(operationID, "SetTokenMapByUidPid err", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = oldConn.Close()
|
err = oldConn.Close()
|
||||||
@ -128,15 +128,15 @@ func (ws *WServer) MultiTerminalLoginChecker(uid string, platformID int32, newCo
|
|||||||
}
|
}
|
||||||
delete(ws.wsConnToUser, oldConn)
|
delete(ws.wsConnToUser, oldConn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError("", "conn close err", err.Error(), uid, platformID)
|
log.NewError(operationID, "conn close err", err.Error(), uid, platformID)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log.NewWarn("", "abnormal uid-conn ", uid, platformID, oldConnMap[constant.PlatformIDToName(platformID)])
|
log.NewWarn(operationID, "abnormal uid-conn ", uid, platformID, oldConnMap[constant.PlatformIDToName(platformID)])
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log.NewDebug("no other conn", ws.wsUserToConn, uid, platformID)
|
log.NewDebug(operationID, "no other conn", ws.wsUserToConn, uid, platformID)
|
||||||
}
|
}
|
||||||
|
|
||||||
case constant.SingleTerminalLogin:
|
case constant.SingleTerminalLogin:
|
||||||
@ -164,14 +164,17 @@ func (ws *WServer) sendKickMsg(oldConn, newConn *UserConn) {
|
|||||||
func (ws *WServer) addUserConn(uid string, platformID int32, conn *UserConn, token string) {
|
func (ws *WServer) addUserConn(uid string, platformID int32, conn *UserConn, token string) {
|
||||||
rwLock.Lock()
|
rwLock.Lock()
|
||||||
defer rwLock.Unlock()
|
defer rwLock.Unlock()
|
||||||
ws.MultiTerminalLoginChecker(uid, platformID, conn, token)
|
operationID := utils.OperationIDGenerator()
|
||||||
|
ws.MultiTerminalLoginChecker(uid, platformID, conn, token, operationID)
|
||||||
if oldConnMap, ok := ws.wsUserToConn[uid]; ok {
|
if oldConnMap, ok := ws.wsUserToConn[uid]; ok {
|
||||||
oldConnMap[constant.PlatformIDToName(platformID)] = conn
|
oldConnMap[constant.PlatformIDToName(platformID)] = conn
|
||||||
ws.wsUserToConn[uid] = oldConnMap
|
ws.wsUserToConn[uid] = oldConnMap
|
||||||
|
log.Debug(operationID, "user not first come in, add conn ", uid, platformID, conn, oldConnMap)
|
||||||
} else {
|
} else {
|
||||||
i := make(map[string]*UserConn)
|
i := make(map[string]*UserConn)
|
||||||
i[constant.PlatformIDToName(platformID)] = conn
|
i[constant.PlatformIDToName(platformID)] = conn
|
||||||
ws.wsUserToConn[uid] = i
|
ws.wsUserToConn[uid] = i
|
||||||
|
log.Debug(operationID, "user first come in, new user, conn", uid, platformID, conn, ws.wsUserToConn[uid])
|
||||||
}
|
}
|
||||||
if oldStringMap, ok := ws.wsConnToUser[conn]; ok {
|
if oldStringMap, ok := ws.wsConnToUser[conn]; ok {
|
||||||
oldStringMap[constant.PlatformIDToName(platformID)] = uid
|
oldStringMap[constant.PlatformIDToName(platformID)] = uid
|
||||||
@ -185,7 +188,7 @@ func (ws *WServer) addUserConn(uid string, platformID int32, conn *UserConn, tok
|
|||||||
for _, v := range ws.wsUserToConn {
|
for _, v := range ws.wsUserToConn {
|
||||||
count = count + len(v)
|
count = count + len(v)
|
||||||
}
|
}
|
||||||
log.Debug("WS Add operation", "", "wsUser added", ws.wsUserToConn, "connection_uid", uid, "connection_platform", constant.PlatformIDToName(platformID), "online_user_num", len(ws.wsUserToConn), "online_conn_num", count)
|
log.Debug(operationID, "WS Add operation", "", "wsUser added", ws.wsUserToConn, "connection_uid", uid, "connection_platform", constant.PlatformIDToName(platformID), "online_user_num", len(ws.wsUserToConn), "online_conn_num", count)
|
||||||
userCount = uint64(len(ws.wsUserToConn))
|
userCount = uint64(len(ws.wsUserToConn))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,11 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"math/rand"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// copy a by b b->a
|
// copy a by b b->a
|
||||||
@ -71,3 +73,6 @@ func Difference(slice1, slice2 []uint32) []uint32 {
|
|||||||
}
|
}
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
func OperationIDGenerator() string {
|
||||||
|
return strconv.FormatInt(time.Now().UnixNano()+int64(rand.Uint32()), 10)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user