Skip to content

Commit

Permalink
Removed Network.Mux.Compat module (#4974)
Browse files Browse the repository at this point in the history
* network-mux: removed the Network.Mux.Compat module

* network-mux: removed MiniProcololBundle newtype wrapper

* network-mux: stylistic changes

* Updated changelogs
  • Loading branch information
coot authored Oct 11, 2024
1 parent 6ff4120 commit 53ceed0
Show file tree
Hide file tree
Showing 19 changed files with 444 additions and 439 deletions.
6 changes: 6 additions & 0 deletions network-mux/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

### Breaking changes

* Removed `Netowrk.Mux.Compat` module with legacy API.
* `Ouroboros.Network.Mux.toApplication` was removed.
* `Ouroboros.Network.Mux.mkMiniProtocolBundle` was renamed to
`mkMiniProtocolInfos`, its type changed.
* Removed `MiniProtocolBundle` newtype wrapper.

### Non-breaking changes

* Fix compilation with `tracetcpinfo` flag.
Expand Down
10 changes: 4 additions & 6 deletions network-mux/demo/mux-demo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ serverWorker bearer = do

runMux nullTracer mux bearer
where
ptcls :: MiniProtocolBundle ResponderMode
ptcls = MiniProtocolBundle
[ MiniProtocolInfo {
ptcls :: [MiniProtocolInfo ResponderMode]
ptcls = [ MiniProtocolInfo {
miniProtocolNum = MiniProtocolNum 2,
miniProtocolDir = ResponderDirectionOnly,
miniProtocolLimits = defaultProtocolLimits
Expand Down Expand Up @@ -195,9 +194,8 @@ clientWorker bearer n msg = do

runMux nullTracer mux bearer
where
ptcls :: MiniProtocolBundle InitiatorMode
ptcls = MiniProtocolBundle
[ MiniProtocolInfo {
ptcls :: [MiniProtocolInfo InitiatorMode]
ptcls = [ MiniProtocolInfo {
miniProtocolNum = MiniProtocolNum 2,
miniProtocolDir = InitiatorDirectionOnly,
miniProtocolLimits = defaultProtocolLimits
Expand Down
1 change: 0 additions & 1 deletion network-mux/network-mux.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ library
Network.Mux.Bearer.Socket
Network.Mux.Channel
Network.Mux.Codec
Network.Mux.Compat
Network.Mux.DeltaQ.TraceStats
Network.Mux.DeltaQ.TraceStatsSupport
Network.Mux.DeltaQ.TraceTransformer
Expand Down
21 changes: 13 additions & 8 deletions network-mux/src/Network/Mux.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTSyntax #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
Expand All @@ -16,7 +15,6 @@ module Network.Mux
, MuxMode (..)
, HasInitiator
, HasResponder
, MiniProtocolBundle (..)
, MiniProtocolInfo (..)
, MiniProtocolNum (..)
, MiniProtocolDirection (..)
Expand Down Expand Up @@ -113,8 +111,15 @@ data MuxStatus
| MuxStopped


newMux :: MonadSTM m => MiniProtocolBundle mode -> m (Mux mode m)
newMux (MiniProtocolBundle ptcls) = do
-- | Create a mux handle.
--
newMux :: forall (mode :: MuxMode) m.
MonadSTM m
=> [MiniProtocolInfo mode]
-- ^ description of protocols run by the mux layer. Only these protocols
-- one will be able to execute.
-> m (Mux mode m)
newMux ptcls = do
muxMiniProtocols <- mkMiniProtocolStateMap ptcls
muxControlCmdQueue <- atomically newTQueue
muxStatus <- newTVarIO MuxReady
Expand Down Expand Up @@ -333,8 +338,8 @@ type MiniProtocolKey = (MiniProtocolNum, MiniProtocolDir)
newtype MonitorCtx m mode = MonitorCtx {
-- | Mini-Protocols started on demand and waiting to be scheduled.
--
mcOnDemandProtocols :: (Map MiniProtocolKey
(MiniProtocolState mode m, MiniProtocolAction m))
mcOnDemandProtocols :: Map MiniProtocolKey
(MiniProtocolState mode m, MiniProtocolAction m)

}

Expand Down Expand Up @@ -364,10 +369,10 @@ monitor tracer timeout jobpool egressQueue cmdQueue muxStatus =
go !monitorCtx@MonitorCtx { mcOnDemandProtocols } = do
result <- atomically $ runFirstToFinish $
-- wait for a mini-protocol thread to terminate
(FirstToFinish $ EventJobResult <$> JobPool.waitForJob jobpool)
FirstToFinish (EventJobResult <$> JobPool.waitForJob jobpool)

-- wait for a new control command
<> (FirstToFinish $ EventControlCmd <$> readTQueue cmdQueue)
<> FirstToFinish (EventControlCmd <$> readTQueue cmdQueue)

-- or wait for data to arrive on the channels that do not yet have
-- responder threads running
Expand Down
156 changes: 0 additions & 156 deletions network-mux/src/Network/Mux/Compat.hs

This file was deleted.

22 changes: 5 additions & 17 deletions network-mux/src/Network/Mux/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
{-# LANGUAGE TypeFamilies #-}

module Network.Mux.Types
( MiniProtocolBundle (..)
, MiniProtocolInfo (..)
( MiniProtocolInfo (..)
, MiniProtocolNum (..)
, MiniProtocolDirection (..)
, MiniProtocolLimits (..)
Expand Down Expand Up @@ -113,27 +112,16 @@ type family HasResponder (mode :: MuxMode) :: Bool where
HasResponder ResponderMode = True
HasResponder InitiatorResponderMode = True

-- | Application run by mux layer.
-- | A static description of a mini-protocol.
--
-- * enumeration of client application, e.g. a wallet application communicating
-- with a node using ChainSync and TxSubmission protocols; this only requires
-- to run client side of each protocol.
--
-- * enumeration of server applications: this application type is mostly useful
-- tests.
--
-- * enumeration of both client and server applications, e.g. a full node
-- serving downstream peers using server side of each protocol and getting
-- updates from upstream peers using client side of each of the protocols.
--
newtype MiniProtocolBundle (mode :: MuxMode) =
MiniProtocolBundle [MiniProtocolInfo mode]

data MiniProtocolInfo (mode :: MuxMode) =
MiniProtocolInfo {
miniProtocolNum :: !MiniProtocolNum,
-- ^ Unique mini-protocol number.
miniProtocolDir :: !(MiniProtocolDirection mode),
-- ^ Mini-protocol direction.
miniProtocolLimits :: !MiniProtocolLimits
-- ^ ingress queue limits for the protocol
}

data MiniProtocolDirection (mode :: MuxMode) where
Expand Down
Loading

0 comments on commit 53ceed0

Please sign in to comment.