优化服务器之间的底层连接方式

This commit is contained in:
flswld
2023-01-08 22:11:14 +08:00
parent 99408a745f
commit 6779ed8f20
21 changed files with 742 additions and 216 deletions

View File

@@ -33,6 +33,8 @@ type DiscoveryNATSRPCServer interface {
GetRegionEc2B(ctx context.Context, req *NullMsg) (*RegionEc2B, error)
// 获取负载最小的网关服务器的地址和端口
GetGateServerAddr(ctx context.Context, req *GetGateServerAddrReq) (*GateServerAddr, error)
// 获取全部网关服务器信息列表
GetAllGateServerInfoList(ctx context.Context, req *NullMsg) (*GateServerInfoList, error)
}
// RegisterDiscoveryNATSRPCServer register Discovery service
@@ -54,6 +56,8 @@ type DiscoveryNATSRPCClient interface {
GetRegionEc2B(ctx context.Context, req *NullMsg, opt ...natsrpc.CallOption) (*RegionEc2B, error)
// 获取负载最小的网关服务器的地址和端口
GetGateServerAddr(ctx context.Context, req *GetGateServerAddrReq, opt ...natsrpc.CallOption) (*GateServerAddr, error)
// 获取全部网关服务器信息列表
GetAllGateServerInfoList(ctx context.Context, req *NullMsg, opt ...natsrpc.CallOption) (*GateServerInfoList, error)
}
type _DiscoveryNATSRPCClient struct {
@@ -101,3 +105,8 @@ func (c *_DiscoveryNATSRPCClient) GetGateServerAddr(ctx context.Context, req *Ge
err := c.c.Request(ctx, "GetGateServerAddr", req, rep, opt...)
return rep, err
}
func (c *_DiscoveryNATSRPCClient) GetAllGateServerInfoList(ctx context.Context, req *NullMsg, opt ...natsrpc.CallOption) (*GateServerInfoList, error) {
rep := &GateServerInfoList{}
err := c.c.Request(ctx, "GetAllGateServerInfoList", req, rep, opt...)
return rep, err
}

View File

@@ -479,8 +479,10 @@ type GateServerAddr struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
IpAddr string `protobuf:"bytes,1,opt,name=ip_addr,json=ipAddr,proto3" json:"ip_addr,omitempty"`
Port uint32 `protobuf:"varint,2,opt,name=port,proto3" json:"port,omitempty"`
KcpAddr string `protobuf:"bytes,1,opt,name=kcp_addr,json=kcpAddr,proto3" json:"kcp_addr,omitempty"`
KcpPort uint32 `protobuf:"varint,2,opt,name=kcp_port,json=kcpPort,proto3" json:"kcp_port,omitempty"`
MqAddr string `protobuf:"bytes,3,opt,name=mq_addr,json=mqAddr,proto3" json:"mq_addr,omitempty"`
MqPort uint32 `protobuf:"varint,4,opt,name=mq_port,json=mqPort,proto3" json:"mq_port,omitempty"`
}
func (x *GateServerAddr) Reset() {
@@ -515,20 +517,144 @@ func (*GateServerAddr) Descriptor() ([]byte, []int) {
return file_api_proto_rawDescGZIP(), []int{9}
}
func (x *GateServerAddr) GetIpAddr() string {
func (x *GateServerAddr) GetKcpAddr() string {
if x != nil {
return x.IpAddr
return x.KcpAddr
}
return ""
}
func (x *GateServerAddr) GetPort() uint32 {
func (x *GateServerAddr) GetKcpPort() uint32 {
if x != nil {
return x.Port
return x.KcpPort
}
return 0
}
func (x *GateServerAddr) GetMqAddr() string {
if x != nil {
return x.MqAddr
}
return ""
}
func (x *GateServerAddr) GetMqPort() uint32 {
if x != nil {
return x.MqPort
}
return 0
}
type GateServerInfo struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
AppId string `protobuf:"bytes,1,opt,name=app_id,json=appId,proto3" json:"app_id,omitempty"`
MqAddr string `protobuf:"bytes,2,opt,name=mq_addr,json=mqAddr,proto3" json:"mq_addr,omitempty"`
MqPort uint32 `protobuf:"varint,3,opt,name=mq_port,json=mqPort,proto3" json:"mq_port,omitempty"`
}
func (x *GateServerInfo) Reset() {
*x = GateServerInfo{}
if protoimpl.UnsafeEnabled {
mi := &file_api_proto_msgTypes[10]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GateServerInfo) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GateServerInfo) ProtoMessage() {}
func (x *GateServerInfo) ProtoReflect() protoreflect.Message {
mi := &file_api_proto_msgTypes[10]
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 GateServerInfo.ProtoReflect.Descriptor instead.
func (*GateServerInfo) Descriptor() ([]byte, []int) {
return file_api_proto_rawDescGZIP(), []int{10}
}
func (x *GateServerInfo) GetAppId() string {
if x != nil {
return x.AppId
}
return ""
}
func (x *GateServerInfo) GetMqAddr() string {
if x != nil {
return x.MqAddr
}
return ""
}
func (x *GateServerInfo) GetMqPort() uint32 {
if x != nil {
return x.MqPort
}
return 0
}
type GateServerInfoList struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
GateServerInfoList []*GateServerInfo `protobuf:"bytes,1,rep,name=gate_server_info_list,json=gateServerInfoList,proto3" json:"gate_server_info_list,omitempty"`
}
func (x *GateServerInfoList) Reset() {
*x = GateServerInfoList{}
if protoimpl.UnsafeEnabled {
mi := &file_api_proto_msgTypes[11]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GateServerInfoList) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GateServerInfoList) ProtoMessage() {}
func (x *GateServerInfoList) ProtoReflect() protoreflect.Message {
mi := &file_api_proto_msgTypes[11]
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 GateServerInfoList.ProtoReflect.Descriptor instead.
func (*GateServerInfoList) Descriptor() ([]byte, []int) {
return file_api_proto_rawDescGZIP(), []int{11}
}
func (x *GateServerInfoList) GetGateServerInfoList() []*GateServerInfo {
if x != nil {
return x.GateServerInfoList
}
return nil
}
var File_api_proto protoreflect.FileDescriptor
var file_api_proto_rawDesc = []byte{
@@ -568,40 +694,61 @@ var file_api_proto_rawDesc = []byte{
0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73,
0x69, 0x6f, 0x6e, 0x22, 0x20, 0x0a, 0x0a, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x45, 0x63, 0x32,
0x62, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52,
0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x3d, 0x0a, 0x0e, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72,
0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x70, 0x5f, 0x61, 0x64,
0x64, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x69, 0x70, 0x41, 0x64, 0x64, 0x72,
0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04,
0x70, 0x6f, 0x72, 0x74, 0x32, 0xba, 0x03, 0x0a, 0x09, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65,
0x72, 0x79, 0x12, 0x4c, 0x0a, 0x0e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65,
0x72, 0x76, 0x65, 0x72, 0x12, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e,
0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65,
0x71, 0x1a, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x67,
0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x73, 0x70, 0x22, 0x00,
0x12, 0x3e, 0x0a, 0x0c, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72,
0x12, 0x19, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x61, 0x6e, 0x63,
0x65, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x11, 0x2e, 0x6e, 0x6f,
0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4e, 0x75, 0x6c, 0x6c, 0x4d, 0x73, 0x67, 0x22, 0x00,
0x12, 0x44, 0x0a, 0x0f, 0x4b, 0x65, 0x65, 0x70, 0x61, 0x6c, 0x69, 0x76, 0x65, 0x53, 0x65, 0x72,
0x76, 0x65, 0x72, 0x12, 0x1c, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4b,
0x65, 0x65, 0x70, 0x61, 0x6c, 0x69, 0x76, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65,
0x71, 0x1a, 0x11, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4e, 0x75, 0x6c,
0x6c, 0x4d, 0x73, 0x67, 0x22, 0x00, 0x12, 0x4c, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72,
0x76, 0x65, 0x72, 0x41, 0x70, 0x70, 0x49, 0x64, 0x12, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e,
0x61, 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x70, 0x70,
0x49, 0x64, 0x52, 0x65, 0x71, 0x1a, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69,
0x2e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x70, 0x70, 0x49, 0x64, 0x52,
0x73, 0x70, 0x22, 0x00, 0x12, 0x3a, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, 0x65, 0x67, 0x69, 0x6f,
0x6e, 0x45, 0x63, 0x32, 0x62, 0x12, 0x11, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69,
0x2e, 0x4e, 0x75, 0x6c, 0x6c, 0x4d, 0x73, 0x67, 0x1a, 0x14, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e,
0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x45, 0x63, 0x32, 0x62, 0x22, 0x00,
0x12, 0x4f, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65,
0x72, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1e, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69,
0x2e, 0x47, 0x65, 0x74, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64,
0x64, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x18, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69,
0x2e, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x22,
0x00, 0x42, 0x13, 0x5a, 0x11, 0x68, 0x6b, 0x34, 0x65, 0x2f, 0x6e, 0x6f, 0x64, 0x65, 0x2f, 0x61,
0x70, 0x69, 0x3b, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x78, 0x0a, 0x0e, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72,
0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x6b, 0x63, 0x70, 0x5f, 0x61,
0x64, 0x64, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6b, 0x63, 0x70, 0x41, 0x64,
0x64, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x6b, 0x63, 0x70, 0x5f, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x02,
0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x6b, 0x63, 0x70, 0x50, 0x6f, 0x72, 0x74, 0x12, 0x17, 0x0a,
0x07, 0x6d, 0x71, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06,
0x6d, 0x71, 0x41, 0x64, 0x64, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x6d, 0x71, 0x5f, 0x70, 0x6f, 0x72,
0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x6d, 0x71, 0x50, 0x6f, 0x72, 0x74, 0x22,
0x59, 0x0a, 0x0e, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x6e, 0x66,
0x6f, 0x12, 0x15, 0x0a, 0x06, 0x61, 0x70, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x6d, 0x71, 0x5f, 0x61,
0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x71, 0x41, 0x64, 0x64,
0x72, 0x12, 0x17, 0x0a, 0x07, 0x6d, 0x71, 0x5f, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x03, 0x20, 0x01,
0x28, 0x0d, 0x52, 0x06, 0x6d, 0x71, 0x50, 0x6f, 0x72, 0x74, 0x22, 0x61, 0x0a, 0x12, 0x47, 0x61,
0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x4c, 0x69, 0x73, 0x74,
0x12, 0x4b, 0x0a, 0x15, 0x67, 0x61, 0x74, 0x65, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f,
0x69, 0x6e, 0x66, 0x6f, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32,
0x18, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x61, 0x74, 0x65, 0x53,
0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x12, 0x67, 0x61, 0x74, 0x65, 0x53,
0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x4c, 0x69, 0x73, 0x74, 0x32, 0x89, 0x04,
0x0a, 0x09, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x12, 0x4c, 0x0a, 0x0e, 0x52,
0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x1b, 0x2e,
0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65,
0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x1b, 0x2e, 0x6e, 0x6f, 0x64,
0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65,
0x72, 0x76, 0x65, 0x72, 0x52, 0x73, 0x70, 0x22, 0x00, 0x12, 0x3e, 0x0a, 0x0c, 0x43, 0x61, 0x6e,
0x63, 0x65, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x19, 0x2e, 0x6e, 0x6f, 0x64, 0x65,
0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x65,
0x72, 0x52, 0x65, 0x71, 0x1a, 0x11, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e,
0x4e, 0x75, 0x6c, 0x6c, 0x4d, 0x73, 0x67, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x0f, 0x4b, 0x65, 0x65,
0x70, 0x61, 0x6c, 0x69, 0x76, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x1c, 0x2e, 0x6e,
0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4b, 0x65, 0x65, 0x70, 0x61, 0x6c, 0x69, 0x76,
0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x11, 0x2e, 0x6e, 0x6f, 0x64,
0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4e, 0x75, 0x6c, 0x6c, 0x4d, 0x73, 0x67, 0x22, 0x00, 0x12,
0x4c, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x70, 0x70, 0x49,
0x64, 0x12, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74,
0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x70, 0x70, 0x49, 0x64, 0x52, 0x65, 0x71, 0x1a, 0x1b,
0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72,
0x76, 0x65, 0x72, 0x41, 0x70, 0x70, 0x49, 0x64, 0x52, 0x73, 0x70, 0x22, 0x00, 0x12, 0x3a, 0x0a,
0x0d, 0x47, 0x65, 0x74, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x45, 0x63, 0x32, 0x62, 0x12, 0x11,
0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4e, 0x75, 0x6c, 0x6c, 0x4d, 0x73,
0x67, 0x1a, 0x14, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x67,
0x69, 0x6f, 0x6e, 0x45, 0x63, 0x32, 0x62, 0x22, 0x00, 0x12, 0x4f, 0x0a, 0x11, 0x47, 0x65, 0x74,
0x47, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1e,
0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74, 0x47, 0x61, 0x74,
0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x18,
0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65,
0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x22, 0x00, 0x12, 0x4d, 0x0a, 0x18, 0x47, 0x65,
0x74, 0x41, 0x6c, 0x6c, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x6e,
0x66, 0x6f, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x11, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70,
0x69, 0x2e, 0x4e, 0x75, 0x6c, 0x6c, 0x4d, 0x73, 0x67, 0x1a, 0x1c, 0x2e, 0x6e, 0x6f, 0x64, 0x65,
0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49,
0x6e, 0x66, 0x6f, 0x4c, 0x69, 0x73, 0x74, 0x22, 0x00, 0x42, 0x13, 0x5a, 0x11, 0x68, 0x6b, 0x34,
0x65, 0x2f, 0x6e, 0x6f, 0x64, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x3b, 0x61, 0x70, 0x69, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@@ -616,7 +763,7 @@ func file_api_proto_rawDescGZIP() []byte {
return file_api_proto_rawDescData
}
var file_api_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
var file_api_proto_msgTypes = make([]protoimpl.MessageInfo, 12)
var file_api_proto_goTypes = []interface{}{
(*NullMsg)(nil), // 0: node.api.NullMsg
(*GetServerAppIdReq)(nil), // 1: node.api.GetServerAppIdReq
@@ -628,26 +775,31 @@ var file_api_proto_goTypes = []interface{}{
(*GetGateServerAddrReq)(nil), // 7: node.api.GetGateServerAddrReq
(*RegionEc2B)(nil), // 8: node.api.RegionEc2b
(*GateServerAddr)(nil), // 9: node.api.GateServerAddr
(*GateServerInfo)(nil), // 10: node.api.GateServerInfo
(*GateServerInfoList)(nil), // 11: node.api.GateServerInfoList
}
var file_api_proto_depIdxs = []int32{
9, // 0: node.api.RegisterServerReq.gate_server_addr:type_name -> node.api.GateServerAddr
3, // 1: node.api.Discovery.RegisterServer:input_type -> node.api.RegisterServerReq
5, // 2: node.api.Discovery.CancelServer:input_type -> node.api.CancelServerReq
6, // 3: node.api.Discovery.KeepaliveServer:input_type -> node.api.KeepaliveServerReq
1, // 4: node.api.Discovery.GetServerAppId:input_type -> node.api.GetServerAppIdReq
0, // 5: node.api.Discovery.GetRegionEc2b:input_type -> node.api.NullMsg
7, // 6: node.api.Discovery.GetGateServerAddr:input_type -> node.api.GetGateServerAddrReq
4, // 7: node.api.Discovery.RegisterServer:output_type -> node.api.RegisterServerRsp
0, // 8: node.api.Discovery.CancelServer:output_type -> node.api.NullMsg
0, // 9: node.api.Discovery.KeepaliveServer:output_type -> node.api.NullMsg
2, // 10: node.api.Discovery.GetServerAppId:output_type -> node.api.GetServerAppIdRsp
8, // 11: node.api.Discovery.GetRegionEc2b:output_type -> node.api.RegionEc2b
9, // 12: node.api.Discovery.GetGateServerAddr:output_type -> node.api.GateServerAddr
7, // [7:13] is the sub-list for method output_type
1, // [1:7] 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
9, // 0: node.api.RegisterServerReq.gate_server_addr:type_name -> node.api.GateServerAddr
10, // 1: node.api.GateServerInfoList.gate_server_info_list:type_name -> node.api.GateServerInfo
3, // 2: node.api.Discovery.RegisterServer:input_type -> node.api.RegisterServerReq
5, // 3: node.api.Discovery.CancelServer:input_type -> node.api.CancelServerReq
6, // 4: node.api.Discovery.KeepaliveServer:input_type -> node.api.KeepaliveServerReq
1, // 5: node.api.Discovery.GetServerAppId:input_type -> node.api.GetServerAppIdReq
0, // 6: node.api.Discovery.GetRegionEc2b:input_type -> node.api.NullMsg
7, // 7: node.api.Discovery.GetGateServerAddr:input_type -> node.api.GetGateServerAddrReq
0, // 8: node.api.Discovery.GetAllGateServerInfoList:input_type -> node.api.NullMsg
4, // 9: node.api.Discovery.RegisterServer:output_type -> node.api.RegisterServerRsp
0, // 10: node.api.Discovery.CancelServer:output_type -> node.api.NullMsg
0, // 11: node.api.Discovery.KeepaliveServer:output_type -> node.api.NullMsg
2, // 12: node.api.Discovery.GetServerAppId:output_type -> node.api.GetServerAppIdRsp
8, // 13: node.api.Discovery.GetRegionEc2b:output_type -> node.api.RegionEc2b
9, // 14: node.api.Discovery.GetGateServerAddr:output_type -> node.api.GateServerAddr
11, // 15: node.api.Discovery.GetAllGateServerInfoList:output_type -> node.api.GateServerInfoList
9, // [9:16] is the sub-list for method output_type
2, // [2:9] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name
2, // [2:2] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name
}
func init() { file_api_proto_init() }
@@ -776,6 +928,30 @@ func file_api_proto_init() {
return nil
}
}
file_api_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GateServerInfo); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_api_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GateServerInfoList); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
@@ -783,7 +959,7 @@ func file_api_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_api_proto_rawDesc,
NumEnums: 0,
NumMessages: 10,
NumMessages: 12,
NumExtensions: 0,
NumServices: 1,
},

View File

@@ -17,6 +17,8 @@ service Discovery {
rpc GetRegionEc2b (NullMsg) returns (RegionEc2b) {}
// 获取负载最小的网关服务器的地址和端口
rpc GetGateServerAddr (GetGateServerAddrReq) returns (GateServerAddr) {}
// 获取全部网关服务器信息列表
rpc GetAllGateServerInfoList (NullMsg) returns (GateServerInfoList) {}
}
message NullMsg {
@@ -60,6 +62,18 @@ message RegionEc2b {
}
message GateServerAddr {
string ip_addr = 1;
uint32 port = 2;
string kcp_addr = 1;
uint32 kcp_port = 2;
string mq_addr = 3;
uint32 mq_port = 4;
}
message GateServerInfo {
string app_id = 1;
string mq_addr = 2;
uint32 mq_port = 3;
}
message GateServerInfoList {
repeated GateServerInfo gate_server_info_list = 1;
}

View File

@@ -33,12 +33,14 @@ func (s ServerInstanceSortList) Swap(i, j int) {
}
type ServerInstance struct {
serverType string
appId string
gateServerIpAddr string
gateServerPort uint32
version string
lastAliveTime int64
serverType string
appId string
gateServerKcpAddr string
gateServerKcpPort uint32
gateServerMqAddr string
gateServerMqPort uint32
version string
lastAliveTime int64
}
type DiscoveryService struct {
@@ -80,13 +82,16 @@ func (s *DiscoveryService) RegisterServer(ctx context.Context, req *api.Register
}
}
inst := &ServerInstance{
serverType: req.ServerType,
appId: appId,
serverType: req.ServerType,
appId: appId,
lastAliveTime: time.Now().Unix(),
}
if req.ServerType == api.GATE {
logger.Info("register new gate server, ip: %v, port: %v", req.GateServerAddr.IpAddr, req.GateServerAddr.Port)
inst.gateServerIpAddr = req.GateServerAddr.IpAddr
inst.gateServerPort = req.GateServerAddr.Port
logger.Info("register new gate server, ip: %v, port: %v", req.GateServerAddr.KcpAddr, req.GateServerAddr.KcpPort)
inst.gateServerKcpAddr = req.GateServerAddr.KcpAddr
inst.gateServerKcpPort = req.GateServerAddr.KcpPort
inst.gateServerMqAddr = req.GateServerAddr.MqAddr
inst.gateServerMqPort = req.GateServerAddr.MqPort
inst.version = req.Version
}
instMap.Store(appId, inst)
@@ -109,6 +114,7 @@ func (s *DiscoveryService) CancelServer(ctx context.Context, req *api.CancelServ
}
_, exist = instMap.Load(req.AppId)
if !exist {
logger.Error("recv not exist server cancel, server type: %v, appid: %v", req.ServerType, req.AppId)
return nil, errors.New("server not exist")
}
instMap.Delete(req.AppId)
@@ -117,12 +123,14 @@ func (s *DiscoveryService) CancelServer(ctx context.Context, req *api.CancelServ
// KeepaliveServer 服务器在线心跳保持
func (s *DiscoveryService) KeepaliveServer(ctx context.Context, req *api.KeepaliveServerReq) (*api.NullMsg, error) {
logger.Debug("server keepalive, server type: %v, appid: %v", req.ServerType, req.AppId)
instMap, exist := s.serverInstanceMap[req.ServerType]
if !exist {
return nil, errors.New("server type not exist")
}
inst, exist := instMap.Load(req.AppId)
if !exist {
logger.Error("recv not exist server keepalive, server type: %v, appid: %v", req.ServerType, req.AppId)
return nil, errors.New("server not exist")
}
serverInstance := inst.(*ServerInstance)
@@ -178,10 +186,35 @@ func (s *DiscoveryService) GetGateServerAddr(ctx context.Context, req *api.GetGa
return nil, errors.New("no gate server found")
}
inst := s.getRandomServerInstance(&versionInstMap)
logger.Debug("get gate server addr is, ip: %v, port: %v", inst.gateServerIpAddr, inst.gateServerPort)
logger.Debug("get gate server addr is, ip: %v, port: %v", inst.gateServerKcpAddr, inst.gateServerKcpPort)
return &api.GateServerAddr{
IpAddr: inst.gateServerIpAddr,
Port: inst.gateServerPort,
KcpAddr: inst.gateServerKcpAddr,
KcpPort: inst.gateServerKcpPort,
}, nil
}
// GetAllGateServerInfoList 获取全部网关服务器信息列表
func (s *DiscoveryService) GetAllGateServerInfoList(ctx context.Context, req *api.NullMsg) (*api.GateServerInfoList, error) {
logger.Debug("get all gate server info list")
instMap, exist := s.serverInstanceMap[api.GATE]
if !exist {
return nil, errors.New("gate server not exist")
}
if s.getServerInstanceMapLen(instMap) == 0 {
return nil, errors.New("no gate server found")
}
gateServerInfoList := make([]*api.GateServerInfo, 0)
instMap.Range(func(key, value any) bool {
serverInstance := value.(*ServerInstance)
gateServerInfoList = append(gateServerInfoList, &api.GateServerInfo{
AppId: serverInstance.appId,
MqAddr: serverInstance.gateServerMqAddr,
MqPort: serverInstance.gateServerMqPort,
})
return true
})
return &api.GateServerInfoList{
GateServerInfoList: gateServerInfoList,
}, nil
}
@@ -216,7 +249,8 @@ func (s *DiscoveryService) removeDeadServer() {
instMap.Range(func(key, value any) bool {
serverInstance := value.(*ServerInstance)
if nowTime-serverInstance.lastAliveTime > 60 {
logger.Warn("remove dead server, server type: %v, appid: %v", serverInstance.serverType, serverInstance.appId)
logger.Warn("remove dead server, server type: %v, appid: %v, last alive time: %v",
serverInstance.serverType, serverInstance.appId, serverInstance.lastAliveTime)
instMap.Delete(key)
}
return true