Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InitiatorOnly mode for local root peers #5021

Merged
merged 13 commits into from
Dec 11, 2024
Merged
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: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repository cardano-haskell-packages
-- repeat the index-state for hackage to work around haskell.nix parsing limitation
index-state:
-- Bump this if you need newer packages from Hackage
, hackage.haskell.org 2024-10-24T05:58:23Z
, hackage.haskell.org 2024-12-10T16:20:07Z

-- Bump this if you need newer packages from CHaP
, cardano-haskell-packages 2024-09-26T15:16:07Z
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nix/ouroboros-network.nix
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ let
preCheck =
lib.mkForce
(if buildSystem == "x86_64-linux"
then "export GHCRTS=-M200M"
then "export GHCRTS=-M300M"
else "");
doCheck = !pkgs.stdenv.hostPlatform.isWindows;

Expand Down
8 changes: 5 additions & 3 deletions ouroboros-network-framework/demo/connection-manager.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import Ouroboros.Network.Context
import Ouroboros.Network.IOManager
import Ouroboros.Network.Mux
import Ouroboros.Network.MuxMode
import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..))
import Ouroboros.Network.Protocol.Handshake
import Ouroboros.Network.Protocol.Handshake.Codec (timeLimitsHandshake)
import Ouroboros.Network.Protocol.Handshake.Unversioned
Expand Down Expand Up @@ -242,7 +243,8 @@ withBidirectionalConnectionManager snocket makeBearer socket
acceptedConnectionsHardLimit = maxBound,
acceptedConnectionsSoftLimit = maxBound,
acceptedConnectionsDelay = 0
}
},
CM.updateVersionData = \a _ -> a
}
(makeConnectionHandler
muxTracer
Expand Down Expand Up @@ -541,9 +543,9 @@ bidirectionalExperiment
Mux.InitiatorResponderMode
UnversionedProtocol))
connect n cm | n <= 1 =
acquireOutboundConnection cm remoteAddr
acquireOutboundConnection cm InitiatorAndResponderDiffusionMode remoteAddr
connect n cm =
acquireOutboundConnection cm remoteAddr
acquireOutboundConnection cm InitiatorAndResponderDiffusionMode remoteAddr
`catch` \(_ :: IOException) -> threadDelay 1
>> connect (pred n) cm
`catch` \(_ :: Mux.Error) -> threadDelay 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ test-suite sim-tests
monoidal-synchronisation,
network,
network-mux,
ouroboros-network-api,
ouroboros-network-framework,
ouroboros-network-framework:testlib,
ouroboros-network-testing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ import Test.Tasty.QuickCheck (testProperty)

import Ouroboros.Network.ConnectionId (ConnectionId (..))
import Ouroboros.Network.ConnectionManager.Core qualified as CM
import Ouroboros.Network.ConnectionManager.State qualified as CM
import Ouroboros.Network.ConnectionManager.Test.Utils (verifyAbstractTransition)
import Ouroboros.Network.ConnectionManager.Types
import Ouroboros.Network.MuxMode
import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..))
import Ouroboros.Network.Server.RateLimiting
import Ouroboros.Network.Snocket (Accept (..), Accepted (..),
AddressFamily (TestFamily), Snocket (..), TestAddress (..))
Expand Down Expand Up @@ -597,16 +599,16 @@ mkConnectionHandler :: forall m handlerTrace.
-> ConnectionHandler Mx.InitiatorResponderMode
handlerTrace (FD m)
Addr (Handle m)
Void (Version, VersionData)
Void Version VersionData
m
mkConnectionHandler snocket =
ConnectionHandler $
WithInitiatorResponderMode
handler
handler
where
handler :: ConnectionHandlerFn handlerTrace (FD m) Addr (Handle m) Void (Version, VersionData) m
handler fd promise _ ConnectionId { remoteAddress } _ =
handler :: ConnectionHandlerFn handlerTrace (FD m) Addr (Handle m) Void Version VersionData m
handler _ fd promise _ ConnectionId { remoteAddress } _ =
MaskedAction $ \unmask ->
do threadId <- myThreadId
let addr = getTestAddress remoteAddress
Expand Down Expand Up @@ -648,8 +650,8 @@ mkConnectionHandler snocket =

type TestConnectionState m = CM.ConnectionState Addr (Handle m) Void Version m
type TestConnectionManagerTrace = CM.Trace Addr ()
type TestTransitionTrace m = TransitionTrace Addr (TestConnectionState m)
type TestAbstractTransitionTrace = AbstractTransitionTrace Addr
type TestTransitionTrace m = TransitionTrace CM.ConnStateId (TestConnectionState m)
type TestAbstractTransitionTrace = AbstractTransitionTrace CM.ConnStateId

newtype SkewedBool = SkewedBool Bool
deriving Show
Expand Down Expand Up @@ -772,7 +774,8 @@ prop_valid_transitions (Fixed rnd) (SkewedBool bindToLocalAddress) scheduleMap =
acceptedConnectionsDelay = 0
},
CM.timeWaitTimeout = testTimeWaitTimeout,
CM.outboundIdleTimeout = testOutboundIdleTimeout
CM.outboundIdleTimeout = testOutboundIdleTimeout,
CM.updateVersionData = \a _ -> a
}
connectionHandler
(\_ -> HandshakeFailure)
Expand All @@ -781,11 +784,7 @@ prop_valid_transitions (Fixed rnd) (SkewedBool bindToLocalAddress) scheduleMap =
:: ConnectionManager Mx.InitiatorResponderMode (FD (IOSim s))
Addr (Handle m) Void (IOSim s)) -> do
fd <- open snocket TestFamily
case myAddress of
Just localAddr ->
bind snocket fd localAddr
Nothing ->
pure ()
traverse_ (bind snocket fd) myAddress

let go :: HasCallStack
=> [Async (IOSim s) ()]
Expand All @@ -811,7 +810,7 @@ prop_valid_transitions (Fixed rnd) (SkewedBool bindToLocalAddress) scheduleMap =
-- handshake negotiation.
timeout (1 + 5 + testTimeWaitTimeout)
(acquireOutboundConnection
connectionManager addr))
connectionManager InitiatorAndResponderDiffusionMode addr))
`catches`
[ Handler $ \(e :: IOException) -> return (Left (toException e))
, Handler $ \(e :: SomeConnectionManagerError) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ import Network.Mux qualified as Mux
import Ouroboros.Network.ConnectionHandler
import Ouroboros.Network.ConnectionId
import Ouroboros.Network.ConnectionManager.Core qualified as CM
import Ouroboros.Network.ConnectionManager.State qualified as CM
import Ouroboros.Network.ConnectionManager.Types
import Ouroboros.Network.InboundGovernor qualified as IG
import Ouroboros.Network.InboundGovernor.State (ConnectionState (..))
import Ouroboros.Network.InboundGovernor.State qualified as IG
import Ouroboros.Network.Mux
import Ouroboros.Network.MuxMode
import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..))
import Ouroboros.Network.Protocol.Handshake.Codec (noTimeLimitsHandshake,
timeLimitsHandshake)
import Ouroboros.Network.Protocol.Handshake.Unversioned
Expand Down Expand Up @@ -626,7 +628,7 @@ multinodeExperiment
=> Tracer m (WithName (Name peerAddr)
(RemoteTransitionTrace peerAddr))
-> Tracer m (WithName (Name peerAddr)
(AbstractTransitionTrace peerAddr))
(AbstractTransitionTrace CM.ConnStateId))
-> Tracer m (WithName (Name peerAddr)
(IG.Trace peerAddr))
-> Tracer m (WithName (Name peerAddr)
Expand Down Expand Up @@ -869,7 +871,7 @@ multinodeExperiment inboundTrTracer trTracer inboundTracer debugTracer cmTracer
case fromException e of
Just SomeAsyncException {} -> Nothing
_ -> Just e)
$ acquireOutboundConnection cm remoteAddr
$ acquireOutboundConnection cm InitiatorAndResponderDiffusionMode remoteAddr
case connHandle of
Left _ ->
go connMap
Expand Down Expand Up @@ -2241,7 +2243,7 @@ multiNodeSimTracer :: ( Alternative (STM m), Monad m, MonadFix m
-> Tracer m
(WithName (Name SimAddr) (RemoteTransitionTrace SimAddr))
-> Tracer m
(WithName (Name SimAddr) (AbstractTransitionTrace SimAddr))
(WithName (Name SimAddr) (AbstractTransitionTrace CM.ConnStateId))
-> Tracer m
(WithName (Name SimAddr) (IG.Trace SimAddr))
-> Tracer m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import Ouroboros.Network.ControlMessage (ControlMessage (..))
import Ouroboros.Network.Mux
import Ouroboros.Network.MuxMode
import Ouroboros.Network.Protocol.Handshake
import Ouroboros.Network.Protocol.Handshake.Version qualified as Handshake
import Ouroboros.Network.RethrowPolicy

-- | We place an upper limit of `30s` on the time we wait on receiving an SDU.
Expand Down Expand Up @@ -179,7 +180,8 @@ type MuxConnectionHandler muxMode socket initiatorCtx responderCtx peerAddr vers
peerAddr
(Handle muxMode initiatorCtx responderCtx versionData bytes m a b)
(HandleError muxMode versionNumber)
(versionNumber, versionData)
versionNumber
versionData
m

-- | Type alias for 'ConnectionManager' using 'Handle'.
Expand Down Expand Up @@ -276,9 +278,11 @@ makeConnectionHandler muxTracer singMuxMode
peerAddr
(Handle muxMode initiatorCtx responderCtx versionData ByteString m a b)
(HandleError muxMode versionNumber)
(versionNumber, versionData)
versionNumber
versionData
m
outboundConnectionHandler socket
outboundConnectionHandler versionDataFn
socket
PromiseWriter { writePromise }
tracer
connectionId@ConnectionId { localAddress
Expand All @@ -299,7 +303,7 @@ makeConnectionHandler muxTracer singMuxMode
unmask (runHandshakeClient handshakeBearer
connectionId
handshakeArguments
versionedApplication)
(Handshake.updateVersionData versionDataFn versionedApplication))
-- 'runHandshakeClient' only deals with protocol limit errors or
-- handshake negotiation failures, but not with 'IOException's or
-- 'MuxError's.
Expand Down Expand Up @@ -343,9 +347,11 @@ makeConnectionHandler muxTracer singMuxMode
peerAddr
(Handle muxMode initiatorCtx responderCtx versionData ByteString m a b)
(HandleError muxMode versionNumber)
(versionNumber, versionData)
versionNumber
versionData
m
inboundConnectionHandler socket
inboundConnectionHandler updateVersionDataFn
socket
PromiseWriter { writePromise }
tracer
connectionId@ConnectionId { localAddress
Expand All @@ -366,7 +372,7 @@ makeConnectionHandler muxTracer singMuxMode
unmask (runHandshakeServer handshakeBearer
connectionId
handshakeArguments
versionedApplication)
(Handshake.updateVersionData updateVersionDataFn versionedApplication))
-- 'runHandshakeServer' only deals with protocol limit errors or
-- handshake negotiation failures, but not with 'IOException's or
-- 'MuxError's.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Ouroboros.Network.ConnectionManager.ConnMap
, lookup
, lookupByRemoteAddr
, updateLocalAddr
, traverseMaybeWithKey
, traverseMaybe
) where

import Prelude hiding (lookup)
Expand Down Expand Up @@ -248,22 +248,17 @@ updateLocalAddr ConnectionId { remoteAddress, localAddress } (ConnMap m) =
m


traverseMaybeWithKey
traverseMaybe
:: Applicative f
=> (Either peerAddr (ConnectionId peerAddr) -> a -> f (Maybe b))
=> (a -> f (Maybe b))
-> ConnMap peerAddr a
-> f [b]
traverseMaybeWithKey fn =
traverseMaybe fn =
fmap (concat . Map.elems)
. Map.traverseMaybeWithKey
(\remoteAddress st ->
(\_ st ->
fmap (Just . Map.elems)
. Map.traverseMaybeWithKey
(\case
UnknownLocalAddr -> fn (Left remoteAddress)
LocalAddr localAddress -> fn (Right ConnectionId { remoteAddress,
localAddress })
)
. Map.traverseMaybeWithKey (\_ -> fn)
$ st
)
. getConnMap
Loading
Loading