optimise broadcast route calculation

...by obtaining our connection set just once. This also guards against
potential locking issues, since we no longer obtain the required
lock on our local peer while holding a lock on Peers.

Note that this change means the connection list can be out of date by
the time we enter Peers.ForEach. However, previously it was possible
for the list to change for each peer we are iterating over. So it's
just a different flavour of out-of-dateness.
This commit is contained in:
Matthias Radestock committed 2015-04-08 21:54:45 +01:00
1 parent ec30bdaf3d
commit 56f5c749e1
1 file changed
+2 -1
+2 -1
View File
@@ -180,6 +180,7 @@ func (routes *Routes) calculateUnicast(establishedAndSymmetric bool) map[PeerNam
func (routes *Routes) calculateBroadcast(establishedAndSymmetric bool) map[PeerName][]PeerName {
broadcast := make(map[PeerName][]PeerName)
ourself := routes.ourself
ourConnections := ourself.Connections()
routes.peers.ForEach(func(peer *Peer) {
hops := []PeerName{}
@@ -187,7 +188,7 @@ func (routes *Routes) calculateBroadcast(establishedAndSymmetric bool) map[PeerN
// This is rather similar to the inner loop on
// peer.Routes(...); the main difference is in the
// locking.
for conn := range ourself.Connections() {
for conn := range ourConnections {
if establishedAndSymmetric && !conn.Established() {
continue
}