replace Peer.ForEachConnection with Peer.Connections

The former is prone to triggering deadlocks since the lock is held on
the peer during the iteration.
This commit is contained in:
Matthias Radestock committed 2015-03-17 16:24:19 +00:00
1 parent 08a08be370
commit d5eb76f32e
6 files changed
+19 -24

No files matched your search

+5 -3
View File
@@ -73,12 +73,14 @@ func (peer *Peer) ConnectionTo(name PeerName) (Connection, bool) {
return conn, found // yes, you really can't inline that. FFS.
}
func (peer *Peer) ForEachConnection(fun func(PeerName, Connection)) {
func (peer *Peer) Connections() []Connection {
peer.RLock()
defer peer.RUnlock()
for name, conn := range peer.connections {
fun(name, conn)
connections := make([]Connection, 0, len(peer.connections))
for _, conn := range peer.connections {
connections = append(connections, conn)
}
return connections
}
func (peer *Peer) SetVersionAndConnections(version uint64, connections map[PeerName]Connection) {