Documentation ¶
Overview ¶
Package ntp provides a time sync client via SNTP protocol.
Index ¶
Constants ¶
View Source
const ( // MinAllowablePoll is the minimum time allowed for a client to query a time server. MinAllowablePoll = 32 * time.Second // MaxAllowablePoll is the maximum allowed interval for querying a time server. MaxAllowablePoll = 2048 * time.Second // RetryPoll is the interval between retries if the error is not Kiss-o-Death. RetryPoll = time.Second // AdjustTimeLimit is a maximum time drift to compensate via adjtimex(). // // Deltas smaller than AdjustTimeLimit are gradually adjusted (slewed) to approach the network time. // Deltas larger than AdjustTimeLimit are set by letting the system time jump. AdjustTimeLimit = 400 * time.Millisecond // EpochLimit is a minimum time difference to signal that change as epoch change. EpochLimit = 15 * time.Minute // ExpectedAccuracy is the expected time sync accuracy, used to adjust poll interval. ExpectedAccuracy = 200 * time.Millisecond )
Variables ¶
View Source
var ( RTCClock *rtc.RTC RTCClockInitialize sync.Once )
Global instance of RTC clock because `rtc` doesn't support closing.
Functions ¶
This section is empty.
Types ¶
type AdjustTimeFunc ¶
AdjustTimeFunc provides a function to adjust time.
type CurrentTimeFunc ¶
CurrentTimeFunc provides a function which returns current time.
type SetTimeFunc ¶
SetTimeFunc provides a function to set system time.
type Syncer ¶
type Syncer struct {
MinPoll, MaxPoll, RetryPoll time.Duration
// these functions are overridden in tests for mocking support
CurrentTime CurrentTimeFunc
NTPQuery QueryFunc
AdjustTime AdjustTimeFunc
// contains filtered or unexported fields
}
Syncer performs time sync via NTP on schedule.
func (*Syncer) EpochChange ¶
func (syncer *Syncer) EpochChange() <-chan struct{}
EpochChange returns a channel which receives a value each time jumps more than EpochLimit.
func (*Syncer) Run ¶
Run runs the sync process.
Run is usually run in a goroutine. When context is canceled, sync process aborts.
func (*Syncer) SetTimeServers ¶
SetTimeServers sets the list of time servers to use.
Click to show internal directories.
Click to hide internal directories.