mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-24 10:22:36 +08:00
msg size
This commit is contained in:
parent
4a3f168720
commit
fdb0ba4349
@ -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)
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user