khatru: allow disabling expiration manager.

This commit is contained in:
fiatjaf
2025-07-28 22:06:12 -03:00
parent a4d8491d2d
commit 88096fbd84
2 changed files with 22 additions and 0 deletions

View File

@@ -39,6 +39,8 @@ type expirationManager struct {
relay *Relay
interval time.Duration
initialScanDone bool
kill chan struct{} // used for manually killing this
killonce *sync.Once
}
func newExpirationManager(relay *Relay) *expirationManager {
@@ -46,9 +48,17 @@ func newExpirationManager(relay *Relay) *expirationManager {
events: make(expiringEventHeap, 0),
relay: relay,
interval: time.Hour,
kill: make(chan struct{}),
killonce: &sync.Once{},
}
}
func (em *expirationManager) stop() {
em.killonce.Do(func() {
close(em.kill)
})
}
func (em *expirationManager) start(ctx context.Context) {
ticker := time.NewTicker(em.interval)
defer ticker.Stop()
@@ -57,6 +67,8 @@ func (em *expirationManager) start(ctx context.Context) {
select {
case <-ctx.Done():
return
case <-em.kill:
return
case <-ticker.C:
if !em.initialScanDone {
em.initialScan(ctx)

View File

@@ -6,6 +6,7 @@ import (
"log"
"net/http"
"os"
"slices"
"strconv"
"strings"
"sync"
@@ -168,3 +169,12 @@ func (rl *Relay) getBaseURL(r *http.Request) string {
}
return proto + "://" + host
}
func (rl *Relay) DisableExpiration() {
rl.expirationManager.stop()
idx := slices.Index(rl.Info.SupportedNIPs, 40)
if idx != -1 {
rl.Info.SupportedNIPs[idx] = rl.Info.SupportedNIPs[len(rl.Info.SupportedNIPs)-1]
rl.Info.SupportedNIPs = rl.Info.SupportedNIPs[0 : len(rl.Info.SupportedNIPs)-1]
}
}