ntp-client-0.0.1
Safe Haskell None
Language Haskell2010

Network.NTP.Client

Synopsis

The API for starting an ntp client-thread.

withNtpClient :: IOManager -> Tracer IO NtpTrace -> NtpSettings -> ( NtpClient -> IO a) -> IO a Source #

Setup a NtpClient and run an application that uses provided NtpClient . The NtpClient is terminated when the callback returns. The application can waitCatch on ntpThread .

data NtpSettings Source #

Settings of the ntp client.

Constructors

NtpSettings

Fields

  • ntpServers :: [ String ]

    List of server addresses. At least three servers are needed.

  • ntpRequiredNumberOfResults :: Int

    Minimum number of results to compute the offset, this should be less or equal to the length of ntpServers (we send a single tnp packet / query to a each server, if the dns name resolves to many addresses we pick the first one).

  • ntpResponseTimeout :: Microsecond

    Timeout for receiving a response from an ntp server.

  • ntpPollDelay :: Microsecond

    How long to wait between two rounds of requests. This should be set to something of an order of one hour, ntp servers should not be abused.

data NtpClient Source #

NtpClient which recieves updates of the wall clcok drift every ntpPollDelay . It also allows to force engaging in ntp protocol.

Constructors

NtpClient

Fields

data NtpStatus Source #

The Ntp client state: either cached results is availbale, or the ntp client is engaged in ntp-protocol or there was a failure: e.g. connection lost, or dns lookups did not return at least ntpRequiredNumberOfResults addresses.

Constructors

NtpDrift !NtpOffset

The difference between NTP time and local system time

NtpSyncPending

NTP client has send requests to the servers

NtpSyncUnavailable

NTP is not available: the client has not received any respond within ntpResponseTimeout from at least ntpRequiredNumberOfResults servers.

Low level interface

Running an ntp query

ntpQuery :: IOManager -> Tracer IO NtpTrace -> NtpSettings -> IO NtpStatus Source #

Perform a series of NTP queries: one for each dns name. Resolve each dns name, get local addresses: both IPv4 and IPv6 and engage in ntp protocol towards one ip address per address family per dns name, but only for address families for which we have a local address. This is to avoid trying to send IPv4/6 requests if IPv4/6 gateway is not configured.

It may throw an IOException :

  • if neither IPv4 nor IPv6 address is configured
  • if network I/O errors

Logging interface

data ResultOrFailure a Source #

Result of two threads running concurrently.

Constructors

BothSucceeded !a

both threads suceeded

SuccessAndFailure !a ! IPVersion ! IOException

one of the threads errors. IPVersion indicates which one.

BothFailed ! IOException ! IOException

both threads failed

Instances

Instances details
Foldable ResultOrFailure Source #
Instance details

Defined in Network.NTP.Client.Query

Eq a => Eq ( ResultOrFailure a) Source #
Instance details

Defined in Network.NTP.Client.Query

Show a => Show ( ResultOrFailure a) Source #
Instance details

Defined in Network.NTP.Client.Query