refactor: increase similarity betweeen parts of route calculation

This commit is contained in:
Matthias Radestock committed 2015-05-11 20:14:24 +01:00
1 parent 039446f756
commit c5c93d3a77
2 files changed
+4 -7

No files matched your search

+3 -5
View File
@@ -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]
}
}
}
+1 -2
View File
@@ -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
}