Make priority queue criteria a const. Remove inner loop
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Sarah Jamie Lewis 2022-12-07 12:55:58 -08:00
parent 06a2539502
commit 5ef2f6f94c
1 changed files with 22 additions and 24 deletions

View File

@ -20,6 +20,8 @@ const circutTimeoutSecs int = 120
const MaxBaseTimeoutSec = 5 * 60 // a max base time out of 5 min 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 maxFailedBackoff = 6 // 2^6 = 64 -> 64 * [2m to 5m] = 2h8m to 5h20m
const PriorityQueueTimeSinceQualifierHours float64 = 168
type connectionType int type connectionType int
const ( const (
@ -180,7 +182,6 @@ func (cr *contactRetry) run() {
// do priority connections first... // do priority connections first...
for connectingCount < cr.maxTorCircuitsPending() && len(cr.priorityQueue.queue) > 0 { for connectingCount < cr.maxTorCircuitsPending() && len(cr.priorityQueue.queue) > 0 {
for {
contact := cr.priorityQueue.dequeue() contact := cr.priorityQueue.dequeue()
if contact == nil { if contact == nil {
break break
@ -192,10 +193,8 @@ func (cr *contactRetry) run() {
break break
} }
} }
}
for connectingCount < cr.maxTorCircuitsPending() && len(cr.pendingQueue.queue) > 0 { for connectingCount < cr.maxTorCircuitsPending() && len(cr.pendingQueue.queue) > 0 {
for {
contact := cr.pendingQueue.dequeue() contact := cr.pendingQueue.dequeue()
if contact == nil { if contact == nil {
break break
@ -207,7 +206,6 @@ func (cr *contactRetry) run() {
break break
} }
} }
}
cr.lastCheck = time.Now() cr.lastCheck = time.Now()
} }
@ -246,7 +244,7 @@ func (cr *contactRetry) run() {
if contact.state == connections.DISCONNECTED && !contact.queued { if contact.state == connections.DISCONNECTED && !contact.queued {
// prioritize connections made in the last week // 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) cr.priorityQueue.insert(contact)
} else { } else {
cr.pendingQueue.insert(contact) cr.pendingQueue.insert(contact)
@ -313,7 +311,7 @@ func (cr *contactRetry) requeueReady() {
return true return true
}) })
for _, contact := range retryable { for _, contact := range retryable {
if time.Since(contact.lastSeen).Hours() < 168 { if time.Since(contact.lastSeen).Hours() < PriorityQueueTimeSinceQualifierHours {
cr.priorityQueue.insert(contact) cr.priorityQueue.insert(contact)
} else { } else {
cr.pendingQueue.insert(contact) cr.pendingQueue.insert(contact)