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
|
// Nodes returns a slice if all nodes in node topology
|
||||||
func (n *node) Nodes() []Node {
|
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
|
// we need to freeze the network graph here
|
||||||
// otherwise we might get invalid results
|
// otherwise we might get invalid results
|
||||||
n.RLock()
|
n.RLock()
|
||||||
defer n.RUnlock()
|
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
|
// push node to the back of queue
|
||||||
queue.PushBack(n)
|
queue.PushBack(n)
|
||||||
// mark the node as visited
|
// mark the node as visited
|
||||||
|
@ -53,8 +53,9 @@ func (m *ListRequest) XXX_DiscardUnknown() {
|
|||||||
|
|
||||||
var xxx_messageInfo_ListRequest proto.InternalMessageInfo
|
var xxx_messageInfo_ListRequest proto.InternalMessageInfo
|
||||||
|
|
||||||
// ListResponse is returned by ListNodes and ListNeighbours
|
// ListResponse is returned by ListNodes
|
||||||
type ListResponse struct {
|
type ListResponse struct {
|
||||||
|
// network nodes
|
||||||
Nodes []*Node `protobuf:"bytes,1,rep,name=nodes,proto3" json:"nodes,omitempty"`
|
Nodes []*Node `protobuf:"bytes,1,rep,name=nodes,proto3" json:"nodes,omitempty"`
|
||||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
XXX_unrecognized []byte `json:"-"`
|
XXX_unrecognized []byte `json:"-"`
|
||||||
@ -93,8 +94,9 @@ func (m *ListResponse) GetNodes() []*Node {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PeerRequest is sent to query node peers
|
// PeerRequest requests list of peers
|
||||||
type PeerRequest struct {
|
type PeerRequest struct {
|
||||||
|
// node id
|
||||||
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:"-"`
|
||||||
@ -133,7 +135,7 @@ func (m *PeerRequest) GetId() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// PeerResponse returns node neighbourhood
|
// PeerResponse is returned by ListPeers
|
||||||
type PeerResponse struct {
|
type PeerResponse struct {
|
||||||
Peers *Peers `protobuf:"bytes,1,opt,name=peers,proto3" json:"peers,omitempty"`
|
Peers *Peers `protobuf:"bytes,1,opt,name=peers,proto3" json:"peers,omitempty"`
|
||||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
@ -173,8 +175,11 @@ func (m *PeerResponse) GetPeers() *Peers {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Peers are node peers
|
||||||
type Peers struct {
|
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"`
|
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:"-"`
|
||||||
@ -222,7 +227,7 @@ func (m *Peers) GetPeers() []*Node {
|
|||||||
|
|
||||||
// Node is network node
|
// Node is network node
|
||||||
type Node struct {
|
type Node struct {
|
||||||
// node ide
|
// node id
|
||||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
// node address
|
// node address
|
||||||
Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"`
|
Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"`
|
||||||
@ -352,7 +357,7 @@ func (m *Close) GetNode() *Node {
|
|||||||
return nil
|
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 {
|
type Solicit 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"`
|
||||||
@ -393,11 +398,11 @@ func (m *Solicit) GetNode() *Node {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peer is used to announce node peers
|
// Peer is used to advertise node peers
|
||||||
type Peer 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
|
// node peers
|
||||||
Peers []*Peer `protobuf:"bytes,2,rep,name=peers,proto3" json:"peers,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:"-"`
|
||||||
|
@ -14,29 +14,34 @@ service Network {
|
|||||||
// Empty request
|
// Empty request
|
||||||
message ListRequest {}
|
message ListRequest {}
|
||||||
|
|
||||||
// ListResponse is returned by ListNodes and ListNeighbours
|
// ListResponse is returned by ListNodes
|
||||||
message ListResponse {
|
message ListResponse {
|
||||||
|
// network nodes
|
||||||
repeated Node nodes = 1;
|
repeated Node nodes = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PeerRequest is sent to query node peers
|
// PeerRequest requests list of peers
|
||||||
message PeerRequest {
|
message PeerRequest {
|
||||||
|
// node id
|
||||||
string id = 1;
|
string id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PeerResponse returns node neighbourhood
|
// PeerResponse is returned by ListPeers
|
||||||
message PeerResponse {
|
message PeerResponse {
|
||||||
Peers peers = 1;
|
Peers peers = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Peers are node peers
|
||||||
message Peers {
|
message Peers {
|
||||||
|
// network node
|
||||||
Node node = 1;
|
Node node = 1;
|
||||||
|
// node peers
|
||||||
repeated Node peers = 2;
|
repeated Node peers = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node is network node
|
// Node is network node
|
||||||
message Node {
|
message Node {
|
||||||
// node ide
|
// node id
|
||||||
string id = 1;
|
string id = 1;
|
||||||
// node address
|
// node address
|
||||||
string address = 2;
|
string address = 2;
|
||||||
@ -54,16 +59,16 @@ message Close {
|
|||||||
Node node = 1;
|
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 {
|
message Solicit {
|
||||||
// network node
|
// network node
|
||||||
Node node = 1;
|
Node node = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peer is used to announce node peers
|
// Peer is used to advertise node peers
|
||||||
message Peer {
|
message Peer {
|
||||||
// network node
|
// network node
|
||||||
Node node = 1;
|
Node node = 1;
|
||||||
// neighbours
|
// node peers
|
||||||
repeated Peer peers = 2;
|
repeated Peer peers = 2;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user