...

Package ntpmonitor

import "github.com/sigstore/timestamp-authority/pkg/ntpmonitor"
Overview
Index

Overview ▾

Variables

var (
    // ErrInvTime indicates that the local time has drifted too much
    // from the monitored NTP servers.
    ErrInvTime = errors.New("local time differs from observed")
    // ErrTooFewServers means that the number of trusted servers are
    // smaller then the selected num servers to query.
    ErrTooFewServers = errors.New("too few ntp servers configured")
    // ErrNoResponse indicates that there is an error to communicate with
    // the remote NTP servers
    ErrNoResponse = errors.New("no ntp response")
    // ErrThreshold means that there is no positive threshold value
    ErrThreshold = errors.New("no valid server threshold set")
    // ErrDeltaTooSmall is referring to when the max delta time is
    // smaller than the request timeout which can give unstable behaviour.
    ErrDeltaTooSmall = errors.New("delta is too small")
)

func RandomChoice

func RandomChoice[T any](s []T, n int, r *rand.Rand) []T

RandomChoice returns a random selection of n items from the slice s. The choice is made using a PSEUDO RANDOM selection. If n is greater than len(s), an empty slice is returned.

type Config

Config holds the configuration for a NTPMonitor

type Config struct {
    RequestAttempts int      `yaml:"request_attempts"`
    RequestTimeout  int      `yaml:"request_timeout"`
    NumServers      int      `yaml:"num_servers"`
    MaxTimeDelta    int      `yaml:"max_time_delta"`
    ServerThreshold int      `yaml:"server_threshold"`
    Period          int      `yaml:"period"`
    Servers         []string `yaml:"servers"`
}

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig reads a yaml file from a provided path, instantiating a new Config object with the vales found. No sanity checking is made of the loaded values.

type LiveNTPClient

type LiveNTPClient struct{}

func (LiveNTPClient) QueryWithOptions

func (c LiveNTPClient) QueryWithOptions(srv string, opts ntp.QueryOptions) (*ntp.Response, error)

type NTPClient

type NTPClient interface {
    QueryWithOptions(srv string, opts ntp.QueryOptions) (*ntp.Response, error)
}

type NTPMonitor

NTPMonitor compares the local time with a set of trusted NTP servers.

type NTPMonitor struct {
    // contains filtered or unexported fields
}

func New

func New(configFile string) (*NTPMonitor, error)

New creates a NTPMonitor, reading the configuration from the provided path.

func NewFromConfig

func NewFromConfig(cfg *Config) (*NTPMonitor, error)

NewFromConfig creates a NTPMonitor from an instantiated configuration.

func NewFromConfigWithClient

func NewFromConfigWithClient(cfg *Config, client NTPClient) (*NTPMonitor, error)

func (*NTPMonitor) Start

func (n *NTPMonitor) Start()

Start the periodic monitor. Once started, it runs until Stop() is called,

func (*NTPMonitor) Stop

func (n *NTPMonitor) Stop()

Stop the monitoring.