@@ -108,6 +108,7 @@ import System.IO qualified as IO
108108import System.Random (initStdGen )
109109import Text.Read (readMaybe )
110110
111+ import Cardano.Network.Diffusion (readIPAndPort )
111112import Cardano.Network.Diffusion.Configuration (defaultChainSyncIdleTimeout )
112113import Cardano.Network.NodeToClient qualified as NodeToClient
113114import Cardano.Network.NodeToClient.Version
@@ -147,7 +148,7 @@ data PingMode =
147148 -- ^ query handshake parameters
148149 deriving (Eq , Show )
149150
150- type Port = Word
151+ type Port = Socket. PortNumber
151152
152153-- | There are three stages for resolving addresses.
153154--
@@ -335,43 +336,13 @@ argParser =
335336 addrParser :: Parser (Address (Unresolved SRVOrFilePathUnresolved ))
336337 addrParser =
337338 argument
338- ( uncurry IP <$> readIPv4AndPort
339- <|> uncurry IP <$> readIPv6AndPort
339+ ( uncurry IP <$> readIPAndPort
340340 <|> readDomainNameOrFilePath
341341 )
342342 ( help " List of IP/DNS/SRV address and ports or UNIX socket paths, e.g. 127.0.0.1:3001 [::1]:3001 example.org:3001."
343343 <> metavar " ADDRS"
344344 )
345345 where
346- -- note: `Read` instances for `IP`, `IPv4`, `IPv6` expect no trailing
347- -- characters after the address, thus we need to find the split position
348- -- first.
349-
350- -- parse IPv4 address and port in a form `127.0.0.1:3001`
351- readIPv4AndPort :: ReadM (IP , Port )
352- readIPv4AndPort =
353- eitherReader $ \ s -> do
354- case splitWith ' :' s of
355- Nothing -> Left s
356- Just (addrStr, portStr) ->
357- maybe (Left s) Right $
358- (,) <$> readMaybe addrStr
359- <*> readMaybe portStr
360-
361- -- parse IPv6 address and port in a form `[::1]:3001` or a UNIX file path
362- readIPv6AndPort :: ReadM (IP , Port )
363- readIPv6AndPort =
364- eitherReader $ \ s ->
365- case s of
366- (' [' : s') ->
367- case splitWith ' ]' s' of
368- Just (addrStr, ' :' : portStr) ->
369- maybe (Left s) Right $
370- (,) <$> readMaybe addrStr
371- <*> readMaybe portStr
372- _ -> Left s
373- _ -> Left s
374-
375346 readDomainNameOrFilePath :: ReadM (Address (Unresolved SRVOrFilePathUnresolved ))
376347 readDomainNameOrFilePath = eitherReader $ Right . mkAddress
377348
@@ -418,7 +389,7 @@ instance Exception AddressResolutionError where
418389-- | Log messages to stderr.
419390--
420391data PingWarning = AddressResolutionError AddressResolutionError
421- | DNSResolution DNS. Domain [IP ] Word
392+ | DNSResolution DNS. Domain [IP ] Port
422393 | Error SomeException
423394 | ConnectError SockAddr SomeException
424395
0 commit comments