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

+3 -2
View File
@@ -140,17 +140,18 @@ func (routes *Routes) calculateBroadcast() map[PeerName][]PeerName {
// This is rather similar to the inner loop on
// peer.Routes(...); the main difference is in the
// locking.
ourself.ForEachConnection(func(remoteName PeerName, conn Connection) {
for _, conn := range ourself.Connections() {
if !conn.Established() {
return
}
remoteName := conn.Remote().Name
if _, found := reached[remoteName]; found {
return
}
if remoteConn, found := conn.Remote().ConnectionTo(ourself.Name); found && remoteConn.Established() {
hops = append(hops, remoteName)
}
})
}
}
broadcast[name] = hops
})