This commit is contained in:
wangchuxiao 2022-11-17 11:17:26 +08:00
parent 4a3f168720
commit fdb0ba4349
3 changed files with 50 additions and 37 deletions

View File

@ -40,7 +40,12 @@ func (ws *WServer) msgParse(conn *UserConn, binaryMsg []byte) {
return
}
log.NewInfo(m.OperationID, "Basic Info Authentication Success", m.SendID, m.MsgIncr, m.ReqIdentifier)
if m.SendID != conn.userID {
if err = conn.Close(); err != nil {
log.NewError(m.OperationID, "close ws conn failed", conn.userID, "send id", m.SendID, err.Error())
return
}
}
switch m.ReqIdentifier {
case constant.WSGetNewestSeq:
log.NewInfo(m.OperationID, "getSeqReq ", m.SendID, m.MsgIncr, m.ReqIdentifier)

View File

@ -34,6 +34,7 @@ type UserConn struct {
platformID int32
PushedMaxSeq uint32
IsCompress bool
userID string
}
type WServer struct {
wsAddr string
@ -82,7 +83,7 @@ func (ws *WServer) wsHandler(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("compression") == "gzip" {
isCompress = true
}
newConn := &UserConn{conn, new(sync.Mutex), utils.StringToInt32(query["platformID"][0]), 0, isCompress}
newConn := &UserConn{conn, new(sync.Mutex), utils.StringToInt32(query["platformID"][0]), 0, isCompress, query["sendID"][0]}
userCount++
ws.addUserConn(query["sendID"][0], utils.StringToInt(query["platformID"][0]), newConn, query["token"][0], operationID)
go ws.readMsg(newConn)
@ -121,6 +122,7 @@ func (ws *WServer) readMsg(conn *UserConn) {
log.NewWarn("", "reader close failed")
}
}
log.NewDebug("", "size", utils.ByteSize(uint64(len(msg))))
ws.msgParse(conn, msg)
}
}

View File

@ -2,14 +2,25 @@ package utils
import (
"Open_IM/pkg/common/constant"
"errors"
"fmt"
"math/rand"
"os"
"path"
"strconv"
"strings"
"time"
)
const (
BYTE = 1 << (10 * iota)
KILOBYTE
MEGABYTE
GIGABYTE
TERABYTE
PETABYTE
EXABYTE
)
// Determine whether the given path is a folder
func IsDir(path string) bool {
s, err := os.Stat(path)
@ -39,39 +50,34 @@ func GetNewFileNameAndContentType(fileName string, fileType int) (string, string
return newName, contentType
}
func GetUploadAppNewName(appType int, version, fileName, yamlName string) (string, string, error) {
var newFileName, newYamlName = "_" + version + "_app", "_" + version + "_yaml"
switch appType {
case constant.IOSPlatformID:
newFileName = constant.IOSPlatformStr + newFileName
newYamlName = constant.IOSPlatformStr + newYamlName
case constant.AndroidPlatformID:
newFileName = constant.AndroidPlatformStr + newFileName
newYamlName = constant.AndroidPlatformStr + newYamlName
case constant.WindowsPlatformID:
newFileName = constant.WindowsPlatformStr + newFileName
newYamlName = constant.WindowsPlatformStr + newYamlName
case constant.OSXPlatformID:
newFileName = constant.OSXPlatformStr + newFileName
newYamlName = constant.OSXPlatformStr + newYamlName
case constant.WebPlatformID:
newFileName = constant.WebPlatformStr + newFileName
newYamlName = constant.WebPlatformStr + newYamlName
case constant.MiniWebPlatformID:
newFileName = constant.MiniWebPlatformStr + newFileName
newYamlName = constant.MiniWebPlatformStr + newYamlName
case constant.LinuxPlatformID:
newFileName = constant.LinuxPlatformStr + newFileName
newYamlName = constant.LinuxPlatformStr + newYamlName
default:
return "", "", errors.New("invalid app type")
func ByteSize(bytes uint64) string {
unit := ""
value := float64(bytes)
switch {
case bytes >= EXABYTE:
unit = "E"
value = value / EXABYTE
case bytes >= PETABYTE:
unit = "P"
value = value / PETABYTE
case bytes >= TERABYTE:
unit = "T"
value = value / TERABYTE
case bytes >= GIGABYTE:
unit = "G"
value = value / GIGABYTE
case bytes >= MEGABYTE:
unit = "M"
value = value / MEGABYTE
case bytes >= KILOBYTE:
unit = "K"
value = value / KILOBYTE
case bytes >= BYTE:
unit = "B"
case bytes == 0:
return "0"
}
suffixFile := path.Ext(fileName)
suffixYaml := path.Ext(yamlName)
newFileName = fmt.Sprintf("%s%s", newFileName, suffixFile)
newYamlName = fmt.Sprintf("%s%s", newYamlName, suffixYaml)
if yamlName == "" {
newYamlName = ""
}
return newFileName, newYamlName, nil
result := strconv.FormatFloat(value, 'f', 1, 64)
result = strings.TrimSuffix(result, ".0")
return result + unit
}