Skip to content

Commit f5ef9bf

Browse files
committed
Update comments and documentation
1 parent 1cf04cc commit f5ef9bf

File tree

5 files changed

+35
-20
lines changed

5 files changed

+35
-20
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2015-2023 Brett Vickers. All rights reserved.
1+
Copyright © 2015-2023 Brett Vickers. All rights reserved.
22

33
Redistribution and use in source and binary forms, with or without
44
modification, are permitted provided that the following conditions

README.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ntp
44
===
55

66
The ntp package is an implementation of a Simple NTP (SNTP) client based on
7-
[RFC5905](https://tools.ietf.org/html/rfc5905). It allows you to connect to
7+
[RFC 5905](https://tools.ietf.org/html/rfc5905). It allows you to connect to
88
a remote NTP server and request information about the current time.
99

1010

@@ -17,9 +17,9 @@ time, err := ntp.Time("0.beevik-ntp.pool.ntp.org")
1717
```
1818

1919

20-
## Querying time metadata
20+
## Querying time synchronization data
2121

22-
To obtain the current time as well as some additional metadata about the time,
22+
To obtain the current time as well as some additional synchronization data,
2323
use the [`Query`](https://godoc.org/github.com/beevik/ntp#Query) function:
2424
```go
2525
response, err := ntp.Query("0.beevik-ntp.pool.ntp.org")
@@ -28,11 +28,11 @@ time := time.Now().Add(response.ClockOffset)
2828

2929
The [`Response`](https://godoc.org/github.com/beevik/ntp#Response) structure
3030
returned by `Query` includes the following information:
31-
* `Time`: The time the server transmitted its response, according to its own
32-
clock.
3331
* `ClockOffset`: The estimated offset of the local system clock relative to
3432
the server's clock. For a more accurate time reading, you may add this
3533
offset to any subsequent system clock reading.
34+
* `Time`: The time the server transmitted its response, according to its own
35+
clock.
3636
* `RTT`: An estimate of the round-trip-time delay between the client and the
3737
server.
3838
* `Precision`: The precision of the server's clock reading.
@@ -57,8 +57,8 @@ returned by `Query` includes the following information:
5757
server.
5858

5959
The `Response` structure's [`Validate`](https://godoc.org/github.com/beevik/ntp#Response.Validate)
60-
method performs additional sanity checks to determine whether the response is
61-
suitable for time synchronization purposes.
60+
function performs additional sanity checks to determine whether the response
61+
is suitable for time synchronization purposes.
6262
```go
6363
err := response.Validate()
6464
if err == nil {
@@ -80,16 +80,16 @@ include:
8080
* `Timeout`: How long to wait before giving up on a response from the NTP
8181
server.
8282
* `Version`: Which version of the NTP protocol to use (2, 3 or 4).
83-
* `LocalAddress`: The local network address to use when connecting to the
84-
server.
85-
* `Port`: The remote NTP server port to contact.
8683
* `TTL`: The maximum number of IP hops before the request packet is discarded.
8784
* `Auth`: The symmetric authentication key and algorithm used by the server to
8885
authenticate the query. The same information is used by the client to
8986
authenticate the server's response.
87+
* `Extensions`: Extensions may be added to modify NTP queries before they are
88+
transmitted and to process NTP responses after they arrive.
9089
* `Dial`: A custom network connection "dialer" function used to override the
9190
default UDP dialer function.
9291

92+
9393
## Using the NTP pool
9494

9595
The NTP pool is a shared resource provided by the [NTP Pool
@@ -98,3 +98,12 @@ over the world. To prevent it from becoming overloaded, please avoid querying
9898
the standard `pool.ntp.org` zone names in your applications. Instead, consider
9999
requesting your own [vendor zone](http://www.pool.ntp.org/en/vendors.html) or
100100
[joining the pool](http://www.pool.ntp.org/join.html).
101+
102+
103+
## Network Time Security (NTS)
104+
105+
Network Time Security (NTS) is a recent enhancement of NTP, designed to add
106+
better authentication and message integrity to the protocol. It is defined by
107+
[RFC 8915](https://tools.ietf.org/html/rfc8915). If you wish to use NTS, see
108+
the [nts package](https://github.com/beevik/nts). (The nts package is
109+
implemented as an extension to this package.)

auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func calcDigest_SHA512(payload, key []byte) []byte {
7272
}
7373

7474
func calcCMAC_AES(payload, key []byte) []byte {
75-
// calculate the CMAC according to the algorithm defined in RFC4493. See
75+
// calculate the CMAC according to the algorithm defined in RFC 4493. See
7676
// https://tools.ietf.org/html/rfc4493 for details.
7777
c, err := aes.NewCipher(key)
7878
if err != nil {

ntp.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Copyright 2015-2023 Brett Vickers.
1+
// Copyright © 2015-2023 Brett Vickers.
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

55
// Package ntp provides an implementation of a Simple NTP (SNTP) client
66
// capable of querying the current time from a remote NTP server. See
7-
// RFC5905 (https://tools.ietf.org/html/rfc5905) for more details.
7+
// RFC 5905 (https://tools.ietf.org/html/rfc5905) for more details.
88
//
99
// This approach grew out of a go-nuts post by Michael Hofmann:
1010
// https://groups.google.com/forum/?fromgroups#!topic/golang-nuts/FlcdMU5fkLQ
@@ -219,7 +219,7 @@ type QueryOptions struct {
219219
TTL int
220220

221221
// Auth contains the settings used to configure NTP symmetric key
222-
// authentication. See RFC5905 for further details.
222+
// authentication. See RFC 5905 for further details.
223223
Auth AuthOptions
224224

225225
// Extensions may be added to modify NTP queries before they are
@@ -244,7 +244,8 @@ type QueryOptions struct {
244244
// and some of which is calculated by this client.
245245
type Response struct {
246246
// Time is the transmit time reported by the server just before it
247-
// responded to the client's NTP query.
247+
// responded to the client's NTP query. You should not use this value
248+
// for time synchronization purposes. Use the ClockOffset instead.
248249
Time time.Time
249250

250251
// ClockOffset is the estimated offset of the local system clock relative
@@ -266,8 +267,13 @@ type Response struct {
266267
// issues too many requests to the server in a short period of time.
267268
Stratum uint8
268269

269-
// ReferenceID is a 32-bit identifier identifying the server or
270-
// reference clock.
270+
// ReferenceID is a 32-bit identifier identifying the server or reference
271+
// clock. For stratum 1 servers, this is typically a meaningful
272+
// zero-padded ASCII-encoded string assigned to the clock. For stratum 2+
273+
// servers, this is a reference identifier for the server and is either
274+
// the server's IPv4 address or a hash of its IPv6 address. For
275+
// kiss-of-death responses (stratum=0), this field contains the
276+
// ASCII-encoded "kiss code".
271277
ReferenceID uint32
272278

273279
// ReferenceTime is the time when the server's system clock was last
@@ -299,7 +305,7 @@ type Response struct {
299305
MinError time.Duration
300306

301307
// KissCode is a 4-character string describing the reason for a
302-
// "kiss of death" response (stratum = 0). For a list of standard kiss
308+
// "kiss of death" response (stratum=0). For a list of standard kiss
303309
// codes, see https://tools.ietf.org/html/rfc5905#section-7.4.
304310
KissCode string
305311

ntp_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015-2023 Brett Vickers.
1+
// Copyright © 2015-2023 Brett Vickers.
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

0 commit comments

Comments
 (0)