From 8e09f3ca04c8a09ef07da8b051470226ef7f9ec7 Mon Sep 17 00:00:00 2001 From: Gordon <46924906+FGadvancer@users.noreply.github.com> Date: Fri, 12 Apr 2024 16:20:22 +0800 Subject: [PATCH] refactor: remove msggateway redis. --- internal/msggateway/hub_server.go | 10 ---------- internal/msggateway/init.go | 1 - internal/msggateway/n_ws_server.go | 7 ------- pkg/authverify/token.go | 15 --------------- pkg/common/cmd/msg_gateway.go | 1 - 5 files changed, 34 deletions(-) diff --git a/internal/msggateway/hub_server.go b/internal/msggateway/hub_server.go index 2bea24a70..bfe81b602 100644 --- a/internal/msggateway/hub_server.go +++ b/internal/msggateway/hub_server.go @@ -16,10 +16,7 @@ package msggateway import ( "context" - "github.com/openimsdk/tools/db/redisutil" - "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/startrpc" "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 { - rdb, err := redisutil.NewRedisClient(ctx, config.RedisConfig.Build()) - if err != nil { - return err - } - - tokenCacheModel := cache.NewTokenCacheModel(rdb) s.LongConnServer.SetDiscoveryRegistry(disCov, config) - s.LongConnServer.SetCacheHandler(tokenCacheModel) msggateway.RegisterMsgGatewayServer(server, s) return nil } diff --git a/internal/msggateway/init.go b/internal/msggateway/init.go index 0e704706d..727ade0af 100644 --- a/internal/msggateway/init.go +++ b/internal/msggateway/init.go @@ -25,7 +25,6 @@ import ( type Config struct { MsgGateway config.MsgGateway - RedisConfig config.Redis ZookeeperConfig config.ZooKeeper Share config.Share WebhooksConfig config.Webhooks diff --git a/internal/msggateway/n_ws_server.go b/internal/msggateway/n_ws_server.go index 59c1b49d0..830735be7 100644 --- a/internal/msggateway/n_ws_server.go +++ b/internal/msggateway/n_ws_server.go @@ -25,7 +25,6 @@ import ( "time" "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/servererrs" "github.com/openimsdk/open-im-server/v3/pkg/rpcclient" @@ -44,7 +43,6 @@ type LongConnServer interface { GetUserAllCons(userID string) ([]*Client, bool) GetUserPlatformCons(userID string, platform int) ([]*Client, bool, bool) Validate(s any) error - SetCacheHandler(cache cache.TokenModel) SetDiscoveryRegistry(client discovery.SvcDiscoveryRegistry, config *Config) KickUserConn(client *Client) error UnRegister(c *Client) @@ -68,7 +66,6 @@ type WsServer struct { handshakeTimeout time.Duration writeBufferSize int validate *validator.Validate - cache cache.TokenModel userClient *rpcclient.UserRpcClient authClient *rpcclient.Auth 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) { ws.unregisterChan <- c } diff --git a/pkg/authverify/token.go b/pkg/authverify/token.go index 5eedf5eed..a96d6de20 100644 --- a/pkg/authverify/token.go +++ b/pkg/authverify/token.go @@ -21,7 +21,6 @@ import ( "github.com/golang-jwt/jwt/v4" "github.com/openimsdk/open-im-server/v3/pkg/common/servererrs" "github.com/openimsdk/tools/mcontext" - "github.com/openimsdk/tools/tokenverify" "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 { 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 -} diff --git a/pkg/common/cmd/msg_gateway.go b/pkg/common/cmd/msg_gateway.go index 2a0c41560..1851f6afe 100644 --- a/pkg/common/cmd/msg_gateway.go +++ b/pkg/common/cmd/msg_gateway.go @@ -36,7 +36,6 @@ func NewMsgGatewayCmd() *MsgGatewayCmd { ret := &MsgGatewayCmd{msgGatewayConfig: msgGatewayConfig} ret.configMap = map[string]any{ OpenIMMsgGatewayCfgFileName: &msgGatewayConfig.MsgGateway, - RedisConfigFileName: &msgGatewayConfig.RedisConfig, ZookeeperConfigFileName: &msgGatewayConfig.ZookeeperConfig, ShareFileName: &msgGatewayConfig.Share, WebhooksConfigFileName: &msgGatewayConfig.WebhooksConfig,