diff --git a/.idea/Open-IM-Server.iml b/.idea/Open-IM-Server.iml new file mode 100644 index 000000000..5e764c4f0 --- /dev/null +++ b/.idea/Open-IM-Server.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 000000000..589964a46 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,14 @@ + + + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:C:\Users\Administrator\Desktop\Open-IM-Server\docker-compose_cfg\grafana.db + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..28a804d89 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..d9805dbb6 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..94a25f7f4 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/internal/api/route.go b/internal/api/route.go index fb8c2d9a0..0c780766e 100644 --- a/internal/api/route.go +++ b/internal/api/route.go @@ -96,7 +96,6 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive authRouterGroup := r.Group("/auth") { a := NewAuthApi(discov) - authRouterGroup.POST("/user_register", u.UserRegister) authRouterGroup.POST("/user_token", a.UserToken) authRouterGroup.POST("/parse_token", a.ParseToken) authRouterGroup.POST("/force_logout", ParseToken, a.ForceLogout) diff --git a/internal/push/push_to_client.go b/internal/push/push_to_client.go index 7f08ee0aa..607d862e1 100644 --- a/internal/push/push_to_client.go +++ b/internal/push/push_to_client.go @@ -244,7 +244,6 @@ func (p *Pusher) GetConnsAndOnlinePush(ctx context.Context, msg *sdkws.MsgData, for _, v := range conns { msgClient := msggateway.NewMsgGatewayClient(v) reply, err := msgClient.SuperGroupOnlineBatchPushOneMsg(ctx, &msggateway.OnlineBatchPushOneMsgReq{MsgData: msg, PushToUserIDs: pushToUserIDs}) - p.discov.CloseConn(v) if err != nil { continue } diff --git a/pkg/discoveryregistry/discovery_register.go b/pkg/discoveryregistry/discovery_register.go index 01ed88d5b..d7ea00c47 100644 --- a/pkg/discoveryregistry/discovery_register.go +++ b/pkg/discoveryregistry/discovery_register.go @@ -4,7 +4,6 @@ import ( "context" "google.golang.org/grpc" - "google.golang.org/grpc/resolver" ) type Conn interface { @@ -13,7 +12,7 @@ type Conn interface { AddOption(opts ...grpc.DialOption) CloseConn(conn grpc.ClientConnInterface) // do not use this method for call rpc - GetClientLocalConns() map[string][]resolver.Address + GetClientLocalConns() map[string][]grpc.ClientConnInterface } type SvcDiscoveryRegistry interface { diff --git a/pkg/discoveryregistry/zookeeper/discover.go b/pkg/discoveryregistry/zookeeper/discover.go index 65dacd397..a9848ee32 100644 --- a/pkg/discoveryregistry/zookeeper/discover.go +++ b/pkg/discoveryregistry/zookeeper/discover.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" + "github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/pkg/errors" "github.com/go-zookeeper/zk" @@ -61,7 +62,7 @@ func (s *ZkClient) GetConnsRemote(serviceName string) (conns []resolver.Address, } return nil, errors.Wrap(err, "get children error") } - log.ZDebug(context.Background(), "get conns from remote", "conn", string(data)) + log.ZDebug(context.Background(), "get addrs from remote", "conn", string(data)) conns = append(conns, resolver.Address{Addr: string(data), ServerName: serviceName}) } } @@ -70,34 +71,31 @@ func (s *ZkClient) GetConnsRemote(serviceName string) (conns []resolver.Address, func (s *ZkClient) GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]grpc.ClientConnInterface, error) { s.logger.Printf("get conns from client, serviceName: %s", serviceName) - s.lock.Lock() opts = append(s.options, opts...) + s.lock.Lock() + defer s.lock.Unlock() conns := s.localConns[serviceName] if len(conns) == 0 { var err error s.logger.Printf("get conns from zk remote, serviceName: %s", serviceName) - conns, err = s.GetConnsRemote(serviceName) + addrs, err := s.GetConnsRemote(serviceName) if err != nil { - s.lock.Unlock() return nil, err } - if len(conns) == 0 { + if len(addrs) == 0 { return nil, fmt.Errorf("no conn for service %s, grpc server may not exist, local conn is %v, please check zookeeper server %v, path: %s", serviceName, s.localConns, s.zkServers, s.zkRoot) } + for _, addr := range addrs { + cc, err := grpc.DialContext(ctx, addr.Addr, append(s.options, opts...)...) + if err != nil { + log.ZError(context.Background(), "dialContext failed", err, "addr", addr.Addr, "opts", append(s.options, opts...)) + return nil, errs.Wrap(err) + } + conns = append(conns, cc) + } s.localConns[serviceName] = conns } - s.lock.Unlock() - var ret []grpc.ClientConnInterface - s.logger.Printf("get conns from zk success, serviceName: %s", serviceName) - for _, conn := range conns { - cc, err := grpc.DialContext(ctx, conn.Addr, append(s.options, opts...)...) - if err != nil { - return nil, errors.Wrap(err, fmt.Sprintf("conns dialContext error, conn: %s", conn.Addr)) - } - ret = append(ret, cc) - } - s.logger.Printf("dial ctx success, serviceName: %s", serviceName) - return ret, nil + return conns, nil } func (s *ZkClient) GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (grpc.ClientConnInterface, error) { diff --git a/pkg/discoveryregistry/zookeeper/register.go b/pkg/discoveryregistry/zookeeper/register.go index 8f38f6d8d..bd7572c92 100644 --- a/pkg/discoveryregistry/zookeeper/register.go +++ b/pkg/discoveryregistry/zookeeper/register.go @@ -5,7 +5,6 @@ import ( "github.com/go-zookeeper/zk" "google.golang.org/grpc" - "google.golang.org/grpc/resolver" ) func (s *ZkClient) CreateRpcRootNodes(serviceNames []string) error { @@ -43,7 +42,7 @@ func (s *ZkClient) UnRegister() error { } time.Sleep(time.Second) s.node = "" - s.localConns = make(map[string][]resolver.Address) + s.localConns = make(map[string][]grpc.ClientConnInterface) s.resolvers = make(map[string]*Resolver) return nil } diff --git a/pkg/discoveryregistry/zookeeper/zk.go b/pkg/discoveryregistry/zookeeper/zk.go index be0fb5bb0..3fab2402e 100644 --- a/pkg/discoveryregistry/zookeeper/zk.go +++ b/pkg/discoveryregistry/zookeeper/zk.go @@ -37,8 +37,9 @@ type ZkClient struct { lock sync.Locker options []grpc.DialOption - resolvers map[string]*Resolver - localConns map[string][]resolver.Address + resolvers map[string]*Resolver + localConns map[string][]grpc.ClientConnInterface + balancerName string logger Logger @@ -89,7 +90,7 @@ func NewClient(zkServers []string, zkRoot string, options ...ZkOption) (*ZkClien zkRoot: "/", scheme: zkRoot, timeout: timeout, - localConns: make(map[string][]resolver.Address), + localConns: make(map[string][]grpc.ClientConnInterface), resolvers: make(map[string]*Resolver), lock: &sync.Mutex{}, } @@ -197,6 +198,6 @@ func (s *ZkClient) AddOption(opts ...grpc.DialOption) { s.options = append(s.options, opts...) } -func (s *ZkClient) GetClientLocalConns() map[string][]resolver.Address { +func (s *ZkClient) GetClientLocalConns() map[string][]grpc.ClientConnInterface { return s.localConns } diff --git a/pkg/proto/user/user.proto b/pkg/proto/user/user.proto index 117eb3a5f..581efeb01 100644 --- a/pkg/proto/user/user.proto +++ b/pkg/proto/user/user.proto @@ -40,7 +40,7 @@ message updateUserInfoResp{ message setGlobalRecvMessageOptReq{ string userID = 1; - int32 globalRecvMsgOpt = 3; + int32 globalRecvMsgOpt = 3; } message setGlobalRecvMessageOptResp{ } diff --git a/test/mongo/cmd/main.go b/test/mongo/cmd/main.go deleted file mode 100644 index 9b4f315f8..000000000 --- a/test/mongo/cmd/main.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright © 2023 OpenIM. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package main - -import ( - "Open_IM/pkg/common/config" - mongo2 "Open_IM/test/mongo" - "context" - "flag" - "fmt" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" -) - -func init() { - uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority" - if config.Config.Mongo.DBUri != "" { - // example: mongodb://$user:$password@mongo1.mongo:27017,mongo2.mongo:27017,mongo3.mongo:27017/$DBDatabase/?replicaSet=rs0&readPreference=secondary&authSource=admin&maxPoolSize=$DBMaxPoolSize - uri = config.Config.Mongo.DBUri - } else { - if config.Config.Mongo.DBPassword != "" && config.Config.Mongo.DBUserName != "" { - uri = fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%d", config.Config.Mongo.DBUserName, config.Config.Mongo.DBPassword, config.Config.Mongo.DBAddress[0], - config.Config.Mongo.DBDatabase, config.Config.Mongo.DBMaxPoolSize) - } else { - uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d", - config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase, - config.Config.Mongo.DBMaxPoolSize) - } - } - var err error - mongo2.Client, err = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) - if err != nil { - panic(err) - } - err = mongo2.Client.Ping(context.TODO(), nil) - if err != nil { - panic(err) - } - fmt.Println("Connected to MongoDB!") -} - -func main() { - userID := flag.String("userID", "", "userID") - flag.Parse() - fmt.Println("userID:", *userID) - mongo2.GetUserAllChat(*userID) -} diff --git a/test/mongo/mongo_utils.go b/test/mongo/mongo_utils.go deleted file mode 100644 index 50d000f99..000000000 --- a/test/mongo/mongo_utils.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright © 2023 OpenIM. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mongo - -import ( - "Open_IM/pkg/common/config" - server_api_params "Open_IM/pkg/proto/sdk_ws" - "context" - "fmt" - "github.com/golang/protobuf/proto" - "go.mongodb.org/mongo-driver/mongo" - "gopkg.in/mgo.v2/bson" - "time" -) - -var ( - Client *mongo.Client -) - -type MsgInfo struct { - SendTime int64 - Msg []byte -} - -type UserChat struct { - UID string - Msg []MsgInfo -} - -func GetUserAllChat(uid string) { - ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second) - collection := Client.Database(config.Config.Mongo.DBDatabase).Collection("msg") - var userChatList []UserChat - uid = uid + ":" - filter := bson.M{"uid": bson.M{"$regex": uid}} - //filter := bson.M{"uid": "17726378428:0"} - result, err := collection.Find(context.Background(), filter) - if err != nil { - fmt.Println("find error", err.Error()) - return - } - if err := result.All(ctx, &userChatList); err != nil { - fmt.Println(err.Error()) - } - for _, userChat := range userChatList { - for _, msg := range userChat.Msg { - msgData := &server_api_params.MsgData{} - err := proto.Unmarshal(msg.Msg, msgData) - if err != nil { - fmt.Println(err.Error(), msg) - continue - } - fmt.Println("seq: ", msgData.Seq, "status: ", msgData.Status, - "sendID: ", msgData.SendID, "recvID: ", msgData.RecvID, - "sendTime: ", msgData.SendTime, - "clientMsgID: ", msgData.ClientMsgID, - "serverMsgID: ", msgData.ServerMsgID, - "content: ", string(msgData.Content)) - } - } -} diff --git a/test/mysql/cmd/main.go b/test/mysql/cmd/main.go deleted file mode 100644 index b3d73b8db..000000000 --- a/test/mysql/cmd/main.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright © 2023 OpenIM. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package main - -import ( - "Open_IM/test/mysql" -) - -func main() { - mysql.ImportUserToSuperGroup() -} diff --git a/test/mysql/importuser.go b/test/mysql/importuser.go deleted file mode 100644 index 07d97340d..000000000 --- a/test/mysql/importuser.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright © 2023 OpenIM. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mysql - -import ( - "Open_IM/pkg/common/db" - "Open_IM/pkg/common/db/mysql_model/im_mysql_model" - "Open_IM/pkg/common/log" - "strconv" - "time" -) - -func ImportUserToSuperGroup() { - for i := 18000000700; i <= 18000000800; i++ { - user := db.User{ - UserID: strconv.Itoa(i), - Nickname: strconv.Itoa(i), - FaceURL: "", - Gender: 0, - PhoneNumber: strconv.Itoa(i), - Birth: time.Time{}, - Email: "", - Ex: "", - CreateTime: time.Time{}, - AppMangerLevel: 0, - GlobalRecvMsgOpt: 0, - } - err := im_mysql_model.UserRegister(user) - if err != nil { - log.NewError("", err.Error(), user) - continue - } - - groupMember := db.GroupMember{ - GroupID: "3907826375", - UserID: strconv.Itoa(i), - Nickname: strconv.Itoa(i), - FaceURL: "", - RoleLevel: 0, - JoinTime: time.Time{}, - JoinSource: 0, - InviterUserID: "openIMAdmin", - OperatorUserID: "openIMAdmin", - MuteEndTime: time.Time{}, - Ex: "", - } - - err = im_mysql_model.InsertIntoGroupMember(groupMember) - if err != nil { - log.NewError("", err.Error(), user) - continue - } - - log.NewInfo("success", i) - - } - -}