Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
For top level release notes, leave all the headers commented out.
-->

### Breaking

- Adapted to `ouroboros-network` changes (`addrFamily` change in `Snocket` API).

<!--
### Non-Breaking

- A bullet item for the Non-Breaking category.

-->
<!--
### Patch

- A bullet item for the Patch category.

-->
2 changes: 2 additions & 0 deletions cardano-diffusion/lib/Cardano/Network/Diffusion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
module Cardano.Network.Diffusion
( module Cardano.Network.Diffusion.Types
, run
-- * Utils
, Diffusion.readIPAndPort
) where

import Control.DeepSeq (NFData)
Expand Down
37 changes: 4 additions & 33 deletions cardano-diffusion/ping/Cardano/Network/Ping.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ import System.IO qualified as IO
import System.Random (initStdGen)
import Text.Read (readMaybe)

import Cardano.Network.Diffusion (readIPAndPort)
import Cardano.Network.Diffusion.Configuration (defaultChainSyncIdleTimeout)
import Cardano.Network.NodeToClient qualified as NodeToClient
import Cardano.Network.NodeToClient.Version
Expand Down Expand Up @@ -149,7 +150,7 @@ data PingMode =
-- ^ query handshake parameters
deriving (Eq, Show)

type Port = Word
type Port = Socket.PortNumber

-- | There are three stages for resolving addresses.
--
Expand Down Expand Up @@ -337,43 +338,13 @@ argParser =
addrParser :: Parser (Address (Unresolved SRVOrFilePathUnresolved))
addrParser =
argument
( uncurry IP <$> readIPv4AndPort
<|> uncurry IP <$> readIPv6AndPort
( uncurry IP <$> readIPAndPort
<|> readDomainNameOrFilePath
)
( 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."
<> metavar "ADDRS"
)
where
-- note: `Read` instances for `IP`, `IPv4`, `IPv6` expect no trailing
-- characters after the address, thus we need to find the split position
-- first.

-- parse IPv4 address and port in a form `127.0.0.1:3001`
readIPv4AndPort :: ReadM (IP, Port)
readIPv4AndPort =
eitherReader $ \s -> do
case splitWith ':' s of
Nothing -> Left s
Just (addrStr, portStr) ->
maybe (Left s) Right $
(,) <$> readMaybe addrStr
<*> readMaybe portStr

-- parse IPv6 address and port in a form `[::1]:3001` or a UNIX file path
readIPv6AndPort :: ReadM (IP, Port)
readIPv6AndPort =
eitherReader $ \s ->
case s of
('[':s') ->
case splitWith ']' s' of
Just (addrStr, ':' : portStr) ->
maybe (Left s) Right $
(,) <$> readMaybe addrStr
<*> readMaybe portStr
_ -> Left s
_ -> Left s

readDomainNameOrFilePath :: ReadM (Address (Unresolved SRVOrFilePathUnresolved))
readDomainNameOrFilePath = eitherReader $ Right . mkAddress

Expand Down Expand Up @@ -420,7 +391,7 @@ instance Exception AddressResolutionError where
-- | Log messages to stderr.
--
data PingWarning = AddressResolutionError AddressResolutionError
| DNSResolution DNS.Domain [IP] Word
| DNSResolution DNS.Domain [IP] Port
| Error SomeException
| ConnectError SockAddr SomeException

Expand Down
Loading