From 6409a8647c95eb46bc06f5f903ed71739404abd4 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sun, 12 Apr 2015 12:11:27 +0100 Subject: [PATCH] simplify connection logic slightly There is no need to remove entries from cm.targets that are in ourConnectedTargets. None of these targets will be in validTargets (since addTarget filters anything in ourConnectedTargets), so they will be removed a few lines further down anyway... Unless the target is in the 'attempting' state. But that is ok, and in fact desirable. Any such targets indicate connection attempts that are in progress, which is something we display in `weave status` and want to be accurate. Eventually the connection attempt will either succeed or fail, and the cm.targets entry will be removed on the next run of connectToTargets. --- router/connection_maker.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/router/connection_maker.go b/router/connection_maker.go index 7860a89d..280f3c8c 100644 --- a/router/connection_maker.go +++ b/router/connection_maker.go @@ -157,7 +157,7 @@ func (cm *ConnectionMaker) checkStateAndAttemptConnections() time.Duration { } }) - return cm.connectToTargets(validTarget, ourConnectedTargets) + return cm.connectToTargets(validTarget) } func (cm *ConnectionMaker) addTarget(address string) { @@ -168,14 +168,10 @@ func (cm *ConnectionMaker) addTarget(address string) { } } -func (cm *ConnectionMaker) connectToTargets(validTarget map[string]struct{}, ourConnectedTargets map[string]struct{}) time.Duration { +func (cm *ConnectionMaker) connectToTargets(validTarget map[string]struct{}) time.Duration { now := time.Now() // make sure we catch items just added after := MaxDuration for address, target := range cm.targets { - if _, connected := ourConnectedTargets[address]; connected { - delete(cm.targets, address) - continue - } if target.attempting { continue }