timesource

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DefaultMaxAllowedFailures defines how many failures will be tolerated.
	DefaultMaxAllowedFailures = 1

	// FastNTPSyncPeriod period between ntp synchronizations before the first
	// successful connection.
	FastNTPSyncPeriod = 2 * time.Minute

	// SlowNTPSyncPeriod period between ntp synchronizations after the first
	// successful connection.
	SlowNTPSyncPeriod = 1 * time.Hour

	// DefaultRPCTimeout defines write deadline for single ntp server request.
	DefaultRPCTimeout = 2 * time.Second
)

Variables

View Source
var DefaultServers = []string{
	"0.pool.ntp.org",
	"1.pool.ntp.org",
	"2.pool.ntp.org",
	"3.pool.ntp.org",
}

DefaultServers will be resolved to the closest available, and with high probability resolved to the different IPs

Functions

This section is empty.

Types

type NTPTimeSource

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

NTPTimeSource provides source of time that tries to be resistant to time skews. It does so by periodically querying time offset from ntp servers.

func NewNTPTimesource

func NewNTPTimesource(ntpServers []string, log *zap.Logger) *NTPTimeSource

NewNTPTimesource creates a timesource that uses NTP

func (*NTPTimeSource) Now

func (s *NTPTimeSource) Now() time.Time

Now returns time adjusted by latest known offset

func (*NTPTimeSource) Start

func (s *NTPTimeSource) Start(ctx context.Context) error

Start runs a goroutine that updates local offset every updatePeriod.

func (*NTPTimeSource) Stop

func (s *NTPTimeSource) Stop()

Stop goroutine that updates time source.

type Timesource

type Timesource interface {
	Now() time.Time
	Start(ctx context.Context) error
	Stop()
}

type WallClockTimeSource

type WallClockTimeSource struct {
}

func NewDefaultClock

func NewDefaultClock() *WallClockTimeSource

func (*WallClockTimeSource) Now

func (t *WallClockTimeSource) Now() time.Time

func (*WallClockTimeSource) Start

func (t *WallClockTimeSource) Start(ctx context.Context) error

func (*WallClockTimeSource) Stop

func (t *WallClockTimeSource) Stop()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL