timesync

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package timesync computes the clock offset and round-trip delay between two hosts from the four-timestamp NTP exchange (DESIGN.md §10, ADR-0010). It is the math seam for one-way-delay measurement: the controller stamps t1/t4 and the agent stamps t2/t3, and these functions turn the four into an offset and delay. The package is pure — no I/O, no clock — so it is trivially testable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delay

func Delay(t1, t2, t3, t4 int64) int64

Delay returns the round-trip network delay in nanoseconds (the total time on the wire, excluding the remote's processing time t3-t2) from the four NTP timestamps described in Offset.

func Offset

func Offset(t1, t2, t3, t4 int64) int64

Offset returns the estimated offset of the remote clock relative to the local clock, in nanoseconds, from the four NTP timestamps:

t1 — local send time
t2 — remote receive time
t3 — remote send time
t4 — local receive time

A positive offset means the remote clock is ahead of the local clock. The estimate assumes the network delay is symmetric.

Types

type Sample

type Sample struct {
	// Offset is the remote clock's offset relative to the local clock; positive
	// means the remote is ahead.
	Offset time.Duration
	// Delay is the round-trip network delay.
	Delay time.Duration
}

Sample is the result of one time-sync exchange.

func NewSample

func NewSample(t1, t2, t3, t4 int64) Sample

NewSample computes a Sample from the four NTP timestamps (see Offset).

Jump to

Keyboard shortcuts

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