From a9d565aff9e2926b9f3ecbe203bc2eb82fc497cd Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 25 Aug 2023 12:21:02 +0800 Subject: [PATCH] fix --- .../websocket/internal/logic/datatransferlogic.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 5cc978c2..1d677b34 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -5,6 +5,7 @@ import ( "bytes" "encoding/hex" "encoding/json" + "errors" "fusenapi/constants" "fusenapi/utils/auth" "fusenapi/utils/encryption_decryption" @@ -138,8 +139,8 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) // 设置连接 func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.UserInfo, isFirefoxBrowser bool) (wsConnectItem, error) { - //生成连接唯一标识 - uniqueId, err := l.getUniqueId(userInfo) + //生成连接唯一标识(失败重试10次) + uniqueId, err := l.getUniqueId(userInfo, 10) if err != nil { //发送获取唯一标识失败的消息 l.sendGetUniqueIdErrResponse(conn) @@ -170,11 +171,15 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.User } // 获取唯一id -func (l *DataTransferLogic) getUniqueId(userInfo auth.UserInfo) (uniqueId string, err error) { +func (l *DataTransferLogic) getUniqueId(userInfo auth.UserInfo, retryTimes int) (uniqueId string, err error) { + if retryTimes < 0 { + return "", errors.New("failed to get unique id") + } //后面拼接上用户id uniqueId = hex.EncodeToString([]byte(uuid.New().String())) + getUserJoinPart(userInfo.UserId, userInfo.GuestId) + //存在则从新获取 if _, ok := mapConnPool.Load(uniqueId); ok { - uniqueId, err = l.getUniqueId(userInfo) + uniqueId, err = l.getUniqueId(userInfo, retryTimes-1) if err != nil { return "", err }