Adding new peers up to given depth. Outline of node gaph Update

This commit is contained in:
Milos Gajdos
2019-09-09 18:47:10 +01:00
parent a6668ae057
commit f0a1031e97
5 changed files with 207 additions and 85 deletions

View File

@@ -35,9 +35,9 @@ var _ server.Option
// Client API for Network service
type NetworkService interface {
ListRoutes(ctx context.Context, in *proto1.Request, opts ...client.CallOption) (*proto1.ListResponse, error)
ListNodes(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error)
Neighbourhood(ctx context.Context, in *NeighbourhoodRequest, opts ...client.CallOption) (*NeighbourhoodResponse, error)
ListRoutes(ctx context.Context, in *proto1.Request, opts ...client.CallOption) (*proto1.ListResponse, error)
}
type networkService struct {
@@ -58,16 +58,6 @@ func NewNetworkService(name string, c client.Client) NetworkService {
}
}
func (c *networkService) ListRoutes(ctx context.Context, in *proto1.Request, opts ...client.CallOption) (*proto1.ListResponse, error) {
req := c.c.NewRequest(c.name, "Network.ListRoutes", in)
out := new(proto1.ListResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *networkService) ListNodes(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) {
req := c.c.NewRequest(c.name, "Network.ListNodes", in)
out := new(ListResponse)
@@ -88,19 +78,29 @@ func (c *networkService) Neighbourhood(ctx context.Context, in *NeighbourhoodReq
return out, nil
}
func (c *networkService) ListRoutes(ctx context.Context, in *proto1.Request, opts ...client.CallOption) (*proto1.ListResponse, error) {
req := c.c.NewRequest(c.name, "Network.ListRoutes", in)
out := new(proto1.ListResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Network service
type NetworkHandler interface {
ListRoutes(context.Context, *proto1.Request, *proto1.ListResponse) error
ListNodes(context.Context, *ListRequest, *ListResponse) error
Neighbourhood(context.Context, *NeighbourhoodRequest, *NeighbourhoodResponse) error
ListRoutes(context.Context, *proto1.Request, *proto1.ListResponse) error
}
func RegisterNetworkHandler(s server.Server, hdlr NetworkHandler, opts ...server.HandlerOption) error {
type network interface {
ListRoutes(ctx context.Context, in *proto1.Request, out *proto1.ListResponse) error
ListNodes(ctx context.Context, in *ListRequest, out *ListResponse) error
Neighbourhood(ctx context.Context, in *NeighbourhoodRequest, out *NeighbourhoodResponse) error
ListRoutes(ctx context.Context, in *proto1.Request, out *proto1.ListResponse) error
}
type Network struct {
network
@@ -113,10 +113,6 @@ type networkHandler struct {
NetworkHandler
}
func (h *networkHandler) ListRoutes(ctx context.Context, in *proto1.Request, out *proto1.ListResponse) error {
return h.NetworkHandler.ListRoutes(ctx, in, out)
}
func (h *networkHandler) ListNodes(ctx context.Context, in *ListRequest, out *ListResponse) error {
return h.NetworkHandler.ListNodes(ctx, in, out)
}
@@ -124,3 +120,7 @@ func (h *networkHandler) ListNodes(ctx context.Context, in *ListRequest, out *Li
func (h *networkHandler) Neighbourhood(ctx context.Context, in *NeighbourhoodRequest, out *NeighbourhoodResponse) error {
return h.NetworkHandler.Neighbourhood(ctx, in, out)
}
func (h *networkHandler) ListRoutes(ctx context.Context, in *proto1.Request, out *proto1.ListResponse) error {
return h.NetworkHandler.ListRoutes(ctx, in, out)
}

View File

@@ -133,12 +133,12 @@ func (m *NeighbourhoodRequest) GetId() string {
return ""
}
// NeighbourhoodResponse contains node neighbourhood hierarchy
// NeighbourhoodResponse returns node neighbourhood
type NeighbourhoodResponse struct {
Neighbourhood *Neighbour `protobuf:"bytes,1,opt,name=neighbourhood,proto3" json:"neighbourhood,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
Neighbourhoodi *Neighbourhood `protobuf:"bytes,1,opt,name=neighbourhoodi,proto3" json:"neighbourhoodi,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *NeighbourhoodResponse) Reset() { *m = NeighbourhoodResponse{} }
@@ -166,9 +166,56 @@ func (m *NeighbourhoodResponse) XXX_DiscardUnknown() {
var xxx_messageInfo_NeighbourhoodResponse proto.InternalMessageInfo
func (m *NeighbourhoodResponse) GetNeighbourhood() *Neighbour {
func (m *NeighbourhoodResponse) GetNeighbourhoodi() *Neighbourhood {
if m != nil {
return m.Neighbourhood
return m.Neighbourhoodi
}
return nil
}
type Neighbourhood struct {
Node *Node `protobuf:"bytes,1,opt,name=node,proto3" json:"node,omitempty"`
Neighbours []*Node `protobuf:"bytes,2,rep,name=neighbours,proto3" json:"neighbours,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Neighbourhood) Reset() { *m = Neighbourhood{} }
func (m *Neighbourhood) String() string { return proto.CompactTextString(m) }
func (*Neighbourhood) ProtoMessage() {}
func (*Neighbourhood) Descriptor() ([]byte, []int) {
return fileDescriptor_8571034d60397816, []int{4}
}
func (m *Neighbourhood) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Neighbourhood.Unmarshal(m, b)
}
func (m *Neighbourhood) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Neighbourhood.Marshal(b, m, deterministic)
}
func (m *Neighbourhood) XXX_Merge(src proto.Message) {
xxx_messageInfo_Neighbourhood.Merge(m, src)
}
func (m *Neighbourhood) XXX_Size() int {
return xxx_messageInfo_Neighbourhood.Size(m)
}
func (m *Neighbourhood) XXX_DiscardUnknown() {
xxx_messageInfo_Neighbourhood.DiscardUnknown(m)
}
var xxx_messageInfo_Neighbourhood proto.InternalMessageInfo
func (m *Neighbourhood) GetNode() *Node {
if m != nil {
return m.Node
}
return nil
}
func (m *Neighbourhood) GetNeighbours() []*Node {
if m != nil {
return m.Neighbours
}
return nil
}
@@ -188,7 +235,7 @@ func (m *Node) Reset() { *m = Node{} }
func (m *Node) String() string { return proto.CompactTextString(m) }
func (*Node) ProtoMessage() {}
func (*Node) Descriptor() ([]byte, []int) {
return fileDescriptor_8571034d60397816, []int{4}
return fileDescriptor_8571034d60397816, []int{5}
}
func (m *Node) XXX_Unmarshal(b []byte) error {
@@ -236,7 +283,7 @@ func (m *Connect) Reset() { *m = Connect{} }
func (m *Connect) String() string { return proto.CompactTextString(m) }
func (*Connect) ProtoMessage() {}
func (*Connect) Descriptor() ([]byte, []int) {
return fileDescriptor_8571034d60397816, []int{5}
return fileDescriptor_8571034d60397816, []int{6}
}
func (m *Connect) XXX_Unmarshal(b []byte) error {
@@ -277,7 +324,7 @@ func (m *Close) Reset() { *m = Close{} }
func (m *Close) String() string { return proto.CompactTextString(m) }
func (*Close) ProtoMessage() {}
func (*Close) Descriptor() ([]byte, []int) {
return fileDescriptor_8571034d60397816, []int{6}
return fileDescriptor_8571034d60397816, []int{7}
}
func (m *Close) XXX_Unmarshal(b []byte) error {
@@ -318,7 +365,7 @@ func (m *Solicit) Reset() { *m = Solicit{} }
func (m *Solicit) String() string { return proto.CompactTextString(m) }
func (*Solicit) ProtoMessage() {}
func (*Solicit) Descriptor() ([]byte, []int) {
return fileDescriptor_8571034d60397816, []int{7}
return fileDescriptor_8571034d60397816, []int{8}
}
func (m *Solicit) XXX_Unmarshal(b []byte) error {
@@ -351,17 +398,17 @@ type Neighbour struct {
// network node
Node *Node `protobuf:"bytes,1,opt,name=node,proto3" json:"node,omitempty"`
// neighbours
Neighbours []*Node `protobuf:"bytes,3,rep,name=neighbours,proto3" json:"neighbours,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
Neighbours []*Neighbour `protobuf:"bytes,2,rep,name=neighbours,proto3" json:"neighbours,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Neighbour) Reset() { *m = Neighbour{} }
func (m *Neighbour) String() string { return proto.CompactTextString(m) }
func (*Neighbour) ProtoMessage() {}
func (*Neighbour) Descriptor() ([]byte, []int) {
return fileDescriptor_8571034d60397816, []int{8}
return fileDescriptor_8571034d60397816, []int{9}
}
func (m *Neighbour) XXX_Unmarshal(b []byte) error {
@@ -389,7 +436,7 @@ func (m *Neighbour) GetNode() *Node {
return nil
}
func (m *Neighbour) GetNeighbours() []*Node {
func (m *Neighbour) GetNeighbours() []*Neighbour {
if m != nil {
return m.Neighbours
}
@@ -401,6 +448,7 @@ func init() {
proto.RegisterType((*ListResponse)(nil), "go.micro.network.ListResponse")
proto.RegisterType((*NeighbourhoodRequest)(nil), "go.micro.network.NeighbourhoodRequest")
proto.RegisterType((*NeighbourhoodResponse)(nil), "go.micro.network.NeighbourhoodResponse")
proto.RegisterType((*Neighbourhood)(nil), "go.micro.network.Neighbourhood")
proto.RegisterType((*Node)(nil), "go.micro.network.Node")
proto.RegisterType((*Connect)(nil), "go.micro.network.Connect")
proto.RegisterType((*Close)(nil), "go.micro.network.Close")
@@ -411,28 +459,29 @@ func init() {
func init() { proto.RegisterFile("network.proto", fileDescriptor_8571034d60397816) }
var fileDescriptor_8571034d60397816 = []byte{
// 360 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0x41, 0x4f, 0xf2, 0x40,
0x10, 0xfd, 0x28, 0xf0, 0x35, 0x0c, 0x1f, 0x5f, 0xcc, 0x46, 0x4d, 0x53, 0x83, 0x21, 0x7b, 0x40,
0x62, 0xb4, 0x18, 0x08, 0x9e, 0xbc, 0x18, 0x0e, 0x5e, 0x08, 0x87, 0x7a, 0xf3, 0x66, 0xbb, 0x9b,
0xb2, 0x11, 0x3a, 0xb8, 0xbb, 0x8d, 0x7f, 0xc0, 0x1f, 0x6e, 0xba, 0x5d, 0xb0, 0x80, 0x60, 0xb8,
0x75, 0xe6, 0xbd, 0x37, 0x6f, 0xa7, 0xfb, 0x16, 0x5a, 0x29, 0xd7, 0x1f, 0x28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5, 0xc2, 0xc7, 0x08, 0xc9, 0x3d, 0xc0, 0xfa, 0xf7, 0x28,
0xaf, 0x7a, 0xf0, 0x12, 0x4b, 0xcc, 0xc1, 0xa7, 0x03, 0xee, 0xb4, 0x00, 0xc9, 0x13, 0x80, 0xc9,
0x44, 0x1e, 0x1b, 0x45, 0xbc, 0x6f, 0xb5, 0x0d, 0x92, 0xbd, 0x65, 0xbf, 0xbd, 0x83, 0x94, 0xa3,
0x44, 0xff, 0x90, 0x09, 0x34, 0xf2, 0x4e, 0x6e, 0xa6, 0x48, 0x7b, 0xf7, 0x14, 0xa5, 0x20, 0xfa,
0x97, 0xfb, 0xe0, 0xf5, 0xb4, 0x08, 0x5a, 0x1b, 0x21, 0x22, 0xdd, 0x03, 0x29, 0x29, 0xa5, 0xd1,
0xbf, 0xfa, 0x95, 0xb7, 0xf2, 0x88, 0xfe, 0x9a, 0x47, 0x32, 0xfc, 0x0a, 0x00, 0x00, 0xff, 0xff,
0x59, 0xcf, 0xab, 0xb5, 0x7c, 0x03, 0x00, 0x00,
// 372 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0x5d, 0x4f, 0xea, 0x40,
0x10, 0xbd, 0xf4, 0xc2, 0x6d, 0x18, 0x2e, 0xc4, 0x6c, 0xd4, 0x34, 0x18, 0x94, 0xec, 0x03, 0x12,
0xa3, 0xc5, 0x40, 0xf0, 0x45, 0xdf, 0x78, 0xe0, 0x85, 0xf0, 0x80, 0x7f, 0x40, 0xdb, 0x6e, 0xca,
0x46, 0xe8, 0xe0, 0xee, 0x36, 0xfe, 0x01, 0x7f, 0xb8, 0xd9, 0x76, 0xc1, 0x52, 0xbe, 0xd2, 0xb7,
0xee, 0xcc, 0x99, 0x73, 0x66, 0xa6, 0x67, 0xa0, 0x1e, 0x31, 0xf5, 0x85, 0xe2, 0xc3, 0x5d, 0x09,
0x54, 0x48, 0xce, 0x42,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, 0xfb,
0x15, 0x17, 0xdc, 0xe7, 0xc5, 0xb4, 0x14, 0x54, 0x37, 0x9b, 0x2c, 0xb4, 0xc5, 0xe7, 0x3d, 0x5b,
0xbc, 0x3a, 0xf2, 0x1f, 0xb3, 0xab, 0xec, 0x7f, 0x5b, 0x60, 0x4f, 0x53, 0x04, 0x99, 0x40, 0x55,
0x7b, 0x52, 0x53, 0x4b, 0xd2, 0xda, 0x65, 0xc8, 0xf8, 0xb7, 0x79, 0x7d, 0x28, 0x9d, 0x1a, 0x8c,
0xfe, 0x21, 0x5e, 0xde, 0x19, 0x9d, 0x53, 0xde, 0x32, 0xd4, 0xb7, 0x27, 0x71, 0x1b, 0x8d, 0x31,
0x40, 0xa2, 0xaa, 0x0f, 0x4d, 0x12, 0xe7, 0xb7, 0xd0, 0x9c, 0xde, 0x9a, 0xb2, 0xb5, 0x93, 0xd9,
0x6e, 0xd6, 0xfb, 0x97, 0x1c, 0xe9, 0xe0, 0x27, 0x00, 0x00, 0xff, 0xff, 0x63, 0xe7, 0xb4, 0xb0,
0xfc, 0x03, 0x00, 0x00,
}

View File

@@ -6,9 +6,9 @@ import "github.com/micro/go-micro/router/proto/router.proto";
// Network service is usesd to gain visibility into networks
service Network {
rpc ListRoutes(go.micro.router.Request) returns (go.micro.router.ListResponse) {};
rpc ListNodes(ListRequest) returns (ListResponse) {};
rpc Neighbourhood(NeighbourhoodRequest) returns (NeighbourhoodResponse) {};
rpc ListRoutes(go.micro.router.Request) returns (go.micro.router.ListResponse) {};
}
// Empty request
@@ -24,9 +24,14 @@ message NeighbourhoodRequest {
string id = 1;
}
// NeighbourhoodResponse contains node neighbourhood hierarchy
// NeighbourhoodResponse returns node neighbourhood
message NeighbourhoodResponse {
Neighbour neighbourhood = 1;
Neighbourhood neighbourhoodi = 1;
}
message Neighbourhood {
Node node = 1;
repeated Node neighbours = 2;
}
// Node is network node
@@ -60,5 +65,5 @@ message Neighbour {
// network node
Node node = 1;
// neighbours
repeated Node neighbours = 3;
repeated Neighbour neighbours = 2;
}