From 651c0a0c27a2394c496d31e0189284bd873c482e Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 10 Sep 2014 16:00:31 +0100 Subject: [PATCH] Remove tickNow() function --- connection_maker.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/connection_maker.go b/connection_maker.go index 58763f99..09958200 100644 --- a/connection_maker.go +++ b/connection_maker.go @@ -55,11 +55,6 @@ func (cm *ConnectionMaker) queryLoop(queryChan <-chan *ConnectionMakerInteractio tick = time.After(5 * time.Second) } } - tickNow := func() { - if tick == nil { - tick = time.After(0 * time.Second) - } - } for { select { case query, ok := <-queryChan: @@ -69,12 +64,12 @@ func (cm *ConnectionMaker) queryLoop(queryChan <-chan *ConnectionMakerInteractio switch { case query.code == CMInitiate: cm.cmdLineAddress[NormalisePeerAddr(query.address)] = true - tickNow() + cm.checkStateAndAttemptConnections(time.Now()) + maybeTick() case query.code == CMStatus: query.resultChan <- cm.status() case query.code == CMAttemptDone: - target := cm.targets[query.address] - if target != nil { + if target, found := cm.targets[query.address]; found { target.state = CSUnconnected target.tryAfter, target.tryInterval = tryAfter(target.tryInterval) maybeTick() @@ -96,7 +91,7 @@ func (cm *ConnectionMaker) checkStateAndAttemptConnections(now time.Time) { ourself := cm.router.Ourself validTarget := make(map[string]bool) - // copy the set of peers we are connected to, so we can access it without locking + // copy the set of things we are connected to, so we can access them without locking our_connected_peers := make(map[PeerName]bool) our_connected_targets := make(map[string]bool) ourself.ForEachConnection(func(peer PeerName, conn Connection) {