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

+1 -5
View File
@@ -61,16 +61,12 @@ func (routes *Routes) MarshalJSON() ([]byte, error) {
}
func (peer *Peer) MarshalJSON() ([]byte, error) {
conns := make([]Connection, 0)
peer.ForEachConnection(func(_ PeerName, conn Connection) {
conns = append(conns, conn)
})
return json.Marshal(struct {
Name string
UID uint64
Version uint64
Connections []Connection
}{peer.Name.String(), peer.UID, peer.version, conns})
}{peer.Name.String(), peer.UID, peer.version, peer.Connections()})
}
func (conn *RemoteConnection) MarshalJSON() ([]byte, error) {