mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 21:02:11 +08:00
refactor: remove msggateway redis.
This commit is contained in:
parent
a921efe62d
commit
8e09f3ca04
@ -16,10 +16,7 @@ package msggateway
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/openimsdk/tools/db/redisutil"
|
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/startrpc"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/startrpc"
|
||||||
"github.com/openimsdk/protocol/constant"
|
"github.com/openimsdk/protocol/constant"
|
||||||
@ -32,14 +29,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) InitServer(ctx context.Context, config *Config, disCov discovery.SvcDiscoveryRegistry, server *grpc.Server) error {
|
func (s *Server) InitServer(ctx context.Context, config *Config, disCov discovery.SvcDiscoveryRegistry, server *grpc.Server) error {
|
||||||
rdb, err := redisutil.NewRedisClient(ctx, config.RedisConfig.Build())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
tokenCacheModel := cache.NewTokenCacheModel(rdb)
|
|
||||||
s.LongConnServer.SetDiscoveryRegistry(disCov, config)
|
s.LongConnServer.SetDiscoveryRegistry(disCov, config)
|
||||||
s.LongConnServer.SetCacheHandler(tokenCacheModel)
|
|
||||||
msggateway.RegisterMsgGatewayServer(server, s)
|
msggateway.RegisterMsgGatewayServer(server, s)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,6 @@ import (
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
MsgGateway config.MsgGateway
|
MsgGateway config.MsgGateway
|
||||||
RedisConfig config.Redis
|
|
||||||
ZookeeperConfig config.ZooKeeper
|
ZookeeperConfig config.ZooKeeper
|
||||||
Share config.Share
|
Share config.Share
|
||||||
WebhooksConfig config.Webhooks
|
WebhooksConfig config.Webhooks
|
||||||
|
|||||||
@ -25,7 +25,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/prommetrics"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/prommetrics"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/rpcclient"
|
"github.com/openimsdk/open-im-server/v3/pkg/rpcclient"
|
||||||
@ -44,7 +43,6 @@ type LongConnServer interface {
|
|||||||
GetUserAllCons(userID string) ([]*Client, bool)
|
GetUserAllCons(userID string) ([]*Client, bool)
|
||||||
GetUserPlatformCons(userID string, platform int) ([]*Client, bool, bool)
|
GetUserPlatformCons(userID string, platform int) ([]*Client, bool, bool)
|
||||||
Validate(s any) error
|
Validate(s any) error
|
||||||
SetCacheHandler(cache cache.TokenModel)
|
|
||||||
SetDiscoveryRegistry(client discovery.SvcDiscoveryRegistry, config *Config)
|
SetDiscoveryRegistry(client discovery.SvcDiscoveryRegistry, config *Config)
|
||||||
KickUserConn(client *Client) error
|
KickUserConn(client *Client) error
|
||||||
UnRegister(c *Client)
|
UnRegister(c *Client)
|
||||||
@ -68,7 +66,6 @@ type WsServer struct {
|
|||||||
handshakeTimeout time.Duration
|
handshakeTimeout time.Duration
|
||||||
writeBufferSize int
|
writeBufferSize int
|
||||||
validate *validator.Validate
|
validate *validator.Validate
|
||||||
cache cache.TokenModel
|
|
||||||
userClient *rpcclient.UserRpcClient
|
userClient *rpcclient.UserRpcClient
|
||||||
authClient *rpcclient.Auth
|
authClient *rpcclient.Auth
|
||||||
disCov discovery.SvcDiscoveryRegistry
|
disCov discovery.SvcDiscoveryRegistry
|
||||||
@ -110,10 +107,6 @@ func (ws *WsServer) SetUserOnlineStatus(ctx context.Context, client *Client, sta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ws *WsServer) SetCacheHandler(cache cache.TokenModel) {
|
|
||||||
ws.cache = cache
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ws *WsServer) UnRegister(c *Client) {
|
func (ws *WsServer) UnRegister(c *Client) {
|
||||||
ws.unregisterChan <- c
|
ws.unregisterChan <- c
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,6 @@ import (
|
|||||||
"github.com/golang-jwt/jwt/v4"
|
"github.com/golang-jwt/jwt/v4"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
||||||
"github.com/openimsdk/tools/mcontext"
|
"github.com/openimsdk/tools/mcontext"
|
||||||
"github.com/openimsdk/tools/tokenverify"
|
|
||||||
"github.com/openimsdk/tools/utils/datautil"
|
"github.com/openimsdk/tools/utils/datautil"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -57,17 +56,3 @@ func CheckAdmin(ctx context.Context, imAdminUserID []string) error {
|
|||||||
func IsManagerUserID(opUserID string, imAdminUserID []string) bool {
|
func IsManagerUserID(opUserID string, imAdminUserID []string) bool {
|
||||||
return datautil.Contain(opUserID, imAdminUserID...)
|
return datautil.Contain(opUserID, imAdminUserID...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WsVerifyToken(token, userID, secret string, platformID int) error {
|
|
||||||
claim, err := tokenverify.GetClaimFromToken(token, Secret(secret))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if claim.UserID != userID {
|
|
||||||
return servererrs.ErrTokenInvalid.WrapMsg(fmt.Sprintf("token uid %s != userID %s", claim.UserID, userID))
|
|
||||||
}
|
|
||||||
if claim.PlatformID != platformID {
|
|
||||||
return servererrs.ErrTokenInvalid.WrapMsg(fmt.Sprintf("token platform %d != %d", claim.PlatformID, platformID))
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
@ -36,7 +36,6 @@ func NewMsgGatewayCmd() *MsgGatewayCmd {
|
|||||||
ret := &MsgGatewayCmd{msgGatewayConfig: msgGatewayConfig}
|
ret := &MsgGatewayCmd{msgGatewayConfig: msgGatewayConfig}
|
||||||
ret.configMap = map[string]any{
|
ret.configMap = map[string]any{
|
||||||
OpenIMMsgGatewayCfgFileName: &msgGatewayConfig.MsgGateway,
|
OpenIMMsgGatewayCfgFileName: &msgGatewayConfig.MsgGateway,
|
||||||
RedisConfigFileName: &msgGatewayConfig.RedisConfig,
|
|
||||||
ZookeeperConfigFileName: &msgGatewayConfig.ZookeeperConfig,
|
ZookeeperConfigFileName: &msgGatewayConfig.ZookeeperConfig,
|
||||||
ShareFileName: &msgGatewayConfig.Share,
|
ShareFileName: &msgGatewayConfig.Share,
|
||||||
WebhooksConfigFileName: &msgGatewayConfig.WebhooksConfig,
|
WebhooksConfigFileName: &msgGatewayConfig.WebhooksConfig,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user