{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
module Ouroboros.Network.ConnectionManager.Types
(
AddressType (..)
, Provenance (..)
, DataFlow (..)
, TimeoutExpired (..)
, ConnectionType (..)
, MaskedAction (..)
, ConnectionHandlerFn
, ConnectionHandler (..)
, Inactive (..)
, ExceptionInHandler (..)
, HandleErrorType (..)
, HandshakeConnectionResult (..)
, PrunePolicy
, simplePrunePolicy
, ConnectionManager (..)
, Connected (..)
, OperationResult (..)
, resultInState
, DemotedToColdRemoteTr (..)
, AcquireOutboundConnection
, IncludeInboundConnection
, acquireOutboundConnection
, promotedToWarmRemote
, demotedToColdRemote
, releaseOutboundConnection
, includeInboundConnection
, releaseInboundConnection
, numberOfConnections
, OutboundConnectionManager (..)
, InboundConnectionManager (..)
, ConnectionManagerError (..)
, SomeConnectionManagerError (..)
, AbstractState (..)
, ConnectionManagerCounters (..)
, WithMuxMode (..)
, withInitiatorMode
, withResponderMode
, newEmptyPromiseIO
, PromiseReader (..)
, readPromiseIO
, PromiseWriter (..)
, PromiseWriterException (..)
, AssertionLocation (..)
, MaybeUnknown (..)
, Transition' (..)
, Transition
, AbstractTransition
, mkTransition
, mkAbsTransition
, TransitionTrace
, TransitionTrace' (..)
, AbstractTransitionTrace
) where
import Control.Concurrent.Class.MonadSTM.Strict
import Control.Monad (unless)
import Control.Monad.Class.MonadThrow
import Control.Monad.Class.MonadTime.SI (DiffTime)
import Control.Tracer (Tracer)
import Data.Functor (void)
import Data.List (sortOn)
import Data.Map.Strict (Map)
import Data.Map.Strict qualified as Map
import Data.Set (Set)
import Data.Set qualified as Set
import Data.Typeable (Typeable, cast)
import Data.Word (Word32)
import GHC.Stack (CallStack, prettyCallStack)
import System.Random (StdGen)
import Network.Mux.Types (HasInitiator, HasResponder, MiniProtocolDir)
import Network.Mux.Types qualified as Mux
import Ouroboros.Network.ConnectionId (ConnectionId)
import Ouroboros.Network.MuxMode
data AddressType = IPv4Address | IPv6Address
deriving Int -> AddressType -> ShowS
[AddressType] -> ShowS
AddressType -> String
(Int -> AddressType -> ShowS)
-> (AddressType -> String)
-> ([AddressType] -> ShowS)
-> Show AddressType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AddressType -> ShowS
showsPrec :: Int -> AddressType -> ShowS
$cshow :: AddressType -> String
show :: AddressType -> String
$cshowList :: [AddressType] -> ShowS
showList :: [AddressType] -> ShowS
Show
data Provenance =
Inbound
| Outbound
deriving (Provenance -> Provenance -> Bool
(Provenance -> Provenance -> Bool)
-> (Provenance -> Provenance -> Bool) -> Eq Provenance
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Provenance -> Provenance -> Bool
== :: Provenance -> Provenance -> Bool
$c/= :: Provenance -> Provenance -> Bool
/= :: Provenance -> Provenance -> Bool
Eq, Eq Provenance
Eq Provenance =>
(Provenance -> Provenance -> Ordering)
-> (Provenance -> Provenance -> Bool)
-> (Provenance -> Provenance -> Bool)
-> (Provenance -> Provenance -> Bool)
-> (Provenance -> Provenance -> Bool)
-> (Provenance -> Provenance -> Provenance)
-> (Provenance -> Provenance -> Provenance)
-> Ord Provenance
Provenance -> Provenance -> Bool
Provenance -> Provenance -> Ordering
Provenance -> Provenance -> Provenance
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Provenance -> Provenance -> Ordering
compare :: Provenance -> Provenance -> Ordering
$c< :: Provenance -> Provenance -> Bool
< :: Provenance -> Provenance -> Bool
$c<= :: Provenance -> Provenance -> Bool
<= :: Provenance -> Provenance -> Bool
$c> :: Provenance -> Provenance -> Bool
> :: Provenance -> Provenance -> Bool
$c>= :: Provenance -> Provenance -> Bool
>= :: Provenance -> Provenance -> Bool
$cmax :: Provenance -> Provenance -> Provenance
max :: Provenance -> Provenance -> Provenance
$cmin :: Provenance -> Provenance -> Provenance
min :: Provenance -> Provenance -> Provenance
Ord, Int -> Provenance -> ShowS
[Provenance] -> ShowS
Provenance -> String
(Int -> Provenance -> ShowS)
-> (Provenance -> String)
-> ([Provenance] -> ShowS)
-> Show Provenance
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Provenance -> ShowS
showsPrec :: Int -> Provenance -> ShowS
$cshow :: Provenance -> String
show :: Provenance -> String
$cshowList :: [Provenance] -> ShowS
showList :: [Provenance] -> ShowS
Show)
data DataFlow
= Unidirectional
| Duplex
deriving (DataFlow -> DataFlow -> Bool
(DataFlow -> DataFlow -> Bool)
-> (DataFlow -> DataFlow -> Bool) -> Eq DataFlow
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DataFlow -> DataFlow -> Bool
== :: DataFlow -> DataFlow -> Bool
$c/= :: DataFlow -> DataFlow -> Bool
/= :: DataFlow -> DataFlow -> Bool
Eq, Eq DataFlow
Eq DataFlow =>
(DataFlow -> DataFlow -> Ordering)
-> (DataFlow -> DataFlow -> Bool)
-> (DataFlow -> DataFlow -> Bool)
-> (DataFlow -> DataFlow -> Bool)
-> (DataFlow -> DataFlow -> Bool)
-> (DataFlow -> DataFlow -> DataFlow)
-> (DataFlow -> DataFlow -> DataFlow)
-> Ord DataFlow
DataFlow -> DataFlow -> Bool
DataFlow -> DataFlow -> Ordering
DataFlow -> DataFlow -> DataFlow
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: DataFlow -> DataFlow -> Ordering
compare :: DataFlow -> DataFlow -> Ordering
$c< :: DataFlow -> DataFlow -> Bool
< :: DataFlow -> DataFlow -> Bool
$c<= :: DataFlow -> DataFlow -> Bool
<= :: DataFlow -> DataFlow -> Bool
$c> :: DataFlow -> DataFlow -> Bool
> :: DataFlow -> DataFlow -> Bool
$c>= :: DataFlow -> DataFlow -> Bool
>= :: DataFlow -> DataFlow -> Bool
$cmax :: DataFlow -> DataFlow -> DataFlow
max :: DataFlow -> DataFlow -> DataFlow
$cmin :: DataFlow -> DataFlow -> DataFlow
min :: DataFlow -> DataFlow -> DataFlow
Ord, Int -> DataFlow -> ShowS
[DataFlow] -> ShowS
DataFlow -> String
(Int -> DataFlow -> ShowS)
-> (DataFlow -> String) -> ([DataFlow] -> ShowS) -> Show DataFlow
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DataFlow -> ShowS
showsPrec :: Int -> DataFlow -> ShowS
$cshow :: DataFlow -> String
show :: DataFlow -> String
$cshowList :: [DataFlow] -> ShowS
showList :: [DataFlow] -> ShowS
Show)
data TimeoutExpired = Expired | Ticking
deriving (TimeoutExpired -> TimeoutExpired -> Bool
(TimeoutExpired -> TimeoutExpired -> Bool)
-> (TimeoutExpired -> TimeoutExpired -> Bool) -> Eq TimeoutExpired
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TimeoutExpired -> TimeoutExpired -> Bool
== :: TimeoutExpired -> TimeoutExpired -> Bool
$c/= :: TimeoutExpired -> TimeoutExpired -> Bool
/= :: TimeoutExpired -> TimeoutExpired -> Bool
Eq, Eq TimeoutExpired
Eq TimeoutExpired =>
(TimeoutExpired -> TimeoutExpired -> Ordering)
-> (TimeoutExpired -> TimeoutExpired -> Bool)
-> (TimeoutExpired -> TimeoutExpired -> Bool)
-> (TimeoutExpired -> TimeoutExpired -> Bool)
-> (TimeoutExpired -> TimeoutExpired -> Bool)
-> (TimeoutExpired -> TimeoutExpired -> TimeoutExpired)
-> (TimeoutExpired -> TimeoutExpired -> TimeoutExpired)
-> Ord TimeoutExpired
TimeoutExpired -> TimeoutExpired -> Bool
TimeoutExpired -> TimeoutExpired -> Ordering
TimeoutExpired -> TimeoutExpired -> TimeoutExpired
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: TimeoutExpired -> TimeoutExpired -> Ordering
compare :: TimeoutExpired -> TimeoutExpired -> Ordering
$c< :: TimeoutExpired -> TimeoutExpired -> Bool
< :: TimeoutExpired -> TimeoutExpired -> Bool
$c<= :: TimeoutExpired -> TimeoutExpired -> Bool
<= :: TimeoutExpired -> TimeoutExpired -> Bool
$c> :: TimeoutExpired -> TimeoutExpired -> Bool
> :: TimeoutExpired -> TimeoutExpired -> Bool
$c>= :: TimeoutExpired -> TimeoutExpired -> Bool
>= :: TimeoutExpired -> TimeoutExpired -> Bool
$cmax :: TimeoutExpired -> TimeoutExpired -> TimeoutExpired
max :: TimeoutExpired -> TimeoutExpired -> TimeoutExpired
$cmin :: TimeoutExpired -> TimeoutExpired -> TimeoutExpired
min :: TimeoutExpired -> TimeoutExpired -> TimeoutExpired
Ord, Int -> TimeoutExpired -> ShowS
[TimeoutExpired] -> ShowS
TimeoutExpired -> String
(Int -> TimeoutExpired -> ShowS)
-> (TimeoutExpired -> String)
-> ([TimeoutExpired] -> ShowS)
-> Show TimeoutExpired
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TimeoutExpired -> ShowS
showsPrec :: Int -> TimeoutExpired -> ShowS
$cshow :: TimeoutExpired -> String
show :: TimeoutExpired -> String
$cshowList :: [TimeoutExpired] -> ShowS
showList :: [TimeoutExpired] -> ShowS
Show)
data ConnectionType
= UnnegotiatedConn !Provenance
| InboundIdleConn !DataFlow
| OutboundIdleConn !DataFlow
| NegotiatedConn !Provenance !DataFlow
| DuplexConn
deriving (ConnectionType -> ConnectionType -> Bool
(ConnectionType -> ConnectionType -> Bool)
-> (ConnectionType -> ConnectionType -> Bool) -> Eq ConnectionType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ConnectionType -> ConnectionType -> Bool
== :: ConnectionType -> ConnectionType -> Bool
$c/= :: ConnectionType -> ConnectionType -> Bool
/= :: ConnectionType -> ConnectionType -> Bool
Eq, Eq ConnectionType
Eq ConnectionType =>
(ConnectionType -> ConnectionType -> Ordering)
-> (ConnectionType -> ConnectionType -> Bool)
-> (ConnectionType -> ConnectionType -> Bool)
-> (ConnectionType -> ConnectionType -> Bool)
-> (ConnectionType -> ConnectionType -> Bool)
-> (ConnectionType -> ConnectionType -> ConnectionType)
-> (ConnectionType -> ConnectionType -> ConnectionType)
-> Ord ConnectionType
ConnectionType -> ConnectionType -> Bool
ConnectionType -> ConnectionType -> Ordering
ConnectionType -> ConnectionType -> ConnectionType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ConnectionType -> ConnectionType -> Ordering
compare :: ConnectionType -> ConnectionType -> Ordering
$c< :: ConnectionType -> ConnectionType -> Bool
< :: ConnectionType -> ConnectionType -> Bool
$c<= :: ConnectionType -> ConnectionType -> Bool
<= :: ConnectionType -> ConnectionType -> Bool
$c> :: ConnectionType -> ConnectionType -> Bool
> :: ConnectionType -> ConnectionType -> Bool
$c>= :: ConnectionType -> ConnectionType -> Bool
>= :: ConnectionType -> ConnectionType -> Bool
$cmax :: ConnectionType -> ConnectionType -> ConnectionType
max :: ConnectionType -> ConnectionType -> ConnectionType
$cmin :: ConnectionType -> ConnectionType -> ConnectionType
min :: ConnectionType -> ConnectionType -> ConnectionType
Ord, Int -> ConnectionType -> ShowS
[ConnectionType] -> ShowS
ConnectionType -> String
(Int -> ConnectionType -> ShowS)
-> (ConnectionType -> String)
-> ([ConnectionType] -> ShowS)
-> Show ConnectionType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ConnectionType -> ShowS
showsPrec :: Int -> ConnectionType -> ShowS
$cshow :: ConnectionType -> String
show :: ConnectionType -> String
$cshowList :: [ConnectionType] -> ShowS
showList :: [ConnectionType] -> ShowS
Show)
data PromiseWriter m a = PromiseWriter {
forall (m :: * -> *) a. PromiseWriter m a -> a -> STM m ()
writePromise :: a -> STM m (),
forall (m :: * -> *) a. PromiseWriter m a -> a -> STM m ()
forcePromise :: a -> STM m ()
}
data PromiseWriterException = PromiseWriterBlocked
deriving (Int -> PromiseWriterException -> ShowS
[PromiseWriterException] -> ShowS
PromiseWriterException -> String
(Int -> PromiseWriterException -> ShowS)
-> (PromiseWriterException -> String)
-> ([PromiseWriterException] -> ShowS)
-> Show PromiseWriterException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PromiseWriterException -> ShowS
showsPrec :: Int -> PromiseWriterException -> ShowS
$cshow :: PromiseWriterException -> String
show :: PromiseWriterException -> String
$cshowList :: [PromiseWriterException] -> ShowS
showList :: [PromiseWriterException] -> ShowS
Show, Typeable)
instance Exception PromiseWriterException
newtype PromiseReader m a = PromiseReader {
forall (m :: * -> *) a. PromiseReader m a -> STM m a
readPromise :: STM m a
}
readPromiseIO :: MonadSTM m => PromiseReader m a -> m a
readPromiseIO :: forall (m :: * -> *) a. MonadSTM m => PromiseReader m a -> m a
readPromiseIO = STM m a -> m a
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m a -> m a)
-> (PromiseReader m a -> STM m a) -> PromiseReader m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PromiseReader m a -> STM m a
forall (m :: * -> *) a. PromiseReader m a -> STM m a
readPromise
newEmptyPromise :: forall m a.
( MonadSTM m
, MonadThrow (STM m) )
=> STM m (PromiseReader m a, PromiseWriter m a)
newEmptyPromise :: forall (m :: * -> *) a.
(MonadSTM m, MonadThrow (STM m)) =>
STM m (PromiseReader m a, PromiseWriter m a)
newEmptyPromise = do
(v :: StrictTMVar m a) <- STM m (StrictTMVar m a)
forall (m :: * -> *) a. MonadSTM m => STM m (StrictTMVar m a)
newEmptyTMVar
let reader = PromiseReader { readPromise :: STM m a
readPromise = StrictTMVar m a -> STM m a
forall (m :: * -> *) a. MonadSTM m => StrictTMVar m a -> STM m a
readTMVar StrictTMVar m a
v }
writer = PromiseWriter {
writePromise :: a -> STM m ()
writePromise = \a
a -> do
r <- StrictTMVar m a -> a -> STM m Bool
forall (m :: * -> *) a.
MonadSTM m =>
StrictTMVar m a -> a -> STM m Bool
tryPutTMVar StrictTMVar m a
v a
a
unless r
(throwSTM PromiseWriterBlocked),
forcePromise :: a -> STM m ()
forcePromise = \a
a -> StrictTMVar m a -> a -> STM m ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTMVar m a -> a -> STM m ()
putTMVar StrictTMVar m a
v a
a
STM m () -> STM m () -> STM m ()
forall a. STM m a -> STM m a -> STM m a
forall (m :: * -> *) a. MonadSTM m => STM m a -> STM m a -> STM m a
`orElse` STM m a -> STM m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (StrictTMVar m a -> a -> STM m a
forall (m :: * -> *) a.
MonadSTM m =>
StrictTMVar m a -> a -> STM m a
swapTMVar StrictTMVar m a
v a
a)
}
pure (reader, writer)
newEmptyPromiseIO :: ( MonadSTM m
, MonadThrow (STM m) )
=> m (PromiseReader m a, PromiseWriter m a)
newEmptyPromiseIO :: forall (m :: * -> *) a.
(MonadSTM m, MonadThrow (STM m)) =>
m (PromiseReader m a, PromiseWriter m a)
newEmptyPromiseIO = STM m (PromiseReader m a, PromiseWriter m a)
-> m (PromiseReader m a, PromiseWriter m a)
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically STM m (PromiseReader m a, PromiseWriter m a)
forall (m :: * -> *) a.
(MonadSTM m, MonadThrow (STM m)) =>
STM m (PromiseReader m a, PromiseWriter m a)
newEmptyPromise
newtype MaskedAction m a = MaskedAction {
forall (m :: * -> *) a.
MaskedAction m a -> (forall x. m x -> m x) -> m a
runWithUnmask :: (forall x. m x -> m x) -> m a
}
type ConnectionHandlerFn handlerTrace socket peerAddr handle handleError version m
= socket
-> PromiseWriter m (Either handleError (HandshakeConnectionResult handle version))
-> Tracer m handlerTrace
-> ConnectionId peerAddr
-> (DiffTime -> socket -> m (Mux.Bearer m))
-> MaskedAction m ()
data HandshakeConnectionResult handle version
= HandshakeConnectionQuery
| HandshakeConnectionResult handle version
newtype ConnectionHandler muxMode handlerTrace socket peerAddr handle handleError version m =
ConnectionHandler {
forall (muxMode :: Mode) handlerTrace socket peerAddr handle
handleError version (m :: * -> *).
ConnectionHandler
muxMode handlerTrace socket peerAddr handle handleError version m
-> WithMuxTuple
muxMode
(ConnectionHandlerFn
handlerTrace socket peerAddr handle handleError version m)
connectionHandler ::
WithMuxTuple muxMode
(ConnectionHandlerFn handlerTrace socket peerAddr handle handleError version m)
}
data Inactive =
Active MiniProtocolDir
| Inactive
deriving (Inactive -> Inactive -> Bool
(Inactive -> Inactive -> Bool)
-> (Inactive -> Inactive -> Bool) -> Eq Inactive
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Inactive -> Inactive -> Bool
== :: Inactive -> Inactive -> Bool
$c/= :: Inactive -> Inactive -> Bool
/= :: Inactive -> Inactive -> Bool
Eq, Int -> Inactive -> ShowS
[Inactive] -> ShowS
Inactive -> String
(Int -> Inactive -> ShowS)
-> (Inactive -> String) -> ([Inactive] -> ShowS) -> Show Inactive
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Inactive -> ShowS
showsPrec :: Int -> Inactive -> ShowS
$cshow :: Inactive -> String
show :: Inactive -> String
$cshowList :: [Inactive] -> ShowS
showList :: [Inactive] -> ShowS
Show)
data ExceptionInHandler where
ExceptionInHandler :: forall peerAddr.
(Typeable peerAddr, Show peerAddr)
=> !peerAddr
-> !SomeException
-> ExceptionInHandler
deriving Typeable
instance Show ExceptionInHandler where
show :: ExceptionInHandler -> String
show (ExceptionInHandler peerAddr
peerAddr SomeException
e) = String
"ExceptionInHandler "
String -> ShowS
forall a. [a] -> [a] -> [a]
++ peerAddr -> String
forall a. Show a => a -> String
show peerAddr
peerAddr
String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" "
String -> ShowS
forall a. [a] -> [a] -> [a]
++ SomeException -> String
forall a. Show a => a -> String
show SomeException
e
instance Exception ExceptionInHandler
data HandleErrorType =
HandshakeFailure
| HandshakeProtocolViolation
type PrunePolicy peerAddr = StdGen
-> Map peerAddr ConnectionType
-> Int
-> Set peerAddr
simplePrunePolicy :: Ord peerAddr
=> PrunePolicy peerAddr
simplePrunePolicy :: forall peerAddr. Ord peerAddr => PrunePolicy peerAddr
simplePrunePolicy StdGen
_ Map peerAddr ConnectionType
m Int
n =
[peerAddr] -> Set peerAddr
forall a. Ord a => [a] -> Set a
Set.fromList
([peerAddr] -> Set peerAddr)
-> (Map peerAddr ConnectionType -> [peerAddr])
-> Map peerAddr ConnectionType
-> Set peerAddr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((peerAddr, ConnectionType) -> peerAddr)
-> [(peerAddr, ConnectionType)] -> [peerAddr]
forall a b. (a -> b) -> [a] -> [b]
map (peerAddr, ConnectionType) -> peerAddr
forall a b. (a, b) -> a
fst
([(peerAddr, ConnectionType)] -> [peerAddr])
-> (Map peerAddr ConnectionType -> [(peerAddr, ConnectionType)])
-> Map peerAddr ConnectionType
-> [peerAddr]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [(peerAddr, ConnectionType)] -> [(peerAddr, ConnectionType)]
forall a. Int -> [a] -> [a]
take Int
n
([(peerAddr, ConnectionType)] -> [(peerAddr, ConnectionType)])
-> (Map peerAddr ConnectionType -> [(peerAddr, ConnectionType)])
-> Map peerAddr ConnectionType
-> [(peerAddr, ConnectionType)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((peerAddr, ConnectionType) -> ConnectionType)
-> [(peerAddr, ConnectionType)] -> [(peerAddr, ConnectionType)]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn (peerAddr, ConnectionType) -> ConnectionType
forall a b. (a, b) -> b
snd
([(peerAddr, ConnectionType)] -> [(peerAddr, ConnectionType)])
-> (Map peerAddr ConnectionType -> [(peerAddr, ConnectionType)])
-> Map peerAddr ConnectionType
-> [(peerAddr, ConnectionType)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map peerAddr ConnectionType -> [(peerAddr, ConnectionType)]
forall k a. Map k a -> [(k, a)]
Map.toList
(Map peerAddr ConnectionType -> Set peerAddr)
-> Map peerAddr ConnectionType -> Set peerAddr
forall a b. (a -> b) -> a -> b
$ Map peerAddr ConnectionType
m
data OperationResult a
= UnsupportedState !AbstractState
| OperationSuccess !a
| TerminatedConnection !AbstractState
deriving (Int -> OperationResult a -> ShowS
[OperationResult a] -> ShowS
OperationResult a -> String
(Int -> OperationResult a -> ShowS)
-> (OperationResult a -> String)
-> ([OperationResult a] -> ShowS)
-> Show (OperationResult a)
forall a. Show a => Int -> OperationResult a -> ShowS
forall a. Show a => [OperationResult a] -> ShowS
forall a. Show a => OperationResult a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> OperationResult a -> ShowS
showsPrec :: Int -> OperationResult a -> ShowS
$cshow :: forall a. Show a => OperationResult a -> String
show :: OperationResult a -> String
$cshowList :: forall a. Show a => [OperationResult a] -> ShowS
showList :: [OperationResult a] -> ShowS
Show, (forall a b. (a -> b) -> OperationResult a -> OperationResult b)
-> (forall a b. a -> OperationResult b -> OperationResult a)
-> Functor OperationResult
forall a b. a -> OperationResult b -> OperationResult a
forall a b. (a -> b) -> OperationResult a -> OperationResult 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) -> OperationResult a -> OperationResult b
fmap :: forall a b. (a -> b) -> OperationResult a -> OperationResult b
$c<$ :: forall a b. a -> OperationResult b -> OperationResult a
<$ :: forall a b. a -> OperationResult b -> OperationResult a
Functor)
resultInState :: OperationResult AbstractState -> AbstractState
resultInState :: OperationResult AbstractState -> AbstractState
resultInState (UnsupportedState AbstractState
st) = AbstractState
st
resultInState (OperationSuccess AbstractState
st) = AbstractState
st
resultInState (TerminatedConnection AbstractState
st) = AbstractState
st
data DemotedToColdRemoteTr =
CommitTr
| KeepTr
deriving Int -> DemotedToColdRemoteTr -> ShowS
[DemotedToColdRemoteTr] -> ShowS
DemotedToColdRemoteTr -> String
(Int -> DemotedToColdRemoteTr -> ShowS)
-> (DemotedToColdRemoteTr -> String)
-> ([DemotedToColdRemoteTr] -> ShowS)
-> Show DemotedToColdRemoteTr
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DemotedToColdRemoteTr -> ShowS
showsPrec :: Int -> DemotedToColdRemoteTr -> ShowS
$cshow :: DemotedToColdRemoteTr -> String
show :: DemotedToColdRemoteTr -> String
$cshowList :: [DemotedToColdRemoteTr] -> ShowS
showList :: [DemotedToColdRemoteTr] -> ShowS
Show
data Connected peerAddr handle handleError =
Connected !(ConnectionId peerAddr) !DataFlow !handle
| Disconnected !(ConnectionId peerAddr) !(Maybe handleError)
type AcquireOutboundConnection peerAddr handle handleError m
= peerAddr -> m (Connected peerAddr handle handleError)
type IncludeInboundConnection socket peerAddr handle handleError m
= Word32
-> socket -> peerAddr -> m (Connected peerAddr handle handleError)
data OutboundConnectionManager (muxMode :: Mux.Mode) socket peerAddr handle handleError m where
OutboundConnectionManager
:: HasInitiator muxMode ~ True
=> { forall (muxMode :: Mode) peerAddr handle handleError (m :: * -> *)
socket.
OutboundConnectionManager
muxMode socket peerAddr handle handleError m
-> AcquireOutboundConnection peerAddr handle handleError m
ocmAcquireConnection :: AcquireOutboundConnection peerAddr handle handleError m
, forall (muxMode :: Mode) peerAddr handle handleError (m :: * -> *)
socket.
OutboundConnectionManager
muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState)
ocmReleaseConnection :: peerAddr -> m (OperationResult AbstractState)
}
-> OutboundConnectionManager muxMode socket peerAddr handle handleError m
data InboundConnectionManager (muxMode :: Mux.Mode) socket peerAddr handle handleError m where
InboundConnectionManager
:: HasResponder muxMode ~ True
=> { forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> IncludeInboundConnection socket peerAddr handle handleError m
icmIncludeConnection :: IncludeInboundConnection socket peerAddr handle handleError m
, forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult DemotedToColdRemoteTr)
icmReleaseConnection :: peerAddr -> m (OperationResult DemotedToColdRemoteTr)
, forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState)
icmPromotedToWarmRemote :: peerAddr -> m (OperationResult AbstractState)
, forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState)
icmDemotedToColdRemote
:: peerAddr -> m (OperationResult AbstractState)
, forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> STM m Int
icmNumberOfConnections :: STM m Int
}
-> InboundConnectionManager muxMode socket peerAddr handle handleError m
data ConnectionManager (muxMode :: Mux.Mode) socket peerAddr handle handleError m =
ConnectionManager {
forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
getConnectionManager
:: WithMuxMode
muxMode
(OutboundConnectionManager muxMode socket peerAddr handle handleError m)
(InboundConnectionManager muxMode socket peerAddr handle handleError m),
forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
ConnectionManager muxMode socket peerAddr handle handleError m
-> STM m (Map peerAddr AbstractState)
readState
:: STM m (Map peerAddr AbstractState),
forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
ConnectionManager muxMode socket peerAddr handle handleError m
-> peerAddr -> STM m ()
waitForOutboundDemotion
:: peerAddr
-> STM m ()
}
acquireOutboundConnection
:: HasInitiator muxMode ~ True
=> ConnectionManager muxMode socket peerAddr handle handleError m
-> AcquireOutboundConnection peerAddr handle handleError m
acquireOutboundConnection :: forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
(HasInitiator muxMode ~ 'True) =>
ConnectionManager muxMode socket peerAddr handle handleError m
-> AcquireOutboundConnection peerAddr handle handleError m
acquireOutboundConnection =
OutboundConnectionManager
muxMode socket peerAddr handle handleError m
-> AcquireOutboundConnection peerAddr handle handleError m
forall (muxMode :: Mode) peerAddr handle handleError (m :: * -> *)
socket.
OutboundConnectionManager
muxMode socket peerAddr handle handleError m
-> AcquireOutboundConnection peerAddr handle handleError m
ocmAcquireConnection (OutboundConnectionManager
muxMode socket peerAddr handle handleError m
-> AcquireOutboundConnection peerAddr handle handleError m)
-> (ConnectionManager muxMode socket peerAddr handle handleError m
-> OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> ConnectionManager muxMode socket peerAddr handle handleError m
-> AcquireOutboundConnection peerAddr handle handleError m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> OutboundConnectionManager
muxMode socket peerAddr handle handleError m
forall (mode :: Mode) a b.
(HasInitiator mode ~ 'True) =>
WithMuxMode mode a b -> a
withInitiatorMode (WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> (ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m))
-> ConnectionManager muxMode socket peerAddr handle handleError m
-> OutboundConnectionManager
muxMode socket peerAddr handle handleError m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
getConnectionManager
releaseOutboundConnection
:: HasInitiator muxMode ~ True
=> ConnectionManager muxMode socket peerAddr handle handleError m
-> peerAddr
-> m (OperationResult AbstractState)
releaseOutboundConnection :: forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
(HasInitiator muxMode ~ 'True) =>
ConnectionManager muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState)
releaseOutboundConnection =
OutboundConnectionManager
muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState)
forall (muxMode :: Mode) peerAddr handle handleError (m :: * -> *)
socket.
OutboundConnectionManager
muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState)
ocmReleaseConnection (OutboundConnectionManager
muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState))
-> (ConnectionManager muxMode socket peerAddr handle handleError m
-> OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> ConnectionManager muxMode socket peerAddr handle handleError m
-> peerAddr
-> m (OperationResult AbstractState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> OutboundConnectionManager
muxMode socket peerAddr handle handleError m
forall (mode :: Mode) a b.
(HasInitiator mode ~ 'True) =>
WithMuxMode mode a b -> a
withInitiatorMode (WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> (ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m))
-> ConnectionManager muxMode socket peerAddr handle handleError m
-> OutboundConnectionManager
muxMode socket peerAddr handle handleError m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
getConnectionManager
promotedToWarmRemote
:: HasResponder muxMode ~ True
=> ConnectionManager muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState)
promotedToWarmRemote :: forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
(HasResponder muxMode ~ 'True) =>
ConnectionManager muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState)
promotedToWarmRemote =
InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState)
forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState)
icmPromotedToWarmRemote (InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState))
-> (ConnectionManager muxMode socket peerAddr handle handleError m
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> ConnectionManager muxMode socket peerAddr handle handleError m
-> peerAddr
-> m (OperationResult AbstractState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m
forall (mode :: Mode) a b.
(HasResponder mode ~ 'True) =>
WithMuxMode mode a b -> b
withResponderMode (WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> (ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m))
-> ConnectionManager muxMode socket peerAddr handle handleError m
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
getConnectionManager
demotedToColdRemote
:: HasResponder muxMode ~ True
=> ConnectionManager muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState)
demotedToColdRemote :: forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
(HasResponder muxMode ~ 'True) =>
ConnectionManager muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState)
demotedToColdRemote =
InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState)
forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState)
icmDemotedToColdRemote (InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult AbstractState))
-> (ConnectionManager muxMode socket peerAddr handle handleError m
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> ConnectionManager muxMode socket peerAddr handle handleError m
-> peerAddr
-> m (OperationResult AbstractState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m
forall (mode :: Mode) a b.
(HasResponder mode ~ 'True) =>
WithMuxMode mode a b -> b
withResponderMode (WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> (ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m))
-> ConnectionManager muxMode socket peerAddr handle handleError m
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
getConnectionManager
includeInboundConnection
:: HasResponder muxMode ~ True
=> ConnectionManager muxMode socket peerAddr handle handleError m
-> IncludeInboundConnection socket peerAddr handle handleError m
includeInboundConnection :: forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
(HasResponder muxMode ~ 'True) =>
ConnectionManager muxMode socket peerAddr handle handleError m
-> IncludeInboundConnection socket peerAddr handle handleError m
includeInboundConnection =
InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> IncludeInboundConnection socket peerAddr handle handleError m
forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> IncludeInboundConnection socket peerAddr handle handleError m
icmIncludeConnection (InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> IncludeInboundConnection socket peerAddr handle handleError m)
-> (ConnectionManager muxMode socket peerAddr handle handleError m
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> ConnectionManager muxMode socket peerAddr handle handleError m
-> IncludeInboundConnection socket peerAddr handle handleError m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m
forall (mode :: Mode) a b.
(HasResponder mode ~ 'True) =>
WithMuxMode mode a b -> b
withResponderMode (WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> (ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m))
-> ConnectionManager muxMode socket peerAddr handle handleError m
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
getConnectionManager
releaseInboundConnection
:: HasResponder muxMode ~ True
=> ConnectionManager muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult DemotedToColdRemoteTr)
releaseInboundConnection :: forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
(HasResponder muxMode ~ 'True) =>
ConnectionManager muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult DemotedToColdRemoteTr)
releaseInboundConnection =
InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult DemotedToColdRemoteTr)
forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult DemotedToColdRemoteTr)
icmReleaseConnection (InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> peerAddr -> m (OperationResult DemotedToColdRemoteTr))
-> (ConnectionManager muxMode socket peerAddr handle handleError m
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> ConnectionManager muxMode socket peerAddr handle handleError m
-> peerAddr
-> m (OperationResult DemotedToColdRemoteTr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m
forall (mode :: Mode) a b.
(HasResponder mode ~ 'True) =>
WithMuxMode mode a b -> b
withResponderMode (WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> (ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m))
-> ConnectionManager muxMode socket peerAddr handle handleError m
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
getConnectionManager
numberOfConnections
:: HasResponder muxMode ~ True
=> ConnectionManager muxMode socket peerAddr handle handleError m
-> STM m Int
numberOfConnections :: forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
(HasResponder muxMode ~ 'True) =>
ConnectionManager muxMode socket peerAddr handle handleError m
-> STM m Int
numberOfConnections =
InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> STM m Int
forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> STM m Int
icmNumberOfConnections (InboundConnectionManager
muxMode socket peerAddr handle handleError m
-> STM m Int)
-> (ConnectionManager muxMode socket peerAddr handle handleError m
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> ConnectionManager muxMode socket peerAddr handle handleError m
-> STM m Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m
forall (mode :: Mode) a b.
(HasResponder mode ~ 'True) =>
WithMuxMode mode a b -> b
withResponderMode (WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m)
-> (ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m))
-> ConnectionManager muxMode socket peerAddr handle handleError m
-> InboundConnectionManager
muxMode socket peerAddr handle handleError m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
forall (muxMode :: Mode) socket peerAddr handle handleError
(m :: * -> *).
ConnectionManager muxMode socket peerAddr handle handleError m
-> WithMuxMode
muxMode
(OutboundConnectionManager
muxMode socket peerAddr handle handleError m)
(InboundConnectionManager
muxMode socket peerAddr handle handleError m)
getConnectionManager
data AbstractState =
UnknownConnectionSt
| ReservedOutboundSt
| UnnegotiatedSt !Provenance
| InboundIdleSt !DataFlow
| InboundSt !DataFlow
| OutboundUniSt
| OutboundDupSt !TimeoutExpired
| OutboundIdleSt !DataFlow
| DuplexSt
| WaitRemoteIdleSt
| TerminatingSt
| TerminatedSt
deriving (AbstractState -> AbstractState -> Bool
(AbstractState -> AbstractState -> Bool)
-> (AbstractState -> AbstractState -> Bool) -> Eq AbstractState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AbstractState -> AbstractState -> Bool
== :: AbstractState -> AbstractState -> Bool
$c/= :: AbstractState -> AbstractState -> Bool
/= :: AbstractState -> AbstractState -> Bool
Eq, Eq AbstractState
Eq AbstractState =>
(AbstractState -> AbstractState -> Ordering)
-> (AbstractState -> AbstractState -> Bool)
-> (AbstractState -> AbstractState -> Bool)
-> (AbstractState -> AbstractState -> Bool)
-> (AbstractState -> AbstractState -> Bool)
-> (AbstractState -> AbstractState -> AbstractState)
-> (AbstractState -> AbstractState -> AbstractState)
-> Ord AbstractState
AbstractState -> AbstractState -> Bool
AbstractState -> AbstractState -> Ordering
AbstractState -> AbstractState -> AbstractState
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: AbstractState -> AbstractState -> Ordering
compare :: AbstractState -> AbstractState -> Ordering
$c< :: AbstractState -> AbstractState -> Bool
< :: AbstractState -> AbstractState -> Bool
$c<= :: AbstractState -> AbstractState -> Bool
<= :: AbstractState -> AbstractState -> Bool
$c> :: AbstractState -> AbstractState -> Bool
> :: AbstractState -> AbstractState -> Bool
$c>= :: AbstractState -> AbstractState -> Bool
>= :: AbstractState -> AbstractState -> Bool
$cmax :: AbstractState -> AbstractState -> AbstractState
max :: AbstractState -> AbstractState -> AbstractState
$cmin :: AbstractState -> AbstractState -> AbstractState
min :: AbstractState -> AbstractState -> AbstractState
Ord, Int -> AbstractState -> ShowS
[AbstractState] -> ShowS
AbstractState -> String
(Int -> AbstractState -> ShowS)
-> (AbstractState -> String)
-> ([AbstractState] -> ShowS)
-> Show AbstractState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AbstractState -> ShowS
showsPrec :: Int -> AbstractState -> ShowS
$cshow :: AbstractState -> String
show :: AbstractState -> String
$cshowList :: [AbstractState] -> ShowS
showList :: [AbstractState] -> ShowS
Show, Typeable)
data ConnectionManagerCounters = ConnectionManagerCounters {
ConnectionManagerCounters -> Int
fullDuplexConns :: !Int,
ConnectionManagerCounters -> Int
duplexConns :: !Int,
ConnectionManagerCounters -> Int
unidirectionalConns :: !Int,
ConnectionManagerCounters -> Int
inboundConns :: !Int,
ConnectionManagerCounters -> Int
outboundConns :: !Int
}
deriving (Int -> ConnectionManagerCounters -> ShowS
[ConnectionManagerCounters] -> ShowS
ConnectionManagerCounters -> String
(Int -> ConnectionManagerCounters -> ShowS)
-> (ConnectionManagerCounters -> String)
-> ([ConnectionManagerCounters] -> ShowS)
-> Show ConnectionManagerCounters
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ConnectionManagerCounters -> ShowS
showsPrec :: Int -> ConnectionManagerCounters -> ShowS
$cshow :: ConnectionManagerCounters -> String
show :: ConnectionManagerCounters -> String
$cshowList :: [ConnectionManagerCounters] -> ShowS
showList :: [ConnectionManagerCounters] -> ShowS
Show, ConnectionManagerCounters -> ConnectionManagerCounters -> Bool
(ConnectionManagerCounters -> ConnectionManagerCounters -> Bool)
-> (ConnectionManagerCounters -> ConnectionManagerCounters -> Bool)
-> Eq ConnectionManagerCounters
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ConnectionManagerCounters -> ConnectionManagerCounters -> Bool
== :: ConnectionManagerCounters -> ConnectionManagerCounters -> Bool
$c/= :: ConnectionManagerCounters -> ConnectionManagerCounters -> Bool
/= :: ConnectionManagerCounters -> ConnectionManagerCounters -> Bool
Eq, Eq ConnectionManagerCounters
Eq ConnectionManagerCounters =>
(ConnectionManagerCounters
-> ConnectionManagerCounters -> Ordering)
-> (ConnectionManagerCounters -> ConnectionManagerCounters -> Bool)
-> (ConnectionManagerCounters -> ConnectionManagerCounters -> Bool)
-> (ConnectionManagerCounters -> ConnectionManagerCounters -> Bool)
-> (ConnectionManagerCounters -> ConnectionManagerCounters -> Bool)
-> (ConnectionManagerCounters
-> ConnectionManagerCounters -> ConnectionManagerCounters)
-> (ConnectionManagerCounters
-> ConnectionManagerCounters -> ConnectionManagerCounters)
-> Ord ConnectionManagerCounters
ConnectionManagerCounters -> ConnectionManagerCounters -> Bool
ConnectionManagerCounters -> ConnectionManagerCounters -> Ordering
ConnectionManagerCounters
-> ConnectionManagerCounters -> ConnectionManagerCounters
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ConnectionManagerCounters -> ConnectionManagerCounters -> Ordering
compare :: ConnectionManagerCounters -> ConnectionManagerCounters -> Ordering
$c< :: ConnectionManagerCounters -> ConnectionManagerCounters -> Bool
< :: ConnectionManagerCounters -> ConnectionManagerCounters -> Bool
$c<= :: ConnectionManagerCounters -> ConnectionManagerCounters -> Bool
<= :: ConnectionManagerCounters -> ConnectionManagerCounters -> Bool
$c> :: ConnectionManagerCounters -> ConnectionManagerCounters -> Bool
> :: ConnectionManagerCounters -> ConnectionManagerCounters -> Bool
$c>= :: ConnectionManagerCounters -> ConnectionManagerCounters -> Bool
>= :: ConnectionManagerCounters -> ConnectionManagerCounters -> Bool
$cmax :: ConnectionManagerCounters
-> ConnectionManagerCounters -> ConnectionManagerCounters
max :: ConnectionManagerCounters
-> ConnectionManagerCounters -> ConnectionManagerCounters
$cmin :: ConnectionManagerCounters
-> ConnectionManagerCounters -> ConnectionManagerCounters
min :: ConnectionManagerCounters
-> ConnectionManagerCounters -> ConnectionManagerCounters
Ord)
instance Semigroup ConnectionManagerCounters where
ConnectionManagerCounters Int
fd1 Int
d1 Int
s1 Int
i1 Int
o1 <> :: ConnectionManagerCounters
-> ConnectionManagerCounters -> ConnectionManagerCounters
<> ConnectionManagerCounters Int
fd2 Int
d2 Int
s2 Int
i2 Int
o2 =
Int -> Int -> Int -> Int -> Int -> ConnectionManagerCounters
ConnectionManagerCounters (Int
fd1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
fd2) (Int
d1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
d2) (Int
s1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
s2) (Int
i1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i2) (Int
o1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o2)
instance Monoid ConnectionManagerCounters where
mempty :: ConnectionManagerCounters
mempty = Int -> Int -> Int -> Int -> Int -> ConnectionManagerCounters
ConnectionManagerCounters Int
0 Int
0 Int
0 Int
0 Int
0
data ConnectionManagerError peerAddr
= ConnectionExists !Provenance !peerAddr !CallStack
| ForbiddenConnection !(ConnectionId peerAddr) !CallStack
| ImpossibleConnection !(ConnectionId peerAddr) !CallStack
| ConnectionTerminating !(ConnectionId peerAddr) !CallStack
| ConnectionTerminated !peerAddr !CallStack
| ImpossibleState !peerAddr !CallStack
| ForbiddenOperation !peerAddr !AbstractState !CallStack
| UnknownPeer !peerAddr !CallStack
deriving (Int -> ConnectionManagerError peerAddr -> ShowS
[ConnectionManagerError peerAddr] -> ShowS
ConnectionManagerError peerAddr -> String
(Int -> ConnectionManagerError peerAddr -> ShowS)
-> (ConnectionManagerError peerAddr -> String)
-> ([ConnectionManagerError peerAddr] -> ShowS)
-> Show (ConnectionManagerError peerAddr)
forall peerAddr.
Show peerAddr =>
Int -> ConnectionManagerError peerAddr -> ShowS
forall peerAddr.
Show peerAddr =>
[ConnectionManagerError peerAddr] -> ShowS
forall peerAddr.
Show peerAddr =>
ConnectionManagerError peerAddr -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall peerAddr.
Show peerAddr =>
Int -> ConnectionManagerError peerAddr -> ShowS
showsPrec :: Int -> ConnectionManagerError peerAddr -> ShowS
$cshow :: forall peerAddr.
Show peerAddr =>
ConnectionManagerError peerAddr -> String
show :: ConnectionManagerError peerAddr -> String
$cshowList :: forall peerAddr.
Show peerAddr =>
[ConnectionManagerError peerAddr] -> ShowS
showList :: [ConnectionManagerError peerAddr] -> ShowS
Show, Typeable)
instance ( Show peerAddr
, Typeable peerAddr ) => Exception (ConnectionManagerError peerAddr) where
toException :: ConnectionManagerError peerAddr -> SomeException
toException = ConnectionManagerError peerAddr -> SomeException
forall addr.
(Typeable addr, Show addr) =>
ConnectionManagerError addr -> SomeException
connectionManagerErrorToException
fromException :: SomeException -> Maybe (ConnectionManagerError peerAddr)
fromException = SomeException -> Maybe (ConnectionManagerError peerAddr)
forall addr.
(Typeable addr, Show addr) =>
SomeException -> Maybe (ConnectionManagerError addr)
connectionManagerErrorFromException
displayException :: ConnectionManagerError peerAddr -> String
displayException (ConnectionExists Provenance
provenance peerAddr
peerAddr CallStack
cs) =
[String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ String
"Connection already exists with peer "
, Provenance -> String
forall a. Show a => a -> String
show Provenance
provenance
, String
" "
, peerAddr -> String
forall a. Show a => a -> String
show peerAddr
peerAddr
, String
"\n"
, CallStack -> String
prettyCallStack CallStack
cs
]
displayException (ForbiddenConnection ConnectionId peerAddr
connId CallStack
cs) =
[String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ String
"Forbidden to reuse a connection (UnidirectionalDataFlow) with peer "
, ConnectionId peerAddr -> String
forall a. Show a => a -> String
show ConnectionId peerAddr
connId
, String
"\n"
, CallStack -> String
prettyCallStack CallStack
cs
]
displayException (ImpossibleConnection ConnectionId peerAddr
connId CallStack
cs) =
[String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ String
"Impossible connection with peer "
, ConnectionId peerAddr -> String
forall a. Show a => a -> String
show ConnectionId peerAddr
connId
, String
"\n"
, CallStack -> String
prettyCallStack CallStack
cs
]
displayException (ConnectionTerminating ConnectionId peerAddr
connId CallStack
cs) =
[String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ String
"Connection terminating "
, ConnectionId peerAddr -> String
forall a. Show a => a -> String
show ConnectionId peerAddr
connId
, String
"\n"
, CallStack -> String
prettyCallStack CallStack
cs
]
displayException (ConnectionTerminated peerAddr
peerAddr CallStack
cs) =
[String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ String
"Connection terminated "
, peerAddr -> String
forall a. Show a => a -> String
show peerAddr
peerAddr
, String
"\n"
, CallStack -> String
prettyCallStack CallStack
cs
]
displayException (ImpossibleState peerAddr
peerAddr CallStack
cs) =
[String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ String
"Imposible connection state for peer "
, peerAddr -> String
forall a. Show a => a -> String
show peerAddr
peerAddr
, String
"\n"
, CallStack -> String
prettyCallStack CallStack
cs
]
displayException (ForbiddenOperation peerAddr
peerAddr AbstractState
reason CallStack
cs) =
[String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ String
"Forbidden operation "
, peerAddr -> String
forall a. Show a => a -> String
show peerAddr
peerAddr
, String
" "
, AbstractState -> String
forall a. Show a => a -> String
show AbstractState
reason
, String
"\n"
, CallStack -> String
prettyCallStack CallStack
cs
]
displayException (UnknownPeer peerAddr
peerAddr CallStack
cs) =
[String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ String
"UnknownPeer "
, peerAddr -> String
forall a. Show a => a -> String
show peerAddr
peerAddr
, String
"\n"
, CallStack -> String
prettyCallStack CallStack
cs
]
data SomeConnectionManagerError =
forall addr. ( Typeable addr
, Show addr
)
=> SomeConnectionManagerError !(ConnectionManagerError addr)
instance Show SomeConnectionManagerError where
show :: SomeConnectionManagerError -> String
show (SomeConnectionManagerError ConnectionManagerError addr
e) = ConnectionManagerError addr -> String
forall a. Show a => a -> String
show ConnectionManagerError addr
e
instance Exception SomeConnectionManagerError where
displayException :: SomeConnectionManagerError -> String
displayException (SomeConnectionManagerError ConnectionManagerError addr
e) = ConnectionManagerError addr -> String
forall e. Exception e => e -> String
displayException ConnectionManagerError addr
e
connectionManagerErrorToException :: (Typeable addr, Show addr)
=> ConnectionManagerError addr
-> SomeException
connectionManagerErrorToException :: forall addr.
(Typeable addr, Show addr) =>
ConnectionManagerError addr -> SomeException
connectionManagerErrorToException = SomeConnectionManagerError -> SomeException
forall e. Exception e => e -> SomeException
toException (SomeConnectionManagerError -> SomeException)
-> (ConnectionManagerError addr -> SomeConnectionManagerError)
-> ConnectionManagerError addr
-> SomeException
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConnectionManagerError addr -> SomeConnectionManagerError
forall addr.
(Typeable addr, Show addr) =>
ConnectionManagerError addr -> SomeConnectionManagerError
SomeConnectionManagerError
connectionManagerErrorFromException :: (Typeable addr, Show addr)
=> SomeException
-> Maybe (ConnectionManagerError addr)
connectionManagerErrorFromException :: forall addr.
(Typeable addr, Show addr) =>
SomeException -> Maybe (ConnectionManagerError addr)
connectionManagerErrorFromException SomeException
x = do
SomeConnectionManagerError a <- SomeException -> Maybe SomeConnectionManagerError
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
x
cast a
data AssertionLocation peerAddr
= ReleaseInboundConnection !(Maybe (ConnectionId peerAddr)) !AbstractState
| AcquireOutboundConnection !(Maybe (ConnectionId peerAddr)) !AbstractState
| ReleaseOutboundConnection !(Maybe (ConnectionId peerAddr)) !AbstractState
| PromotedToWarmRemote !(Maybe (ConnectionId peerAddr)) !AbstractState
| DemotedToColdRemote !(Maybe (ConnectionId peerAddr)) !AbstractState
deriving Int -> AssertionLocation peerAddr -> ShowS
[AssertionLocation peerAddr] -> ShowS
AssertionLocation peerAddr -> String
(Int -> AssertionLocation peerAddr -> ShowS)
-> (AssertionLocation peerAddr -> String)
-> ([AssertionLocation peerAddr] -> ShowS)
-> Show (AssertionLocation peerAddr)
forall peerAddr.
Show peerAddr =>
Int -> AssertionLocation peerAddr -> ShowS
forall peerAddr.
Show peerAddr =>
[AssertionLocation peerAddr] -> ShowS
forall peerAddr.
Show peerAddr =>
AssertionLocation peerAddr -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall peerAddr.
Show peerAddr =>
Int -> AssertionLocation peerAddr -> ShowS
showsPrec :: Int -> AssertionLocation peerAddr -> ShowS
$cshow :: forall peerAddr.
Show peerAddr =>
AssertionLocation peerAddr -> String
show :: AssertionLocation peerAddr -> String
$cshowList :: forall peerAddr.
Show peerAddr =>
[AssertionLocation peerAddr] -> ShowS
showList :: [AssertionLocation peerAddr] -> ShowS
Show
data MaybeUnknown state
= Known !state
| Race !state
| Unknown
deriving (Int -> MaybeUnknown state -> ShowS
[MaybeUnknown state] -> ShowS
MaybeUnknown state -> String
(Int -> MaybeUnknown state -> ShowS)
-> (MaybeUnknown state -> String)
-> ([MaybeUnknown state] -> ShowS)
-> Show (MaybeUnknown state)
forall state. Show state => Int -> MaybeUnknown state -> ShowS
forall state. Show state => [MaybeUnknown state] -> ShowS
forall state. Show state => MaybeUnknown state -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall state. Show state => Int -> MaybeUnknown state -> ShowS
showsPrec :: Int -> MaybeUnknown state -> ShowS
$cshow :: forall state. Show state => MaybeUnknown state -> String
show :: MaybeUnknown state -> String
$cshowList :: forall state. Show state => [MaybeUnknown state] -> ShowS
showList :: [MaybeUnknown state] -> ShowS
Show, (forall a b. (a -> b) -> MaybeUnknown a -> MaybeUnknown b)
-> (forall a b. a -> MaybeUnknown b -> MaybeUnknown a)
-> Functor MaybeUnknown
forall a b. a -> MaybeUnknown b -> MaybeUnknown a
forall a b. (a -> b) -> MaybeUnknown a -> MaybeUnknown 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) -> MaybeUnknown a -> MaybeUnknown b
fmap :: forall a b. (a -> b) -> MaybeUnknown a -> MaybeUnknown b
$c<$ :: forall a b. a -> MaybeUnknown b -> MaybeUnknown a
<$ :: forall a b. a -> MaybeUnknown b -> MaybeUnknown a
Functor)
data Transition' state = Transition
{ forall state. Transition' state -> state
fromState :: !state
, forall state. Transition' state -> state
toState :: !state
}
deriving (Transition' state -> Transition' state -> Bool
(Transition' state -> Transition' state -> Bool)
-> (Transition' state -> Transition' state -> Bool)
-> Eq (Transition' state)
forall state.
Eq state =>
Transition' state -> Transition' state -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall state.
Eq state =>
Transition' state -> Transition' state -> Bool
== :: Transition' state -> Transition' state -> Bool
$c/= :: forall state.
Eq state =>
Transition' state -> Transition' state -> Bool
/= :: Transition' state -> Transition' state -> Bool
Eq, (forall a b. (a -> b) -> Transition' a -> Transition' b)
-> (forall a b. a -> Transition' b -> Transition' a)
-> Functor Transition'
forall a b. a -> Transition' b -> Transition' a
forall a b. (a -> b) -> Transition' a -> Transition' 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) -> Transition' a -> Transition' b
fmap :: forall a b. (a -> b) -> Transition' a -> Transition' b
$c<$ :: forall a b. a -> Transition' b -> Transition' a
<$ :: forall a b. a -> Transition' b -> Transition' a
Functor)
instance Show state
=> Show (Transition' state) where
show :: Transition' state -> String
show Transition { state
fromState :: forall state. Transition' state -> state
fromState :: state
fromState, state
toState :: forall state. Transition' state -> state
toState :: state
toState } =
[String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ state -> String
forall a. Show a => a -> String
show state
fromState
, String
" → "
, state -> String
forall a. Show a => a -> String
show state
toState
]
type Transition state = Transition' (MaybeUnknown state)
type AbstractTransition = Transition' AbstractState
mkTransition :: state -> state -> Transition state
mkTransition :: forall state. state -> state -> Transition state
mkTransition state
from state
to = Transition { fromState :: MaybeUnknown state
fromState = state -> MaybeUnknown state
forall state. state -> MaybeUnknown state
Known state
from
, toState :: MaybeUnknown state
toState = state -> MaybeUnknown state
forall state. state -> MaybeUnknown state
Known state
to
}
mkAbsTransition :: AbstractState -> AbstractState -> AbstractTransition
mkAbsTransition :: AbstractState -> AbstractState -> AbstractTransition
mkAbsTransition AbstractState
from AbstractState
to = Transition { fromState :: AbstractState
fromState = AbstractState
from
, toState :: AbstractState
toState = AbstractState
to
}
data TransitionTrace' peerAddr state = TransitionTrace
{ forall peerAddr state. TransitionTrace' peerAddr state -> peerAddr
ttPeerAddr :: peerAddr
, forall peerAddr state.
TransitionTrace' peerAddr state -> Transition' state
ttTransition :: Transition' state
}
deriving (forall a b.
(a -> b)
-> TransitionTrace' peerAddr a -> TransitionTrace' peerAddr b)
-> (forall a b.
a -> TransitionTrace' peerAddr b -> TransitionTrace' peerAddr a)
-> Functor (TransitionTrace' peerAddr)
forall a b.
a -> TransitionTrace' peerAddr b -> TransitionTrace' peerAddr a
forall a b.
(a -> b)
-> TransitionTrace' peerAddr a -> TransitionTrace' peerAddr b
forall peerAddr a b.
a -> TransitionTrace' peerAddr b -> TransitionTrace' peerAddr a
forall peerAddr a b.
(a -> b)
-> TransitionTrace' peerAddr a -> TransitionTrace' peerAddr b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall peerAddr a b.
(a -> b)
-> TransitionTrace' peerAddr a -> TransitionTrace' peerAddr b
fmap :: forall a b.
(a -> b)
-> TransitionTrace' peerAddr a -> TransitionTrace' peerAddr b
$c<$ :: forall peerAddr a b.
a -> TransitionTrace' peerAddr b -> TransitionTrace' peerAddr a
<$ :: forall a b.
a -> TransitionTrace' peerAddr b -> TransitionTrace' peerAddr a
Functor
instance (Show peerAddr, Show state)
=> Show (TransitionTrace' peerAddr state) where
show :: TransitionTrace' peerAddr state -> String
show (TransitionTrace peerAddr
addr Transition' state
tr) =
[String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ String
"TransitionTrace @("
, peerAddr -> String
forall a. Show a => a -> String
show peerAddr
addr
, String
") ("
, Transition' state -> String
forall a. Show a => a -> String
show Transition' state
tr
, String
")"
]
type TransitionTrace peerAddr state = TransitionTrace' peerAddr (MaybeUnknown state)
type AbstractTransitionTrace peerAddr = TransitionTrace' peerAddr AbstractState