diff --git a/.gitignore b/.gitignore index 96475ea72..76bd6371e 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ *.log .vscode +./bin/conf ./bin/log ~$*.xlsx cmd/luban/ \ No newline at end of file diff --git a/comm/core.go b/comm/core.go index b1bc85cc8..4de97fdd4 100644 --- a/comm/core.go +++ b/comm/core.go @@ -4,6 +4,7 @@ import ( "reflect" "github.com/liwei1dao/lego/core" + "google.golang.org/protobuf/proto" ) const ( @@ -34,7 +35,9 @@ type IUserSession interface { GetSessionId() string GetIP() string GetGatewayServiceId() string - SendMsg(ServiceMethod string, msg interface{}) (err error) + Build(uid uint32) (err error) + UnBuild(ServiceMethod string, msg proto.Message) (err error) + SendMsg(ServiceMethod string, msg proto.Message) (err error) Close() (err error) ToString() string } diff --git a/comm/errorcode.go b/comm/errorcode.go new file mode 100644 index 000000000..653452f14 --- /dev/null +++ b/comm/errorcode.go @@ -0,0 +1,40 @@ +package comm + +import ( + "github.com/liwei1dao/lego/core" +) + +///内置错误码 0-1000 请外部应用服务不要占用 +const ( + ErrorCode_Success core.ErrorCode = 0 //成功 + ErrorCode_NoFindService core.ErrorCode = 10 //没有找到远程服务器 + ErrorCode_RpcFuncExecutionError core.ErrorCode = 11 //Rpc方法执行错误 + ErrorCode_CacheReadError core.ErrorCode = 12 //缓存读取失败 + ErrorCode_SqlExecutionError core.ErrorCode = 13 //数据库执行错误 + ErrorCode_ReqParameterError core.ErrorCode = 14 //请求参数错误 + ErrorCode_SignError core.ErrorCode = 15 //签名错误 + ErrorCode_InsufficientPermissions core.ErrorCode = 16 //权限不足 + ErrorCode_NoLogin core.ErrorCode = 17 //未登录 + ErrorCode_UserSessionNobeing core.ErrorCode = 18 //用户不存在 +) + +var ErrorCodeMsg = map[core.ErrorCode]string{ + ErrorCode_Success: "成功", + ErrorCode_NoFindService: "没有找到远程服务器", + ErrorCode_RpcFuncExecutionError: "Rpc方法执行错误", + ErrorCode_CacheReadError: "缓存读取失败", + ErrorCode_SqlExecutionError: "数据库执行错误", + ErrorCode_ReqParameterError: "请求参数错误", + ErrorCode_SignError: "签名错误", + ErrorCode_InsufficientPermissions: "权限不足", + ErrorCode_NoLogin: "未登录", + ErrorCode_UserSessionNobeing: "用户不存在", +} + +func GetErrorCodeMsg(code core.ErrorCode) string { + if v, ok := ErrorCodeMsg[code]; ok { + return v + } else { + return core.GetErrorCodeMsg(code) + } +} diff --git a/comm/usersession.go b/comm/usersession.go index 5c259ed60..9c6a4048c 100644 --- a/comm/usersession.go +++ b/comm/usersession.go @@ -1,9 +1,13 @@ package comm import ( + "context" "fmt" + "go_dreamfactory/pb" "github.com/liwei1dao/lego/base" + "github.com/liwei1dao/lego/sys/log" + "google.golang.org/protobuf/proto" ) func NewUserSession(service base.IRPCXService, ip, sessionId, gatewayServiceId string, uid uint32) IUserSession { @@ -33,13 +37,50 @@ func (this *UserSession) GetIP() string { func (this *UserSession) GetGatewayServiceId() string { return this.GatewayServiceId } -func (this *UserSession) SendMsg(ServiceMethod string, msg interface{}) (err error) { +func (this *UserSession) Build(uid uint32) (err error) { + reply := &pb.RPCMessageReply{} + if err := this.service.RpcCallById(this.GatewayServiceId, string(Rpc_GatewayAgentBuild), context.Background(), &pb.AgentBuildReq{ + UserSessionId: this.SessionId, + UserId: uid, + }, reply); err != nil { + log.Errorf("UserSession:%s UserId:%d Build:%s err:%v", this.SessionId, this.UserId, err) + } + return +} + +func (this *UserSession) UnBuild(ServiceMethod string, msg proto.Message) (err error) { + reply := &pb.RPCMessageReply{} + if err := this.service.RpcCallById(this.GatewayServiceId, string(Rpc_GatewayAgentUnBuild), context.Background(), &pb.AgentUnBuildReq{ + UserSessionId: this.SessionId, + }, reply); err != nil { + log.Errorf("UserSession:%s UserId:%d UnBuild err:%v", this.SessionId, this.UserId, err) + } + return +} + +func (this *UserSession) SendMsg(ServiceMethod string, msg proto.Message) (err error) { + reply := &pb.RPCMessageReply{} + data, _ := proto.Marshal(msg) + if err := this.service.RpcCallById(this.GatewayServiceId, string(Rpc_GatewayAgentSendMsg), context.Background(), &pb.AgentSendMessageReq{ + UserSessionId: this.SessionId, + ServiceMethod: ServiceMethod, + Data: data, + }, reply); err != nil { + log.Errorf("UserSession:%s UserId:%d SendMsg:%s err:%v", this.SessionId, this.UserId, ServiceMethod, err) + } return } func (this *UserSession) Close() (err error) { + reply := &pb.RPCMessageReply{} + if err := this.service.RpcCallById(this.GatewayServiceId, string(Rpc_GatewayAgentSendMsg), context.Background(), &pb.AgentCloseeReq{ + UserSessionId: this.SessionId, + }, reply); err != nil { + log.Errorf("UserSession:%s UserId:%d Close:%s err:%v", this.SessionId, this.UserId, err) + } return } + func (this *UserSession) ToString() string { return fmt.Sprintf("SessionId:%s UserId:%d GatewayServiceId:%s", this.SessionId, this.UserId, this.GatewayServiceId) } diff --git a/modules/gateway/agent.go b/modules/gateway/agent.go index 44d05f232..768bf5b9d 100644 --- a/modules/gateway/agent.go +++ b/modules/gateway/agent.go @@ -19,7 +19,7 @@ func newAgent(gateway IGateway, conn *websocket.Conn) *Agent { wsConn: conn, sessionId: id.NewUUId(), uId: 0, - writeChan: make(chan *pb.Message, 2), + writeChan: make(chan *pb.UserMessage, 2), closeSignal: make(chan bool), state: 1, } @@ -35,7 +35,7 @@ type Agent struct { wsConn *websocket.Conn sessionId string uId uint32 - writeChan chan *pb.Message + writeChan chan *pb.UserMessage closeSignal chan bool state int32 //状态 0 关闭 1 运行 2 关闭中 wg sync.WaitGroup @@ -45,7 +45,7 @@ func (this *Agent) readLoop() { defer this.wg.Done() var ( data []byte - msg *pb.Message = &pb.Message{} + msg *pb.UserMessage = &pb.UserMessage{} err error ) locp: @@ -102,7 +102,20 @@ func (this *Agent) IP() string { func (this *Agent) UserId() uint32 { return this.uId } + +func (this *Agent) Build(uId uint32) { + this.uId = uId +} + +func (this *Agent) UnBuild() { + this.uId = 0 +} + func (this *Agent) WriteMsg(msg *pb.UserMessage) (err error) { + if atomic.LoadInt32(&this.state) != 1 { + return + } + this.writeChan <- msg return } @@ -119,15 +132,15 @@ func (this *Agent) Close() { } //分发用户消息 -func (this *Agent) messageDistribution(msg *pb.Message) { - reply := &pb.UserMessageReply{} - log.Debugf("agent:%s uId:%d MessageDistribution msg:%s", this.sessionId, this.uId, msg.Head.ServiceMethod) - if err := this.gateway.Service().RpcCallByType("worker", string(comm.Rpc_GatewayRoute), context.Background(), &pb.UserMessage{ +func (this *Agent) messageDistribution(msg *pb.UserMessage) { + reply := &pb.RPCMessageReply{} + log.Debugf("agent:%s uId:%d MessageDistribution msg:%s", this.sessionId, this.uId, msg.ServiceMethod) + if err := this.gateway.Service().RpcCallByType("worker", string(comm.Rpc_GatewayRoute), context.Background(), &pb.AgentMessage{ Ip: this.IP(), UserSessionId: this.sessionId, UserId: this.uId, GatewayServiceId: this.gateway.Service().GetId(), - Method: msg.Head.ServiceMethod, + Method: msg.ServiceMethod, Message: msg.Data, }, reply); err != nil { log.Errorf("agent:%s uId:%d MessageDistribution err:%v", this.sessionId, this.uId, err) diff --git a/modules/gateway/agentmgr_comp.go b/modules/gateway/agentmgr_comp.go index 8f3542dc3..6d11b2569 100644 --- a/modules/gateway/agentmgr_comp.go +++ b/modules/gateway/agentmgr_comp.go @@ -1,6 +1,9 @@ package gateway import ( + "context" + "go_dreamfactory/comm" + "go_dreamfactory/pb" "sync" "github.com/liwei1dao/lego/core" @@ -23,3 +26,63 @@ func (this *AgentMgr_Comp) Connect(a IAgent) { func (this *AgentMgr_Comp) DisConnect(a IAgent) { this.agents.Delete(a.SessionId()) } + +//用户登录绑定Id +func (this *AgentMgr_Comp) Build(ctx context.Context, args *pb.AgentBuildReq, reply *pb.RPCMessageReply) error { + if a, ok := this.agents.Load(args.UserSessionId); ok { + a.(IAgent).Build(args.UserId) + } else { + reply.Code = int32(comm.ErrorCode_UserSessionNobeing) + reply.Msg = comm.GetErrorCodeMsg(comm.ErrorCode_UserSessionNobeing) + } + return nil +} + +//用户登录解绑Id +func (this *AgentMgr_Comp) UnBuild(ctx context.Context, args *pb.AgentUnBuildReq, reply *pb.RPCMessageReply) error { + if a, ok := this.agents.Load(args.UserSessionId); ok { + a.(IAgent).UnBuild() + } else { + reply.Code = int32(comm.ErrorCode_UserSessionNobeing) + reply.Msg = comm.GetErrorCodeMsg(comm.ErrorCode_UserSessionNobeing) + } + return nil +} + +//向用户发送消息 +func (this *AgentMgr_Comp) SendMsgToAgent(ctx context.Context, args *pb.AgentSendMessageReq, reply *pb.RPCMessageReply) error { + if a, ok := this.agents.Load(args.UserSessionId); ok { + a.(IAgent).WriteMsg(&pb.UserMessage{ + ServiceMethod: args.ServiceMethod, + Data: args.Data, + }) + } else { + reply.Code = int32(comm.ErrorCode_UserSessionNobeing) + reply.Msg = comm.GetErrorCodeMsg(comm.ErrorCode_UserSessionNobeing) + } + return nil +} + +//向所有户发送消息 +func (this *AgentMgr_Comp) SendMsgToAllAgent(ctx context.Context, args *pb.BroadCastMessageReq, reply *pb.RPCMessageReply) error { + msg := &pb.UserMessage{ + ServiceMethod: args.ServiceMethod, + Data: args.Data, + } + this.agents.Range(func(key, value any) bool { + value.(IAgent).WriteMsg(msg) + return true + }) + return nil +} + +//关闭代理 +func (this *AgentMgr_Comp) CloseAgent(ctx context.Context, args *pb.AgentCloseeReq, reply *pb.RPCMessageReply) error { + if a, ok := this.agents.Load(args.UserSessionId); ok { + a.(IAgent).Close() + } else { + reply.Code = int32(comm.ErrorCode_UserSessionNobeing) + reply.Msg = comm.GetErrorCodeMsg(comm.ErrorCode_UserSessionNobeing) + } + return nil +} diff --git a/modules/gateway/client_test.go b/modules/gateway/client_test.go index 150ac28f6..d1e3fe9e8 100644 --- a/modules/gateway/client_test.go +++ b/modules/gateway/client_test.go @@ -3,8 +3,10 @@ package gateway_test import ( "fmt" "go_dreamfactory/pb" + "os" + "os/signal" + "syscall" "testing" - "time" "github.com/gorilla/websocket" "google.golang.org/protobuf/proto" @@ -17,18 +19,40 @@ func Test_WebSocket(t *testing.T) { fmt.Printf("err:%v", err) return } + + go func() { + var msg *pb.UserMessage = &pb.UserMessage{} + for { + _, data, err := ws.ReadMessage() + if err != nil { + fmt.Printf("err:%v\n", err) + } + if err = proto.Unmarshal(data, msg); err != nil { + fmt.Printf("err:%v\n", err) + } else { + fmt.Printf("ReadMessage msg:%v\n", msg) + } + } + }() + loginreq := &pb.UserLoginReq{ Name: "liwei", } logindata, _ := proto.Marshal(loginreq) - message := &pb.Message{ - Head: &pb.MessageHead{ServiceMethod: "Login"}, - Data: logindata, + message := &pb.UserMessage{ + ServiceMethod: "Login", + Data: logindata, } data, _ := proto.Marshal(message) err = ws.WriteMessage(websocket.BinaryMessage, data) if err != nil { - fmt.Printf("err:%v", err) + fmt.Printf("err:%v\n", err) + } + + sigterm := make(chan os.Signal, 1) + signal.Notify(sigterm, syscall.SIGINT, syscall.SIGTERM) + select { + case <-sigterm: + fmt.Printf("terminating: via signal\n") } - time.Sleep(time.Second * 2) } diff --git a/modules/gateway/core.go b/modules/gateway/core.go index 0d662ff16..566c19d29 100644 --- a/modules/gateway/core.go +++ b/modules/gateway/core.go @@ -12,6 +12,8 @@ type ( SessionId() string IP() string UserId() uint32 + Build(uId uint32) + UnBuild() WriteMsg(msg *pb.UserMessage) (err error) Close() //主动关闭接口 } diff --git a/modules/gateway/module.go b/modules/gateway/module.go index f2753846c..5fe6e74ba 100644 --- a/modules/gateway/module.go +++ b/modules/gateway/module.go @@ -36,13 +36,15 @@ func (this *Gateway) Service() base.IRPCXService { func (this *Gateway) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) this.service = service.(base.IRPCXService) - log.Debugf("Module.Gate Init") return } func (this *Gateway) Start() (err error) { + this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentBuild), this.agentmgr_comp.Build) + this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentUnBuild), this.agentmgr_comp.UnBuild) + this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentSendMsg), this.agentmgr_comp.SendMsgToAgent) + this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentClose), this.agentmgr_comp.CloseAgent) err = this.ModuleBase.Start() - log.Debugf("Module.Gate Start") return } diff --git a/modules/web/user_comp.go b/modules/web/user_comp.go index ee6f82943..19bf605ea 100644 --- a/modules/web/user_comp.go +++ b/modules/web/user_comp.go @@ -21,5 +21,8 @@ func (this *User_Comp) Init(service core.IService, module core.IModule, comp cor func (this *User_Comp) Login(ctx context.Context, session comm.IUserSession, rsp *pb.UserLoginReq) error { log.Debugf("User_Comp Login: session:%v rsp:%v", session.ToString(), rsp) + session.SendMsg("LogigResp", &pb.UserLoginResp{ + Code: 200, + }) return nil } diff --git a/pb/comm.pb.go b/pb/comm.pb.go index 0afdb6900..7b1d02fad 100644 --- a/pb/comm.pb.go +++ b/pb/comm.pb.go @@ -20,127 +20,20 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -//消息体 -type MessageHead struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - ServiceMethod string `protobuf:"bytes,1,opt,name=ServiceMethod,proto3" json:"ServiceMethod,omitempty"` //服务名 -} - -func (x *MessageHead) Reset() { - *x = MessageHead{} - if protoimpl.UnsafeEnabled { - mi := &file_comm_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *MessageHead) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*MessageHead) ProtoMessage() {} - -func (x *MessageHead) ProtoReflect() protoreflect.Message { - mi := &file_comm_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use MessageHead.ProtoReflect.Descriptor instead. -func (*MessageHead) Descriptor() ([]byte, []int) { - return file_comm_proto_rawDescGZIP(), []int{0} -} - -func (x *MessageHead) GetServiceMethod() string { - if x != nil { - return x.ServiceMethod - } - return "" -} - -//处理JSON消息 -type Message struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Head *MessageHead `protobuf:"bytes,1,opt,name=Head,proto3" json:"Head,omitempty"` - Data []byte `protobuf:"bytes,2,opt,name=Data,proto3" json:"Data,omitempty"` -} - -func (x *Message) Reset() { - *x = Message{} - if protoimpl.UnsafeEnabled { - mi := &file_comm_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Message) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Message) ProtoMessage() {} - -func (x *Message) ProtoReflect() protoreflect.Message { - mi := &file_comm_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Message.ProtoReflect.Descriptor instead. -func (*Message) Descriptor() ([]byte, []int) { - return file_comm_proto_rawDescGZIP(), []int{1} -} - -func (x *Message) GetHead() *MessageHead { - if x != nil { - return x.Head - } - return nil -} - -func (x *Message) GetData() []byte { - if x != nil { - return x.Data - } - return nil -} - +//用户消息流结构 type UserMessage struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Ip string `protobuf:"bytes,1,opt,name=Ip,proto3" json:"Ip,omitempty"` - UserSessionId string `protobuf:"bytes,2,opt,name=UserSessionId,proto3" json:"UserSessionId,omitempty"` - UserId uint32 `protobuf:"varint,3,opt,name=UserId,proto3" json:"UserId,omitempty"` - GatewayServiceId string `protobuf:"bytes,4,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId,omitempty"` - Method string `protobuf:"bytes,5,opt,name=Method,proto3" json:"Method,omitempty"` - Message []byte `protobuf:"bytes,6,opt,name=Message,proto3" json:"Message,omitempty"` + ServiceMethod string `protobuf:"bytes,1,opt,name=ServiceMethod,proto3" json:"ServiceMethod,omitempty"` //服务名 + Data []byte `protobuf:"bytes,2,opt,name=Data,proto3" json:"Data,omitempty"` } func (x *UserMessage) Reset() { *x = UserMessage{} if protoimpl.UnsafeEnabled { - mi := &file_comm_proto_msgTypes[2] + mi := &file_comm_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -153,7 +46,7 @@ func (x *UserMessage) String() string { func (*UserMessage) ProtoMessage() {} func (x *UserMessage) ProtoReflect() protoreflect.Message { - mi := &file_comm_proto_msgTypes[2] + mi := &file_comm_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -166,52 +59,113 @@ func (x *UserMessage) ProtoReflect() protoreflect.Message { // Deprecated: Use UserMessage.ProtoReflect.Descriptor instead. func (*UserMessage) Descriptor() ([]byte, []int) { - return file_comm_proto_rawDescGZIP(), []int{2} + return file_comm_proto_rawDescGZIP(), []int{0} } -func (x *UserMessage) GetIp() string { +func (x *UserMessage) GetServiceMethod() string { + if x != nil { + return x.ServiceMethod + } + return "" +} + +func (x *UserMessage) GetData() []byte { + if x != nil { + return x.Data + } + return nil +} + +//代理用户转发消息结构 +type AgentMessage struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Ip string `protobuf:"bytes,1,opt,name=Ip,proto3" json:"Ip,omitempty"` + UserSessionId string `protobuf:"bytes,2,opt,name=UserSessionId,proto3" json:"UserSessionId,omitempty"` + UserId uint32 `protobuf:"varint,3,opt,name=UserId,proto3" json:"UserId,omitempty"` + GatewayServiceId string `protobuf:"bytes,4,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId,omitempty"` + Method string `protobuf:"bytes,5,opt,name=Method,proto3" json:"Method,omitempty"` + Message []byte `protobuf:"bytes,6,opt,name=Message,proto3" json:"Message,omitempty"` +} + +func (x *AgentMessage) Reset() { + *x = AgentMessage{} + if protoimpl.UnsafeEnabled { + mi := &file_comm_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AgentMessage) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AgentMessage) ProtoMessage() {} + +func (x *AgentMessage) ProtoReflect() protoreflect.Message { + mi := &file_comm_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AgentMessage.ProtoReflect.Descriptor instead. +func (*AgentMessage) Descriptor() ([]byte, []int) { + return file_comm_proto_rawDescGZIP(), []int{1} +} + +func (x *AgentMessage) GetIp() string { if x != nil { return x.Ip } return "" } -func (x *UserMessage) GetUserSessionId() string { +func (x *AgentMessage) GetUserSessionId() string { if x != nil { return x.UserSessionId } return "" } -func (x *UserMessage) GetUserId() uint32 { +func (x *AgentMessage) GetUserId() uint32 { if x != nil { return x.UserId } return 0 } -func (x *UserMessage) GetGatewayServiceId() string { +func (x *AgentMessage) GetGatewayServiceId() string { if x != nil { return x.GatewayServiceId } return "" } -func (x *UserMessage) GetMethod() string { +func (x *AgentMessage) GetMethod() string { if x != nil { return x.Method } return "" } -func (x *UserMessage) GetMessage() []byte { +func (x *AgentMessage) GetMessage() []byte { if x != nil { return x.Message } return nil } -type UserMessageReply struct { +//RPC 服务固定回复结构 +type RPCMessageReply struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields @@ -220,8 +174,64 @@ type UserMessageReply struct { Msg string `protobuf:"bytes,2,opt,name=Msg,proto3" json:"Msg,omitempty"` } -func (x *UserMessageReply) Reset() { - *x = UserMessageReply{} +func (x *RPCMessageReply) Reset() { + *x = RPCMessageReply{} + if protoimpl.UnsafeEnabled { + mi := &file_comm_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RPCMessageReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RPCMessageReply) ProtoMessage() {} + +func (x *RPCMessageReply) ProtoReflect() protoreflect.Message { + mi := &file_comm_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RPCMessageReply.ProtoReflect.Descriptor instead. +func (*RPCMessageReply) Descriptor() ([]byte, []int) { + return file_comm_proto_rawDescGZIP(), []int{2} +} + +func (x *RPCMessageReply) GetCode() int32 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *RPCMessageReply) GetMsg() string { + if x != nil { + return x.Msg + } + return "" +} + +//用户代理绑定Uid请求 +type AgentBuildReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId,omitempty"` + UserId uint32 `protobuf:"varint,2,opt,name=UserId,proto3" json:"UserId,omitempty"` +} + +func (x *AgentBuildReq) Reset() { + *x = AgentBuildReq{} if protoimpl.UnsafeEnabled { mi := &file_comm_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -229,13 +239,13 @@ func (x *UserMessageReply) Reset() { } } -func (x *UserMessageReply) String() string { +func (x *AgentBuildReq) String() string { return protoimpl.X.MessageStringOf(x) } -func (*UserMessageReply) ProtoMessage() {} +func (*AgentBuildReq) ProtoMessage() {} -func (x *UserMessageReply) ProtoReflect() protoreflect.Message { +func (x *AgentBuildReq) ProtoReflect() protoreflect.Message { mi := &file_comm_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -247,21 +257,237 @@ func (x *UserMessageReply) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use UserMessageReply.ProtoReflect.Descriptor instead. -func (*UserMessageReply) Descriptor() ([]byte, []int) { +// Deprecated: Use AgentBuildReq.ProtoReflect.Descriptor instead. +func (*AgentBuildReq) Descriptor() ([]byte, []int) { return file_comm_proto_rawDescGZIP(), []int{3} } -func (x *UserMessageReply) GetCode() int32 { +func (x *AgentBuildReq) GetUserSessionId() string { if x != nil { - return x.Code + return x.UserSessionId + } + return "" +} + +func (x *AgentBuildReq) GetUserId() uint32 { + if x != nil { + return x.UserId } return 0 } -func (x *UserMessageReply) GetMsg() string { +//用户代理解绑请求 +type AgentUnBuildReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId,omitempty"` +} + +func (x *AgentUnBuildReq) Reset() { + *x = AgentUnBuildReq{} + if protoimpl.UnsafeEnabled { + mi := &file_comm_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AgentUnBuildReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AgentUnBuildReq) ProtoMessage() {} + +func (x *AgentUnBuildReq) ProtoReflect() protoreflect.Message { + mi := &file_comm_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AgentUnBuildReq.ProtoReflect.Descriptor instead. +func (*AgentUnBuildReq) Descriptor() ([]byte, []int) { + return file_comm_proto_rawDescGZIP(), []int{4} +} + +func (x *AgentUnBuildReq) GetUserSessionId() string { if x != nil { - return x.Msg + return x.UserSessionId + } + return "" +} + +//向用户代理发送消息请求 +type AgentSendMessageReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId,omitempty"` + ServiceMethod string `protobuf:"bytes,2,opt,name=ServiceMethod,proto3" json:"ServiceMethod,omitempty"` //服务名 + Data []byte `protobuf:"bytes,3,opt,name=Data,proto3" json:"Data,omitempty"` +} + +func (x *AgentSendMessageReq) Reset() { + *x = AgentSendMessageReq{} + if protoimpl.UnsafeEnabled { + mi := &file_comm_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AgentSendMessageReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AgentSendMessageReq) ProtoMessage() {} + +func (x *AgentSendMessageReq) ProtoReflect() protoreflect.Message { + mi := &file_comm_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AgentSendMessageReq.ProtoReflect.Descriptor instead. +func (*AgentSendMessageReq) Descriptor() ([]byte, []int) { + return file_comm_proto_rawDescGZIP(), []int{5} +} + +func (x *AgentSendMessageReq) GetUserSessionId() string { + if x != nil { + return x.UserSessionId + } + return "" +} + +func (x *AgentSendMessageReq) GetServiceMethod() string { + if x != nil { + return x.ServiceMethod + } + return "" +} + +func (x *AgentSendMessageReq) GetData() []byte { + if x != nil { + return x.Data + } + return nil +} + +//广播消息到所有用户代理 +type BroadCastMessageReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ServiceMethod string `protobuf:"bytes,1,opt,name=ServiceMethod,proto3" json:"ServiceMethod,omitempty"` //服务名 + Data []byte `protobuf:"bytes,2,opt,name=Data,proto3" json:"Data,omitempty"` +} + +func (x *BroadCastMessageReq) Reset() { + *x = BroadCastMessageReq{} + if protoimpl.UnsafeEnabled { + mi := &file_comm_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BroadCastMessageReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BroadCastMessageReq) ProtoMessage() {} + +func (x *BroadCastMessageReq) ProtoReflect() protoreflect.Message { + mi := &file_comm_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BroadCastMessageReq.ProtoReflect.Descriptor instead. +func (*BroadCastMessageReq) Descriptor() ([]byte, []int) { + return file_comm_proto_rawDescGZIP(), []int{6} +} + +func (x *BroadCastMessageReq) GetServiceMethod() string { + if x != nil { + return x.ServiceMethod + } + return "" +} + +func (x *BroadCastMessageReq) GetData() []byte { + if x != nil { + return x.Data + } + return nil +} + +//关闭用户代理 +type AgentCloseeReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId,omitempty"` +} + +func (x *AgentCloseeReq) Reset() { + *x = AgentCloseeReq{} + if protoimpl.UnsafeEnabled { + mi := &file_comm_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AgentCloseeReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AgentCloseeReq) ProtoMessage() {} + +func (x *AgentCloseeReq) ProtoReflect() protoreflect.Message { + mi := &file_comm_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AgentCloseeReq.ProtoReflect.Descriptor instead. +func (*AgentCloseeReq) Descriptor() ([]byte, []int) { + return file_comm_proto_rawDescGZIP(), []int{7} +} + +func (x *AgentCloseeReq) GetUserSessionId() string { + if x != nil { + return x.UserSessionId } return "" } @@ -269,31 +495,53 @@ func (x *UserMessageReply) GetMsg() string { var File_comm_proto protoreflect.FileDescriptor var file_comm_proto_rawDesc = []byte{ - 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x33, 0x0a, 0x0b, - 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x48, 0x65, 0x61, 0x64, 0x12, 0x24, 0x0a, 0x0d, 0x53, + 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x47, 0x0a, 0x0b, + 0x55, 0x73, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, - 0x64, 0x22, 0x3f, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x20, 0x0a, 0x04, - 0x48, 0x65, 0x61, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x4d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x48, 0x65, 0x61, 0x64, 0x52, 0x04, 0x48, 0x65, 0x61, 0x64, 0x12, 0x12, - 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x44, 0x61, - 0x74, 0x61, 0x22, 0xb9, 0x01, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, - 0x67, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, - 0x49, 0x70, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, - 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, - 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, - 0x12, 0x2a, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, - 0x63, 0x65, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x47, 0x61, 0x74, 0x65, - 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, - 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x4d, 0x65, - 0x74, 0x68, 0x6f, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, - 0x06, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x38, - 0x0a, 0x10, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x70, - 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, - 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x03, 0x4d, 0x73, 0x67, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x64, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0xba, 0x01, 0x0a, 0x0c, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x4d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x70, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x02, 0x49, 0x70, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, + 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, + 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, + 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x55, 0x73, + 0x65, 0x72, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, + 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, + 0x12, 0x16, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x22, 0x37, 0x0a, 0x0f, 0x52, 0x50, 0x43, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x4d, 0x73, 0x67, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x4d, 0x73, 0x67, 0x22, 0x4d, 0x0a, 0x0d, 0x41, + 0x67, 0x65, 0x6e, 0x74, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, + 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, + 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0d, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x37, 0x0a, 0x0f, 0x41, 0x67, + 0x65, 0x6e, 0x74, 0x55, 0x6e, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, + 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, + 0x6e, 0x49, 0x64, 0x22, 0x75, 0x0a, 0x13, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x6e, 0x64, + 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, + 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, + 0x12, 0x24, 0x0a, 0x0d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, + 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x4f, 0x0a, 0x13, 0x42, 0x72, + 0x6f, 0x61, 0x64, 0x43, 0x61, 0x73, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, + 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4d, 0x65, 0x74, 0x68, + 0x6f, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x36, 0x0a, 0x0e, 0x41, + 0x67, 0x65, 0x6e, 0x74, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, + 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, + 0x6e, 0x49, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( @@ -308,20 +556,23 @@ func file_comm_proto_rawDescGZIP() []byte { return file_comm_proto_rawDescData } -var file_comm_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_comm_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_comm_proto_goTypes = []interface{}{ - (*MessageHead)(nil), // 0: MessageHead - (*Message)(nil), // 1: Message - (*UserMessage)(nil), // 2: UserMessage - (*UserMessageReply)(nil), // 3: UserMessageReply + (*UserMessage)(nil), // 0: UserMessage + (*AgentMessage)(nil), // 1: AgentMessage + (*RPCMessageReply)(nil), // 2: RPCMessageReply + (*AgentBuildReq)(nil), // 3: AgentBuildReq + (*AgentUnBuildReq)(nil), // 4: AgentUnBuildReq + (*AgentSendMessageReq)(nil), // 5: AgentSendMessageReq + (*BroadCastMessageReq)(nil), // 6: BroadCastMessageReq + (*AgentCloseeReq)(nil), // 7: AgentCloseeReq } var file_comm_proto_depIdxs = []int32{ - 0, // 0: Message.Head:type_name -> MessageHead - 1, // [1:1] is the sub-list for method output_type - 1, // [1:1] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name } func init() { file_comm_proto_init() } @@ -331,30 +582,6 @@ func file_comm_proto_init() { } if !protoimpl.UnsafeEnabled { file_comm_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*MessageHead); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_comm_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Message); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_comm_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*UserMessage); i { case 0: return &v.state @@ -366,8 +593,80 @@ func file_comm_proto_init() { return nil } } + file_comm_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*AgentMessage); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comm_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RPCMessageReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } file_comm_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*UserMessageReply); i { + switch v := v.(*AgentBuildReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comm_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*AgentUnBuildReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comm_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*AgentSendMessageReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comm_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BroadCastMessageReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comm_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*AgentCloseeReq); i { case 0: return &v.state case 1: @@ -385,7 +684,7 @@ func file_comm_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_comm_proto_rawDesc, NumEnums: 0, - NumMessages: 4, + NumMessages: 8, NumExtensions: 0, NumServices: 0, }, diff --git a/pb/proto/comm.proto b/pb/proto/comm.proto index 0ce5656f8..ed1b80c62 100644 --- a/pb/proto/comm.proto +++ b/pb/proto/comm.proto @@ -1,19 +1,14 @@ syntax = "proto3"; option go_package = ".;pb"; - -//消息体 -message MessageHead { - string ServiceMethod =1; //服务名 -} - -//处理JSON消息 -message Message { - MessageHead Head =1; +//用户消息流结构 +message UserMessage { + string ServiceMethod =1; //服务名 bytes Data = 2; } -message UserMessage { +//代理用户转发消息结构 +message AgentMessage { string Ip = 1; string UserSessionId = 2; uint32 UserId = 3; @@ -22,7 +17,33 @@ message UserMessage { bytes Message = 6; } -message UserMessageReply { +//RPC 服务固定回复结构 +message RPCMessageReply { int32 Code = 1; string Msg = 2; +} + +//用户代理绑定Uid请求 +message AgentBuildReq { + string UserSessionId = 1; + uint32 UserId = 2; +} +//用户代理解绑请求 +message AgentUnBuildReq { + string UserSessionId = 1; +} +//向用户代理发送消息请求 +message AgentSendMessageReq { + string UserSessionId = 1; + string ServiceMethod = 2; //服务名 + bytes Data = 3; +} +//广播消息到所有用户代理 +message BroadCastMessageReq { + string ServiceMethod = 1; //服务名 + bytes Data = 2; +} +//关闭用户代理 +message AgentCloseeReq { + string UserSessionId = 1; } \ No newline at end of file diff --git a/services/s_comps/comp_gateroute.go b/services/s_comps/comp_gateroute.go index 75c5bf3ec..c031f0309 100644 --- a/services/s_comps/comp_gateroute.go +++ b/services/s_comps/comp_gateroute.go @@ -65,7 +65,7 @@ func (this *SComp_GateRouteComp) RegisterRoute(methodName string, comp reflect.V this.mrlock.Unlock() } -func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.UserMessage, reply *pb.UserMessageReply) error { +func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) error { log.Debugf("SComp_GateRouteComp ReceiveMsg agent:%s uId:%d MessageDistribution msg:%s", args.UserSessionId, args.UserId, args.Method) this.mrlock.RLock() msghandle, ok := this.msghandles[args.Method]