ntp-client
Safe HaskellNone
LanguageHaskell2010

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.

Instances

Instances details
Show NtpStatus Source # 
Instance details

Defined in Network.NTP.Client.Query

Eq NtpStatus Source # 
Instance details

Defined in Network.NTP.Client.Query

Low level interface

Running an ntp query

ntpQuery :: IOManager -> Tracer IO NtpTrace -> NtpSettings -> IO CompletedNtpStatus 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.

We produce a CompletedNtpStatus rather than an NtpStatus because we would never construct an NtpStatus using NtpSyncPending, so callers can avoid catching and killing that case.

It may throw an IOException:

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

Logging interface

data IPVersion Source #

A tag which describes which version of the ip protocol was used.

Constructors

IPv4 
IPv6 

Instances

Instances details
Show IPVersion Source # 
Instance details

Defined in Network.NTP.Client.Query

Eq IPVersion Source # 
Instance details

Defined in Network.NTP.Client.Query

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

Methods

fold :: Monoid m => ResultOrFailure m -> m #

foldMap :: Monoid m => (a -> m) -> ResultOrFailure a -> m #

foldMap' :: Monoid m => (a -> m) -> ResultOrFailure a -> m #

foldr :: (a -> b -> b) -> b -> ResultOrFailure a -> b #

foldr' :: (a -> b -> b) -> b -> ResultOrFailure a -> b #

foldl :: (b -> a -> b) -> b -> ResultOrFailure a -> b #

foldl' :: (b -> a -> b) -> b -> ResultOrFailure a -> b #

foldr1 :: (a -> a -> a) -> ResultOrFailure a -> a #

foldl1 :: (a -> a -> a) -> ResultOrFailure a -> a #

toList :: ResultOrFailure a -> [a] #

null :: ResultOrFailure a -> Bool #

length :: ResultOrFailure a -> Int #

elem :: Eq a => a -> ResultOrFailure a -> Bool #

maximum :: Ord a => ResultOrFailure a -> a #

minimum :: Ord a => ResultOrFailure a -> a #

sum :: Num a => ResultOrFailure a -> a #

product :: Num a => ResultOrFailure a -> a #

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

Defined in Network.NTP.Client.Query

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

Defined in Network.NTP.Client.Query