Lock the Nodes method properly when collecting them.
This commit is contained in:
parent
4c709f7ac1
commit
cbce5490d7
@ -46,16 +46,16 @@ func (n *node) Network() Network {
|
||||
|
||||
// Nodes returns a slice if all nodes in node topology
|
||||
func (n *node) 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()
|
||||
|
||||
//track the visited nodes
|
||||
visited := make(map[string]*node)
|
||||
// queue of the nodes to visit
|
||||
queue := list.New()
|
||||
|
||||
// push node to the back of queue
|
||||
queue.PushBack(n)
|
||||
// mark the node as visited
|
||||
|
@ -53,8 +53,9 @@ func (m *ListRequest) XXX_DiscardUnknown() {
|
||||
|
||||
var xxx_messageInfo_ListRequest proto.InternalMessageInfo
|
||||
|
||||
// ListResponse is returned by ListNodes and ListNeighbours
|
||||
// ListResponse is returned by ListNodes
|
||||
type ListResponse struct {
|
||||
// network nodes
|
||||
Nodes []*Node `protobuf:"bytes,1,rep,name=nodes,proto3" json:"nodes,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
@ -93,8 +94,9 @@ func (m *ListResponse) GetNodes() []*Node {
|
||||
return nil
|
||||
}
|
||||
|
||||
// PeerRequest is sent to query node peers
|
||||
// PeerRequest requests list of peers
|
||||
type PeerRequest struct {
|
||||
// node id
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
@ -133,7 +135,7 @@ func (m *PeerRequest) GetId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// PeerResponse returns node neighbourhood
|
||||
// PeerResponse is returned by ListPeers
|
||||
type PeerResponse struct {
|
||||
Peers *Peers `protobuf:"bytes,1,opt,name=peers,proto3" json:"peers,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
@ -173,8 +175,11 @@ func (m *PeerResponse) GetPeers() *Peers {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Peers are node peers
|
||||
type Peers struct {
|
||||
Node *Node `protobuf:"bytes,1,opt,name=node,proto3" json:"node,omitempty"`
|
||||
// network node
|
||||
Node *Node `protobuf:"bytes,1,opt,name=node,proto3" json:"node,omitempty"`
|
||||
// node peers
|
||||
Peers []*Node `protobuf:"bytes,2,rep,name=peers,proto3" json:"peers,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
@ -222,7 +227,7 @@ func (m *Peers) GetPeers() []*Node {
|
||||
|
||||
// Node is network node
|
||||
type Node struct {
|
||||
// node ide
|
||||
// node id
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
// node address
|
||||
Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"`
|
||||
@ -352,7 +357,7 @@ func (m *Close) GetNode() *Node {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Solicit is sent when requesting route advertisement from the network nodes
|
||||
// Solicit is sent when soliciting routes from the network nodes
|
||||
type Solicit struct {
|
||||
// network node
|
||||
Node *Node `protobuf:"bytes,1,opt,name=node,proto3" json:"node,omitempty"`
|
||||
@ -393,11 +398,11 @@ func (m *Solicit) GetNode() *Node {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Peer is used to announce node peers
|
||||
// Peer is used to advertise node peers
|
||||
type Peer struct {
|
||||
// network node
|
||||
Node *Node `protobuf:"bytes,1,opt,name=node,proto3" json:"node,omitempty"`
|
||||
// neighbours
|
||||
// node peers
|
||||
Peers []*Peer `protobuf:"bytes,2,rep,name=peers,proto3" json:"peers,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
|
@ -14,29 +14,34 @@ service Network {
|
||||
// Empty request
|
||||
message ListRequest {}
|
||||
|
||||
// ListResponse is returned by ListNodes and ListNeighbours
|
||||
// ListResponse is returned by ListNodes
|
||||
message ListResponse {
|
||||
// network nodes
|
||||
repeated Node nodes = 1;
|
||||
}
|
||||
|
||||
// PeerRequest is sent to query node peers
|
||||
// PeerRequest requests list of peers
|
||||
message PeerRequest {
|
||||
// node id
|
||||
string id = 1;
|
||||
}
|
||||
|
||||
// PeerResponse returns node neighbourhood
|
||||
// PeerResponse is returned by ListPeers
|
||||
message PeerResponse {
|
||||
Peers peers = 1;
|
||||
}
|
||||
|
||||
// Peers are node peers
|
||||
message Peers {
|
||||
// network node
|
||||
Node node = 1;
|
||||
// node peers
|
||||
repeated Node peers = 2;
|
||||
}
|
||||
|
||||
// Node is network node
|
||||
message Node {
|
||||
// node ide
|
||||
// node id
|
||||
string id = 1;
|
||||
// node address
|
||||
string address = 2;
|
||||
@ -54,16 +59,16 @@ message Close {
|
||||
Node node = 1;
|
||||
}
|
||||
|
||||
// Solicit is sent when requesting route advertisement from the network nodes
|
||||
// Solicit is sent when soliciting routes from the network nodes
|
||||
message Solicit {
|
||||
// network node
|
||||
Node node = 1;
|
||||
}
|
||||
|
||||
// Peer is used to announce node peers
|
||||
// Peer is used to advertise node peers
|
||||
message Peer {
|
||||
// network node
|
||||
Node node = 1;
|
||||
// neighbours
|
||||
// node peers
|
||||
repeated Peer peers = 2;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user