{-# LANGUAGE DeriveFunctor #-}

-- | Initiator and responder execution context.
--
module Ouroboros.Network.Context
  ( ExpandedInitiatorContext (..)
  , MinimalInitiatorContext (..)
  , ResponderContext (..)
    -- * Re-exports
  , ConnectionId (..)
  , ControlMessageSTM
  , IsBigLedgerPeer (..)
  ) where

import Ouroboros.Network.ConnectionId
import Ouroboros.Network.ControlMessage
import Ouroboros.Network.PeerSelection.LedgerPeers.Type


-- | Context passed to initiator mini-protocol execution.
--
data ExpandedInitiatorContext addr m = ExpandedInitiatorContext {
    forall addr (m :: * -> *).
ExpandedInitiatorContext addr m -> ConnectionId addr
eicConnectionId    :: !(ConnectionId addr),
    forall addr (m :: * -> *).
ExpandedInitiatorContext addr m -> ControlMessageSTM m
eicControlMessage  :: !(ControlMessageSTM m),
    forall addr (m :: * -> *).
ExpandedInitiatorContext addr m -> IsBigLedgerPeer
eicIsBigLedgerPeer :: !IsBigLedgerPeer
  }

-- | A context passed to initiator mini-protocol execution for non-p2p
-- applications.
--
newtype MinimalInitiatorContext addr = MinimalInitiatorContext {
    forall addr. MinimalInitiatorContext addr -> ConnectionId addr
micConnectionId   :: ConnectionId addr
  }
  deriving (forall a b.
 (a -> b) -> MinimalInitiatorContext a -> MinimalInitiatorContext b)
-> (forall a b.
    a -> MinimalInitiatorContext b -> MinimalInitiatorContext a)
-> Functor MinimalInitiatorContext
forall a b.
a -> MinimalInitiatorContext b -> MinimalInitiatorContext a
forall a b.
(a -> b) -> MinimalInitiatorContext a -> MinimalInitiatorContext b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b.
(a -> b) -> MinimalInitiatorContext a -> MinimalInitiatorContext b
fmap :: forall a b.
(a -> b) -> MinimalInitiatorContext a -> MinimalInitiatorContext b
$c<$ :: forall a b.
a -> MinimalInitiatorContext b -> MinimalInitiatorContext a
<$ :: forall a b.
a -> MinimalInitiatorContext b -> MinimalInitiatorContext a
Functor

-- | Context passed to each responder mini-protocol execution.
--
newtype ResponderContext addr = ResponderContext {
    forall addr. ResponderContext addr -> ConnectionId addr
rcConnectionId    :: ConnectionId addr
  }
  deriving (forall a b. (a -> b) -> ResponderContext a -> ResponderContext b)
-> (forall a b. a -> ResponderContext b -> ResponderContext a)
-> Functor ResponderContext
forall a b. a -> ResponderContext b -> ResponderContext a
forall a b. (a -> b) -> ResponderContext a -> ResponderContext b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> ResponderContext a -> ResponderContext b
fmap :: forall a b. (a -> b) -> ResponderContext a -> ResponderContext b
$c<$ :: forall a b. a -> ResponderContext b -> ResponderContext a
<$ :: forall a b. a -> ResponderContext b -> ResponderContext a
Functor