Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 8e17a6f

Browse files
committed
[CDEC-439] updated & spellchecked comments
1 parent a8bc8bb commit 8e17a6f

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

networking/src/Ntp/Client.hs

+17-17
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import Ntp.Util (AddrFamily (..), Addresses, EitherOrBoth (..),
5151
import Pos.Util.Trace (traceWith)
5252

5353
data NtpStatus =
54-
-- | The difference between ntp time and local system time
54+
-- | The difference between NTP time and local system time
5555
NtpDrift NtpOffset
5656
-- | NTP client has send requests to the servers
5757
| NtpSyncPending
@@ -164,12 +164,12 @@ sendLoop cli addrs = do
164164

165165
() <- withAsync
166166
(do
167-
-- wait for reponses and update status
167+
-- wait for responses and update status
168168
_ <- timeout respTimeout waitForResponses
169169
updateStatus cli
170170
)
171171
(\a -> do
172-
-- send packets and wait untill end of poll delay
172+
-- send packets and wait until end of poll delay
173173
sock <- atomically $ readTVar $ ncSockets cli
174174
pack <- mkNtpPacket
175175
sendPacket sock pack addrs
@@ -193,7 +193,7 @@ sendLoop cli addrs = do
193193
logDebug "collected all responses"
194194

195195
-- |
196-
-- Start listening for responses on the socket `ncSockets
196+
-- Start listening for responses on the socket @'ncSockets'@
197197
startReceive :: NtpClient -> IO ()
198198
startReceive cli =
199199
atomically (readTVar $ ncSockets cli) >>= \case
@@ -206,7 +206,7 @@ startReceive cli =
206206
EBSecond (Last (WithIPv4 sock_ipv4)) ->
207207
loop IPv4 sock_ipv4
208208
where
209-
-- Receive responses from the network and update ntp client state.
209+
-- Receive responses from the network and update NTP client state.
210210
loop :: AddrFamily -> Socket.Socket -> IO ()
211211
loop addressFamily sock
212212
= handle (handleIOException addressFamily) $ forever $ do
@@ -217,7 +217,7 @@ startReceive cli =
217217
Right (_, _, packet) ->
218218
handleNtpPacket packet
219219

220-
-- Restart the @loop@ in case of errors; wait 5s before recreacting the
220+
-- Restart the @loop@ in case of errors; wait 5s before recreating the
221221
-- socket.
222222
handleIOException
223223
:: AddrFamily
@@ -238,8 +238,8 @@ startReceive cli =
238238
EBBoth _ _
239239
-> error "NtpClient: startReceive: impossible"
240240

241-
-- Compute the clock offset based on current time and record it in the ntp
242-
-- client state. A packet will be digarded if it came after
241+
-- Compute the clock offset based on current time and record it in the NTP
242+
-- client state. A packet will be disgarded if it came after
243243
-- @'ntpResponseTimeout'@.
244244
handleNtpPacket
245245
:: NtpPacket
@@ -256,10 +256,10 @@ startReceive cli =
256256
atomically $ modifyTVar' (ncState cli) ( offset : )
257257

258258
-- |
259-
-- Spawn ntp client which will send request to ntp servers every ntpPollDelay
260-
-- and will lisent for responses. The `ncStatus` will be updated every
261-
-- `ntpPollDelay` with the most recent value. It should be run in a seprate
262-
-- thread, since it will block infinitelly.
259+
-- Spawn NTP client which will send request to NTP servers every @'ntpPollDelay'@
260+
-- and will listen for responses. The @'ncStatus'@ will be updated every
261+
-- @'ntpPollDelay'@ with the most recent value. It should be run in a separate
262+
-- thread, since it will block infinitely.
263263
spawnNtpClient :: NtpClientSettings -> TVar NtpStatus -> IO ()
264264
spawnNtpClient settings ncStatus = do
265265
logInfo "starting"
@@ -281,16 +281,16 @@ spawnNtpClient settings ncStatus = do
281281
fn (Last sock) = Socket.close $ runWithAddrFamily sock
282282

283283
-- |
284-
-- Run Ntp client in a seprate thread; it returns a mutable cell which holds
285-
-- `NtpStatus`.
284+
-- Run NTP client in a separate thread; it returns a mutable cell which holds
285+
-- @'NtpStatus'@.
286286
--
287-
-- This function should be called once, it will run an ntp client in a new
288-
-- thread untill the program terminates.
287+
-- This function should be called once, it will run an NTP client in a new
288+
-- thread until the program terminates.
289289
withNtpClient :: MonadIO m => NtpClientSettings -> m (TVar NtpStatus)
290290
withNtpClient ntpSettings = do
291291
liftIO $ logInfo "withNtpClient"
292292
ncStatus <- newTVarIO NtpSyncPending
293-
-- using async so the ntp thread will be left running even if the parent
293+
-- using async so the NTP thread will be left running even if the parent
294294
-- thread finished.
295295
_ <- liftIO $ async (spawnNtpClient ntpSettings ncStatus)
296296
return ncStatus

networking/src/Ntp/Packet.hs

+9-11
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ instance Binary NtpPacket where
5151
ntpPoll <- getInt8
5252
_ <- getWord8
5353

54-
-- skip 5 `Word32` words
54+
-- skip 5 @'Word32'@ words
5555
skip 20
5656

5757
ntpOriginTime <- getTimestamp
@@ -76,9 +76,9 @@ ntpPacketSize :: Int
7676
ntpPacketSize = 48
7777

7878
-- |
79-
-- For pairs `(x, y) :: (Word32, Word32)` with `y \`mod\` 4294 == 0` it is
80-
-- be righ inverse of `realMsgToNtp`. In general it is not injective (for that
81-
-- we'd need to use `Picosecond` insteaed of `Microsecond`).
79+
-- For pairs @(x, y) :: (Word32, Word32)@ with @y \`mod\` 4294 == 0@ it is
80+
-- be right inverse of @'realMsgToNtp'@. In general it is not injective (for that
81+
-- we'd need to use @'Picosecond'@ instead of @'Microsecond'@).
8282
ntpToRealMcs :: Word32 -> Word32 -> Microsecond
8383
ntpToRealMcs sec frac =
8484
let -- microseconds
@@ -91,7 +91,7 @@ ntpToRealMcs sec frac =
9191
in fromMicroseconds $ secMicro + fracMicro
9292

9393
-- |
94-
-- It is a partial function, since `Microsecond ~ Integer`; it is well defined
94+
-- It is a partial function, since @Microsecond ~ Integer@; it is well defined
9595
-- for:
9696
-- @
9797
-- x < 2085978496 = (maxBound @Word32 * 1000000) - ntpTimestampDelta + 1`
@@ -104,7 +104,7 @@ realMcsToNtp (toMicroseconds -> mcs) =
104104
, fromIntegral $ frac * 4294)
105105

106106
-- |
107-
-- Smart constructor for @NptPacket@.
107+
-- Smart constructor for @'NtpPacket'@.
108108
mkNtpPacket :: IO NtpPacket
109109
mkNtpPacket = do
110110
let ntpParams = 0x1b
@@ -115,23 +115,21 @@ mkNtpPacket = do
115115
return NtpPacket{..}
116116

117117
-- |
118-
-- NtpOffset is the difference between ntp time and localtime
118+
-- @'NtpOffset'@ is the difference between NTP time and local time.
119119
newtype NtpOffset = NtpOffset { getNtpOffset :: Microsecond }
120120
deriving (Enum, Eq, Integral, Num, Ord, Real, Show, TimeUnit)
121121

122-
-- |
123-
-- TODO: add a test
124122
clockOffsetPure :: NtpPacket -> Microsecond -> NtpOffset
125123
clockOffsetPure NtpPacket{..} localTime = NtpOffset
126124
$ (ntpReceivedTime - ntpOriginTime + ntpTransmitTime - localTime)
127125
`div` 2
128126

129127
-- |
130-
-- Compute clock offset unless the ntp packet was requested more than the given
128+
-- Compute clock offset unless the NTP packet was requested more than the given
131129
-- timeout.
132130
clockOffset
133131
:: Microsecond
134-
-- ^ @'ntpResponseTimeout'@, ignore reponses which come after it passed.
132+
-- ^ @'ntpResponseTimeout'@, ignore responses which come after it passed.
135133
-> NtpPacket
136134
-> IO (Maybe NtpOffset)
137135
clockOffset respTimeout packet = do

networking/src/Ntp/Util.hs

+4-5
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ resolveHost :: String -> IO (Maybe Addresses)
176176
resolveHost host = do
177177
let hints = Socket.defaultHints
178178
{ addrSocketType = Datagram
179-
, addrFlags = [AI_ADDRCONFIG] -- since we use AF_INET family
179+
, addrFlags = [AI_ADDRCONFIG] -- since we use @AF_INET@ family
180180
}
181-
-- TBD why catch here? Why not let 'resolveHost' throw the exception?
181+
-- TBD why catch here? Why not let @'resolveHost'@ throw the exception?
182182
addrInfos <- Socket.getAddrInfo (Just hints) (Just host) Nothing
183183
`catch` (\(_ :: IOException) -> return [])
184184

@@ -219,7 +219,7 @@ replacePort _ sockAddr = sockAddr
219219

220220
createAndBindSock
221221
:: AddrFamily
222-
-- ^ indicates which socket family to create, either AF_INET6 or AF_INET
222+
-- ^ indicates which socket family to create, either @AF_INET6@ or @AF_INET@
223223
-> [AddrInfo]
224224
-- ^ list of local addresses
225225
-> IO (Maybe Sockets)
@@ -284,7 +284,7 @@ sendTo sock bs addr = case fmap (foldEitherOrBoth . bimap fn fn) $ pairEitherOrB
284284
handleIOException addressFamily e = throw (SendToIOException addressFamily e)
285285

286286
-- |
287-
-- Low level primitive which sends a request to a single ntp server.
287+
-- Low level primitive which sends a request to a single NTP server.
288288
sendPacket
289289
:: Sockets
290290
-> NtpPacket
@@ -299,7 +299,6 @@ sendPacket sock packet addrs = do
299299
)
300300
addrs
301301
where
302-
-- just log; socket closure is handled by receiver
303302
handleSendToException :: Addresses -> SendToException -> IO ()
304303
handleSendToException addr e@NoMatchingSocket =
305304
logError $ sformat

0 commit comments

Comments
 (0)