增加邻居master服务发现功能

This commit is contained in:
boyce
2021-05-07 15:22:54 +08:00
parent bbab004f65
commit 212798dc04
6 changed files with 211 additions and 171 deletions

View File

@@ -151,9 +151,10 @@ func (m *ServiceDiscoverReq) GetNodeInfo() *NodeInfo {
//Master->Client
type SubscribeDiscoverNotify struct {
IsFull bool `protobuf:"varint,1,opt,name=IsFull,proto3" json:"IsFull,omitempty"`
DelNodeId int32 `protobuf:"varint,2,opt,name=DelNodeId,proto3" json:"DelNodeId,omitempty"`
NodeInfo []*NodeInfo `protobuf:"bytes,3,rep,name=nodeInfo,proto3" json:"nodeInfo,omitempty"`
MasterNodeId int32 `protobuf:"varint,1,opt,name=MasterNodeId,proto3" json:"MasterNodeId,omitempty"`
IsFull bool `protobuf:"varint,2,opt,name=IsFull,proto3" json:"IsFull,omitempty"`
DelNodeId int32 `protobuf:"varint,3,opt,name=DelNodeId,proto3" json:"DelNodeId,omitempty"`
NodeInfo []*NodeInfo `protobuf:"bytes,4,rep,name=nodeInfo,proto3" json:"nodeInfo,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@@ -192,6 +193,13 @@ func (m *SubscribeDiscoverNotify) XXX_DiscardUnknown() {
var xxx_messageInfo_SubscribeDiscoverNotify proto.InternalMessageInfo
func (m *SubscribeDiscoverNotify) GetMasterNodeId() int32 {
if m != nil {
return m.MasterNodeId
}
return 0
}
func (m *SubscribeDiscoverNotify) GetIsFull() bool {
if m != nil {
return m.IsFull
@@ -214,25 +222,24 @@ func (m *SubscribeDiscoverNotify) GetNodeInfo() []*NodeInfo {
}
//Master->Client
type ServiceDiscoverRes struct {
NodeInfo []*NodeInfo `protobuf:"bytes,1,rep,name=nodeInfo,proto3" json:"nodeInfo,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
type Empty struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ServiceDiscoverRes) Reset() { *m = ServiceDiscoverRes{} }
func (m *ServiceDiscoverRes) String() string { return proto.CompactTextString(m) }
func (*ServiceDiscoverRes) ProtoMessage() {}
func (*ServiceDiscoverRes) Descriptor() ([]byte, []int) {
func (m *Empty) Reset() { *m = Empty{} }
func (m *Empty) String() string { return proto.CompactTextString(m) }
func (*Empty) ProtoMessage() {}
func (*Empty) Descriptor() ([]byte, []int) {
return fileDescriptor_9bfdd3ec0419520f, []int{3}
}
func (m *ServiceDiscoverRes) XXX_Unmarshal(b []byte) error {
func (m *Empty) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *ServiceDiscoverRes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
func (m *Empty) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_ServiceDiscoverRes.Marshal(b, m, deterministic)
return xxx_messageInfo_Empty.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
@@ -242,55 +249,49 @@ func (m *ServiceDiscoverRes) XXX_Marshal(b []byte, deterministic bool) ([]byte,
return b[:n], nil
}
}
func (m *ServiceDiscoverRes) XXX_Merge(src proto.Message) {
xxx_messageInfo_ServiceDiscoverRes.Merge(m, src)
func (m *Empty) XXX_Merge(src proto.Message) {
xxx_messageInfo_Empty.Merge(m, src)
}
func (m *ServiceDiscoverRes) XXX_Size() int {
func (m *Empty) XXX_Size() int {
return m.Size()
}
func (m *ServiceDiscoverRes) XXX_DiscardUnknown() {
xxx_messageInfo_ServiceDiscoverRes.DiscardUnknown(m)
func (m *Empty) XXX_DiscardUnknown() {
xxx_messageInfo_Empty.DiscardUnknown(m)
}
var xxx_messageInfo_ServiceDiscoverRes proto.InternalMessageInfo
func (m *ServiceDiscoverRes) GetNodeInfo() []*NodeInfo {
if m != nil {
return m.NodeInfo
}
return nil
}
var xxx_messageInfo_Empty proto.InternalMessageInfo
func init() {
proto.RegisterType((*NodeInfo)(nil), "rpc.NodeInfo")
proto.RegisterType((*ServiceDiscoverReq)(nil), "rpc.ServiceDiscoverReq")
proto.RegisterType((*SubscribeDiscoverNotify)(nil), "rpc.SubscribeDiscoverNotify")
proto.RegisterType((*ServiceDiscoverRes)(nil), "rpc.ServiceDiscoverRes")
proto.RegisterType((*Empty)(nil), "rpc.Empty")
}
func init() { proto.RegisterFile("rpc/dynamicdiscover.proto", fileDescriptor_9bfdd3ec0419520f) }
var fileDescriptor_9bfdd3ec0419520f = []byte{
// 295 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x91, 0xcd, 0x4a, 0xfc, 0x30,
0x14, 0xc5, 0xc9, 0xf4, 0xdf, 0xf9, 0xb7, 0x57, 0x5c, 0x18, 0x41, 0xa3, 0x48, 0x29, 0x5d, 0x55,
0x90, 0x0e, 0xe8, 0x03, 0x88, 0x32, 0x08, 0x03, 0x52, 0x86, 0xcc, 0xce, 0x5d, 0x9b, 0x64, 0x20,
0xd0, 0x69, 0x6a, 0xfa, 0x01, 0xe3, 0x03, 0xf9, 0x2c, 0x2e, 0x7d, 0x04, 0xe9, 0x93, 0xc8, 0xc4,
0x4c, 0xfd, 0x64, 0x76, 0xf9, 0xdd, 0x9b, 0x9c, 0x7b, 0xce, 0x0d, 0x9c, 0xe8, 0x8a, 0x4d, 0xf8,
0xba, 0xcc, 0x56, 0x92, 0x71, 0x59, 0x33, 0xd5, 0x09, 0x9d, 0x54, 0x5a, 0x35, 0x0a, 0x3b, 0xba,
0x62, 0xd1, 0x33, 0x02, 0x2f, 0x55, 0x5c, 0xcc, 0xca, 0xa5, 0xc2, 0x47, 0x30, 0x36, 0x67, 0x4e,
0x50, 0x88, 0x62, 0x97, 0x5a, 0xc2, 0xa7, 0x1f, 0x77, 0xd2, 0x6c, 0x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e, 0xbd, 0xcb, 0xbc, 0x7f, 0x7d, 0x98, 0x1b, 0xcd, 0xf2, 0x75, 0x25, 0xba, 0x91, 0xd3, 0x37,
0x04, 0xa7, 0xe3, 0x59, 0xd9, 0x30, 0x23, 0xcb, 0xcd, 0x1b, 0x43, 0x65, 0xe5, 0x64, 0x81, 0x53,
0x38, 0x78, 0x2e, 0x1a, 0xbb, 0xe2, 0xad, 0xfa, 0x3b, 0xb3, 0xd5, 0x72, 0x06, 0xcd, 0xe3, 0xac,
0xaa, 0xdc, 0x0a, 0x22, 0xea, 0x09, 0x5f, 0x40, 0xb7, 0x2f, 0x2a, 0x6f, 0x0c, 0x9c, 0xf1, 0x77,
0xb0, 0x13, 0xb0, 0x95, 0x04, 0xff, 0x05, 0xec, 0x40, 0xf8, 0x30, 0xd5, 0x76, 0x71, 0x7f, 0xfc,
0xb1, 0x8c, 0xd1, 0xe7, 0x32, 0x46, 0x5f, 0xcb, 0x18, 0xbd, 0x84, 0x79, 0xcf, 0x68, 0x56, 0xb6,
0xdd, 0xa7, 0xdd, 0x7c, 0x07, 0x00, 0x00, 0xff, 0xff, 0xa7, 0x79, 0x82, 0x2a, 0xd1, 0x01, 0x00,
0x00,
}
func (m *NodeInfo) Marshal() (dAtA []byte, err error) {
@@ -432,13 +433,13 @@ func (m *SubscribeDiscoverNotify) MarshalToSizedBuffer(dAtA []byte) (int, error)
i = encodeVarintDynamicdiscover(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x1a
dAtA[i] = 0x22
}
}
if m.DelNodeId != 0 {
i = encodeVarintDynamicdiscover(dAtA, i, uint64(m.DelNodeId))
i--
dAtA[i] = 0x10
dAtA[i] = 0x18
}
if m.IsFull {
i--
@@ -448,12 +449,17 @@ func (m *SubscribeDiscoverNotify) MarshalToSizedBuffer(dAtA []byte) (int, error)
dAtA[i] = 0
}
i--
dAtA[i] = 0x10
}
if m.MasterNodeId != 0 {
i = encodeVarintDynamicdiscover(dAtA, i, uint64(m.MasterNodeId))
i--
dAtA[i] = 0x8
}
return len(dAtA) - i, nil
}
func (m *ServiceDiscoverRes) Marshal() (dAtA []byte, err error) {
func (m *Empty) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
@@ -463,12 +469,12 @@ func (m *ServiceDiscoverRes) Marshal() (dAtA []byte, err error) {
return dAtA[:n], nil
}
func (m *ServiceDiscoverRes) MarshalTo(dAtA []byte) (int, error) {
func (m *Empty) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *ServiceDiscoverRes) MarshalToSizedBuffer(dAtA []byte) (int, error) {
func (m *Empty) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
@@ -477,20 +483,6 @@ func (m *ServiceDiscoverRes) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i -= len(m.XXX_unrecognized)
copy(dAtA[i:], m.XXX_unrecognized)
}
if len(m.NodeInfo) > 0 {
for iNdEx := len(m.NodeInfo) - 1; iNdEx >= 0; iNdEx-- {
{
size, err := m.NodeInfo[iNdEx].MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintDynamicdiscover(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0xa
}
}
return len(dAtA) - i, nil
}
@@ -559,6 +551,9 @@ func (m *SubscribeDiscoverNotify) Size() (n int) {
}
var l int
_ = l
if m.MasterNodeId != 0 {
n += 1 + sovDynamicdiscover(uint64(m.MasterNodeId))
}
if m.IsFull {
n += 2
}
@@ -577,18 +572,12 @@ func (m *SubscribeDiscoverNotify) Size() (n int) {
return n
}
func (m *ServiceDiscoverRes) Size() (n int) {
func (m *Empty) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if len(m.NodeInfo) > 0 {
for _, e := range m.NodeInfo {
l = e.Size()
n += 1 + l + sovDynamicdiscover(uint64(l))
}
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
@@ -910,6 +899,25 @@ func (m *SubscribeDiscoverNotify) Unmarshal(dAtA []byte) error {
}
switch fieldNum {
case 1:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field MasterNodeId", wireType)
}
m.MasterNodeId = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowDynamicdiscover
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.MasterNodeId |= int32(b&0x7F) << shift
if b < 0x80 {
break
}
}
case 2:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field IsFull", wireType)
}
@@ -929,7 +937,7 @@ func (m *SubscribeDiscoverNotify) Unmarshal(dAtA []byte) error {
}
}
m.IsFull = bool(v != 0)
case 2:
case 3:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field DelNodeId", wireType)
}
@@ -948,7 +956,7 @@ func (m *SubscribeDiscoverNotify) Unmarshal(dAtA []byte) error {
break
}
}
case 3:
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field NodeInfo", wireType)
}
@@ -1007,7 +1015,7 @@ func (m *SubscribeDiscoverNotify) Unmarshal(dAtA []byte) error {
}
return nil
}
func (m *ServiceDiscoverRes) Unmarshal(dAtA []byte) error {
func (m *Empty) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
@@ -1030,46 +1038,12 @@ func (m *ServiceDiscoverRes) Unmarshal(dAtA []byte) error {
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: ServiceDiscoverRes: wiretype end group for non-group")
return fmt.Errorf("proto: Empty: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: ServiceDiscoverRes: illegal tag %d (wire type %d)", fieldNum, wire)
return fmt.Errorf("proto: Empty: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field NodeInfo", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowDynamicdiscover
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthDynamicdiscover
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthDynamicdiscover
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.NodeInfo = append(m.NodeInfo, &NodeInfo{})
if err := m.NodeInfo[len(m.NodeInfo)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipDynamicdiscover(dAtA[iNdEx:])