module Network.LibP2P.Mux.Yamux.Types
( SessionRole (..)
, StreamState (..)
, YamuxError (..)
, YamuxStream (..)
, YamuxSession (..)
) where
import Control.Concurrent.STM (TMVar, TQueue, TVar)
import Data.ByteString (ByteString)
import qualified Data.Map.Strict as Map
import Data.Word (Word32)
import Network.LibP2P.Mux.Yamux.Frame (GoAwayCode, YamuxHeader)
data SessionRole = RoleClient | RoleServer
deriving (Int -> SessionRole -> ShowS
[SessionRole] -> ShowS
SessionRole -> String
(Int -> SessionRole -> ShowS)
-> (SessionRole -> String)
-> ([SessionRole] -> ShowS)
-> Show SessionRole
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SessionRole -> ShowS
showsPrec :: Int -> SessionRole -> ShowS
$cshow :: SessionRole -> String
show :: SessionRole -> String
$cshowList :: [SessionRole] -> ShowS
showList :: [SessionRole] -> ShowS
Show, SessionRole -> SessionRole -> Bool
(SessionRole -> SessionRole -> Bool)
-> (SessionRole -> SessionRole -> Bool) -> Eq SessionRole
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SessionRole -> SessionRole -> Bool
== :: SessionRole -> SessionRole -> Bool
$c/= :: SessionRole -> SessionRole -> Bool
/= :: SessionRole -> SessionRole -> Bool
Eq)
data StreamState
= StreamSYNSent
| StreamSYNReceived
| StreamEstablished
| StreamLocalClose
| StreamRemoteClose
| StreamClosed
| StreamReset
deriving (Int -> StreamState -> ShowS
[StreamState] -> ShowS
StreamState -> String
(Int -> StreamState -> ShowS)
-> (StreamState -> String)
-> ([StreamState] -> ShowS)
-> Show StreamState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StreamState -> ShowS
showsPrec :: Int -> StreamState -> ShowS
$cshow :: StreamState -> String
show :: StreamState -> String
$cshowList :: [StreamState] -> ShowS
showList :: [StreamState] -> ShowS
Show, StreamState -> StreamState -> Bool
(StreamState -> StreamState -> Bool)
-> (StreamState -> StreamState -> Bool) -> Eq StreamState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StreamState -> StreamState -> Bool
== :: StreamState -> StreamState -> Bool
$c/= :: StreamState -> StreamState -> Bool
/= :: StreamState -> StreamState -> Bool
Eq)
data YamuxError
= YamuxProtocolError !String
| YamuxStreamClosed
| YamuxStreamReset
| YamuxSessionShutdown
| YamuxGoAway !GoAwayCode
deriving (Int -> YamuxError -> ShowS
[YamuxError] -> ShowS
YamuxError -> String
(Int -> YamuxError -> ShowS)
-> (YamuxError -> String)
-> ([YamuxError] -> ShowS)
-> Show YamuxError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> YamuxError -> ShowS
showsPrec :: Int -> YamuxError -> ShowS
$cshow :: YamuxError -> String
show :: YamuxError -> String
$cshowList :: [YamuxError] -> ShowS
showList :: [YamuxError] -> ShowS
Show, YamuxError -> YamuxError -> Bool
(YamuxError -> YamuxError -> Bool)
-> (YamuxError -> YamuxError -> Bool) -> Eq YamuxError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: YamuxError -> YamuxError -> Bool
== :: YamuxError -> YamuxError -> Bool
$c/= :: YamuxError -> YamuxError -> Bool
/= :: YamuxError -> YamuxError -> Bool
Eq)
data YamuxStream = YamuxStream
{ YamuxStream -> Word32
ysStreamId :: !Word32
, YamuxStream -> TVar StreamState
ysState :: !(TVar StreamState)
, YamuxStream -> TVar Word32
ysSendWindow :: !(TVar Word32)
, YamuxStream -> TVar Word32
ysRecvWindow :: !(TVar Word32)
, YamuxStream -> TQueue ByteString
ysRecvBuf :: !(TQueue ByteString)
, YamuxStream -> TMVar ()
ysSendNotify :: !(TMVar ())
, YamuxStream -> YamuxSession
ysSession :: !YamuxSession
}
data YamuxSession = YamuxSession
{ YamuxSession -> SessionRole
ysRole :: !SessionRole
, YamuxSession -> TVar Word32
ysNextStreamId :: !(TVar Word32)
, YamuxSession -> TVar (Map Word32 YamuxStream)
ysStreams :: !(TVar (Map.Map Word32 YamuxStream))
, YamuxSession -> TQueue YamuxStream
ysAcceptCh :: !(TQueue YamuxStream)
, YamuxSession -> TQueue (YamuxHeader, ByteString)
ysSendCh :: !(TQueue (YamuxHeader, ByteString))
, YamuxSession -> TVar Bool
ysShutdown :: !(TVar Bool)
, YamuxSession -> TVar Bool
ysRemoteGoAway :: !(TVar Bool)
, YamuxSession -> TVar (Map Word32 (TMVar ()))
ysPings :: !(TVar (Map.Map Word32 (TMVar ())))
, YamuxSession -> TVar Word32
ysNextPingId :: !(TVar Word32)
, YamuxSession -> ByteString -> IO ()
ysWrite :: !(ByteString -> IO ())
, YamuxSession -> Int -> IO ByteString
ysRead :: !(Int -> IO ByteString)
}