From 5b18864aec2027e425de5782bb0d3d4aad834c19 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 15 Sep 2014 13:51:57 +0100 Subject: [PATCH] refactoring - rename addToTargets to addTarget - immediately add to cm.targets; the phasing was unnecessary - don't normalise addresses in addTarget - they are already normalised --- connection_maker.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/connection_maker.go b/connection_maker.go index ea4b1949..a2dc733d 100644 --- a/connection_maker.go +++ b/connection_maker.go @@ -105,6 +105,7 @@ func (cm *ConnectionMaker) checkStateAndAttemptConnections(now time.Time) { addTarget := func(address string) { if !our_connected_targets[address] { validTarget[address] = true + cm.addTarget(address) } } @@ -129,10 +130,6 @@ func (cm *ConnectionMaker) checkStateAndAttemptConnections(now time.Time) { }) }) - for address, _ := range validTarget { - cm.addToTargets(address) - } - now = time.Now() // make sure we catch items just added for address, target := range cm.targets { if our_connected_targets[address] { @@ -154,11 +151,9 @@ func (cm *ConnectionMaker) checkStateAndAttemptConnections(now time.Time) { } } -func (cm *ConnectionMaker) addToTargets(address string) { - address = NormalisePeerAddr(address) - target := cm.targets[address] - if target == nil { - target = &Target{} +func (cm *ConnectionMaker) addTarget(address string) { + if _, found := cm.targets[address]; !found { + target := &Target{} target.tryAfter, target.tryInterval = tryImmediately() cm.targets[address] = target }