Skip to content

Commit

Permalink
Refactor ControlChannel
Browse files Browse the repository at this point in the history
So that we can use it for sharing information between InboundGovernor
and Outbound Governor.
  • Loading branch information
bolt12 committed Feb 8, 2023
1 parent e8fa78d commit 6f3b49d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
Expand Up @@ -57,7 +57,7 @@ import Ouroboros.Network.ConnectionId
import Ouroboros.Network.ConnectionManager.Types
import qualified Ouroboros.Network.ConnectionManager.Types as CM
import Ouroboros.Network.InboundGovernor.ControlChannel
(ControlChannel (..))
(ControlChannel (..), NewConnection)
import qualified Ouroboros.Network.InboundGovernor.ControlChannel as ControlChannel
import Ouroboros.Network.MuxMode
import Ouroboros.Network.Server.RateLimiting
Expand Down Expand Up @@ -549,7 +549,7 @@ withConnectionManager
-- ^ Callback which runs in a thread dedicated for a given connection.
-> (handleError -> HandleErrorType)
-- ^ classify 'handleError's
-> InResponderMode muxMode (ControlChannel peerAddr handle m)
-> InResponderMode muxMode (ControlChannel (NewConnection peerAddr handle) m)
-- ^ On outbound duplex connections we need to notify the server about
-- a new connection.
-> (ConnectionManager muxMode socket peerAddr handle handleError m -> m a)
Expand Down
Expand Up @@ -11,6 +11,7 @@ module Ouroboros.Network.InboundGovernor.ControlChannel
( NewConnection (..)
, ControlChannel (..)
, ServerControlChannel
, GovernorControlChannel
, newControlChannel
) where

Expand All @@ -24,6 +25,7 @@ import Network.Mux.Types (MuxMode)
import Ouroboros.Network.ConnectionHandler
import Ouroboros.Network.ConnectionId (ConnectionId (..))
import Ouroboros.Network.ConnectionManager.Types
import Ouroboros.Network.PeerSelection.PeerSharing.Type (PeerSharing)


-- | Announcement message for a new connection.
Expand Down Expand Up @@ -53,31 +55,41 @@ instance Show peerAddr



-- | A Server control channel which instantiates 'handle'.
-- | A Server control channel which instantiates to 'NewConnection' and 'Handle'.
--
-- It allows to pass 'STM' transactions which will resolve to 'NewConnection'.
-- Server's monitoring thread is the consumer of these messages; there are two
-- producers: accept loop and connection handler for outbound connections.
--
type ServerControlChannel (muxMode :: MuxMode) peerAddr versionData bytes m a b =
ControlChannel peerAddr (Handle muxMode peerAddr versionData bytes m a b) m
ControlChannel (NewConnection peerAddr (Handle muxMode peerAddr versionData bytes m a b)) m

-- | Control Channel between Server and Outbound Governor.
--
-- Control channel that is meant to share inbound connections with the Peer
-- Selection Governor. So the consumer is the Governor and Producer is the
-- Server.
--
type GovernorControlChannel peerAddr m =
ControlChannel (peerAddr, PeerSharing) m

-- | Control channel. It allows to pass 'STM' transactions which will
-- resolve to 'NewConnection'. Server's monitoring thread is the consumer
-- of these messages; there are two producers: accept loop and connection
-- handler for outbound connections.
-- | Control channel.
--
data ControlChannel peerAddr handle m =
data ControlChannel a m =
ControlChannel {
-- | Read a single 'NewConnection' instruction from the channel.
-- | Read a single value from the channel.
--
readMessage :: STM m (NewConnection peerAddr handle),
readMessage :: STM m a,

-- | Write a 'NewConnection' to the channel.
-- | Write a value to the channel.
--
writeMessage :: NewConnection peerAddr handle -> STM m ()
writeMessage :: a -> STM m ()
}


newControlChannel :: forall peerAddr handle m.
newControlChannel :: forall a m.
MonadLabelledSTM m
=> m (ControlChannel peerAddr handle m)
=> m (ControlChannel a m)
newControlChannel = do
channel <-
atomically $
Expand Down

0 comments on commit 6f3b49d

Please sign in to comment.