p2p/simulations: use RLock where possible

This commit is contained in:
Ferenc Szabo 2018-12-14 14:16:36 +01:00
parent bba796bc62
commit fc086dcd80

View file

@ -373,16 +373,16 @@ func (net *Network) DidReceive(sender, receiver enode.ID, proto string, code uin
// GetNode gets the node with the given ID, returning nil if the node does not
// exist
func (net *Network) GetNode(id enode.ID) *Node {
net.lock.Lock()
defer net.lock.Unlock()
net.lock.RLock()
defer net.lock.RUnlock()
return net.getNode(id)
}
// GetNode gets the node with the given name, returning nil if the node does
// not exist
func (net *Network) GetNodeByName(name string) *Node {
net.lock.Lock()
defer net.lock.Unlock()
net.lock.RLock()
defer net.lock.RUnlock()
return net.getNodeByName(name)
}
@ -397,8 +397,8 @@ func (net *Network) getNodeByName(name string) *Node {
// GetNodes returns the existing nodes
func (net *Network) GetNodes() (nodes []*Node) {
net.lock.Lock()
defer net.lock.Unlock()
net.lock.RLock()
defer net.lock.RUnlock()
nodes = append(nodes, net.Nodes...)
return nodes
@ -471,8 +471,8 @@ func filterIDs(ids []enode.ID, excludeIDs []enode.ID) []enode.ID {
// GetConn returns the connection which exists between "one" and "other"
// regardless of which node initiated the connection
func (net *Network) GetConn(oneID, otherID enode.ID) *Conn {
net.lock.Lock()
defer net.lock.Unlock()
net.lock.RLock()
defer net.lock.RUnlock()
return net.getConn(oneID, otherID)
}