From c5c93d3a77c7897e6421169ff5bc9f2231979db8 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 11 May 2015 20:14:24 +0100 Subject: [PATCH] refactor: increase similarity betweeen parts of route calculation --- router/peer.go | 8 +++----- router/routes.go | 3 +-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/router/peer.go b/router/peer.go index 5fcf277a..cbfa9f59 100644 --- a/router/peer.go +++ b/router/peer.go @@ -73,7 +73,6 @@ func (peer *Peer) Routes(stopAt *Peer, establishedAndSymmetric bool) (bool, map[ if curPeer == stopAt { return true, routes } - curName := curPeer.Name for remoteName, conn := range curPeer.connections { if establishedAndSymmetric && !conn.Established() { continue @@ -81,9 +80,8 @@ func (peer *Peer) Routes(stopAt *Peer, establishedAndSymmetric bool) (bool, map[ if _, found := routes[remoteName]; found { continue } - remote := conn.Remote() - if remoteConn, found := remote.connections[curName]; !establishedAndSymmetric || (found && remoteConn.Established()) { - nextWorklist = append(nextWorklist, remote) + if remoteConn, found := conn.Remote().connections[curPeer.Name]; !establishedAndSymmetric || (found && remoteConn.Established()) { + nextWorklist = append(nextWorklist, conn.Remote()) // We now know how to get to remoteName: the same // way we get to curPeer. Except, if curPeer is // the starting peer in which case we know we can @@ -91,7 +89,7 @@ func (peer *Peer) Routes(stopAt *Peer, establishedAndSymmetric bool) (bool, map[ if curPeer == peer { routes[remoteName] = remoteName } else { - routes[remoteName] = routes[curName] + routes[remoteName] = routes[curPeer.Name] } } } diff --git a/router/routes.go b/router/routes.go index f7c7c746..e464c8e2 100644 --- a/router/routes.go +++ b/router/routes.go @@ -225,11 +225,10 @@ 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 routes.ourself.connections { + for remoteName, conn := range routes.ourself.connections { if establishedAndSymmetric && !conn.Established() { continue } - remoteName := conn.Remote().Name if _, found := reached[remoteName]; found { continue }