khatru: allow disabling expiration manager.
This commit is contained in:
@@ -39,6 +39,8 @@ type expirationManager struct {
|
|||||||
relay *Relay
|
relay *Relay
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
initialScanDone bool
|
initialScanDone bool
|
||||||
|
kill chan struct{} // used for manually killing this
|
||||||
|
killonce *sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
func newExpirationManager(relay *Relay) *expirationManager {
|
func newExpirationManager(relay *Relay) *expirationManager {
|
||||||
@@ -46,9 +48,17 @@ func newExpirationManager(relay *Relay) *expirationManager {
|
|||||||
events: make(expiringEventHeap, 0),
|
events: make(expiringEventHeap, 0),
|
||||||
relay: relay,
|
relay: relay,
|
||||||
interval: time.Hour,
|
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) {
|
func (em *expirationManager) start(ctx context.Context) {
|
||||||
ticker := time.NewTicker(em.interval)
|
ticker := time.NewTicker(em.interval)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
@@ -57,6 +67,8 @@ func (em *expirationManager) start(ctx context.Context) {
|
|||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
|
case <-em.kill:
|
||||||
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
if !em.initialScanDone {
|
if !em.initialScanDone {
|
||||||
em.initialScan(ctx)
|
em.initialScan(ctx)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -168,3 +169,12 @@ func (rl *Relay) getBaseURL(r *http.Request) string {
|
|||||||
}
|
}
|
||||||
return proto + "://" + host
|
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