From 5ef2f6f94c86dc723612a9ab283f98e52fffcac1 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 7 Dec 2022 12:55:58 -0800 Subject: [PATCH] Make priority queue criteria a const. Remove inner loop --- app/plugins/contactRetry.go | 46 ++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/app/plugins/contactRetry.go b/app/plugins/contactRetry.go index 3ca5ab9..2ab5da1 100644 --- a/app/plugins/contactRetry.go +++ b/app/plugins/contactRetry.go @@ -20,6 +20,8 @@ const circutTimeoutSecs int = 120 const MaxBaseTimeoutSec = 5 * 60 // a max base time out of 5 min const maxFailedBackoff = 6 // 2^6 = 64 -> 64 * [2m to 5m] = 2h8m to 5h20m +const PriorityQueueTimeSinceQualifierHours float64 = 168 + type connectionType int const ( @@ -180,32 +182,28 @@ func (cr *contactRetry) run() { // do priority connections first... for connectingCount < cr.maxTorCircuitsPending() && len(cr.priorityQueue.queue) > 0 { - for { - contact := cr.priorityQueue.dequeue() - if contact == nil { - break - } - // could have received incoming connection while in queue, make sure still disconnected before trying - if contact.state == connections.DISCONNECTED { - cr.publishConnectionRequest(contact) - connectingCount++ - break - } + contact := cr.priorityQueue.dequeue() + if contact == nil { + break + } + // could have received incoming connection while in queue, make sure still disconnected before trying + if contact.state == connections.DISCONNECTED { + cr.publishConnectionRequest(contact) + connectingCount++ + break } } for connectingCount < cr.maxTorCircuitsPending() && len(cr.pendingQueue.queue) > 0 { - for { - contact := cr.pendingQueue.dequeue() - if contact == nil { - break - } - // could have received incoming connection while in queue, make sure still disconnected before trying - if contact.state == connections.DISCONNECTED { - cr.publishConnectionRequest(contact) - connectingCount++ - break - } + contact := cr.pendingQueue.dequeue() + if contact == nil { + break + } + // could have received incoming connection while in queue, make sure still disconnected before trying + if contact.state == connections.DISCONNECTED { + cr.publishConnectionRequest(contact) + connectingCount++ + break } } cr.lastCheck = time.Now() @@ -246,7 +244,7 @@ func (cr *contactRetry) run() { if contact.state == connections.DISCONNECTED && !contact.queued { // prioritize connections made in the last week - if time.Since(contact.lastSeen).Hours() < 168 { + if time.Since(contact.lastSeen).Hours() < PriorityQueueTimeSinceQualifierHours { cr.priorityQueue.insert(contact) } else { cr.pendingQueue.insert(contact) @@ -313,7 +311,7 @@ func (cr *contactRetry) requeueReady() { return true }) for _, contact := range retryable { - if time.Since(contact.lastSeen).Hours() < 168 { + if time.Since(contact.lastSeen).Hours() < PriorityQueueTimeSinceQualifierHours { cr.priorityQueue.insert(contact) } else { cr.pendingQueue.insert(contact)