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 // GetNode gets the node with the given ID, returning nil if the node does not
// exist // exist
func (net *Network) GetNode(id enode.ID) *Node { func (net *Network) GetNode(id enode.ID) *Node {
net.lock.Lock() net.lock.RLock()
defer net.lock.Unlock() defer net.lock.RUnlock()
return net.getNode(id) return net.getNode(id)
} }
// GetNode gets the node with the given name, returning nil if the node does // GetNode gets the node with the given name, returning nil if the node does
// not exist // not exist
func (net *Network) GetNodeByName(name string) *Node { func (net *Network) GetNodeByName(name string) *Node {
net.lock.Lock() net.lock.RLock()
defer net.lock.Unlock() defer net.lock.RUnlock()
return net.getNodeByName(name) return net.getNodeByName(name)
} }
@ -397,8 +397,8 @@ func (net *Network) getNodeByName(name string) *Node {
// GetNodes returns the existing nodes // GetNodes returns the existing nodes
func (net *Network) GetNodes() (nodes []*Node) { func (net *Network) GetNodes() (nodes []*Node) {
net.lock.Lock() net.lock.RLock()
defer net.lock.Unlock() defer net.lock.RUnlock()
nodes = append(nodes, net.Nodes...) nodes = append(nodes, net.Nodes...)
return 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" // GetConn returns the connection which exists between "one" and "other"
// regardless of which node initiated the connection // regardless of which node initiated the connection
func (net *Network) GetConn(oneID, otherID enode.ID) *Conn { func (net *Network) GetConn(oneID, otherID enode.ID) *Conn {
net.lock.Lock() net.lock.RLock()
defer net.lock.Unlock() defer net.lock.RUnlock()
return net.getConn(oneID, otherID) return net.getConn(oneID, otherID)
} }