Add a Priority Queue for Most Common Contacts #481

Merged
dan merged 4 commits from priority into master 2022-12-07 21:37:30 +00:00
1 changed files with 22 additions and 24 deletions
Showing only changes of commit 5ef2f6f94c - Show all commits

View File

@ -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...
dan marked this conversation as resolved
Review

why the nested inner for loop?

why the nested inner for loop?
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 {
Review

this shouldn't be needed, the outer loop checks len, so it should be redundant

this shouldn't be needed, the outer loop checks len, so it should be redundant
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 {
dan marked this conversation as resolved
Review

define 168 as something like PriorityQueueTimeSinceQualifierHours or... umm.. something less unwordly so we can tweak it in one place instead of two

define 168 as something like PriorityQueueTimeSinceQualifierHours or... umm.. something less unwordly so we can tweak it in one place instead of two
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)