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.
This commit is contained in:
Matthias Radestock committed 2015-04-12 12:11:27 +01:00
1 parent 21102d3615
commit 6409a8647c
1 file changed
+2 -6
+2 -6
View File
@@ -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
}