From bfe8b1e51f14504b52ff92337e11257748222bb1 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 7 Dec 2022 11:13:37 -0800 Subject: [PATCH] Restrict Active Connections to Those Found in the Last Week --- app/plugins/contactRetry.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/plugins/contactRetry.go b/app/plugins/contactRetry.go index 3589c1a..cad53cd 100644 --- a/app/plugins/contactRetry.go +++ b/app/plugins/contactRetry.go @@ -177,11 +177,17 @@ func (cr *contactRetry) run() { connectingCount := cr.connectingCount() log.Debugf("checking queue (len: %v) of total conns watched: %v, with current connecingCount: %v", len(cr.pendingQueue.queue), cr.connCount, connectingCount) for connectingCount < cr.maxTorCircuitsPending() && len(cr.pendingQueue.queue) > 0 { - contact := cr.pendingQueue.dequeue() - // could have received incoming connection while in queue, make sure still disconnected before trying - if contact.state == connections.DISCONNECTED { - cr.publishConnectionRequest(contact) - connectingCount++ + 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 + } } } cr.lastCheck = time.Now() @@ -304,6 +310,11 @@ func (cr *contactRetry) addConnection(id string, state connections.ConnectionSta return } + // if it's been more than a week then don't add + if time.Now().Sub(lastSeen).Hours() > 168 { + return + } + if _, exists := cr.connections.Load(id); !exists { p := &contact{id: id, state: state, failedCount: 0, lastAttempt: event.CwtchEpoch, ctype: ctype, lastSeen: lastSeen, queued: false} cr.connections.Store(id, p)