Skip to content

AndrewLester/NTPal

Repository files navigation

NTPal (Network Time Pal) — A Network Time Protocol System

NTPal is an in-development, incomplete, and rough around the edges implementation of an NTP client/server process.

NTPal Association Terminal UI Table

Code Credits

The code for NTPal is very similar to pseudocode provided in the NTPv4 RFC, which is nicely documented and made for a good rewriting experience. Certain changes were made based on more recent additions to projects such as ntpd, chrony, and others. Additionally, some care was taken to map the program's requirements into better-fit Golang structures, but there's room for improvement (especially regarding race conditions).

Usage

Installation

The NTPal binary (ntpal) can be downloaded for MacOS or Linux via the most recent GitHub release.

Once the daemon (ntpald) is started, running the binary again will open a terminal UI to see the program's operating status.

time.andrewlester.net is the canonical server running NTPal for anyone to synchronize with. It does not support symmetric synchronization.

The server is hosted on fly.io with a configuration outlined in the fly.toml. Deployment is as simple as running fly deploy.

Configuration

NTPal uses a configuration format similar to the standard ntpd config, but with far fewer options. The available commands, with arguments defined in the ntpd config docs, are as follows:

  • server <address> [burst] [iburst] [version _version_] [prefer] [minpoll _minpoll_] [maxpoll _maxpoll_]
  • driftfile <path>

Some environment variables are also available to configure the application's runtime and logging:

  • SYMMETRIC: Set to "1" to allow symmetric active servers to connect.
  • INFO: Set to "1" to print periodic system information logs.
  • DEBUG: Set to "1" to print timeseries clock statistics meant for graphing.

NTPal — Query

NTPal supports a simpler "query" flag to simply obtain your device's time offset from an NTP server. Accessible via --query or -q, 5 messages are sent in an attempt to obtain the best measurement possible. This command functions almost identically to the sntp command shipped with OSX, though NTPal has far less functionality.

Development

Run

sudo -E go run github.com/AndrewLester/ntpal/cmd/ntpal --config ntp.conf --drift ntp.drift

Debug Log Transform

CTRL+F

\*\*\*\*\*ADJUSTING:\nTIME: (\d+?) SYS OFFSET: (.*?) CLOCK OFFSET: (.*?)\nFREQ:  (.*?) OFFSET \(dtemp\): (.*?)\n(Adjtime:  .*? .*?\n)?

$1,$2,$3,$4,$5\n