Neighbour is now peer. Neighbourhood is Peers. Small refactor.
This commit is contained in:
		| @@ -1,7 +1,6 @@ | |||||||
| package network | package network | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"container/list" |  | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"sync" | 	"sync" | ||||||
| 	"time" | 	"time" | ||||||
| @@ -109,7 +108,7 @@ func newNetwork(opts ...Option) Network { | |||||||
| 		node: &node{ | 		node: &node{ | ||||||
| 			id:      options.Id, | 			id:      options.Id, | ||||||
| 			address: options.Address, | 			address: options.Address, | ||||||
| 			neighbours: make(map[string]*node), | 			peers:   make(map[string]*node), | ||||||
| 		}, | 		}, | ||||||
| 		options:   options, | 		options:   options, | ||||||
| 		Router:    options.Router, | 		Router:    options.Router, | ||||||
| @@ -261,70 +260,69 @@ func (n *network) processNetChan(client transport.Client, listener tunnel.Listen | |||||||
| 				n.Lock() | 				n.Lock() | ||||||
| 				log.Debugf("Network received connect message from: %s", pbNetConnect.Node.Id) | 				log.Debugf("Network received connect message from: %s", pbNetConnect.Node.Id) | ||||||
| 				// if the entry already exists skip adding it | 				// if the entry already exists skip adding it | ||||||
| 				if neighbour, ok := n.neighbours[pbNetConnect.Node.Id]; ok { | 				if peer, ok := n.peers[pbNetConnect.Node.Id]; ok { | ||||||
| 					// update lastSeen timestamp | 					// update lastSeen timestamp | ||||||
| 					if n.neighbours[pbNetConnect.Node.Id].lastSeen.Before(now) { | 					if n.peers[pbNetConnect.Node.Id].lastSeen.Before(now) { | ||||||
| 						neighbour.lastSeen = now | 						peer.lastSeen = now | ||||||
| 					} | 					} | ||||||
| 					n.Unlock() | 					n.Unlock() | ||||||
| 					continue | 					continue | ||||||
| 				} | 				} | ||||||
| 				// add a new neighbour | 				// add a new peer to the node peers | ||||||
| 				// NOTE: new node does not have any neighbours | 				// NOTE: new node does not have any peers, yet | ||||||
| 				n.neighbours[pbNetConnect.Node.Id] = &node{ | 				n.peers[pbNetConnect.Node.Id] = &node{ | ||||||
| 					id:       pbNetConnect.Node.Id, | 					id:       pbNetConnect.Node.Id, | ||||||
| 					address:  pbNetConnect.Node.Address, | 					address:  pbNetConnect.Node.Address, | ||||||
| 					neighbours: make(map[string]*node), | 					peers:    make(map[string]*node), | ||||||
| 					lastSeen: now, | 					lastSeen: now, | ||||||
| 				} | 				} | ||||||
| 				n.Unlock() | 				n.Unlock() | ||||||
| 				// advertise yourself to the network | 				// advertise yourself to the network | ||||||
| 				if err := n.sendMsg("neighbour", NetworkChannel); err != nil { | 				if err := n.sendMsg("peer", NetworkChannel); err != nil { | ||||||
| 					log.Debugf("Network failed to advertise neighbours: %v", err) | 					log.Debugf("Network failed to advertise peers: %v", err) | ||||||
| 				} | 				} | ||||||
| 				// advertise all the routes when a new node has connected | 				// advertise all the routes when a new node has connected | ||||||
| 				if err := n.Router.Solicit(); err != nil { | 				if err := n.Router.Solicit(); err != nil { | ||||||
| 					log.Debugf("Network failed to solicit routes: %s", err) | 					log.Debugf("Network failed to solicit routes: %s", err) | ||||||
| 				} | 				} | ||||||
| 			case "neighbour": | 			case "peer": | ||||||
| 				// mark the time the message has been received | 				// mark the time the message has been received | ||||||
| 				now := time.Now() | 				now := time.Now() | ||||||
| 				pbNetNeighbour := &pbNet.Neighbour{} | 				pbNetPeer := &pbNet.Peer{} | ||||||
| 				if err := proto.Unmarshal(m.Body, pbNetNeighbour); err != nil { | 				if err := proto.Unmarshal(m.Body, pbNetPeer); err != nil { | ||||||
| 					log.Debugf("Network tunnel [%s] neighbour unmarshal error: %v", NetworkChannel, err) | 					log.Debugf("Network tunnel [%s] peer unmarshal error: %v", NetworkChannel, err) | ||||||
| 					continue | 					continue | ||||||
| 				} | 				} | ||||||
| 				// don't process your own messages | 				// don't process your own messages | ||||||
| 				if pbNetNeighbour.Node.Id == n.options.Id { | 				if pbNetPeer.Node.Id == n.options.Id { | ||||||
| 					continue | 					continue | ||||||
| 				} | 				} | ||||||
| 				n.Lock() | 				n.Lock() | ||||||
| 				log.Debugf("Network received neighbour message from: %s", pbNetNeighbour.Node.Id) | 				log.Debugf("Network received peer message from: %s", pbNetPeer.Node.Id) | ||||||
| 				// only add the neighbour if it is NOT already in node's list of neighbours | 				// only add the peer if it is NOT already in node's list of peers | ||||||
| 				_, exists := n.neighbours[pbNetNeighbour.Node.Id] | 				_, exists := n.peers[pbNetPeer.Node.Id] | ||||||
| 				if !exists { | 				if !exists { | ||||||
| 					n.neighbours[pbNetNeighbour.Node.Id] = &node{ | 					n.peers[pbNetPeer.Node.Id] = &node{ | ||||||
| 						id:         pbNetNeighbour.Node.Id, | 						id:       pbNetPeer.Node.Id, | ||||||
| 						address:    pbNetNeighbour.Node.Address, | 						address:  pbNetPeer.Node.Address, | ||||||
| 						neighbours: make(map[string]*node), | 						peers:    make(map[string]*node), | ||||||
| 						lastSeen: now, | 						lastSeen: now, | ||||||
| 					} | 					} | ||||||
| 					n.Unlock() | 					n.Unlock() | ||||||
| 					// send a solicit message when discovering new neighbour | 					// send a solicit message when discovering new peer | ||||||
| 					// NOTE: we need to release the Lock here as sendMsg locsk, too | 					// NOTE: we need to release the Lock here as sendMsg locsk, too | ||||||
| 					if err := n.sendMsg("solicit", ControlChannel); err != nil { | 					if err := n.sendMsg("solicit", ControlChannel); err != nil { | ||||||
| 						log.Debugf("Network failed to send solicit message: %s", err) | 						log.Debugf("Network failed to send solicit message: %s", err) | ||||||
| 					} | 					} | ||||||
| 					continue | 					continue | ||||||
| 				} | 				} | ||||||
| 				// update/store the node neighbour neighbours up to (MaxDepth-1) topology depth |  | ||||||
| 				// NOTE: we don't update max topology depth as we dont include this network node | 				// NOTE: we don't update max topology depth as we dont include this network node | ||||||
| 				if err := n.node.updateNeighbour(pbNetNeighbour, MaxDepth-1); err != nil { | 				if err := n.node.updatePeerTopology(pbNetPeer, MaxDepth-1); err != nil { | ||||||
| 					log.Debugf("Network failed to update neighbours") | 					log.Debugf("Network failed to update peers") | ||||||
| 				} | 				} | ||||||
| 				// update lastSeen timestamp if outdated | 				// update lastSeen timestamp if outdated | ||||||
| 				if n.neighbours[pbNetNeighbour.Node.Id].lastSeen.Before(now) { | 				if n.peers[pbNetPeer.Node.Id].lastSeen.Before(now) { | ||||||
| 					n.neighbours[pbNetNeighbour.Node.Id].lastSeen = now | 					n.peers[pbNetPeer.Node.Id].lastSeen = now | ||||||
| 				} | 				} | ||||||
| 				n.Unlock() | 				n.Unlock() | ||||||
| 			case "close": | 			case "close": | ||||||
| @@ -373,13 +371,13 @@ func (n *network) sendMsg(msgType string, channel string) error { | |||||||
| 		protoMsg = &pbNet.Solicit{ | 		protoMsg = &pbNet.Solicit{ | ||||||
| 			Node: node, | 			Node: node, | ||||||
| 		} | 		} | ||||||
| 	case "neighbour": | 	case "peer": | ||||||
| 		n.RLock() | 		n.RLock() | ||||||
| 		var err error | 		var err error | ||||||
| 		// get all the neighbours down to MaxDepth | 		// get all the node peers down to MaxDepth | ||||||
| 		protoMsg, err = n.node.getNeighbours(MaxDepth) | 		protoMsg, err = n.node.getProtoTopology(MaxDepth) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			log.Debugf("Network unable to retrieve node neighbours: %s", err) | 			log.Debugf("Network unable to retrieve node peers: %s", err) | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 		n.RUnlock() | 		n.RUnlock() | ||||||
| @@ -416,7 +414,7 @@ func (n *network) sendMsg(msgType string, channel string) error { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // announce announces node neighbourhood to the network | // announce announces node peers to the network | ||||||
| func (n *network) announce(client transport.Client) { | func (n *network) announce(client transport.Client) { | ||||||
| 	announce := time.NewTicker(AnnounceTime) | 	announce := time.NewTicker(AnnounceTime) | ||||||
| 	defer announce.Stop() | 	defer announce.Stop() | ||||||
| @@ -427,18 +425,18 @@ func (n *network) announce(client transport.Client) { | |||||||
| 			return | 			return | ||||||
| 		case <-announce.C: | 		case <-announce.C: | ||||||
| 			// advertise yourself to the network | 			// advertise yourself to the network | ||||||
| 			if err := n.sendMsg("neighbour", NetworkChannel); err != nil { | 			if err := n.sendMsg("peer", NetworkChannel); err != nil { | ||||||
| 				log.Debugf("Network failed to advertise neighbours: %v", err) | 				log.Debugf("Network failed to advertise peers: %v", err) | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| // pruneNode removes a node with given id from the list of neighbours. It also removes all routes originted by this node. | // pruneNode removes a node with given id from the list of peers. It also removes all routes originted by this node. | ||||||
| // NOTE: this method is not thread-safe; when calling it make sure you lock the particular code segment | // NOTE: this method is not thread-safe; when calling it make sure you lock the particular code segment | ||||||
| func (n *network) pruneNode(id string) error { | func (n *network) pruneNode(id string) error { | ||||||
| 	delete(n.neighbours, id) | 	delete(n.peers, id) | ||||||
| 	// lookup all the routes originated at this node | 	// lookup all the routes originated at this node | ||||||
| 	q := router.NewQuery( | 	q := router.NewQuery( | ||||||
| 		router.QueryRouter(id), | 		router.QueryRouter(id), | ||||||
| @@ -470,7 +468,7 @@ func (n *network) prune() { | |||||||
| 			return | 			return | ||||||
| 		case <-prune.C: | 		case <-prune.C: | ||||||
| 			n.Lock() | 			n.Lock() | ||||||
| 			for id, node := range n.neighbours { | 			for id, node := range n.peers { | ||||||
| 				if id == n.options.Id { | 				if id == n.options.Id { | ||||||
| 					continue | 					continue | ||||||
| 				} | 				} | ||||||
| @@ -528,8 +526,8 @@ func (n *network) acceptCtrlConn(l tunnel.Listener, recv chan *transport.Message | |||||||
|  |  | ||||||
| // setRouteMetric calculates metric of the route and updates it in place | // setRouteMetric calculates metric of the route and updates it in place | ||||||
| // - Local route metric is 1 | // - Local route metric is 1 | ||||||
| // - Routes with ID of adjacent neighbour are 10 | // - Routes with ID of adjacent nodes are 10 | ||||||
| // - Routes of neighbours of the advertiser are 100 | // - Routes by peers of the advertiser are 100 | ||||||
| // - Routes beyond your neighbourhood are 1000 | // - Routes beyond your neighbourhood are 1000 | ||||||
| func (n *network) setRouteMetric(route *router.Route) { | func (n *network) setRouteMetric(route *router.Route) { | ||||||
| 	// we are the origin of the route | 	// we are the origin of the route | ||||||
| @@ -539,16 +537,16 @@ func (n *network) setRouteMetric(route *router.Route) { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	n.RLock() | 	n.RLock() | ||||||
| 	// check if the route origin is our neighbour | 	// check if the route origin is our peer | ||||||
| 	if _, ok := n.neighbours[route.Router]; ok { | 	if _, ok := n.peers[route.Router]; ok { | ||||||
| 		route.Metric = 10 | 		route.Metric = 10 | ||||||
| 		n.RUnlock() | 		n.RUnlock() | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// check if the route origin is the neighbour of our neighbour | 	// check if the route origin is the peer of our peer | ||||||
| 	for _, node := range n.neighbours { | 	for _, peer := range n.peers { | ||||||
| 		for id := range node.neighbours { | 		for id := range peer.peers { | ||||||
| 			if route.Router == id { | 			if route.Router == id { | ||||||
| 				route.Metric = 100 | 				route.Metric = 100 | ||||||
| 				n.RUnlock() | 				n.RUnlock() | ||||||
| @@ -586,19 +584,19 @@ func (n *network) processCtrlChan(client transport.Client, listener tunnel.Liste | |||||||
| 				if pbRtrAdvert.Id == n.options.Id { | 				if pbRtrAdvert.Id == n.options.Id { | ||||||
| 					continue | 					continue | ||||||
| 				} | 				} | ||||||
| 				// loookup advertising node in our neighbourhood | 				// loookup advertising node in our peers | ||||||
| 				n.RLock() | 				n.RLock() | ||||||
| 				log.Debugf("Network received advert message from: %s", pbRtrAdvert.Id) | 				log.Debugf("Network received advert message from: %s", pbRtrAdvert.Id) | ||||||
| 				advertNode, ok := n.neighbours[pbRtrAdvert.Id] | 				advertNode, ok := n.peers[pbRtrAdvert.Id] | ||||||
| 				if !ok { | 				if !ok { | ||||||
| 					// advertising node has not been registered as our neighbour, yet | 					// advertising node has not been registered as our peer, yet | ||||||
| 					// let's add it to the map of our neighbours | 					// let's add it to our peers | ||||||
| 					advertNode = &node{ | 					advertNode = &node{ | ||||||
| 						id:       pbRtrAdvert.Id, | 						id:       pbRtrAdvert.Id, | ||||||
| 						neighbours: make(map[string]*node), | 						peers:    make(map[string]*node), | ||||||
| 						lastSeen: now, | 						lastSeen: now, | ||||||
| 					} | 					} | ||||||
| 					n.neighbours[pbRtrAdvert.Id] = advertNode | 					n.peers[pbRtrAdvert.Id] = advertNode | ||||||
| 					// send a solicit message when discovering a new node | 					// send a solicit message when discovering a new node | ||||||
| 					if err := n.sendMsg("solicit", NetworkChannel); err != nil { | 					if err := n.sendMsg("solicit", NetworkChannel); err != nil { | ||||||
| 						log.Debugf("Network failed to send solicit message: %s", err) | 						log.Debugf("Network failed to send solicit message: %s", err) | ||||||
| @@ -611,16 +609,16 @@ func (n *network) processCtrlChan(client transport.Client, listener tunnel.Liste | |||||||
| 					// set the address of the advertising node | 					// set the address of the advertising node | ||||||
| 					// we know Route.Gateway is the address of advertNode | 					// we know Route.Gateway is the address of advertNode | ||||||
| 					// NOTE: this is true only when advertNode had not been registered | 					// NOTE: this is true only when advertNode had not been registered | ||||||
| 					// as our neighbour when we received the advert from it | 					// as our peer when we received the advert from it | ||||||
| 					if advertNode.address == "" { | 					if advertNode.address == "" { | ||||||
| 						advertNode.address = event.Route.Gateway | 						advertNode.address = event.Route.Gateway | ||||||
| 					} | 					} | ||||||
| 					// if advertising node id is not the same as Route.Router | 					// if advertising node id is not the same as Route.Router | ||||||
| 					// we know the advertising node is not the origin of the route | 					// we know the advertising node is not the origin of the route | ||||||
| 					if advertNode.id != event.Route.Router { | 					if advertNode.id != event.Route.Router { | ||||||
| 						// if the origin router is not in the advertising node neighbourhood | 						// if the origin router is not the advertising node peer | ||||||
| 						// we can't rule out potential routing loops so we bail here | 						// we can't rule out potential routing loops so we bail here | ||||||
| 						if _, ok := advertNode.neighbours[event.Route.Router]; !ok { | 						if _, ok := advertNode.peers[event.Route.Router]; !ok { | ||||||
| 							continue | 							continue | ||||||
| 						} | 						} | ||||||
| 					} | 					} | ||||||
| @@ -821,7 +819,7 @@ func (n *network) Connect() error { | |||||||
|  |  | ||||||
| 	// go resolving network nodes | 	// go resolving network nodes | ||||||
| 	go n.resolve() | 	go n.resolve() | ||||||
| 	// broadcast neighbourhood | 	// broadcast peers | ||||||
| 	go n.announce(netClient) | 	go n.announce(netClient) | ||||||
| 	// prune stale nodes | 	// prune stale nodes | ||||||
| 	go n.prune() | 	go n.prune() | ||||||
| @@ -839,48 +837,6 @@ func (n *network) Connect() error { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // Nodes returns a list of all network nodes |  | ||||||
| func (n *network) Nodes() []Node { |  | ||||||
| 	//track the visited nodes |  | ||||||
| 	visited := make(map[string]*node) |  | ||||||
| 	// queue of the nodes to visit |  | ||||||
| 	queue := list.New() |  | ||||||
|  |  | ||||||
| 	// we need to freeze the network graph here |  | ||||||
| 	// otherwise we might get invalid results |  | ||||||
| 	n.RLock() |  | ||||||
| 	defer n.RUnlock() |  | ||||||
|  |  | ||||||
| 	// push network node to the back of queue |  | ||||||
| 	queue.PushBack(n.node) |  | ||||||
| 	// mark the node as visited |  | ||||||
| 	visited[n.node.id] = n.node |  | ||||||
|  |  | ||||||
| 	// keep iterating over the queue until its empty |  | ||||||
| 	for queue.Len() > 0 { |  | ||||||
| 		// pop the node from the front of the queue |  | ||||||
| 		qnode := queue.Front() |  | ||||||
| 		// iterate through all of its neighbours |  | ||||||
| 		// mark the visited nodes; enqueue the non-visted |  | ||||||
| 		for id, node := range qnode.Value.(*node).neighbours { |  | ||||||
| 			if _, ok := visited[id]; !ok { |  | ||||||
| 				visited[id] = node |  | ||||||
| 				queue.PushBack(node) |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		// remove the node from the queue |  | ||||||
| 		queue.Remove(qnode) |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	var nodes []Node |  | ||||||
| 	// collect all the nodes and return them |  | ||||||
| 	for _, node := range visited { |  | ||||||
| 		nodes = append(nodes, node) |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	return nodes |  | ||||||
| } |  | ||||||
|  |  | ||||||
| func (n *network) close() error { | func (n *network) close() error { | ||||||
| 	// stop the server | 	// stop the server | ||||||
| 	if err := n.server.Stop(); err != nil { | 	if err := n.server.Stop(); err != nil { | ||||||
|   | |||||||
| @@ -16,6 +16,74 @@ type Network struct { | |||||||
| 	Network network.Network | 	Network network.Network | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // ListNodes returns a list of all accessible nodes in the network | ||||||
|  | func (n *Network) ListNodes(ctx context.Context, req *pbNet.ListRequest, resp *pbNet.ListResponse) error { | ||||||
|  | 	nodes := n.Network.Nodes() | ||||||
|  |  | ||||||
|  | 	var respNodes []*pbNet.Node | ||||||
|  | 	for _, node := range nodes { | ||||||
|  | 		respNode := &pbNet.Node{ | ||||||
|  | 			Id:      node.Id(), | ||||||
|  | 			Address: node.Address(), | ||||||
|  | 		} | ||||||
|  | 		respNodes = append(respNodes, respNode) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	resp.Nodes = respNodes | ||||||
|  |  | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // 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 { | ||||||
|  | 	// extract the id of the node to query | ||||||
|  | 	id := req.Id | ||||||
|  | 	// if no id is passed, we assume local node | ||||||
|  | 	if id == "" { | ||||||
|  | 		id = n.Network.Id() | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// get all the nodes in the network | ||||||
|  | 	nodes := n.Network.Nodes() | ||||||
|  |  | ||||||
|  | 	// sort the slice of nodes | ||||||
|  | 	sort.Slice(nodes, func(i, j int) bool { return nodes[i].Id() <= nodes[j].Id() }) | ||||||
|  | 	// find a node with a given id | ||||||
|  | 	i := sort.Search(len(nodes), func(j int) bool { return nodes[j].Id() >= id }) | ||||||
|  |  | ||||||
|  | 	var nodePeers []*pbNet.Node | ||||||
|  | 	// collect all the node peers into slice | ||||||
|  | 	if i < len(nodes) && nodes[i].Id() == id { | ||||||
|  | 		for _, peer := range nodes[i].Peers() { | ||||||
|  | 			// don't return yourself in response | ||||||
|  | 			if peer.Id() == n.Network.Id() { | ||||||
|  | 				continue | ||||||
|  | 			} | ||||||
|  | 			pbPeer := &pbNet.Node{ | ||||||
|  | 				Id:      peer.Id(), | ||||||
|  | 				Address: peer.Address(), | ||||||
|  | 			} | ||||||
|  | 			nodePeers = append(nodePeers, pbPeer) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// requested node | ||||||
|  | 	node := &pbNet.Node{ | ||||||
|  | 		Id:      nodes[i].Id(), | ||||||
|  | 		Address: nodes[i].Address(), | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// creaate peers answer | ||||||
|  | 	peers := &pbNet.Peers{ | ||||||
|  | 		Node:  node, | ||||||
|  | 		Peers: nodePeers, | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	resp.Peers = peers | ||||||
|  |  | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  |  | ||||||
| // ListRoutes returns a list of routing table routes | // ListRoutes returns a list of routing table routes | ||||||
| func (n *Network) ListRoutes(ctx context.Context, req *pbRtr.Request, resp *pbRtr.ListResponse) error { | func (n *Network) ListRoutes(ctx context.Context, req *pbRtr.Request, resp *pbRtr.ListResponse) error { | ||||||
| 	routes, err := n.Network.Options().Router.Table().List() | 	routes, err := n.Network.Options().Router.Table().List() | ||||||
| @@ -41,71 +109,3 @@ func (n *Network) ListRoutes(ctx context.Context, req *pbRtr.Request, resp *pbRt | |||||||
|  |  | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // ListNodes returns a list of all accessible nodes in the network |  | ||||||
| func (n *Network) ListNodes(ctx context.Context, req *pbNet.ListRequest, resp *pbNet.ListResponse) error { |  | ||||||
| 	nodes := n.Network.Nodes() |  | ||||||
|  |  | ||||||
| 	var respNodes []*pbNet.Node |  | ||||||
| 	for _, node := range nodes { |  | ||||||
| 		respNode := &pbNet.Node{ |  | ||||||
| 			Id:      node.Id(), |  | ||||||
| 			Address: node.Address(), |  | ||||||
| 		} |  | ||||||
| 		respNodes = append(respNodes, respNode) |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	resp.Nodes = respNodes |  | ||||||
|  |  | ||||||
| 	return nil |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // Neighbourhood returns a list of immediate neighbours |  | ||||||
| func (n *Network) Neighbourhood(ctx context.Context, req *pbNet.NeighbourhoodRequest, resp *pbNet.NeighbourhoodResponse) error { |  | ||||||
| 	// extract the id of the node to query |  | ||||||
| 	id := req.Id |  | ||||||
| 	// if no id is passed, we assume local node |  | ||||||
| 	if id == "" { |  | ||||||
| 		id = n.Network.Id() |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	// get all the nodes in the network |  | ||||||
| 	nodes := n.Network.Nodes() |  | ||||||
|  |  | ||||||
| 	// sort the slice of nodes |  | ||||||
| 	sort.Slice(nodes, func(i, j int) bool { return nodes[i].Id() <= nodes[j].Id() }) |  | ||||||
| 	// find a node with a given id |  | ||||||
| 	i := sort.Search(len(nodes), func(j int) bool { return nodes[j].Id() >= id }) |  | ||||||
|  |  | ||||||
| 	var neighbours []*pbNet.Node |  | ||||||
| 	// collect all the nodes in the neighbourhood of the found node |  | ||||||
| 	if i < len(nodes) && nodes[i].Id() == id { |  | ||||||
| 		for _, neighbour := range nodes[i].Neighbourhood() { |  | ||||||
| 			// don't return yourself in response |  | ||||||
| 			if neighbour.Id() == n.Network.Id() { |  | ||||||
| 				continue |  | ||||||
| 			} |  | ||||||
| 			pbNeighbour := &pbNet.Node{ |  | ||||||
| 				Id:      neighbour.Id(), |  | ||||||
| 				Address: neighbour.Address(), |  | ||||||
| 			} |  | ||||||
| 			neighbours = append(neighbours, pbNeighbour) |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	// requested neighbourhood node |  | ||||||
| 	node := &pbNet.Node{ |  | ||||||
| 		Id:      nodes[i].Id(), |  | ||||||
| 		Address: nodes[i].Address(), |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	// creaate neighbourhood answer |  | ||||||
| 	neighbourhood := &pbNet.Neighbourhood{ |  | ||||||
| 		Node:       node, |  | ||||||
| 		Neighbours: neighbours, |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	resp.Neighbourhood = neighbourhood |  | ||||||
|  |  | ||||||
| 	return nil |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -28,8 +28,8 @@ type Node interface { | |||||||
| 	Id() string | 	Id() string | ||||||
| 	// Address is node bind address | 	// Address is node bind address | ||||||
| 	Address() string | 	Address() string | ||||||
| 	// Neighbourhood is node neighbourhood | 	// Peers returns node peers | ||||||
| 	Neighbourhood() []Node | 	Peers() []Node | ||||||
| 	// Network is the network node is in | 	// Network is the network node is in | ||||||
| 	Network() Network | 	Network() Network | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										168
									
								
								network/node.go
									
									
									
									
									
								
							
							
						
						
									
										168
									
								
								network/node.go
									
									
									
									
									
								
							| @@ -1,6 +1,7 @@ | |||||||
| package network | package network | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
|  | 	"container/list" | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"sync" | 	"sync" | ||||||
| 	"time" | 	"time" | ||||||
| @@ -20,11 +21,11 @@ type node struct { | |||||||
| 	id string | 	id string | ||||||
| 	// address is node address | 	// address is node address | ||||||
| 	address string | 	address string | ||||||
| 	// neighbours maps the node neighbourhood | 	// peers are nodes with direct link to this node | ||||||
| 	neighbours map[string]*node | 	peers map[string]*node | ||||||
| 	// network returns the node network | 	// network returns the node network | ||||||
| 	network Network | 	network Network | ||||||
| 	// lastSeen stores the time the node has been seen last time | 	// lastSeen keeps track of node lifetime and updates | ||||||
| 	lastSeen time.Time | 	lastSeen time.Time | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -43,112 +44,147 @@ func (n *node) Network() Network { | |||||||
| 	return n.network | 	return n.network | ||||||
| } | } | ||||||
|  |  | ||||||
| // Neighbourhood returns node neighbourhood | // Nodes returns a slice if all nodes in node topology | ||||||
| func (n *node) Neighbourhood() []Node { | func (n *node) Nodes() []Node { | ||||||
| 	var nodes []Node | 	//track the visited nodes | ||||||
|  | 	visited := make(map[string]*node) | ||||||
|  | 	// queue of the nodes to visit | ||||||
|  | 	queue := list.New() | ||||||
|  |  | ||||||
|  | 	// we need to freeze the network graph here | ||||||
|  | 	// otherwise we might get invalid results | ||||||
| 	n.RLock() | 	n.RLock() | ||||||
| 	for _, neighbourNode := range n.neighbours { | 	defer n.RUnlock() | ||||||
| 		// make a copy of the node |  | ||||||
| 		n := &node{ | 	// push node to the back of queue | ||||||
| 			id:      neighbourNode.id, | 	queue.PushBack(n) | ||||||
| 			address: neighbourNode.address, | 	// mark the node as visited | ||||||
| 			network: neighbourNode.network, | 	visited[n.id] = n | ||||||
|  |  | ||||||
|  | 	// keep iterating over the queue until its empty | ||||||
|  | 	for queue.Len() > 0 { | ||||||
|  | 		// pop the node from the front of the queue | ||||||
|  | 		qnode := queue.Front() | ||||||
|  | 		// iterate through all of the node peers | ||||||
|  | 		// mark the visited nodes; enqueue the non-visted | ||||||
|  | 		for id, node := range qnode.Value.(*node).peers { | ||||||
|  | 			if _, ok := visited[id]; !ok { | ||||||
|  | 				visited[id] = node | ||||||
|  | 				queue.PushBack(node) | ||||||
| 			} | 			} | ||||||
| 		// NOTE: we do not care about neighbour's neighbours |  | ||||||
| 		nodes = append(nodes, n) |  | ||||||
| 		} | 		} | ||||||
| 	n.RUnlock() | 		// remove the node from the queue | ||||||
|  | 		queue.Remove(qnode) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	var nodes []Node | ||||||
|  | 	// collect all the nodes and return them | ||||||
|  | 	for _, node := range visited { | ||||||
|  | 		nodes = append(nodes, node) | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	return nodes | 	return nodes | ||||||
| } | } | ||||||
|  |  | ||||||
| // getNeighbours collects node neighbours up to given depth into pbNeighbours | // Peers returns node peers | ||||||
| // NOTE: this method is not thread safe, so make sure you serialize access to it | func (n *node) Peers() []Node { | ||||||
| // NOTE: we should be able to read-Lock this, even though it's recursive | 	var peers []Node | ||||||
| func (n *node) getNeighbours(depth int) (*pbNet.Neighbour, error) { | 	n.RLock() | ||||||
|  | 	for _, peer := range n.peers { | ||||||
|  | 		// make a copy of the node | ||||||
|  | 		p := &node{ | ||||||
|  | 			id:      peer.id, | ||||||
|  | 			address: peer.address, | ||||||
|  | 			network: peer.network, | ||||||
|  | 		} | ||||||
|  | 		// NOTE: we do not care about peer's peers | ||||||
|  | 		peers = append(peers, p) | ||||||
|  | 	} | ||||||
|  | 	n.RUnlock() | ||||||
|  |  | ||||||
|  | 	return peers | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // getProtoTopology returns node peers up to given depth encoded in protobufs | ||||||
|  | // NOTE: this method is NOT thread-safe, so make sure you serialize access to it | ||||||
|  | func (n *node) getProtoTopology(depth int) (*pbNet.Peer, error) { | ||||||
| 	node := &pbNet.Node{ | 	node := &pbNet.Node{ | ||||||
| 		Id:      n.id, | 		Id:      n.id, | ||||||
| 		Address: n.address, | 		Address: n.address, | ||||||
| 	} | 	} | ||||||
| 	pbNeighbours := &pbNet.Neighbour{ |  | ||||||
|  | 	pbPeers := &pbNet.Peer{ | ||||||
| 		Node:  node, | 		Node:  node, | ||||||
| 		Neighbours: make([]*pbNet.Neighbour, 0), | 		Peers: make([]*pbNet.Peer, 0), | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// return if have either reached the depth or have no more neighbours | 	// return if have either reached the depth or have no more peers | ||||||
| 	if depth == 0 || len(n.neighbours) == 0 { | 	if depth == 0 || len(n.peers) == 0 { | ||||||
| 		return pbNeighbours, nil | 		return pbPeers, nil | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// decrement the depth | 	// decrement the depth | ||||||
| 	depth-- | 	depth-- | ||||||
|  |  | ||||||
| 	var neighbours []*pbNet.Neighbour | 	var peers []*pbNet.Peer | ||||||
| 	for _, neighbour := range n.neighbours { | 	for _, peer := range n.peers { | ||||||
| 		// get neighbours of the neighbour | 		// get peers of the node peers | ||||||
| 		// NOTE: this is [not] a recursive call | 		// NOTE: this is [not] a recursive call | ||||||
| 		pbNodeNeighbour, err := neighbour.getNeighbours(depth) | 		pbPeerPeer, err := peer.getProtoTopology(depth) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
| 		// add current neighbour to explored neighbours | 		// add current peer to explored peers | ||||||
| 		neighbours = append(neighbours, pbNodeNeighbour) | 		peers = append(peers, pbPeerPeer) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// add neighbours to the parent topology | 	// add peers to the parent topology | ||||||
| 	pbNeighbours.Neighbours = neighbours | 	pbPeers.Peers = peers | ||||||
|  |  | ||||||
| 	return pbNeighbours, nil | 	return pbPeers, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // unpackNeighbour unpacks pbNet.Neighbour into node of given depth | // unpackPeer unpacks pbNet.Peer into node topology of given depth | ||||||
| // NOTE: this method is not thread safe, so make sure you serialize access to it | // NOTE: this method is NOT thread-safe, so make sure you serialize access to it | ||||||
| func unpackNeighbour(pbNeighbour *pbNet.Neighbour, depth int) (*node, error) { | func unpackPeer(pbPeer *pbNet.Peer, depth int) *node { | ||||||
| 	if pbNeighbour == nil { | 	peerNode := &node{ | ||||||
| 		return nil, errors.New("neighbour not initialized") | 		id:      pbPeer.Node.Id, | ||||||
|  | 		address: pbPeer.Node.Address, | ||||||
|  | 		peers:   make(map[string]*node), | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	neighbourNode := &node{ | 	// return if have either reached the depth or have no more peers | ||||||
| 		id:         pbNeighbour.Node.Id, | 	if depth == 0 || len(pbPeer.Peers) == 0 { | ||||||
| 		address:    pbNeighbour.Node.Address, | 		return peerNode | ||||||
| 		neighbours: make(map[string]*node), |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	// return if have either reached the depth or have no more neighbours |  | ||||||
| 	if depth == 0 || len(pbNeighbour.Neighbours) == 0 { |  | ||||||
| 		return neighbourNode, nil |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// decrement the depth | 	// decrement the depth | ||||||
| 	depth-- | 	depth-- | ||||||
|  |  | ||||||
| 	neighbours := make(map[string]*node) | 	peers := make(map[string]*node) | ||||||
| 	for _, pbNode := range pbNeighbour.Neighbours { | 	for _, pbPeer := range pbPeer.Peers { | ||||||
| 		node, err := unpackNeighbour(pbNode, depth) | 		peer := unpackPeer(pbPeer, depth) | ||||||
| 		if err != nil { | 		peers[pbPeer.Node.Id] = peer | ||||||
| 			return nil, err |  | ||||||
| 		} |  | ||||||
| 		neighbours[pbNode.Node.Id] = node |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	neighbourNode.neighbours = neighbours | 	peerNode.peers = peers | ||||||
|  |  | ||||||
| 	return neighbourNode, nil | 	return peerNode | ||||||
| } | } | ||||||
|  |  | ||||||
| // updateNeighbour updates node neighbour up to given depth | // updatePeer updates node peer up to given depth | ||||||
| // NOTE: this method is not thread safe, so make sure you serialize access to it | // NOTE: this method is not thread safe, so make sure you serialize access to it | ||||||
| func (n *node) updateNeighbour(neighbour *pbNet.Neighbour, depth int) error { | func (n *node) updatePeerTopology(pbPeer *pbNet.Peer, depth int) error { | ||||||
| 	// unpack neighbour into topology of size MaxDepth-1 | 	if pbPeer == nil { | ||||||
| 	// NOTE: we need MaxDepth-1 because node n is the parent adding which | 		return errors.New("peer not initialized") | ||||||
| 	// gives us the max neighbour topology we maintain and propagate |  | ||||||
| 	node, err := unpackNeighbour(neighbour, MaxDepth-1) |  | ||||||
| 	if err != nil { |  | ||||||
| 		return err |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// update node neighbours with new topology | 	// NOTE: we need MaxDepth-1 because node n is the parent adding which | ||||||
| 	n.neighbours[neighbour.Node.Id] = node | 	// gives us the max peer topology we maintain and propagate | ||||||
|  | 	peer := unpackPeer(pbPeer, MaxDepth-1) | ||||||
|  |  | ||||||
|  | 	// update node peers with new topology | ||||||
|  | 	n.peers[pbPeer.Node.Id] = peer | ||||||
|  |  | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|   | |||||||
| @@ -36,7 +36,7 @@ var _ server.Option | |||||||
|  |  | ||||||
| type NetworkService interface { | type NetworkService interface { | ||||||
| 	ListNodes(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) | 	ListNodes(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) | ||||||
| 	Neighbourhood(ctx context.Context, in *NeighbourhoodRequest, opts ...client.CallOption) (*NeighbourhoodResponse, error) | 	ListPeers(ctx context.Context, in *PeerRequest, opts ...client.CallOption) (*PeerResponse, error) | ||||||
| 	ListRoutes(ctx context.Context, in *proto1.Request, opts ...client.CallOption) (*proto1.ListResponse, error) | 	ListRoutes(ctx context.Context, in *proto1.Request, opts ...client.CallOption) (*proto1.ListResponse, error) | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -68,9 +68,9 @@ func (c *networkService) ListNodes(ctx context.Context, in *ListRequest, opts .. | |||||||
| 	return out, nil | 	return out, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (c *networkService) Neighbourhood(ctx context.Context, in *NeighbourhoodRequest, opts ...client.CallOption) (*NeighbourhoodResponse, error) { | func (c *networkService) ListPeers(ctx context.Context, in *PeerRequest, opts ...client.CallOption) (*PeerResponse, error) { | ||||||
| 	req := c.c.NewRequest(c.name, "Network.Neighbourhood", in) | 	req := c.c.NewRequest(c.name, "Network.ListPeers", in) | ||||||
| 	out := new(NeighbourhoodResponse) | 	out := new(PeerResponse) | ||||||
| 	err := c.c.Call(ctx, req, out, opts...) | 	err := c.c.Call(ctx, req, out, opts...) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| @@ -92,14 +92,14 @@ func (c *networkService) ListRoutes(ctx context.Context, in *proto1.Request, opt | |||||||
|  |  | ||||||
| type NetworkHandler interface { | type NetworkHandler interface { | ||||||
| 	ListNodes(context.Context, *ListRequest, *ListResponse) error | 	ListNodes(context.Context, *ListRequest, *ListResponse) error | ||||||
| 	Neighbourhood(context.Context, *NeighbourhoodRequest, *NeighbourhoodResponse) error | 	ListPeers(context.Context, *PeerRequest, *PeerResponse) error | ||||||
| 	ListRoutes(context.Context, *proto1.Request, *proto1.ListResponse) error | 	ListRoutes(context.Context, *proto1.Request, *proto1.ListResponse) error | ||||||
| } | } | ||||||
|  |  | ||||||
| func RegisterNetworkHandler(s server.Server, hdlr NetworkHandler, opts ...server.HandlerOption) error { | func RegisterNetworkHandler(s server.Server, hdlr NetworkHandler, opts ...server.HandlerOption) error { | ||||||
| 	type network interface { | 	type network interface { | ||||||
| 		ListNodes(ctx context.Context, in *ListRequest, out *ListResponse) error | 		ListNodes(ctx context.Context, in *ListRequest, out *ListResponse) error | ||||||
| 		Neighbourhood(ctx context.Context, in *NeighbourhoodRequest, out *NeighbourhoodResponse) error | 		ListPeers(ctx context.Context, in *PeerRequest, out *PeerResponse) error | ||||||
| 		ListRoutes(ctx context.Context, in *proto1.Request, out *proto1.ListResponse) error | 		ListRoutes(ctx context.Context, in *proto1.Request, out *proto1.ListResponse) error | ||||||
| 	} | 	} | ||||||
| 	type Network struct { | 	type Network struct { | ||||||
| @@ -117,8 +117,8 @@ func (h *networkHandler) ListNodes(ctx context.Context, in *ListRequest, out *Li | |||||||
| 	return h.NetworkHandler.ListNodes(ctx, in, out) | 	return h.NetworkHandler.ListNodes(ctx, in, out) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (h *networkHandler) Neighbourhood(ctx context.Context, in *NeighbourhoodRequest, out *NeighbourhoodResponse) error { | func (h *networkHandler) ListPeers(ctx context.Context, in *PeerRequest, out *PeerResponse) error { | ||||||
| 	return h.NetworkHandler.Neighbourhood(ctx, in, out) | 	return h.NetworkHandler.ListPeers(ctx, in, out) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (h *networkHandler) ListRoutes(ctx context.Context, in *proto1.Request, out *proto1.ListResponse) error { | func (h *networkHandler) ListRoutes(ctx context.Context, in *proto1.Request, out *proto1.ListResponse) error { | ||||||
|   | |||||||
| @@ -93,129 +93,129 @@ func (m *ListResponse) GetNodes() []*Node { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // NeighbourhoodRequest is sent to query node neighbourhood | // PeerRequest is sent to query node peers | ||||||
| type NeighbourhoodRequest struct { | type PeerRequest struct { | ||||||
| 	Id                   string   `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` | 	Id                   string   `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` | ||||||
| 	XXX_NoUnkeyedLiteral struct{} `json:"-"` | 	XXX_NoUnkeyedLiteral struct{} `json:"-"` | ||||||
| 	XXX_unrecognized     []byte   `json:"-"` | 	XXX_unrecognized     []byte   `json:"-"` | ||||||
| 	XXX_sizecache        int32    `json:"-"` | 	XXX_sizecache        int32    `json:"-"` | ||||||
| } | } | ||||||
|  |  | ||||||
| func (m *NeighbourhoodRequest) Reset()         { *m = NeighbourhoodRequest{} } | func (m *PeerRequest) Reset()         { *m = PeerRequest{} } | ||||||
| func (m *NeighbourhoodRequest) String() string { return proto.CompactTextString(m) } | func (m *PeerRequest) String() string { return proto.CompactTextString(m) } | ||||||
| func (*NeighbourhoodRequest) ProtoMessage()    {} | func (*PeerRequest) ProtoMessage()    {} | ||||||
| func (*NeighbourhoodRequest) Descriptor() ([]byte, []int) { | func (*PeerRequest) Descriptor() ([]byte, []int) { | ||||||
| 	return fileDescriptor_8571034d60397816, []int{2} | 	return fileDescriptor_8571034d60397816, []int{2} | ||||||
| } | } | ||||||
|  |  | ||||||
| func (m *NeighbourhoodRequest) XXX_Unmarshal(b []byte) error { | func (m *PeerRequest) XXX_Unmarshal(b []byte) error { | ||||||
| 	return xxx_messageInfo_NeighbourhoodRequest.Unmarshal(m, b) | 	return xxx_messageInfo_PeerRequest.Unmarshal(m, b) | ||||||
| } | } | ||||||
| func (m *NeighbourhoodRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { | func (m *PeerRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { | ||||||
| 	return xxx_messageInfo_NeighbourhoodRequest.Marshal(b, m, deterministic) | 	return xxx_messageInfo_PeerRequest.Marshal(b, m, deterministic) | ||||||
| } | } | ||||||
| func (m *NeighbourhoodRequest) XXX_Merge(src proto.Message) { | func (m *PeerRequest) XXX_Merge(src proto.Message) { | ||||||
| 	xxx_messageInfo_NeighbourhoodRequest.Merge(m, src) | 	xxx_messageInfo_PeerRequest.Merge(m, src) | ||||||
| } | } | ||||||
| func (m *NeighbourhoodRequest) XXX_Size() int { | func (m *PeerRequest) XXX_Size() int { | ||||||
| 	return xxx_messageInfo_NeighbourhoodRequest.Size(m) | 	return xxx_messageInfo_PeerRequest.Size(m) | ||||||
| } | } | ||||||
| func (m *NeighbourhoodRequest) XXX_DiscardUnknown() { | func (m *PeerRequest) XXX_DiscardUnknown() { | ||||||
| 	xxx_messageInfo_NeighbourhoodRequest.DiscardUnknown(m) | 	xxx_messageInfo_PeerRequest.DiscardUnknown(m) | ||||||
| } | } | ||||||
|  |  | ||||||
| var xxx_messageInfo_NeighbourhoodRequest proto.InternalMessageInfo | var xxx_messageInfo_PeerRequest proto.InternalMessageInfo | ||||||
|  |  | ||||||
| func (m *NeighbourhoodRequest) GetId() string { | func (m *PeerRequest) GetId() string { | ||||||
| 	if m != nil { | 	if m != nil { | ||||||
| 		return m.Id | 		return m.Id | ||||||
| 	} | 	} | ||||||
| 	return "" | 	return "" | ||||||
| } | } | ||||||
|  |  | ||||||
| // NeighbourhoodResponse returns node neighbourhood | // PeerResponse returns node neighbourhood | ||||||
| type NeighbourhoodResponse struct { | type PeerResponse struct { | ||||||
| 	Neighbourhoodi       *Neighbourhood `protobuf:"bytes,1,opt,name=neighbourhoodi,proto3" json:"neighbourhoodi,omitempty"` | 	Peers                *Peers   `protobuf:"bytes,1,opt,name=peers,proto3" json:"peers,omitempty"` | ||||||
| 	XXX_NoUnkeyedLiteral struct{} `json:"-"` | 	XXX_NoUnkeyedLiteral struct{} `json:"-"` | ||||||
| 	XXX_unrecognized     []byte   `json:"-"` | 	XXX_unrecognized     []byte   `json:"-"` | ||||||
| 	XXX_sizecache        int32    `json:"-"` | 	XXX_sizecache        int32    `json:"-"` | ||||||
| } | } | ||||||
|  |  | ||||||
| func (m *NeighbourhoodResponse) Reset()         { *m = NeighbourhoodResponse{} } | func (m *PeerResponse) Reset()         { *m = PeerResponse{} } | ||||||
| func (m *NeighbourhoodResponse) String() string { return proto.CompactTextString(m) } | func (m *PeerResponse) String() string { return proto.CompactTextString(m) } | ||||||
| func (*NeighbourhoodResponse) ProtoMessage()    {} | func (*PeerResponse) ProtoMessage()    {} | ||||||
| func (*NeighbourhoodResponse) Descriptor() ([]byte, []int) { | func (*PeerResponse) Descriptor() ([]byte, []int) { | ||||||
| 	return fileDescriptor_8571034d60397816, []int{3} | 	return fileDescriptor_8571034d60397816, []int{3} | ||||||
| } | } | ||||||
|  |  | ||||||
| func (m *NeighbourhoodResponse) XXX_Unmarshal(b []byte) error { | func (m *PeerResponse) XXX_Unmarshal(b []byte) error { | ||||||
| 	return xxx_messageInfo_NeighbourhoodResponse.Unmarshal(m, b) | 	return xxx_messageInfo_PeerResponse.Unmarshal(m, b) | ||||||
| } | } | ||||||
| func (m *NeighbourhoodResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { | func (m *PeerResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { | ||||||
| 	return xxx_messageInfo_NeighbourhoodResponse.Marshal(b, m, deterministic) | 	return xxx_messageInfo_PeerResponse.Marshal(b, m, deterministic) | ||||||
| } | } | ||||||
| func (m *NeighbourhoodResponse) XXX_Merge(src proto.Message) { | func (m *PeerResponse) XXX_Merge(src proto.Message) { | ||||||
| 	xxx_messageInfo_NeighbourhoodResponse.Merge(m, src) | 	xxx_messageInfo_PeerResponse.Merge(m, src) | ||||||
| } | } | ||||||
| func (m *NeighbourhoodResponse) XXX_Size() int { | func (m *PeerResponse) XXX_Size() int { | ||||||
| 	return xxx_messageInfo_NeighbourhoodResponse.Size(m) | 	return xxx_messageInfo_PeerResponse.Size(m) | ||||||
| } | } | ||||||
| func (m *NeighbourhoodResponse) XXX_DiscardUnknown() { | func (m *PeerResponse) XXX_DiscardUnknown() { | ||||||
| 	xxx_messageInfo_NeighbourhoodResponse.DiscardUnknown(m) | 	xxx_messageInfo_PeerResponse.DiscardUnknown(m) | ||||||
| } | } | ||||||
|  |  | ||||||
| var xxx_messageInfo_NeighbourhoodResponse proto.InternalMessageInfo | var xxx_messageInfo_PeerResponse proto.InternalMessageInfo | ||||||
|  |  | ||||||
| func (m *NeighbourhoodResponse) GetNeighbourhoodi() *Neighbourhood { | func (m *PeerResponse) GetPeers() *Peers { | ||||||
| 	if m != nil { | 	if m != nil { | ||||||
| 		return m.Neighbourhoodi | 		return m.Peers | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| type Neighbourhood struct { | type Peers struct { | ||||||
| 	Node                 *Node    `protobuf:"bytes,1,opt,name=node,proto3" json:"node,omitempty"` | 	Node                 *Node    `protobuf:"bytes,1,opt,name=node,proto3" json:"node,omitempty"` | ||||||
| 	Neighbours           []*Node  `protobuf:"bytes,2,rep,name=neighbours,proto3" json:"neighbours,omitempty"` | 	Peers                []*Node  `protobuf:"bytes,2,rep,name=peers,proto3" json:"peers,omitempty"` | ||||||
| 	XXX_NoUnkeyedLiteral struct{} `json:"-"` | 	XXX_NoUnkeyedLiteral struct{} `json:"-"` | ||||||
| 	XXX_unrecognized     []byte   `json:"-"` | 	XXX_unrecognized     []byte   `json:"-"` | ||||||
| 	XXX_sizecache        int32    `json:"-"` | 	XXX_sizecache        int32    `json:"-"` | ||||||
| } | } | ||||||
|  |  | ||||||
| func (m *Neighbourhood) Reset()         { *m = Neighbourhood{} } | func (m *Peers) Reset()         { *m = Peers{} } | ||||||
| func (m *Neighbourhood) String() string { return proto.CompactTextString(m) } | func (m *Peers) String() string { return proto.CompactTextString(m) } | ||||||
| func (*Neighbourhood) ProtoMessage()    {} | func (*Peers) ProtoMessage()    {} | ||||||
| func (*Neighbourhood) Descriptor() ([]byte, []int) { | func (*Peers) Descriptor() ([]byte, []int) { | ||||||
| 	return fileDescriptor_8571034d60397816, []int{4} | 	return fileDescriptor_8571034d60397816, []int{4} | ||||||
| } | } | ||||||
|  |  | ||||||
| func (m *Neighbourhood) XXX_Unmarshal(b []byte) error { | func (m *Peers) XXX_Unmarshal(b []byte) error { | ||||||
| 	return xxx_messageInfo_Neighbourhood.Unmarshal(m, b) | 	return xxx_messageInfo_Peers.Unmarshal(m, b) | ||||||
| } | } | ||||||
| func (m *Neighbourhood) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { | func (m *Peers) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { | ||||||
| 	return xxx_messageInfo_Neighbourhood.Marshal(b, m, deterministic) | 	return xxx_messageInfo_Peers.Marshal(b, m, deterministic) | ||||||
| } | } | ||||||
| func (m *Neighbourhood) XXX_Merge(src proto.Message) { | func (m *Peers) XXX_Merge(src proto.Message) { | ||||||
| 	xxx_messageInfo_Neighbourhood.Merge(m, src) | 	xxx_messageInfo_Peers.Merge(m, src) | ||||||
| } | } | ||||||
| func (m *Neighbourhood) XXX_Size() int { | func (m *Peers) XXX_Size() int { | ||||||
| 	return xxx_messageInfo_Neighbourhood.Size(m) | 	return xxx_messageInfo_Peers.Size(m) | ||||||
| } | } | ||||||
| func (m *Neighbourhood) XXX_DiscardUnknown() { | func (m *Peers) XXX_DiscardUnknown() { | ||||||
| 	xxx_messageInfo_Neighbourhood.DiscardUnknown(m) | 	xxx_messageInfo_Peers.DiscardUnknown(m) | ||||||
| } | } | ||||||
|  |  | ||||||
| var xxx_messageInfo_Neighbourhood proto.InternalMessageInfo | var xxx_messageInfo_Peers proto.InternalMessageInfo | ||||||
|  |  | ||||||
| func (m *Neighbourhood) GetNode() *Node { | func (m *Peers) GetNode() *Node { | ||||||
| 	if m != nil { | 	if m != nil { | ||||||
| 		return m.Node | 		return m.Node | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (m *Neighbourhood) GetNeighbours() []*Node { | func (m *Peers) GetPeers() []*Node { | ||||||
| 	if m != nil { | 	if m != nil { | ||||||
| 		return m.Neighbours | 		return m.Peers | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| @@ -393,52 +393,52 @@ func (m *Solicit) GetNode() *Node { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // Neighbour is used to nnounce node neighbourhood | // Peer is used to announce node peers | ||||||
| type Neighbour struct { | type Peer struct { | ||||||
| 	// network node | 	// network node | ||||||
| 	Node *Node `protobuf:"bytes,1,opt,name=node,proto3" json:"node,omitempty"` | 	Node *Node `protobuf:"bytes,1,opt,name=node,proto3" json:"node,omitempty"` | ||||||
| 	// neighbours | 	// neighbours | ||||||
| 	Neighbours           []*Neighbour `protobuf:"bytes,2,rep,name=neighbours,proto3" json:"neighbours,omitempty"` | 	Peers                []*Peer  `protobuf:"bytes,2,rep,name=peers,proto3" json:"peers,omitempty"` | ||||||
| 	XXX_NoUnkeyedLiteral struct{} `json:"-"` | 	XXX_NoUnkeyedLiteral struct{} `json:"-"` | ||||||
| 	XXX_unrecognized     []byte   `json:"-"` | 	XXX_unrecognized     []byte   `json:"-"` | ||||||
| 	XXX_sizecache        int32    `json:"-"` | 	XXX_sizecache        int32    `json:"-"` | ||||||
| } | } | ||||||
|  |  | ||||||
| func (m *Neighbour) Reset()         { *m = Neighbour{} } | func (m *Peer) Reset()         { *m = Peer{} } | ||||||
| func (m *Neighbour) String() string { return proto.CompactTextString(m) } | func (m *Peer) String() string { return proto.CompactTextString(m) } | ||||||
| func (*Neighbour) ProtoMessage()    {} | func (*Peer) ProtoMessage()    {} | ||||||
| func (*Neighbour) Descriptor() ([]byte, []int) { | func (*Peer) Descriptor() ([]byte, []int) { | ||||||
| 	return fileDescriptor_8571034d60397816, []int{9} | 	return fileDescriptor_8571034d60397816, []int{9} | ||||||
| } | } | ||||||
|  |  | ||||||
| func (m *Neighbour) XXX_Unmarshal(b []byte) error { | func (m *Peer) XXX_Unmarshal(b []byte) error { | ||||||
| 	return xxx_messageInfo_Neighbour.Unmarshal(m, b) | 	return xxx_messageInfo_Peer.Unmarshal(m, b) | ||||||
| } | } | ||||||
| func (m *Neighbour) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { | func (m *Peer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { | ||||||
| 	return xxx_messageInfo_Neighbour.Marshal(b, m, deterministic) | 	return xxx_messageInfo_Peer.Marshal(b, m, deterministic) | ||||||
| } | } | ||||||
| func (m *Neighbour) XXX_Merge(src proto.Message) { | func (m *Peer) XXX_Merge(src proto.Message) { | ||||||
| 	xxx_messageInfo_Neighbour.Merge(m, src) | 	xxx_messageInfo_Peer.Merge(m, src) | ||||||
| } | } | ||||||
| func (m *Neighbour) XXX_Size() int { | func (m *Peer) XXX_Size() int { | ||||||
| 	return xxx_messageInfo_Neighbour.Size(m) | 	return xxx_messageInfo_Peer.Size(m) | ||||||
| } | } | ||||||
| func (m *Neighbour) XXX_DiscardUnknown() { | func (m *Peer) XXX_DiscardUnknown() { | ||||||
| 	xxx_messageInfo_Neighbour.DiscardUnknown(m) | 	xxx_messageInfo_Peer.DiscardUnknown(m) | ||||||
| } | } | ||||||
|  |  | ||||||
| var xxx_messageInfo_Neighbour proto.InternalMessageInfo | var xxx_messageInfo_Peer proto.InternalMessageInfo | ||||||
|  |  | ||||||
| func (m *Neighbour) GetNode() *Node { | func (m *Peer) GetNode() *Node { | ||||||
| 	if m != nil { | 	if m != nil { | ||||||
| 		return m.Node | 		return m.Node | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (m *Neighbour) GetNeighbours() []*Neighbour { | func (m *Peer) GetPeers() []*Peer { | ||||||
| 	if m != nil { | 	if m != nil { | ||||||
| 		return m.Neighbours | 		return m.Peers | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| @@ -446,42 +446,41 @@ func (m *Neighbour) GetNeighbours() []*Neighbour { | |||||||
| func init() { | func init() { | ||||||
| 	proto.RegisterType((*ListRequest)(nil), "go.micro.network.ListRequest") | 	proto.RegisterType((*ListRequest)(nil), "go.micro.network.ListRequest") | ||||||
| 	proto.RegisterType((*ListResponse)(nil), "go.micro.network.ListResponse") | 	proto.RegisterType((*ListResponse)(nil), "go.micro.network.ListResponse") | ||||||
| 	proto.RegisterType((*NeighbourhoodRequest)(nil), "go.micro.network.NeighbourhoodRequest") | 	proto.RegisterType((*PeerRequest)(nil), "go.micro.network.PeerRequest") | ||||||
| 	proto.RegisterType((*NeighbourhoodResponse)(nil), "go.micro.network.NeighbourhoodResponse") | 	proto.RegisterType((*PeerResponse)(nil), "go.micro.network.PeerResponse") | ||||||
| 	proto.RegisterType((*Neighbourhood)(nil), "go.micro.network.Neighbourhood") | 	proto.RegisterType((*Peers)(nil), "go.micro.network.Peers") | ||||||
| 	proto.RegisterType((*Node)(nil), "go.micro.network.Node") | 	proto.RegisterType((*Node)(nil), "go.micro.network.Node") | ||||||
| 	proto.RegisterType((*Connect)(nil), "go.micro.network.Connect") | 	proto.RegisterType((*Connect)(nil), "go.micro.network.Connect") | ||||||
| 	proto.RegisterType((*Close)(nil), "go.micro.network.Close") | 	proto.RegisterType((*Close)(nil), "go.micro.network.Close") | ||||||
| 	proto.RegisterType((*Solicit)(nil), "go.micro.network.Solicit") | 	proto.RegisterType((*Solicit)(nil), "go.micro.network.Solicit") | ||||||
| 	proto.RegisterType((*Neighbour)(nil), "go.micro.network.Neighbour") | 	proto.RegisterType((*Peer)(nil), "go.micro.network.Peer") | ||||||
| } | } | ||||||
|  |  | ||||||
| func init() { proto.RegisterFile("network.proto", fileDescriptor_8571034d60397816) } | func init() { proto.RegisterFile("network.proto", fileDescriptor_8571034d60397816) } | ||||||
|  |  | ||||||
| var fileDescriptor_8571034d60397816 = []byte{ | var fileDescriptor_8571034d60397816 = []byte{ | ||||||
| 	// 372 bytes of a gzipped FileDescriptorProto | 	// 353 bytes of a gzipped FileDescriptorProto | ||||||
| 	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0x5d, 0x4f, 0xea, 0x40, | 	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x93, 0x51, 0x4f, 0xc2, 0x30, | ||||||
| 	0x10, 0xbd, 0xf4, 0xc2, 0x6d, 0x18, 0x2e, 0xc4, 0x6c, 0xd4, 0x34, 0x18, 0x94, 0xec, 0x03, 0x12, | 	0x10, 0xc7, 0x19, 0x32, 0x17, 0x6e, 0x60, 0x4c, 0x1f, 0x74, 0x21, 0x99, 0x21, 0x7d, 0x22, 0x46, | ||||||
| 	0xa3, 0xc5, 0x40, 0xf0, 0x45, 0xdf, 0x78, 0xe0, 0x85, 0xf0, 0x80, 0x7f, 0x40, 0xdb, 0x6e, 0xca, | 	0x86, 0x81, 0xf0, 0xa6, 0x4f, 0x3c, 0xf8, 0x42, 0x88, 0x99, 0x5f, 0x40, 0xd8, 0x2e, 0xd8, 0x08, | ||||||
| 	0x46, 0xe8, 0xe0, 0xee, 0x36, 0xfe, 0x01, 0x7f, 0xb8, 0xd9, 0x76, 0xc1, 0x52, 0xbe, 0xd2, 0xb7, | 	0x3b, 0x6c, 0x4b, 0xfc, 0xd6, 0x7e, 0x06, 0xd3, 0x76, 0x44, 0x84, 0xcc, 0x84, 0xc4, 0xb7, 0xde, | ||||||
| 	0xee, 0xcc, 0x99, 0x73, 0x66, 0xa6, 0x67, 0xa0, 0x1e, 0x31, 0xf5, 0x85, 0xe2, 0xc3, 0x5d, 0x09, | 	0xdd, 0xff, 0x7e, 0x77, 0x6d, 0xef, 0xa0, 0x5d, 0xa0, 0xfe, 0x24, 0xf9, 0x9e, 0x6c, 0x24, 0x69, | ||||||
| 	0x54, 0x48, 0xce, 0x42, 0x74, 0x97, 0xdc, 0x17, 0xe8, 0x9a, 0x78, 0x73, 0x10, 0x72, 0x35, 0x8f, | 	0x62, 0x97, 0x4b, 0x4a, 0xd6, 0x22, 0x93, 0x94, 0x94, 0xfe, 0xce, 0x68, 0x29, 0xf4, 0xdb, 0x76, | ||||||
| 	0x3d, 0xd7, 0xc7, 0x65, 0x2f, 0xc9, 0xf4, 0x42, 0x7c, 0x48, 0x3f, 0x04, 0xc6, 0x8a, 0x89, 0x5e, | 	0x91, 0x64, 0xb4, 0x1e, 0xd8, 0xc8, 0x60, 0x49, 0x7d, 0x77, 0x90, 0xb4, 0xd5, 0x28, 0x07, 0x36, | ||||||
| 	0x52, 0x69, 0x1e, 0x29, 0x0d, 0xad, 0x43, 0x6d, 0xc2, 0xa5, 0x9a, 0xb1, 0xcf, 0x98, 0x49, 0x45, | 	0xb3, 0x34, 0x1c, 0x86, 0xb7, 0x21, 0x9c, 0x0a, 0xa5, 0x53, 0xfc, 0xd8, 0xa2, 0xd2, 0xfc, 0x01, | ||||||
| 	0x5f, 0xe0, 0x7f, 0xfa, 0x94, 0x2b, 0x8c, 0x24, 0x23, 0xf7, 0x50, 0x89, 0x30, 0x60, 0xd2, 0x29, | 	0x5a, 0xce, 0x54, 0x1b, 0x2a, 0x14, 0xb2, 0x3b, 0xf0, 0x0b, 0xca, 0x51, 0x45, 0x5e, 0xf7, 0xac, | ||||||
| 	0xb5, 0xff, 0x76, 0x6b, 0xfd, 0x4b, 0x37, 0xaf, 0xea, 0x4e, 0x31, 0x60, 0xb3, 0x14, 0x44, 0x3b, | 	0x17, 0x0e, 0xaf, 0x92, 0xc3, 0xaa, 0xc9, 0x8c, 0x72, 0x4c, 0x9d, 0x88, 0xc7, 0x10, 0x3e, 0x23, | ||||||
| 	0x70, 0x3e, 0x65, 0x3c, 0x9c, 0x7b, 0x18, 0x8b, 0x39, 0x62, 0x60, 0x58, 0x49, 0x03, 0x2c, 0x1e, | 	0xca, 0x12, 0xc6, 0x2e, 0xa0, 0x2e, 0xf2, 0xc8, 0xeb, 0x7a, 0xbd, 0x66, 0x5a, 0x17, 0x39, 0x7f, | ||||||
| 	0x38, 0xa5, 0x76, 0xa9, 0x5b, 0x9d, 0x59, 0x3c, 0xa0, 0x6f, 0x70, 0x91, 0xc3, 0x19, 0xb9, 0x31, | 	0x84, 0x96, 0x0b, 0x97, 0xf0, 0x3e, 0xf8, 0x1b, 0x44, 0xa9, 0xac, 0x24, 0x1c, 0x5e, 0x1f, 0xc3, | ||||||
| 	0x34, 0xa2, 0x6c, 0x82, 0x27, 0x45, 0xb5, 0xfe, 0xcd, 0x1e, 0xdd, 0x2d, 0x82, 0x5c, 0x19, 0x95, | 	0x8d, 0x5c, 0xa5, 0x4e, 0xc5, 0xe7, 0xe0, 0x5b, 0x9b, 0xdd, 0x42, 0xc3, 0xd4, 0x2b, 0xd3, 0xaa, | ||||||
| 	0x50, 0xdf, 0x02, 0x90, 0x3b, 0x28, 0xeb, 0x1e, 0x0d, 0xdf, 0xa1, 0x39, 0x12, 0x0c, 0x79, 0x02, | 	0x7a, 0xb2, 0x1a, 0x73, 0x01, 0x57, 0xa3, 0xfe, 0xf7, 0x05, 0x5c, 0x89, 0x7b, 0x68, 0x18, 0xf3, | ||||||
| 	0xd8, 0xd0, 0x49, 0xc7, 0x3a, 0x3a, 0x79, 0x06, 0x49, 0x1f, 0xa1, 0xac, 0x63, 0xf9, 0x71, 0x89, | 	0xb0, 0x73, 0x16, 0x41, 0x30, 0xcf, 0x73, 0x89, 0xca, 0x70, 0x8c, 0x73, 0x67, 0xf2, 0x31, 0x04, | ||||||
| 	0x03, 0xf6, 0x7b, 0x10, 0x08, 0x26, 0x35, 0x99, 0x0e, 0xae, 0x9f, 0x74, 0x08, 0xf6, 0x08, 0xa3, | 	0x13, 0x2a, 0x0a, 0xcc, 0xf4, 0x29, 0x6d, 0xf1, 0x11, 0xf8, 0x93, 0x15, 0x29, 0x3c, 0x29, 0x69, | ||||||
| 	0x88, 0xf9, 0xaa, 0x48, 0x83, 0x74, 0x00, 0x95, 0xd1, 0x02, 0x25, 0x2b, 0x54, 0x34, 0x04, 0xfb, | 	0x0c, 0xc1, 0x0b, 0xad, 0x44, 0x26, 0x4e, 0xab, 0xf5, 0x0a, 0x0d, 0xf3, 0x6e, 0xff, 0xfc, 0x6c, | ||||||
| 	0x15, 0x17, 0xdc, 0xe7, 0xc5, 0xb4, 0x14, 0x54, 0x37, 0x9b, 0x2c, 0xb4, 0xc5, 0xe7, 0x3d, 0x5b, | 	0xf6, 0x27, 0x9d, 0x68, 0xf8, 0xe5, 0x41, 0x30, 0x73, 0x7e, 0x36, 0x85, 0xa6, 0x99, 0x20, 0xc3, | ||||||
| 	0xbc, 0x3a, 0xf2, 0x1f, 0xb3, 0xab, 0xec, 0x7f, 0x5b, 0x60, 0x4f, 0x53, 0x04, 0x99, 0x40, 0x55, | 	0x52, 0x2c, 0x3e, 0xce, 0xdb, 0x9b, 0xb6, 0xce, 0x4d, 0x55, 0xd8, 0x0d, 0x08, 0xaf, 0xed, 0x68, | ||||||
| 	0x7b, 0x52, 0x53, 0x4b, 0xd2, 0xda, 0x65, 0xc8, 0xf8, 0xb7, 0x79, 0x7d, 0x28, 0x9d, 0x1a, 0x8c, | 	0xee, 0xdf, 0xe3, 0x8a, 0x2e, 0xaa, 0x69, 0xfb, 0xe3, 0xc6, 0x6b, 0xec, 0x09, 0xc0, 0xf2, 0xcd, | ||||||
| 	0xfe, 0x21, 0x5e, 0xde, 0x19, 0x9d, 0x53, 0xde, 0x32, 0xd4, 0xb7, 0x27, 0x71, 0x1b, 0x8d, 0x31, | 	0x02, 0x28, 0x16, 0xfd, 0xe8, 0xcb, 0x95, 0xd8, 0x91, 0xe2, 0xa3, 0xc8, 0xef, 0xb6, 0x16, 0xe7, | ||||||
| 	0x40, 0xa2, 0xaa, 0x0f, 0x4d, 0x12, 0xe7, 0xb7, 0xd0, 0x9c, 0xde, 0x9a, 0xb2, 0xb5, 0x93, 0xd9, | 	0x76, 0x79, 0x46, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xaf, 0xb8, 0x9b, 0x3f, 0x94, 0x03, 0x00, | ||||||
| 	0x6e, 0xd6, 0xfb, 0x97, 0x1c, 0xe9, 0xe0, 0x27, 0x00, 0x00, 0xff, 0xff, 0x63, 0xe7, 0xb4, 0xb0, | 	0x00, | ||||||
| 	0xfc, 0x03, 0x00, 0x00, |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ import "github.com/micro/go-micro/router/proto/router.proto"; | |||||||
| // Network service is usesd to gain visibility into networks | // Network service is usesd to gain visibility into networks | ||||||
| service Network { | service Network { | ||||||
|         rpc ListNodes(ListRequest) returns (ListResponse) {}; |         rpc ListNodes(ListRequest) returns (ListResponse) {}; | ||||||
|         rpc Neighbourhood(NeighbourhoodRequest) returns (NeighbourhoodResponse) {}; |         rpc ListPeers(PeerRequest) returns (PeerResponse) {}; | ||||||
|         rpc ListRoutes(go.micro.router.Request) returns (go.micro.router.ListResponse) {}; |         rpc ListRoutes(go.micro.router.Request) returns (go.micro.router.ListResponse) {}; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -19,19 +19,19 @@ message ListResponse { | |||||||
| 	repeated Node nodes = 1; | 	repeated Node nodes = 1; | ||||||
| } | } | ||||||
|  |  | ||||||
| // NeighbourhoodRequest is sent to query node neighbourhood | // PeerRequest is sent to query node peers | ||||||
| message NeighbourhoodRequest { | message PeerRequest { | ||||||
|         string id = 1; |         string id = 1; | ||||||
| } | } | ||||||
|  |  | ||||||
| // NeighbourhoodResponse returns node neighbourhood | // PeerResponse returns node neighbourhood | ||||||
| message NeighbourhoodResponse { | message PeerResponse { | ||||||
|         Neighbourhood neighbourhoodi = 1; |         Peers peers = 1; | ||||||
| } | } | ||||||
|  |  | ||||||
| message Neighbourhood { | message Peers { | ||||||
|         Node node = 1; |         Node node = 1; | ||||||
|         repeated Node neighbours = 2; |         repeated Node peers = 2; | ||||||
| } | } | ||||||
|  |  | ||||||
| // Node is network node | // Node is network node | ||||||
| @@ -60,10 +60,10 @@ message Solicit { | |||||||
|         Node node = 1; |         Node node = 1; | ||||||
| } | } | ||||||
|  |  | ||||||
| // Neighbour is used to nnounce node neighbourhood | // Peer is used to announce node peers | ||||||
| message Neighbour { | message Peer { | ||||||
|         // network node |         // network node | ||||||
|         Node node = 1; |         Node node = 1; | ||||||
|         // neighbours |         // neighbours | ||||||
|         repeated Neighbour neighbours = 2; |         repeated Peer peers = 2; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user