Skip to content

Commit

Permalink
ouroboros-network-framework: renamed MuxPeer to MiniProtocolCb
Browse files Browse the repository at this point in the history
  • Loading branch information
coot committed Mar 20, 2023
1 parent 5f8d50e commit c11adbc
Show file tree
Hide file tree
Showing 17 changed files with 222 additions and 156 deletions.
4 changes: 2 additions & 2 deletions cardano-client/src/Cardano/Client/Subscription.hs
Expand Up @@ -11,7 +11,7 @@ module Cardano.Client.Subscription
, LocalAddress
, NodeToClientProtocols (..)
, BlockNodeToClientVersion
, MuxPeer (..)
, MiniProtocolCb (..)
, MuxTrace
, RunMiniProtocol (..)
, WithMuxBearer
Expand All @@ -31,7 +31,7 @@ import Network.Mux.Trace (MuxTrace, WithMuxBearer)

import Ouroboros.Network.ControlMessage (ControlMessage (..))
import Ouroboros.Network.Magic (NetworkMagic)
import Ouroboros.Network.Mux (MuxMode (..), MuxPeer (..),
import Ouroboros.Network.Mux (MuxMode (..), MiniProtocolCb (..),
OuroborosApplicationWithMinimalCtx, RunMiniProtocol (..))
import Ouroboros.Network.NodeToClient (ClientSubscriptionParams (..),
ConnectionId, LocalAddress,
Expand Down
Expand Up @@ -469,12 +469,16 @@ responder version Apps {..} =
nodeToClientProtocols
(NodeToClientProtocols {
localChainSyncProtocol =
ResponderProtocolOnly $ MuxPeerRaw $ \ctx -> aChainSyncServer (rcConnectionId ctx),
ResponderProtocolOnly $ MiniProtocolCb $ \ctx ->
aChainSyncServer (rcConnectionId ctx),
localTxSubmissionProtocol =
ResponderProtocolOnly $ MuxPeerRaw $ \ctx -> aTxSubmissionServer (rcConnectionId ctx),
ResponderProtocolOnly $ MiniProtocolCb $ \ctx ->
aTxSubmissionServer (rcConnectionId ctx),
localStateQueryProtocol =
ResponderProtocolOnly $ MuxPeerRaw $ \ctx -> aStateQueryServer (rcConnectionId ctx),
ResponderProtocolOnly $ MiniProtocolCb $ \ctx ->
aStateQueryServer (rcConnectionId ctx),
localTxMonitorProtocol =
ResponderProtocolOnly $ MuxPeerRaw $ \ctx -> aTxMonitorServer (rcConnectionId ctx)
ResponderProtocolOnly $ MiniProtocolCb $ \ctx ->
aTxMonitorServer (rcConnectionId ctx)
})
version
Expand Up @@ -795,15 +795,15 @@ initiator miniProtocolParameters version ownPeerSharing Apps {..} =
-- a quadruple uniquely determining a connection).
(NodeToNodeProtocols {
chainSyncProtocol =
(InitiatorProtocolOnly (MuxPeerRaw (\ctx -> aChainSyncClient version ctx))),
(InitiatorProtocolOnly (MiniProtocolCb (\ctx -> aChainSyncClient version ctx))),
blockFetchProtocol =
(InitiatorProtocolOnly (MuxPeerRaw (\ctx -> aBlockFetchClient version ctx))),
(InitiatorProtocolOnly (MiniProtocolCb (\ctx -> aBlockFetchClient version ctx))),
txSubmissionProtocol =
(InitiatorProtocolOnly (MuxPeerRaw (\ctx -> aTxSubmission2Client version ctx))),
(InitiatorProtocolOnly (MiniProtocolCb (\ctx -> aTxSubmission2Client version ctx))),
keepAliveProtocol =
(InitiatorProtocolOnly (MuxPeerRaw (\ctx -> aKeepAliveClient version ctx))),
(InitiatorProtocolOnly (MiniProtocolCb (\ctx -> aKeepAliveClient version ctx))),
peerSharingProtocol =
(InitiatorProtocolOnly (MuxPeerRaw (\ctx -> aPeerSharingClient version ctx)))
(InitiatorProtocolOnly (MiniProtocolCb (\ctx -> aPeerSharingClient version ctx)))
})
version
ownPeerSharing
Expand All @@ -825,25 +825,25 @@ initiatorAndResponder miniProtocolParameters version ownPeerSharing Apps {..} =
(NodeToNodeProtocols {
chainSyncProtocol =
(InitiatorAndResponderProtocol
(MuxPeerRaw (\initiatorCtx -> aChainSyncClient version initiatorCtx))
(MuxPeerRaw (\responderCtx -> aChainSyncServer version responderCtx))),
(MiniProtocolCb (\initiatorCtx -> aChainSyncClient version initiatorCtx))
(MiniProtocolCb (\responderCtx -> aChainSyncServer version responderCtx))),
blockFetchProtocol =
(InitiatorAndResponderProtocol
(MuxPeerRaw (\initiatorCtx -> aBlockFetchClient version initiatorCtx))
(MuxPeerRaw (\responderCtx -> aBlockFetchServer version responderCtx))),
(MiniProtocolCb (\initiatorCtx -> aBlockFetchClient version initiatorCtx))
(MiniProtocolCb (\responderCtx -> aBlockFetchServer version responderCtx))),
txSubmissionProtocol =
(InitiatorAndResponderProtocol
(MuxPeerRaw (\initiatorCtx -> aTxSubmission2Client version initiatorCtx))
(MuxPeerRaw (\responderCtx -> aTxSubmission2Server version responderCtx))),
(MiniProtocolCb (\initiatorCtx -> aTxSubmission2Client version initiatorCtx))
(MiniProtocolCb (\responderCtx -> aTxSubmission2Server version responderCtx))),
keepAliveProtocol =
(InitiatorAndResponderProtocol
(MuxPeerRaw (\initiatorCtx -> aKeepAliveClient version initiatorCtx))
(MuxPeerRaw (\responderCtx -> aKeepAliveServer version responderCtx))),
(MiniProtocolCb (\initiatorCtx -> aKeepAliveClient version initiatorCtx))
(MiniProtocolCb (\responderCtx -> aKeepAliveServer version responderCtx))),

peerSharingProtocol =
(InitiatorAndResponderProtocol
(MuxPeerRaw (\initiatorCtx -> aPeerSharingClient version initiatorCtx))
(MuxPeerRaw (\responderCtx -> aPeerSharingServer version responderCtx)))
(MiniProtocolCb (\initiatorCtx -> aPeerSharingClient version initiatorCtx))
(MiniProtocolCb (\responderCtx -> aPeerSharingServer version responderCtx)))
})
version
ownPeerSharing
21 changes: 14 additions & 7 deletions ouroboros-network-framework/CHANGELOG.md
Expand Up @@ -43,13 +43,20 @@
- `Ouroboros.Network.Socket.withServerNode`
- inbound governor API

* `MuxPeer` and `MuxPeerPipelined` constructors of `MuxPeer` type were removed.
Use `mkMuxPeer` and `mkMuxPeerPipelined` instead. Note that these are not
inplace replacment.

* `runMuxPeer` changed its type. It receives two arguments: the context and
`Network.Mux.Channel.Channel` rather than `Ouroboros.Network.Channel.Channel`
(no need to use `Ouroboros.Network.Channel.fromChannel`)
* `MuxPeer` changed it's kind and it was renamed to `MiniProtocolCb`, the old
type is still provided but deprecated. The `MuxPeerRaw` constructor was
renamed to `MiniProtocolCb` (the old one is still provided but deprecated).
`MuxPeer` and `MuxPeerPipelined` constructors also changed its type and are
now deprecated. Use `mkMiniProtocolCbFromPeer` and
`mkMiniProtocolCbFromPeerPipelined` instead.

Also note that even the deprecated constructors have changed their types.

* `runMuxPeer` change its type but also is now deprecated in favour of `runMiniProtocolCb`. The latter
receives two arguments: the context and `Network.Mux.Channel.Channel` rather
than `Ouroboros.Network.Channel.Channel` (no need to use
`Ouroboros.Network.Channel.fromChannel`). `runMuxPeer` accepts the context (added argument) and
`Ouroboros.Network.Channel.Channel`.

### Non-breaking changes

Expand Down
6 changes: 3 additions & 3 deletions ouroboros-network-framework/demo/connection-manager.hs
Expand Up @@ -332,7 +332,7 @@ withBidirectionalConnectionManager snocket makeBearer socket
InitiatorResponderMode peerAddr ByteString m () ()
reqRespInitiatorAndResponder protocolNum requestsVar =
InitiatorAndResponderProtocol
(mkMuxPeer
(mkMiniProtocolCbFromPeer
(\_ctx -> ( ("Initiator",protocolNum,) `contramap` debugTracer -- TraceSendRecv
, codecReqResp @Int @Int
, Effect $ do
Expand All @@ -346,7 +346,7 @@ withBidirectionalConnectionManager snocket makeBearer socket
pure $ reqRespClientPeer (reqRespClient reqs)
)
))
(mkMuxPeer
(mkMiniProtocolCbFromPeer
(\_ctx -> ( ("Responder",protocolNum,) `contramap` debugTracer -- TraceSendRecv
, codecReqResp @Int @Int
, Effect $ reqRespServerPeer <$> reqRespServerId
Expand Down Expand Up @@ -420,7 +420,7 @@ runInitiatorProtocols
SingInitiatorMode -> Mux.InitiatorDirectionOnly
SingInitiatorResponderMode -> Mux.InitiatorDirection)
Mux.StartEagerly
(runMuxPeer
(runMiniProtocolCb
(case miniProtocolRun ptcl of
InitiatorProtocolOnly initiator -> initiator
InitiatorAndResponderProtocol initiator _ -> initiator)
Expand Down
14 changes: 7 additions & 7 deletions ouroboros-network-framework/demo/ping-pong.hs
Expand Up @@ -125,15 +125,15 @@ clientPingPong pipelined =

pingPongInitiator | pipelined =
InitiatorProtocolOnly $
mkMuxPeerPipelined $ \_ctx ->
mkMiniProtocolCbFromPeerPipelined $ \_ctx ->
(contramap show stdoutTracer
, codecPingPong
, pingPongClientPeerPipelined (pingPongClientPipelinedMax 5)
)

| otherwise =
InitiatorProtocolOnly $
mkMuxPeer $ \_ctx ->
mkMiniProtocolCbFromPeer $ \_ctx ->
( contramap show stdoutTracer
, codecPingPong
, pingPongClientPeer (pingPongClientCount 5)
Expand Down Expand Up @@ -172,7 +172,7 @@ serverPingPong =

pingPongResponder =
ResponderProtocolOnly $
mkMuxPeer $ \_ctx ->
mkMiniProtocolCbFromPeer $ \_ctx ->
( contramap show stdoutTracer
, codecPingPong
, pingPongServerPeer pingPongServerStandard
Expand Down Expand Up @@ -232,15 +232,15 @@ clientPingPong2 =

pingpong =
InitiatorProtocolOnly $
mkMuxPeer $ \_ctx ->
mkMiniProtocolCbFromPeer $ \_ctx ->
( contramap (show . (,) (1 :: Int)) stdoutTracer
, codecPingPong
, pingPongClientPeer (pingPongClientCount 5)
)

pingpong'=
InitiatorProtocolOnly $
mkMuxPeer $ \_ctx ->
mkMiniProtocolCbFromPeer $ \_ctx ->
( contramap (show . (,) (2 :: Int)) stdoutTracer
, codecPingPong
, pingPongClientPeer (pingPongClientCount 5)
Expand Down Expand Up @@ -292,15 +292,15 @@ serverPingPong2 =

pingpong =
ResponderProtocolOnly $
mkMuxPeer $ \_ctx ->
mkMiniProtocolCbFromPeer $ \_ctx ->
( contramap (show . (,) (1 :: Int)) stdoutTracer
, codecPingPong
, pingPongServerPeer pingPongServerStandard
)

pingpong' =
ResponderProtocolOnly $
mkMuxPeer $ \_ctx ->
mkMiniProtocolCbFromPeer $ \_ctx ->
( contramap (show . (,) (2 :: Int)) stdoutTracer
, codecPingPong
, pingPongServerPeer pingPongServerStandard
Expand Down
Expand Up @@ -493,14 +493,14 @@ runResponder mux
mux (miniProtocolNum miniProtocol)
Mux.ResponderDirectionOnly
startStrategy
(runMuxPeer responder responderContext)
(runMiniProtocolCb responder responderContext)

InitiatorAndResponderProtocol _ responder ->
Mux.runMiniProtocol
mux (miniProtocolNum miniProtocol)
Mux.ResponderDirection
startStrategy
(runMuxPeer responder responderContext)
(runMiniProtocolCb responder responderContext)


--
Expand Down

0 comments on commit c11adbc

Please sign in to comment.