khatru: allow disabling expiration manager.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user