mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
Merge remote-tracking branch 'origin/v3dev' into v3dev
This commit is contained in:
commit
d787668911
9
.idea/Open-IM-Server.iml
generated
Normal file
9
.idea/Open-IM-Server.iml
generated
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="Go" enabled="true" />
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
14
.idea/dataSources.xml
generated
Normal file
14
.idea/dataSources.xml
generated
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="grafana" uuid="95aae14a-3593-4ff7-ab49-5e4316cbecd1">
|
||||
<driver-ref>sqlite.xerial</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
||||
<jdbc-url>jdbc:sqlite:C:\Users\Administrator\Desktop\Open-IM-Server\docker-compose_cfg\grafana.db</jdbc-url>
|
||||
<driver-properties>
|
||||
<property name="enable_load_extension" value="true" />
|
||||
</driver-properties>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/Open-IM-Server.iml" filepath="$PROJECT_DIR$/.idea/Open-IM-Server.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ message updateUserInfoResp{
|
||||
|
||||
message setGlobalRecvMessageOptReq{
|
||||
string userID = 1;
|
||||
int32 globalRecvMsgOpt = 3;
|
||||
int32 globalRecvMsgOpt = 3;
|
||||
}
|
||||
message setGlobalRecvMessageOptResp{
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
@ -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()
|
||||
}
|
@ -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)
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user