clock

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package clock measures how far this machine's clock is from UTC.

ETSI EN 319 401 §7.10 asks that the clock be synchronised with UTC and that the synchronisation be recorded. Recording it is the part that concerns this repository: an audit trail whose timestamps nobody ever checked is one whose ordering an auditor has to take on faith, and "recorded" means there is an event saying it was checked and by how much it was out.

What this does not do is set the clock. That belongs to whatever runs the machine, and a component that both sets the time and records the times of things would be marking its own paper.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reading

type Reading struct {
	// Source is the reference that answered.
	Source string
	// Offset is the correction this clock needs to match the reference: the
	// reference's time minus this clock's. Positive means this clock is behind
	// and should move forward. That is the sign RFC 5905 §8 gives it, and the
	// sign matters more than most: a recorded offset whose direction a reader
	// has to guess says nothing about whether events were stamped early or late.
	Offset time.Duration
	// Delay is the round trip less the time the server held the request. Of
	// several readings the one with the shortest round trip is the most
	// trustworthy, because the offset's error is bounded by half the delay.
	Delay time.Duration
	// Stratum is how far the reference is from a reference clock.
	Stratum uint8
}

Reading is one comparison against one reference.

func Best

func Best(ctx context.Context, servers []string, timeout time.Duration) (Reading, []error, error)

Best asks every server and returns the reading with the shortest round trip, because the error in an offset is bounded by half the delay that carried it.

A server that does not answer is not a failure: the point of naming several is that one may be unreachable. All of them failing is.

func Query

func Query(ctx context.Context, server string, timeout time.Duration) (Reading, error)

Query asks one server for the time and returns what it says about this clock.

It is SNTP: one request, one reply, the four timestamps of RFC 5905 §8. That is the whole of what is needed to say how far out a clock is, and a component that is not disciplining a clock needs no more.

Jump to

Keyboard shortcuts

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