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 return
} }
log.NewInfo(m.OperationID, "Basic Info Authentication Success", m.SendID, m.MsgIncr, m.ReqIdentifier) 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 { switch m.ReqIdentifier {
case constant.WSGetNewestSeq: case constant.WSGetNewestSeq:
log.NewInfo(m.OperationID, "getSeqReq ", m.SendID, m.MsgIncr, m.ReqIdentifier) log.NewInfo(m.OperationID, "getSeqReq ", m.SendID, m.MsgIncr, m.ReqIdentifier)

View File

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

View File

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