From 4260913b45b4f3ca4231adc6643e2d075a03d02d Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 23 Sep 2019 15:41:05 +0100 Subject: [PATCH] Set rpc methods as Network.Graph/Nodes/Routes --- network/handler/handler.go | 78 +++++- network/proto/network.micro.go | 53 ++-- network/proto/network.pb.go | 438 +++++++++++++++++++++++++++------ network/proto/network.proto | 27 +- 4 files changed, 499 insertions(+), 97 deletions(-) diff --git a/network/handler/handler.go b/network/handler/handler.go index a0905936..4d52a63e 100644 --- a/network/handler/handler.go +++ b/network/handler/handler.go @@ -15,8 +15,75 @@ type Network struct { Network network.Network } -// ListPeers returns a list of all the nodes the node has a direct link with -func (n *Network) ListPeers(ctx context.Context, req *pbNet.PeerRequest, resp *pbNet.PeerResponse) error { +func flatten(n network.Node, visited map[string]bool) []network.Node { + // if node is nil runaway + if n == nil { + return nil + } + + // set visisted + if visited == nil { + visited = make(map[string]bool) + } + + // check if already visited + if visited[n.Id()] == true { + return nil + } + + // create new list of nodes + var nodes []network.Node + + // append the current node + nodes = append(nodes, n) + + // set to visited + visited[n.Id()] = true + + // visit the list of peers + for _, node := range n.Peers() { + nodes = append(nodes, flatten(node, visited)...) + } + + return nodes +} + +// Nodes returns the list of nodes +func (n *Network) Nodes(ctx context.Context, req *pbNet.NodesRequest, resp *pbNet.NodesResponse) error { + depth := uint(req.Depth) + if depth <= 0 || depth > network.MaxDepth { + depth = network.MaxDepth + } + + // root node + nodes := map[string]network.Node{} + + // get peers encoded into protobuf + peers := flatten(n.Network, nil) + + // walk all the peers + for _, peer := range peers { + if peer == nil { + continue + } + if _, ok := nodes[peer.Id()]; ok { + continue + } + + // add to visited list + nodes[n.Network.Id()] = peer + + resp.Nodes = append(resp.Nodes, &pbNet.Node{ + Id: peer.Id(), + Address: peer.Address(), + }) + } + + return nil +} + +// Graph returns the network graph from this root node +func (n *Network) Graph(ctx context.Context, req *pbNet.GraphRequest, resp *pbNet.GraphResponse) error { depth := uint(req.Depth) if depth <= 0 || depth > network.MaxDepth { depth = network.MaxDepth @@ -25,13 +92,14 @@ func (n *Network) ListPeers(ctx context.Context, req *pbNet.PeerRequest, resp *p // get peers encoded into protobuf peers := network.PeersToProto(n.Network, depth) - resp.Peers = peers + // set the root node + resp.Root = peers return nil } -// ListRoutes returns a list of routing table routes -func (n *Network) ListRoutes(ctx context.Context, req *pbRtr.Request, resp *pbRtr.ListResponse) error { +// Routes returns a list of routing table routes +func (n *Network) Routes(ctx context.Context, req *pbNet.RoutesRequest, resp *pbNet.RoutesResponse) error { routes, err := n.Network.Options().Router.Table().List() if err != nil { return errors.InternalServerError("go.micro.network", "failed to list routes: %s", err) diff --git a/network/proto/network.micro.go b/network/proto/network.micro.go index e1499490..24194579 100644 --- a/network/proto/network.micro.go +++ b/network/proto/network.micro.go @@ -1,12 +1,12 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: network.proto +// source: github.com/micro/go-micro/network/proto/network.proto package go_micro_network import ( fmt "fmt" proto "github.com/golang/protobuf/proto" - proto1 "github.com/micro/go-micro/router/proto" + _ "github.com/micro/go-micro/router/proto" math "math" ) @@ -35,8 +35,9 @@ var _ server.Option // Client API for Network service type NetworkService interface { - ListPeers(ctx context.Context, in *PeerRequest, opts ...client.CallOption) (*PeerResponse, error) - ListRoutes(ctx context.Context, in *proto1.Request, opts ...client.CallOption) (*proto1.ListResponse, error) + Graph(ctx context.Context, in *GraphRequest, opts ...client.CallOption) (*GraphResponse, error) + Nodes(ctx context.Context, in *NodesRequest, opts ...client.CallOption) (*NodesResponse, error) + Routes(ctx context.Context, in *RoutesRequest, opts ...client.CallOption) (*RoutesResponse, error) } type networkService struct { @@ -57,9 +58,9 @@ func NewNetworkService(name string, c client.Client) NetworkService { } } -func (c *networkService) ListPeers(ctx context.Context, in *PeerRequest, opts ...client.CallOption) (*PeerResponse, error) { - req := c.c.NewRequest(c.name, "Network.ListPeers", in) - out := new(PeerResponse) +func (c *networkService) Graph(ctx context.Context, in *GraphRequest, opts ...client.CallOption) (*GraphResponse, error) { + req := c.c.NewRequest(c.name, "Network.Graph", in) + out := new(GraphResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { return nil, err @@ -67,9 +68,19 @@ func (c *networkService) ListPeers(ctx context.Context, in *PeerRequest, opts .. 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) +func (c *networkService) Nodes(ctx context.Context, in *NodesRequest, opts ...client.CallOption) (*NodesResponse, error) { + req := c.c.NewRequest(c.name, "Network.Nodes", in) + out := new(NodesResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *networkService) Routes(ctx context.Context, in *RoutesRequest, opts ...client.CallOption) (*RoutesResponse, error) { + req := c.c.NewRequest(c.name, "Network.Routes", in) + out := new(RoutesResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { return nil, err @@ -80,14 +91,16 @@ func (c *networkService) ListRoutes(ctx context.Context, in *proto1.Request, opt // Server API for Network service type NetworkHandler interface { - ListPeers(context.Context, *PeerRequest, *PeerResponse) error - ListRoutes(context.Context, *proto1.Request, *proto1.ListResponse) error + Graph(context.Context, *GraphRequest, *GraphResponse) error + Nodes(context.Context, *NodesRequest, *NodesResponse) error + Routes(context.Context, *RoutesRequest, *RoutesResponse) error } func RegisterNetworkHandler(s server.Server, hdlr NetworkHandler, opts ...server.HandlerOption) error { type network interface { - ListPeers(ctx context.Context, in *PeerRequest, out *PeerResponse) error - ListRoutes(ctx context.Context, in *proto1.Request, out *proto1.ListResponse) error + Graph(ctx context.Context, in *GraphRequest, out *GraphResponse) error + Nodes(ctx context.Context, in *NodesRequest, out *NodesResponse) error + Routes(ctx context.Context, in *RoutesRequest, out *RoutesResponse) error } type Network struct { network @@ -100,10 +113,14 @@ type networkHandler struct { NetworkHandler } -func (h *networkHandler) ListPeers(ctx context.Context, in *PeerRequest, out *PeerResponse) error { - return h.NetworkHandler.ListPeers(ctx, in, out) +func (h *networkHandler) Graph(ctx context.Context, in *GraphRequest, out *GraphResponse) error { + return h.NetworkHandler.Graph(ctx, in, out) } -func (h *networkHandler) ListRoutes(ctx context.Context, in *proto1.Request, out *proto1.ListResponse) error { - return h.NetworkHandler.ListRoutes(ctx, in, out) +func (h *networkHandler) Nodes(ctx context.Context, in *NodesRequest, out *NodesResponse) error { + return h.NetworkHandler.Nodes(ctx, in, out) +} + +func (h *networkHandler) Routes(ctx context.Context, in *RoutesRequest, out *RoutesResponse) error { + return h.NetworkHandler.Routes(ctx, in, out) } diff --git a/network/proto/network.pb.go b/network/proto/network.pb.go index 3cacfb00..d1ee9600 100644 --- a/network/proto/network.pb.go +++ b/network/proto/network.pb.go @@ -1,12 +1,14 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: network.proto +// source: github.com/micro/go-micro/network/proto/network.proto package go_micro_network import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" - _ "github.com/micro/go-micro/router/proto" + proto1 "github.com/micro/go-micro/router/proto" + grpc "google.golang.org/grpc" math "math" ) @@ -22,7 +24,7 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // PeerRequest requests list of peers -type PeerRequest struct { +type NodesRequest struct { // node topology depth Depth uint32 `protobuf:"varint,1,opt,name=depth,proto3" json:"depth,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -30,32 +32,32 @@ type PeerRequest struct { XXX_sizecache int32 `json:"-"` } -func (m *PeerRequest) Reset() { *m = PeerRequest{} } -func (m *PeerRequest) String() string { return proto.CompactTextString(m) } -func (*PeerRequest) ProtoMessage() {} -func (*PeerRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{0} +func (m *NodesRequest) Reset() { *m = NodesRequest{} } +func (m *NodesRequest) String() string { return proto.CompactTextString(m) } +func (*NodesRequest) ProtoMessage() {} +func (*NodesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_0b7953b26a7c4730, []int{0} } -func (m *PeerRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_PeerRequest.Unmarshal(m, b) +func (m *NodesRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_NodesRequest.Unmarshal(m, b) } -func (m *PeerRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_PeerRequest.Marshal(b, m, deterministic) +func (m *NodesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_NodesRequest.Marshal(b, m, deterministic) } -func (m *PeerRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_PeerRequest.Merge(m, src) +func (m *NodesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_NodesRequest.Merge(m, src) } -func (m *PeerRequest) XXX_Size() int { - return xxx_messageInfo_PeerRequest.Size(m) +func (m *NodesRequest) XXX_Size() int { + return xxx_messageInfo_NodesRequest.Size(m) } -func (m *PeerRequest) XXX_DiscardUnknown() { - xxx_messageInfo_PeerRequest.DiscardUnknown(m) +func (m *NodesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_NodesRequest.DiscardUnknown(m) } -var xxx_messageInfo_PeerRequest proto.InternalMessageInfo +var xxx_messageInfo_NodesRequest proto.InternalMessageInfo -func (m *PeerRequest) GetDepth() uint32 { +func (m *NodesRequest) GetDepth() uint32 { if m != nil { return m.Depth } @@ -63,42 +65,191 @@ func (m *PeerRequest) GetDepth() uint32 { } // PeerResponse is returned by ListPeers -type PeerResponse struct { +type NodesResponse struct { // return peer topology - Peers *Peer `protobuf:"bytes,1,opt,name=peers,proto3" json:"peers,omitempty"` + Nodes []*Node `protobuf:"bytes,1,rep,name=nodes,proto3" json:"nodes,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } -func (m *PeerResponse) Reset() { *m = PeerResponse{} } -func (m *PeerResponse) String() string { return proto.CompactTextString(m) } -func (*PeerResponse) ProtoMessage() {} -func (*PeerResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{1} +func (m *NodesResponse) Reset() { *m = NodesResponse{} } +func (m *NodesResponse) String() string { return proto.CompactTextString(m) } +func (*NodesResponse) ProtoMessage() {} +func (*NodesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_0b7953b26a7c4730, []int{1} } -func (m *PeerResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_PeerResponse.Unmarshal(m, b) +func (m *NodesResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_NodesResponse.Unmarshal(m, b) } -func (m *PeerResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_PeerResponse.Marshal(b, m, deterministic) +func (m *NodesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_NodesResponse.Marshal(b, m, deterministic) } -func (m *PeerResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_PeerResponse.Merge(m, src) +func (m *NodesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_NodesResponse.Merge(m, src) } -func (m *PeerResponse) XXX_Size() int { - return xxx_messageInfo_PeerResponse.Size(m) +func (m *NodesResponse) XXX_Size() int { + return xxx_messageInfo_NodesResponse.Size(m) } -func (m *PeerResponse) XXX_DiscardUnknown() { - xxx_messageInfo_PeerResponse.DiscardUnknown(m) +func (m *NodesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_NodesResponse.DiscardUnknown(m) } -var xxx_messageInfo_PeerResponse proto.InternalMessageInfo +var xxx_messageInfo_NodesResponse proto.InternalMessageInfo -func (m *PeerResponse) GetPeers() *Peer { +func (m *NodesResponse) GetNodes() []*Node { if m != nil { - return m.Peers + return m.Nodes + } + return nil +} + +type GraphRequest struct { + // node topology depth + Depth uint32 `protobuf:"varint,1,opt,name=depth,proto3" json:"depth,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GraphRequest) Reset() { *m = GraphRequest{} } +func (m *GraphRequest) String() string { return proto.CompactTextString(m) } +func (*GraphRequest) ProtoMessage() {} +func (*GraphRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_0b7953b26a7c4730, []int{2} +} + +func (m *GraphRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GraphRequest.Unmarshal(m, b) +} +func (m *GraphRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GraphRequest.Marshal(b, m, deterministic) +} +func (m *GraphRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GraphRequest.Merge(m, src) +} +func (m *GraphRequest) XXX_Size() int { + return xxx_messageInfo_GraphRequest.Size(m) +} +func (m *GraphRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GraphRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GraphRequest proto.InternalMessageInfo + +func (m *GraphRequest) GetDepth() uint32 { + if m != nil { + return m.Depth + } + return 0 +} + +type GraphResponse struct { + Root *Peer `protobuf:"bytes,1,opt,name=root,proto3" json:"root,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GraphResponse) Reset() { *m = GraphResponse{} } +func (m *GraphResponse) String() string { return proto.CompactTextString(m) } +func (*GraphResponse) ProtoMessage() {} +func (*GraphResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_0b7953b26a7c4730, []int{3} +} + +func (m *GraphResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GraphResponse.Unmarshal(m, b) +} +func (m *GraphResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GraphResponse.Marshal(b, m, deterministic) +} +func (m *GraphResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GraphResponse.Merge(m, src) +} +func (m *GraphResponse) XXX_Size() int { + return xxx_messageInfo_GraphResponse.Size(m) +} +func (m *GraphResponse) XXX_DiscardUnknown() { + xxx_messageInfo_GraphResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_GraphResponse proto.InternalMessageInfo + +func (m *GraphResponse) GetRoot() *Peer { + if m != nil { + return m.Root + } + return nil +} + +type RoutesRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *RoutesRequest) Reset() { *m = RoutesRequest{} } +func (m *RoutesRequest) String() string { return proto.CompactTextString(m) } +func (*RoutesRequest) ProtoMessage() {} +func (*RoutesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_0b7953b26a7c4730, []int{4} +} + +func (m *RoutesRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_RoutesRequest.Unmarshal(m, b) +} +func (m *RoutesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_RoutesRequest.Marshal(b, m, deterministic) +} +func (m *RoutesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_RoutesRequest.Merge(m, src) +} +func (m *RoutesRequest) XXX_Size() int { + return xxx_messageInfo_RoutesRequest.Size(m) +} +func (m *RoutesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_RoutesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_RoutesRequest proto.InternalMessageInfo + +type RoutesResponse struct { + Routes []*proto1.Route `protobuf:"bytes,1,rep,name=routes,proto3" json:"routes,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *RoutesResponse) Reset() { *m = RoutesResponse{} } +func (m *RoutesResponse) String() string { return proto.CompactTextString(m) } +func (*RoutesResponse) ProtoMessage() {} +func (*RoutesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_0b7953b26a7c4730, []int{5} +} + +func (m *RoutesResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_RoutesResponse.Unmarshal(m, b) +} +func (m *RoutesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_RoutesResponse.Marshal(b, m, deterministic) +} +func (m *RoutesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_RoutesResponse.Merge(m, src) +} +func (m *RoutesResponse) XXX_Size() int { + return xxx_messageInfo_RoutesResponse.Size(m) +} +func (m *RoutesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_RoutesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_RoutesResponse proto.InternalMessageInfo + +func (m *RoutesResponse) GetRoutes() []*proto1.Route { + if m != nil { + return m.Routes } return nil } @@ -118,7 +269,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{2} + return fileDescriptor_0b7953b26a7c4730, []int{6} } func (m *Node) XXX_Unmarshal(b []byte) error { @@ -166,7 +317,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{3} + return fileDescriptor_0b7953b26a7c4730, []int{7} } func (m *Connect) XXX_Unmarshal(b []byte) error { @@ -207,7 +358,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{4} + return fileDescriptor_0b7953b26a7c4730, []int{8} } func (m *Close) XXX_Unmarshal(b []byte) error { @@ -250,7 +401,7 @@ func (m *Peer) Reset() { *m = Peer{} } func (m *Peer) String() string { return proto.CompactTextString(m) } func (*Peer) ProtoMessage() {} func (*Peer) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{5} + return fileDescriptor_0b7953b26a7c4730, []int{9} } func (m *Peer) XXX_Unmarshal(b []byte) error { @@ -286,35 +437,184 @@ func (m *Peer) GetPeers() []*Peer { } func init() { - proto.RegisterType((*PeerRequest)(nil), "go.micro.network.PeerRequest") - proto.RegisterType((*PeerResponse)(nil), "go.micro.network.PeerResponse") + proto.RegisterType((*NodesRequest)(nil), "go.micro.network.NodesRequest") + proto.RegisterType((*NodesResponse)(nil), "go.micro.network.NodesResponse") + proto.RegisterType((*GraphRequest)(nil), "go.micro.network.GraphRequest") + proto.RegisterType((*GraphResponse)(nil), "go.micro.network.GraphResponse") + proto.RegisterType((*RoutesRequest)(nil), "go.micro.network.RoutesRequest") + proto.RegisterType((*RoutesResponse)(nil), "go.micro.network.RoutesResponse") proto.RegisterType((*Node)(nil), "go.micro.network.Node") proto.RegisterType((*Connect)(nil), "go.micro.network.Connect") proto.RegisterType((*Close)(nil), "go.micro.network.Close") proto.RegisterType((*Peer)(nil), "go.micro.network.Peer") } -func init() { proto.RegisterFile("network.proto", fileDescriptor_8571034d60397816) } - -var fileDescriptor_8571034d60397816 = []byte{ - // 292 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0xcd, 0x4a, 0xc3, 0x40, - 0x10, 0x36, 0x31, 0x31, 0x74, 0x6a, 0x45, 0x16, 0x91, 0x50, 0xa8, 0x94, 0xf5, 0x22, 0xa2, 0x1b, - 0x69, 0xf0, 0xe6, 0xad, 0x07, 0x2f, 0xa5, 0x48, 0x9e, 0x40, 0x9b, 0x1d, 0xd2, 0xa0, 0xcd, 0xc4, - 0xdd, 0x0d, 0xbe, 0x8e, 0x8f, 0x2a, 0xd9, 0x4d, 0x2d, 0x28, 0xa1, 0xf4, 0x96, 0xf9, 0xfe, 0x32, - 0xc3, 0xb7, 0x30, 0xaa, 0xd0, 0x7c, 0x91, 0x7a, 0x17, 0xb5, 0x22, 0x43, 0xec, 0xbc, 0x20, 0xb1, - 0x29, 0x73, 0x45, 0xa2, 0xc3, 0xc7, 0x69, 0x51, 0x9a, 0x75, 0xb3, 0x12, 0x39, 0x6d, 0x12, 0xcb, - 0x24, 0x05, 0xdd, 0xbb, 0x0f, 0x45, 0x8d, 0x41, 0x95, 0x58, 0x67, 0x37, 0xb8, 0x18, 0x7e, 0x0d, - 0xc3, 0x17, 0x44, 0x95, 0xe1, 0x67, 0x83, 0xda, 0xb0, 0x0b, 0x08, 0x25, 0xd6, 0x66, 0x1d, 0x7b, - 0x53, 0xef, 0x66, 0x94, 0xb9, 0x81, 0x3f, 0xc1, 0xa9, 0x13, 0xe9, 0x9a, 0x2a, 0x8d, 0xec, 0x0e, - 0xc2, 0x1a, 0x51, 0x69, 0xab, 0x1a, 0xce, 0x2e, 0xc5, 0xdf, 0x5d, 0x84, 0x95, 0x3b, 0x11, 0x7f, - 0x80, 0x60, 0x49, 0x12, 0xd9, 0x19, 0xf8, 0xa5, 0xb4, 0x96, 0x41, 0xe6, 0x97, 0x92, 0xc5, 0x10, - 0xbd, 0x49, 0xa9, 0x50, 0xeb, 0xd8, 0xb7, 0xe0, 0x76, 0xe4, 0x8f, 0x10, 0xcd, 0xa9, 0xaa, 0x30, - 0x37, 0xec, 0x16, 0x82, 0x8a, 0x24, 0xf6, 0xff, 0xa9, 0x8d, 0xce, 0xac, 0x86, 0xa7, 0x10, 0xce, - 0x3f, 0x48, 0xe3, 0x41, 0xa6, 0x57, 0x08, 0xda, 0x65, 0x0f, 0xf1, 0xec, 0xee, 0xf7, 0xa7, 0xc7, - 0x7b, 0xef, 0x9f, 0x7d, 0x7b, 0x10, 0x2d, 0x1d, 0xce, 0x16, 0x30, 0x58, 0x94, 0xda, 0xb4, 0xb4, - 0x66, 0x93, 0x1e, 0x9f, 0xeb, 0x62, 0x7c, 0xd5, 0x47, 0xbb, 0x16, 0xf8, 0x11, 0x7b, 0x06, 0x68, - 0xd3, 0xb2, 0xb6, 0x50, 0xcd, 0xe2, 0x9d, 0xbe, 0xab, 0x78, 0x9b, 0x34, 0xf9, 0xc7, 0x58, 0xdb, - 0x6f, 0xd0, 0xea, 0xc4, 0x3e, 0x86, 0xf4, 0x27, 0x00, 0x00, 0xff, 0xff, 0x68, 0x11, 0x14, 0x79, - 0x64, 0x02, 0x00, 0x00, +func init() { + proto.RegisterFile("github.com/micro/go-micro/network/proto/network.proto", fileDescriptor_0b7953b26a7c4730) +} + +var fileDescriptor_0b7953b26a7c4730 = []byte{ + // 371 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xd1, 0x4b, 0x3a, 0x41, + 0x10, 0xc7, 0x3d, 0xf5, 0x94, 0xdf, 0xfc, 0x3a, 0x8b, 0x25, 0xe2, 0xf0, 0xa1, 0x64, 0xe9, 0x41, + 0xa2, 0xce, 0x50, 0x7c, 0x8a, 0x20, 0xf0, 0x21, 0x08, 0x92, 0xd8, 0xbf, 0x20, 0xf5, 0x16, 0x3d, + 0xca, 0x9b, 0x6b, 0x6f, 0xa5, 0x7f, 0xbb, 0x3f, 0x21, 0x76, 0x76, 0x2f, 0xb4, 0xee, 0xa4, 0xde, + 0x9c, 0xf1, 0x33, 0xdf, 0x99, 0xef, 0xce, 0x1c, 0x8c, 0x97, 0x89, 0x5e, 0x6d, 0xe6, 0xd1, 0x02, + 0xd7, 0x83, 0x75, 0xb2, 0x50, 0x38, 0x58, 0xe2, 0x95, 0xfd, 0x91, 0x4a, 0xfd, 0x8e, 0xea, 0x65, + 0x90, 0x29, 0xd4, 0x5f, 0x51, 0x44, 0x11, 0x3b, 0x5a, 0x62, 0x44, 0x54, 0xe4, 0xf2, 0xdd, 0x51, + 0xb5, 0x90, 0xc2, 0x8d, 0x96, 0xca, 0xe9, 0xd8, 0xc0, 0xca, 0xf0, 0x73, 0x38, 0x98, 0x62, 0x2c, + 0x73, 0x21, 0xdf, 0x36, 0x32, 0xd7, 0xec, 0x18, 0xfc, 0x58, 0x66, 0x7a, 0x15, 0x7a, 0x3d, 0xaf, + 0x1f, 0x08, 0x1b, 0xf0, 0x5b, 0x08, 0x1c, 0x95, 0x67, 0x98, 0xe6, 0x92, 0x5d, 0x82, 0x9f, 0x9a, + 0x44, 0xe8, 0xf5, 0x1a, 0xfd, 0xff, 0xc3, 0x93, 0xe8, 0xfb, 0x34, 0x91, 0xe1, 0x85, 0x85, 0x4c, + 0x93, 0x7b, 0x35, 0xcb, 0x56, 0xfb, 0x9b, 0xdc, 0x40, 0xe0, 0x28, 0xd7, 0xe4, 0x02, 0x9a, 0x0a, + 0x51, 0x13, 0x55, 0xda, 0xe3, 0x49, 0x4a, 0x25, 0x88, 0xe1, 0x87, 0x10, 0x08, 0xe3, 0xab, 0x30, + 0xc2, 0xef, 0xa0, 0x53, 0x24, 0x9c, 0x5c, 0x04, 0x2d, 0xb2, 0x5e, 0x32, 0xb4, 0x7b, 0x12, 0x2a, + 0x10, 0x8e, 0xe2, 0xd7, 0xd0, 0x34, 0x26, 0x58, 0x07, 0xea, 0x49, 0x4c, 0x43, 0xfc, 0x13, 0xf5, + 0x24, 0x66, 0x21, 0xb4, 0x67, 0x71, 0xac, 0x64, 0x9e, 0x87, 0x75, 0x4a, 0x16, 0x21, 0x1f, 0x43, + 0x7b, 0x82, 0x69, 0x2a, 0x17, 0xda, 0xcc, 0x6e, 0xbc, 0x57, 0xcf, 0x4e, 0xef, 0x43, 0x0c, 0x1f, + 0x81, 0x3f, 0x79, 0x45, 0x6b, 0xf8, 0xd7, 0x45, 0xcf, 0xd0, 0x34, 0xf6, 0xff, 0x52, 0x63, 0xb6, + 0x96, 0x49, 0xa9, 0xcc, 0xdc, 0x8d, 0x3d, 0x2f, 0x6a, 0xa1, 0xe1, 0x87, 0x07, 0xed, 0xa9, 0xcd, + 0xb3, 0x07, 0xf0, 0x69, 0x37, 0xec, 0xf4, 0x67, 0xcd, 0xf6, 0x6a, 0xbb, 0x67, 0x95, 0xff, 0xdb, + 0x2d, 0xf0, 0x9a, 0xd1, 0xa2, 0x63, 0x2a, 0xd3, 0xda, 0xbe, 0xc5, 0x32, 0xad, 0x9d, 0x2b, 0xe4, + 0x35, 0xf6, 0x08, 0x2d, 0xbb, 0x65, 0x56, 0x02, 0xef, 0x1c, 0x44, 0xb7, 0x57, 0x0d, 0x14, 0x72, + 0xf3, 0x16, 0x7d, 0x14, 0xa3, 0xcf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x21, 0x74, 0xcb, 0x32, 0x94, + 0x03, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// NetworkClient is the client API for Network service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type NetworkClient interface { + Graph(ctx context.Context, in *GraphRequest, opts ...grpc.CallOption) (*GraphResponse, error) + Nodes(ctx context.Context, in *NodesRequest, opts ...grpc.CallOption) (*NodesResponse, error) + Routes(ctx context.Context, in *RoutesRequest, opts ...grpc.CallOption) (*RoutesResponse, error) +} + +type networkClient struct { + cc *grpc.ClientConn +} + +func NewNetworkClient(cc *grpc.ClientConn) NetworkClient { + return &networkClient{cc} +} + +func (c *networkClient) Graph(ctx context.Context, in *GraphRequest, opts ...grpc.CallOption) (*GraphResponse, error) { + out := new(GraphResponse) + err := c.cc.Invoke(ctx, "/go.micro.network.Network/Graph", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *networkClient) Nodes(ctx context.Context, in *NodesRequest, opts ...grpc.CallOption) (*NodesResponse, error) { + out := new(NodesResponse) + err := c.cc.Invoke(ctx, "/go.micro.network.Network/Nodes", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *networkClient) Routes(ctx context.Context, in *RoutesRequest, opts ...grpc.CallOption) (*RoutesResponse, error) { + out := new(RoutesResponse) + err := c.cc.Invoke(ctx, "/go.micro.network.Network/Routes", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// NetworkServer is the server API for Network service. +type NetworkServer interface { + Graph(context.Context, *GraphRequest) (*GraphResponse, error) + Nodes(context.Context, *NodesRequest) (*NodesResponse, error) + Routes(context.Context, *RoutesRequest) (*RoutesResponse, error) +} + +func RegisterNetworkServer(s *grpc.Server, srv NetworkServer) { + s.RegisterService(&_Network_serviceDesc, srv) +} + +func _Network_Graph_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GraphRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(NetworkServer).Graph(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.network.Network/Graph", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(NetworkServer).Graph(ctx, req.(*GraphRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Network_Nodes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(NodesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(NetworkServer).Nodes(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.network.Network/Nodes", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(NetworkServer).Nodes(ctx, req.(*NodesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Network_Routes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RoutesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(NetworkServer).Routes(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.network.Network/Routes", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(NetworkServer).Routes(ctx, req.(*RoutesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Network_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.network.Network", + HandlerType: (*NetworkServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Graph", + Handler: _Network_Graph_Handler, + }, + { + MethodName: "Nodes", + Handler: _Network_Nodes_Handler, + }, + { + MethodName: "Routes", + Handler: _Network_Routes_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "github.com/micro/go-micro/network/proto/network.proto", } diff --git a/network/proto/network.proto b/network/proto/network.proto index 2d95a455..4d8bf2a6 100644 --- a/network/proto/network.proto +++ b/network/proto/network.proto @@ -6,20 +6,37 @@ import "github.com/micro/go-micro/router/proto/router.proto"; // Network service is usesd to gain visibility into networks service Network { - rpc ListPeers(PeerRequest) returns (PeerResponse) {}; - rpc ListRoutes(go.micro.router.Request) returns (go.micro.router.ListResponse) {}; + rpc Graph(GraphRequest) returns (GraphResponse) {}; + rpc Nodes(NodesRequest) returns (NodesResponse) {}; + rpc Routes(RoutesRequest) returns (RoutesResponse) {}; } // PeerRequest requests list of peers -message PeerRequest { +message NodesRequest { // node topology depth uint32 depth = 1; } // PeerResponse is returned by ListPeers -message PeerResponse { +message NodesResponse { // return peer topology - Peer peers = 1; + repeated Node nodes = 1; +} + +message GraphRequest { + // node topology depth + uint32 depth = 1; +} + +message GraphResponse { + Peer root = 1; +} + +message RoutesRequest { +} + +message RoutesResponse { + repeated go.micro.router.Route routes = 1; } // Node is network node