Documentation
¶
Overview ¶
package ntp implements the NTP protocol as described in RFC 5905.
Index ¶
- Constants
- func BaseTime() time.Time
- func CalculateSystemPrecision(nowNano func() int64, iters []int64) int8
- type Client
- func (c *Client) ConnectionID() *uint64
- func (c *Client) Demux(carrierData []byte, frameOffset int) error
- func (c *Client) Encapsulate(carrierData []byte, offsetToIP, offsetToFrame int) (int, error)
- func (c *Client) IsDone() bool
- func (c *Client) LocalPort() uint16
- func (c *Client) Now() time.Time
- func (c *Client) Offset() time.Duration
- func (c *Client) OffsetUnsynced() time.Duration
- func (c *Client) Protocol() uint64
- func (c *Client) Reset(sysprec int8, now func() time.Time)
- func (c *Client) RoundTripDelay() time.Duration
- func (c *Client) ServerStratum() Stratum
- type Date
- type Frame
- func (frm Frame) ClearHeader()
- func (frm Frame) Flags() (mode Mode, version uint8, lp LeapIndicator)
- func (frm Frame) OriginTime() Timestamp
- func (frm Frame) Poll() int8
- func (frm Frame) Precision() int8
- func (frm Frame) ReceiveTime() Timestamp
- func (frm Frame) ReferenceID() *[4]byte
- func (frm Frame) ReferenceTime() Timestamp
- func (frm Frame) RootDelay() Short
- func (frm Frame) RootDispersion() Short
- func (frm Frame) SetFlags(mode Mode, version uint8, lp LeapIndicator)
- func (frm Frame) SetOriginTime(ot Timestamp)
- func (frm Frame) SetPoll(Poll int8)
- func (frm Frame) SetPrecision(Precision int8)
- func (frm Frame) SetReceiveTime(rt Timestamp)
- func (frm Frame) SetReferenceTime(rt Timestamp)
- func (frm Frame) SetRootDelay(rd Short)
- func (frm Frame) SetRootDispersion(rd Short)
- func (frm Frame) SetStratum(stratum Stratum)
- func (frm Frame) SetTransmitTime(rt Timestamp)
- func (frm Frame) Stratum() Stratum
- func (frm Frame) TransmitTime() Timestamp
- type LeapIndicator
- type Mode
- type Short
- type Stratum
- type Timestamp
Constants ¶
const ( SizeHeader = 48 ClientPort = 1023 // Typical Client port number. ServerPort = 123 // NTP server port number Version4 = 4 // Current NTP Version Number MinPoll = 4 // Minimum poll exponent (16s) MaxPoll = 17 // Maximum poll exponent (~36h) MaxDisp = 16 // Maximum dispersion (16s) MaxDist = 1 // Distance threshold (1s) MaxStratum = 16 // Maximum stratum MinDispDiv = 200 // Minimum dispersion divisor 1/(200) == 0.005 )
NTP Global Parameters.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) ConnectionID ¶
func (*Client) Encapsulate ¶
func (*Client) Offset ¶
Offset is a helper method to determine the difference between the Client's clock and the server's clock. Use Client.Now to calculate the server's time.
func (*Client) OffsetUnsynced ¶
OffsetUnsynced returns the absolute time offset difference between client and server clock as calculated by the clock synchonization algorithm. It is unsynchonized- the result of OffsetUnsynced will not change with time.
func (*Client) RoundTripDelay ¶
func (*Client) ServerStratum ¶
ServerStratum returns the stratum of the server client synchronized with.
type Date ¶
type Date struct {
// contains filtered or unexported fields
}
The 128-bit date format is used where sufficient storage and word size are available. It includes a 64-bit signed seconds field spanning 584 billion years and a 64-bit fraction field resolving .05 attosecond (i.e., 0.5e-18).
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame encapsulates the raw data of an NTP packet and provides methods for manipulating, validating and retrieving fields and payload data. See RFC5905.
func (Frame) ClearHeader ¶
func (frm Frame) ClearHeader()
ClearHeader zeros out the header contents.
func (Frame) OriginTime ¶
OriginTime is time at the client when the request departed for the server, in NTP timestamp format.
func (Frame) Poll ¶
Poll is 8-bit signed integer representing the maximum interval between successive messages, in log2 seconds. Suggested default limits for minimum and maximum poll intervals are 6 and 10, respectively.
func (Frame) Precision ¶
Precision is 8-bit signed integer representing the precision of the system clock, in log2 seconds. For instance, a value of -18 corresponds to a precision of about one microsecond. The precision can be determined when the service first starts up as the minimum time of several iterations to read the system clock.
func (Frame) ReceiveTime ¶
ReceiveTime time at the server when the request arrived from the client, in NTP timestamp format.
func (Frame) ReferenceID ¶
32-bit code identifying the particular server or reference clock. The interpretation depends on the value in the stratum field. For packet stratum 0 (unspecified or invalid), this is a four-character ASCII [RFC1345] string, called the "kiss code", used for debugging and monitoring purposes. For stratum 1 (reference clock), this is a four-octet, left-justified, zero-padded ASCII string assigned to the reference clock. The authoritative list of Reference Identifiers is maintained by IANA; however, any string beginning with the ASCII character "X" is reserved for unregistered experimentation and development.
func (Frame) ReferenceTime ¶
ReferenceTime is when the system clock was last set or corrected, in NTP timestamp format.
func (Frame) RootDispersion ¶
Total dispersion to the reference clock, in NTP short format.
func (Frame) SetOriginTime ¶
func (Frame) SetPrecision ¶
func (Frame) SetReceiveTime ¶
func (Frame) SetReferenceTime ¶
func (Frame) SetRootDelay ¶
func (Frame) SetRootDispersion ¶
func (Frame) SetStratum ¶
func (Frame) SetTransmitTime ¶
func (Frame) TransmitTime ¶
TransmitTime at the server when the response left for the client, in NTP timestamp format.
type LeapIndicator ¶
type LeapIndicator uint8
LeapIndicator represents the leap second indicator. It indicates whether there is no warning, an extra second (61 seconds in the last minute), or a missing second (59 seconds in the last minute).
const ( LeapNoWarning LeapIndicator = iota // no warning LeapLastMinute61 // last minute 61 LeapLastMinute59 // last minute 59 )
type Mode ¶
type Mode uint8
Mode represents the mode of the NTP message. It can be undefined, symmetric active, symmetric passive, client, server, broadcast, NTP control message, or private use.
const ( ModeSymmetricActive Mode // symmetric active ModeSymmetricPassive // symmetric passive ModeClient // client ModeServer // server ModeBroadcast // broadcast ModeNTPControlMessage // control message ModePrivateUse // private use )
type Stratum ¶
type Stratum uint8
Stratum represents the stratum level of the NTP server.
const ( // If the Stratum field is 0, which implies unspecified or invalid, the // Reference Identifier field can be used to convey messages useful for // status reporting and access control. These are called Kiss-o'-Death // (KoD) packets and the ASCII messages they convey are called kiss codes. StratumUnspecified Stratum = 0 // unspecified StratumPrimary Stratum = 1 // primary StratumUnsync Stratum = 16 // unsynchronized )
func (Stratum) IsSecondary ¶
type Timestamp ¶
type Timestamp struct {
// contains filtered or unexported fields
}
Timestamp format is used in packet headers and other places with limited word size. It includes a 32-bit unsigned seconds field spanning 136 years and a 32-bit fraction field resolving 232 picoseconds. The 32-bit short format is used in delay and dispersion header fields where the full resolution and range of the other formats are not justified. It includes a 16-bit unsigned seconds field and a 16-bit fraction field.