From efa4160bf5295cc3e508b1bc76f8025f1e65df22 Mon Sep 17 00:00:00 2001 From: Matthias Frei Date: Tue, 10 Oct 2023 13:37:33 +0200 Subject: [PATCH] control: formatted duration for config trustengine.cache.expiration The `trustengine.cache.expiration` configuration option would accept durations as number of nanoseconds. Most likely, this was accidental, all other configuration options for durations accept formatted duration strings, with unit suffix. Change `trustengine.cache.expiration` to accept (only) formatted duration strings. This is a potentially compatibility breaking change for existing control service configuration files. The `trustengine.cache` configuration block is marked as experimental and is likely not widely used, so no transition mechanism is added. --- doc/manuals/control.rst | 6 ++---- private/trust/config/config.go | 11 ++++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/doc/manuals/control.rst b/doc/manuals/control.rst index 0bcbe80173..dfb7c28abf 100644 --- a/doc/manuals/control.rst +++ b/doc/manuals/control.rst @@ -311,11 +311,9 @@ considers the following options. Disable caching entirely. - .. option:: trustengine.cache.expiration = (Default: 60000000000) + .. option:: trustengine.cache.expiration = (Default: "1m") - Expiration of cached entries in nanoseconds. - - **TODO:** this should be changed to accept values in :ref:`duration format `. + Expiration time for cached entries. .. object:: drkey diff --git a/private/trust/config/config.go b/private/trust/config/config.go index 35df7d2f16..43ac04ed48 100644 --- a/private/trust/config/config.go +++ b/private/trust/config/config.go @@ -20,6 +20,7 @@ import ( "github.com/patrickmn/go-cache" + "github.com/scionproto/scion/pkg/private/util" "github.com/scionproto/scion/private/config" ) @@ -47,20 +48,20 @@ func (cfg *Config) ConfigName() string { } type Cache struct { - Disable bool `toml:"disable,omitempty"` - Expiration time.Duration `toml:"expiration,omitempty"` + Disable bool `toml:"disable,omitempty"` + Expiration util.DurWrap `toml:"expiration,omitempty"` } func (cfg *Cache) New() *cache.Cache { if cfg.Disable { return nil } - return cache.New(cfg.Expiration, time.Minute) + return cache.New(cfg.Expiration.Duration, time.Minute) } func (cfg *Cache) InitDefaults() { - if cfg.Expiration == 0 { - cfg.Expiration = defaultExpiration + if cfg.Expiration.Duration == 0 { + cfg.Expiration.Duration = defaultExpiration } }