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
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 @@ -108,6 +108,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 @@ -147,7 +148,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 @@ -335,43 +336,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 @@ -418,7 +389,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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Test.Cardano.Network.Diffusion.Testnet.Simulation
, DiffusionTestTrace (..)
, ppDiffusionTestTrace
-- * Re-exports
, TestAddress (..)
, Node.NetworkAddress (..)
, RelayAccessPoint (..)
, Script (..)
, module PeerSelection
Expand Down Expand Up @@ -125,7 +125,7 @@ import Ouroboros.Network.Protocol.PeerSharing.Codec (byteLimitsPeerSharing,
import Ouroboros.Network.Protocol.TxSubmission2.Codec (byteLimitsTxSubmission2,
timeLimitsTxSubmission2)
import Ouroboros.Network.Server qualified as Server
import Ouroboros.Network.Snocket (Snocket, TestAddress (..))
import Ouroboros.Network.Snocket (Snocket)
import Ouroboros.Network.TxSubmission.Inbound.V2.Policy (TxDecisionPolicy)
import Ouroboros.Network.TxSubmission.Inbound.V2.Types (TraceTxLogic,
TraceTxSubmissionInbound)
Expand All @@ -138,7 +138,7 @@ import Simulation.Network.Snocket (BearerInfo (..), FD, SnocketTrace,
import Test.Ouroboros.Network.Data.Script
import Test.Ouroboros.Network.Diffusion.Node qualified as Node
import Test.Ouroboros.Network.Diffusion.Node.Kernel (NtCAddr, NtCVersion,
NtCVersionData, NtNAddr, NtNAddr_ (IPAddr), NtNVersion,
NtCVersionData, NtNAddr, NtNVersion,
NtNVersionData)
import Test.Ouroboros.Network.LedgerPeers (LedgerPools (..), cardanoSRVPrefix,
genLedgerPoolsFrom)
Expand Down Expand Up @@ -474,7 +474,7 @@ genNodeArgs relays minConnected localRootPeers self txs = flip suchThat hasUpstr
-- `UseLedgerPeers 0`!
, naConsensusMode
, naBootstrapPeers = bootstrapPeersDomain
, naAddr = TestAddress ((\(_, ip, port, _) -> IPAddr ip port) self)
, naAddr = ((\(_, ip, port, _) -> Node.IPAddr ip port) self)
, naLocalRootPeers = localRootPeers
, naLedgerPeers = ledgerPeersScript
, naPeerTargets = peerTargets
Expand Down Expand Up @@ -1001,7 +1001,7 @@ ppDiffusionTestTrace (DiffusionInboundGovernorTransitionTrace tr) = show tr
ppDiffusionTestTrace (DiffusionServerTrace tr) = show tr
ppDiffusionTestTrace (DiffusionFetchTrace tr) = show tr
ppDiffusionTestTrace (DiffusionChurnModeTrace tr) = show tr
ppDiffusionTestTrace (DiffusionTxSubmissionInbound (TestAddress peer) tr) = prettyShow peer ++ " " ++ show tr
ppDiffusionTestTrace (DiffusionTxSubmissionInbound peer tr) = prettyShow peer ++ " " ++ show tr
ppDiffusionTestTrace (DiffusionTxLogic tr) = show tr
ppDiffusionTestTrace (DiffusionDebugTrace tr) = tr
ppDiffusionTestTrace (DiffusionDNSTrace tr) = show tr
Expand Down Expand Up @@ -1071,15 +1071,13 @@ diffusionSimulationM
-- TODO: we should use `snocket` per node, this will allow us to set up
-- bearer info per node
withSnocket netSimTracer defaultBearerInfo Map.empty
$ \ntnSnocket _ ->
withSnocket nullTracer defaultBearerInfo Map.empty
$ \ntcSnocket _ -> do
$ \snocket _ -> do
dnsMapVar <- fromLazyTVar <$> playTimedScript nullTracer dnsMapScript
withAsyncAll
(zipWith
(\(args, commands) nodeId -> do
labelThisThread ("ctrl-" ++ show nodeId)
runCommand ntnSnocket ntcSnocket dnsMapVar simArgs args connStateIdSupply nodeId Nothing commands)
runCommand snocket dnsMapVar simArgs args connStateIdSupply nodeId Nothing commands)
nodeArgs
[NodeId 1..]
)
Expand All @@ -1088,16 +1086,14 @@ diffusionSimulationM
return x
)
where
netSimTracer :: Tracer m (WithAddr NtNAddr (SnocketTrace m NtNAddr))
netSimTracer = (\(WithAddr l _ a) -> WithName (fromMaybe (TestAddress $ IPAddr (read "0.0.0.0") 0) l) (show a))
netSimTracer :: Tracer m (WithAddr (SnocketTrace m))
netSimTracer = (\(WithAddr l _ a) -> WithName (fromMaybe (Node.IPAddr (read "0.0.0.0") 0) l) (show a))
`contramap` tracerWithTime nullTracer

-- | Runs a single node according to a list of commands.
runCommand
:: Snocket m (FD m NtNAddr) NtNAddr
-- ^ Node to node Snocket
-> Snocket m (FD m NtCAddr) NtCAddr
-- ^ Node to client Snocket
:: Snocket m (FD m) Node.NetworkAddress
-- ^ snocket
-> StrictTVar m MockDNSMap
-- ^ Map of domain map TVars to be updated in case a node changes its IP
-> SimArgs -- ^ Simulation arguments needed in order to run a simulation
Expand All @@ -1113,7 +1109,7 @@ diffusionSimulationM
-- TVar.
-> [Command] -- ^ List of commands/actions to perform for a single node
-> m Void
runCommand ntnSocket ntcSocket dnsMapVar sArgs nArgs@NodeArgs { naAddr, naConsensusMode }
runCommand snocket dnsMapVar sArgs nArgs@NodeArgs { naAddr, naConsensusMode }
connStateIdSupply nodeId hostAndLRP cmds = do
traceWith (diffSimTracer naAddr) . TrSay $ show nodeId ++ "@" ++ prettyShow naAddr
runCommand' hostAndLRP cmds
Expand All @@ -1134,7 +1130,7 @@ diffusionSimulationM
threadDelay delay
traceWith (diffSimTracer naAddr) (TrJoiningNetwork naConsensusMode)
lrpVar <- newTVarIO $ naLocalRootPeers nArgs
withAsync (runNode sArgs nArgs ntnSocket ntcSocket connStateIdSupply lrpVar dnsMapVar nodeId) $ \nodeAsync ->
withAsync (runNode sArgs nArgs snocket connStateIdSupply lrpVar dnsMapVar nodeId) $ \nodeAsync ->
runCommand' (Just (nodeAsync, lrpVar)) cs
runCommand' _ (JoinNetwork _:_) =
error "runCommand: Impossible happened"
Expand All @@ -1160,8 +1156,7 @@ diffusionSimulationM

runNode :: SimArgs
-> NodeArgs
-> Snocket m (FD m NtNAddr) NtNAddr
-> Snocket m (FD m NtCAddr) NtCAddr
-> Snocket m (FD m) Node.NetworkAddress
-> CM.ConnStateIdSupply m
-> StrictTVar m [( HotValency
, WarmValency
Expand Down Expand Up @@ -1192,8 +1187,7 @@ diffusionSimulationM
, naTxs = txs
, naTxImpairment = txImpairment
}
ntnSnocket
ntcSnocket
snocket
connStateIdSupply
lrpVar
dMapVar
Expand Down Expand Up @@ -1259,11 +1253,10 @@ diffusionSimulationM
interfaces :: Node.Interfaces (Cardano.LedgerPeersConsensusInterface m) m
interfaces =
Node.Interfaces
{ Node.iNtnSnocket = ntnSnocket
{ Node.iSnocket = snocket
, Node.iNtnBearer = makeFDBearer
, Node.iAcceptVersion = acceptVersion
, Node.iNtnDomainResolver = domainResolver dMapVar
, Node.iNtcSnocket = ntcSnocket
, Node.iNtcBearer = makeFDBearer
, Node.iRng = rng
, Node.iDomainMap = dMapVar
Expand Down Expand Up @@ -1445,7 +1438,7 @@ diffusionSimulationM
let mapDomains :: [(DomainAccessPoint, Set NtNAddr)]
mapDomains =
[ ( dap
, Set.fromList [ TestAddress (IPAddr a p) | (a, p) <- addrs ]
, Set.fromList [ Node.IPAddr a p | (a, p) <- addrs ]
)
| dap <- daps
, let addrs = case dap of
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
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

- `Ouroboros.Network.Diffusion.Configuration` now has a single `dcAddresses ::
[Either ntnFd ntnAddr]` field, instead of the two `dcIPv[46]Address`. This
allows us to support multiple interfaces. Use
`Ouroboros.Network.Diffusion.readIPAddressAndPort` to parse `IP:Port` pari
from a command line.

<!--
### Non-Breaking

- A bullet item for the Non-Breaking category.

-->
<!--
### Patch

- A bullet item for the Patch category.

-->
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

- Removed `addressType` API from `ConnectionManager.Arguments` and thus from `Diffusion.Interfaces`, we use `Snocket.addrFamily` instead.

<!--
### Non-Breaking

- A bullet item for the Non-Breaking category.

-->
<!--
### Patch

- A bullet item for the Patch category.

-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
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

- `Snocket`'s `addrFamily` API change
* Simplified `AddressFamily` data type, now it's a simple enumerationo of `AFInet`, `AFInet6` and `AFLocal`, removed `TestFamily`.
- The `Simulation.Netork.Snocket` is now monomorphic over address type, e.g.
`NetworkAddress` (brought from diffusion testnet), which simplifies test
cases. This makes the API easier to use in tests.

<!--
### Non-Breaking

- A bullet item for the Non-Breaking category.

-->
<!--
### Patch

- A bullet item for the Patch category.

-->
11 changes: 5 additions & 6 deletions ouroboros-network/demo/connection-manager.hs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ withBidirectionalConnectionManager
-> CM.ConnStateIdSupply m
-> DiffTime -- protocol idle timeout
-> DiffTime -- wait time timeout
-> Maybe peerAddr
-> [peerAddr]
-> Random.StdGen
-> ClientAndServerData
-- ^ series of request possible to do with the bidirectional connection
Expand All @@ -214,7 +214,7 @@ withBidirectionalConnectionManager snocket makeBearer socket
connStateIdSupply
protocolIdleTimeout
timeWaitTimeout
localAddress
localAddresses
stdGen
ClientAndServerData {
hotInitiatorRequests,
Expand Down Expand Up @@ -261,9 +261,8 @@ withBidirectionalConnectionManager snocket makeBearer socket
-- ConnectionManagerTrace
tracer = ("cm",) `contramap` debugTracer,
trTracer = ("cm-state",) `contramap` debugTracer,
ipv4Address = localAddress,
ipv6Address = Nothing,
addressType = \_ -> Just IPv4Address,
ipv4Address = localAddresses,
ipv6Address = [],
snocket = snocket,
makeBearer = makeBearer,
CM.withBuffer = \f -> f Nothing,
Expand Down Expand Up @@ -488,7 +487,7 @@ bidirectionalExperiment
withBidirectionalConnectionManager
snocket makeBearer socket0 connStateIdSupply
protocolIdleTimeout timeWaitTimeout
(Just localAddr) stdGen clientAndServerData $
[localAddr] stdGen clientAndServerData $
\connectionManager _serverAddr _inbGovAsync -> forever' $ do
-- runInitiatorProtocols returns a list of results per each protocol
-- in each bucket (warm \/ hot \/ established); but we run only one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ prop_socket_recv_error f rerr =
snocket = socketSnocket iomgr

bracket
(open snocket (SocketFamily Socket.AF_INET))
(open snocket AFInet)
(close snocket)
$ \sd -> do
-- bind the socket
Expand Down Expand Up @@ -436,7 +436,7 @@ prop_socket_send_error rerr =
snocket = socketSnocket iomgr

bracket
(open snocket (SocketFamily Socket.AF_INET))
(open snocket AFInet)
(close snocket)
$ \sd -> do
-- bind the socket
Expand Down
Loading
Loading