{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}

module Network.QUIC.Connection.Types where

import Control.Concurrent
import Control.Concurrent.STM
import qualified Crypto.Token as CT
import Data.Array.IO
import Data.ByteString.Internal
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.X509 (CertificateChain)
import Foreign.Marshal.Alloc
import Foreign.Ptr (nullPtr)
import Network.Control (Rate, RxFlow, TxFlow, newRate, newRxFlow, newTxFlow)
import Network.Socket (Cmsg, SockAddr, Socket)
import Network.TLS.QUIC

import Network.QUIC.Config
import Network.QUIC.Connector
import Network.QUIC.Crypto
import Network.QUIC.Imports
import Network.QUIC.Logger
import Network.QUIC.Parameters
import Network.QUIC.Qlog
import Network.QUIC.Recovery
import Network.QUIC.Stream
import Network.QUIC.Types

----------------------------------------------------------------

dummySecrets :: TrafficSecrets a
dummySecrets :: forall a. TrafficSecrets a
dummySecrets = (ByteString -> ClientTrafficSecret a
forall a. ByteString -> ClientTrafficSecret a
ClientTrafficSecret ByteString
"", ByteString -> ServerTrafficSecret a
forall a. ByteString -> ServerTrafficSecret a
ServerTrafficSecret ByteString
"")

----------------------------------------------------------------

data RoleInfo
    = ClientInfo
        { RoleInfo -> ByteString
clientInitialToken :: Token -- new or retry token
        , RoleInfo -> ResumptionInfo
resumptionInfo :: ResumptionInfo
        , RoleInfo -> Bool
incompatibleVN :: Bool
        }
    | ServerInfo
        { RoleInfo -> TokenManager
tokenManager :: ~CT.TokenManager
        , RoleInfo -> CID -> Connection -> IO ()
registerCID :: CID -> Connection -> IO ()
        , RoleInfo -> CID -> IO ()
unregisterCID :: CID -> IO ()
        , RoleInfo -> Bool
askRetry :: Bool
        , RoleInfo -> ThreadId
baseThreadId :: ~ThreadId
        , RoleInfo -> Maybe CertificateChain
certChain :: Maybe CertificateChain
        }

defaultClientRoleInfo :: RoleInfo
defaultClientRoleInfo :: RoleInfo
defaultClientRoleInfo =
    ClientInfo
        { clientInitialToken :: ByteString
clientInitialToken = ByteString
emptyToken
        , resumptionInfo :: ResumptionInfo
resumptionInfo = ResumptionInfo
defaultResumptionInfo
        , incompatibleVN :: Bool
incompatibleVN = Bool
False
        }

defaultServerRoleInfo :: RoleInfo
defaultServerRoleInfo :: RoleInfo
defaultServerRoleInfo =
    ServerInfo
        { tokenManager :: TokenManager
tokenManager = TokenManager
forall a. HasCallStack => a
undefined
        , registerCID :: CID -> Connection -> IO ()
registerCID = \CID
_ Connection
_ -> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
        , unregisterCID :: CID -> IO ()
unregisterCID = \CID
_ -> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
        , askRetry :: Bool
askRetry = Bool
False
        , baseThreadId :: ThreadId
baseThreadId = ThreadId
forall a. HasCallStack => a
undefined
        , certChain :: Maybe CertificateChain
certChain = Maybe CertificateChain
forall a. Maybe a
Nothing
        }

data CIDDB = CIDDB
    { CIDDB -> CIDInfo
usedCIDInfo :: CIDInfo
    , CIDDB -> IntMap CIDInfo
cidInfos :: IntMap CIDInfo
    , CIDDB -> Map CID Int
revInfos :: Map CID Int
    , CIDDB -> Int
nextSeqNum :: Int -- only for mine (new)
    , CIDDB -> Bool
triggeredByMe :: Bool -- only for peer's
    }
    deriving (Int -> CIDDB -> ShowS
[CIDDB] -> ShowS
CIDDB -> String
(Int -> CIDDB -> ShowS)
-> (CIDDB -> String) -> ([CIDDB] -> ShowS) -> Show CIDDB
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CIDDB -> ShowS
showsPrec :: Int -> CIDDB -> ShowS
$cshow :: CIDDB -> String
show :: CIDDB -> String
$cshowList :: [CIDDB] -> ShowS
showList :: [CIDDB] -> ShowS
Show)

newCIDDB :: CID -> CIDDB
newCIDDB :: CID -> CIDDB
newCIDDB CID
cid =
    CIDDB
        { usedCIDInfo :: CIDInfo
usedCIDInfo = CIDInfo
cidInfo
        , cidInfos :: IntMap CIDInfo
cidInfos = Int -> CIDInfo -> IntMap CIDInfo
forall a. Int -> a -> IntMap a
IntMap.singleton Int
0 CIDInfo
cidInfo
        , revInfos :: Map CID Int
revInfos = CID -> Int -> Map CID Int
forall k a. k -> a -> Map k a
Map.singleton CID
cid Int
0
        , nextSeqNum :: Int
nextSeqNum = Int
1
        , triggeredByMe :: Bool
triggeredByMe = Bool
False
        }
  where
    cidInfo :: CIDInfo
cidInfo = Int -> CID -> StatelessResetToken -> CIDInfo
CIDInfo Int
0 CID
cid (Bytes -> StatelessResetToken
StatelessResetToken Bytes
"")

----------------------------------------------------------------

data MigrationState
    = NonMigration
    | MigrationStarted
    | SendChallenge PathData
    | RecvResponse
    deriving (MigrationState -> MigrationState -> Bool
(MigrationState -> MigrationState -> Bool)
-> (MigrationState -> MigrationState -> Bool) -> Eq MigrationState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MigrationState -> MigrationState -> Bool
== :: MigrationState -> MigrationState -> Bool
$c/= :: MigrationState -> MigrationState -> Bool
/= :: MigrationState -> MigrationState -> Bool
Eq, Int -> MigrationState -> ShowS
[MigrationState] -> ShowS
MigrationState -> String
(Int -> MigrationState -> ShowS)
-> (MigrationState -> String)
-> ([MigrationState] -> ShowS)
-> Show MigrationState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MigrationState -> ShowS
showsPrec :: Int -> MigrationState -> ShowS
$cshow :: MigrationState -> String
show :: MigrationState -> String
$cshowList :: [MigrationState] -> ShowS
showList :: [MigrationState] -> ShowS
Show)

----------------------------------------------------------------

data Coder = Coder
    { Coder -> Buffer -> ByteString -> AssDat -> Int -> IO Int
encrypt :: Buffer -> PlainText -> AssDat -> PacketNumber -> IO Int
    , Coder -> Buffer -> ByteString -> AssDat -> Int -> IO Int
decrypt :: Buffer -> CipherText -> AssDat -> PacketNumber -> IO Int
    , Coder -> Maybe Supplement
supplement :: Maybe Supplement
    }

initialCoder :: Coder
initialCoder :: Coder
initialCoder =
    Coder
        { encrypt :: Buffer -> ByteString -> AssDat -> Int -> IO Int
encrypt = \Buffer
_ ByteString
_ AssDat
_ Int
_ -> Int -> IO Int
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (-Int
1)
        , decrypt :: Buffer -> ByteString -> AssDat -> Int -> IO Int
decrypt = \Buffer
_ ByteString
_ AssDat
_ Int
_ -> Int -> IO Int
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (-Int
1)
        , supplement :: Maybe Supplement
supplement = Maybe Supplement
forall a. Maybe a
Nothing
        }

data Coder1RTT = Coder1RTT
    { Coder1RTT -> Coder
coder1RTT :: Coder
    , Coder1RTT -> TrafficSecrets ApplicationSecret
secretN :: TrafficSecrets ApplicationSecret
    }

initialCoder1RTT :: Coder1RTT
initialCoder1RTT :: Coder1RTT
initialCoder1RTT =
    Coder1RTT
        { coder1RTT :: Coder
coder1RTT = Coder
initialCoder
        , secretN :: TrafficSecrets ApplicationSecret
secretN = (ByteString -> ClientTrafficSecret ApplicationSecret
forall a. ByteString -> ClientTrafficSecret a
ClientTrafficSecret ByteString
"", ByteString -> ServerTrafficSecret ApplicationSecret
forall a. ByteString -> ServerTrafficSecret a
ServerTrafficSecret ByteString
"")
        }

data Protector = Protector
    { Protector -> Buffer -> IO ()
setSample :: Buffer -> IO ()
    , Protector -> IO Buffer
getMask :: IO Buffer
    , Protector -> Sample -> Mask
unprotect :: Sample -> Mask
    }

initialProtector :: Protector
initialProtector :: Protector
initialProtector =
    Protector
        { setSample :: Buffer -> IO ()
setSample = \Buffer
_ -> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
        , getMask :: IO Buffer
getMask = Buffer -> IO Buffer
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Buffer
forall a. Ptr a
nullPtr
        , unprotect :: Sample -> Mask
unprotect = \Sample
_ -> ByteString -> Mask
Mask ByteString
""
        }

----------------------------------------------------------------

data Negotiated = Negotiated
    { Negotiated -> HandshakeMode13
tlsHandshakeMode :: HandshakeMode13
    , Negotiated -> Maybe ByteString
applicationProtocol :: Maybe NegotiatedProtocol
    , Negotiated -> ApplicationSecretInfo
applicationSecretInfo :: ApplicationSecretInfo
    }

initialNegotiated :: Negotiated
initialNegotiated :: Negotiated
initialNegotiated =
    Negotiated
        { tlsHandshakeMode :: HandshakeMode13
tlsHandshakeMode = HandshakeMode13
FullHandshake
        , applicationProtocol :: Maybe ByteString
applicationProtocol = Maybe ByteString
forall a. Maybe a
Nothing
        , applicationSecretInfo :: ApplicationSecretInfo
applicationSecretInfo = TrafficSecrets ApplicationSecret -> ApplicationSecretInfo
ApplicationSecretInfo TrafficSecrets ApplicationSecret
forall a. TrafficSecrets a
defaultTrafficSecrets
        }

----------------------------------------------------------------

newtype StreamIdBase = StreamIdBase {StreamIdBase -> Int
fromStreamIdBase :: Int}
    deriving (StreamIdBase -> StreamIdBase -> Bool
(StreamIdBase -> StreamIdBase -> Bool)
-> (StreamIdBase -> StreamIdBase -> Bool) -> Eq StreamIdBase
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StreamIdBase -> StreamIdBase -> Bool
== :: StreamIdBase -> StreamIdBase -> Bool
$c/= :: StreamIdBase -> StreamIdBase -> Bool
/= :: StreamIdBase -> StreamIdBase -> Bool
Eq, Int -> StreamIdBase -> ShowS
[StreamIdBase] -> ShowS
StreamIdBase -> String
(Int -> StreamIdBase -> ShowS)
-> (StreamIdBase -> String)
-> ([StreamIdBase] -> ShowS)
-> Show StreamIdBase
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StreamIdBase -> ShowS
showsPrec :: Int -> StreamIdBase -> ShowS
$cshow :: StreamIdBase -> String
show :: StreamIdBase -> String
$cshowList :: [StreamIdBase] -> ShowS
showList :: [StreamIdBase] -> ShowS
Show)

data Concurrency = Concurrency
    { Concurrency -> Int
currentStream :: StreamId
    , Concurrency -> StreamIdBase
maxStreams :: StreamIdBase
    }
    deriving (Int -> Concurrency -> ShowS
[Concurrency] -> ShowS
Concurrency -> String
(Int -> Concurrency -> ShowS)
-> (Concurrency -> String)
-> ([Concurrency] -> ShowS)
-> Show Concurrency
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Concurrency -> ShowS
showsPrec :: Int -> Concurrency -> ShowS
$cshow :: Concurrency -> String
show :: Concurrency -> String
$cshowList :: [Concurrency] -> ShowS
showList :: [Concurrency] -> ShowS
Show)

newConcurrency :: Role -> Direction -> Int -> Concurrency
newConcurrency :: Role -> Direction -> Int -> Concurrency
newConcurrency Role
rl Direction
dir Int
n = Int -> StreamIdBase -> Concurrency
Concurrency Int
ini (StreamIdBase -> Concurrency) -> StreamIdBase -> Concurrency
forall a b. (a -> b) -> a -> b
$ Int -> StreamIdBase
StreamIdBase Int
n
  where
    bidi :: Bool
bidi = Direction
dir Direction -> Direction -> Bool
forall a. Eq a => a -> a -> Bool
== Direction
Bidirectional
    ini :: Int
ini
        | Role
rl Role -> Role -> Bool
forall a. Eq a => a -> a -> Bool
== Role
Client = if Bool
bidi then Int
0 else Int
2
        | Bool
otherwise = if Bool
bidi then Int
1 else Int
3

----------------------------------------------------------------

type Send = Buffer -> Int -> IO ()
type Recv = IO ReceivedPacket

data PeerInfo = PeerInfo SockAddr [Cmsg] deriving (PeerInfo -> PeerInfo -> Bool
(PeerInfo -> PeerInfo -> Bool)
-> (PeerInfo -> PeerInfo -> Bool) -> Eq PeerInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PeerInfo -> PeerInfo -> Bool
== :: PeerInfo -> PeerInfo -> Bool
$c/= :: PeerInfo -> PeerInfo -> Bool
/= :: PeerInfo -> PeerInfo -> Bool
Eq, Int -> PeerInfo -> ShowS
[PeerInfo] -> ShowS
PeerInfo -> String
(Int -> PeerInfo -> ShowS)
-> (PeerInfo -> String) -> ([PeerInfo] -> ShowS) -> Show PeerInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PeerInfo -> ShowS
showsPrec :: Int -> PeerInfo -> ShowS
$cshow :: PeerInfo -> String
show :: PeerInfo -> String
$cshowList :: [PeerInfo] -> ShowS
showList :: [PeerInfo] -> ShowS
Show)

----------------------------------------------------------------

-- | A quic connection to carry multiple streams.
data Connection = Connection
    { Connection -> ConnState
connState :: ConnState
    , -- Actions
      Connection -> DebugLogger
connDebugLog :: DebugLogger
    -- ^ A logger for debugging.
    , Connection -> QLogger
connQLog :: QLogger
    , Connection -> Hooks
connHooks :: Hooks
    , Connection -> Send
connSend :: ~Send -- ~ for testing
    , Connection -> Recv
connRecv :: ~Recv -- ~ for testing
    -- Manage
    , Connection -> RecvQ
connRecvQ :: RecvQ
    , Connection -> IORef Socket
connSocket :: IORef Socket
    , Connection -> IORef (IO ())
readers :: IORef (IO ())
    , Connection -> ThreadId
mainThreadId :: ThreadId
    , Connection -> Rate
controlRate :: Rate
    , -- Info
      Connection -> IORef RoleInfo
roleInfo :: IORef RoleInfo
    , Connection -> IORef VersionInfo
quicVersionInfo :: IORef VersionInfo
    , Connection -> VersionInfo
origVersionInfo :: VersionInfo -- chosenVersion is client's ver in Initial
    -- Mine
    , Connection -> Parameters
myParameters :: Parameters
    , Connection -> IORef CIDDB
myCIDDB :: IORef CIDDB
    , -- Peer
      Connection -> IORef Parameters
peerParameters :: IORef Parameters
    , Connection -> TVar CIDDB
peerCIDDB :: TVar CIDDB
    , Connection -> IORef PeerInfo
peerInfo :: IORef PeerInfo
    , -- Queues
      Connection -> InputQ
inputQ :: InputQ
    , Connection -> CryptoQ
cryptoQ :: CryptoQ
    , Connection -> OutputQ
outputQ :: OutputQ
    , Connection -> OutputQLim
outputQLim :: OutputQLim
    , Connection -> MigrationQ
migrationQ :: MigrationQ
    , Connection -> Shared
shared :: Shared
    , Connection -> IORef Int
delayedAckCount :: IORef Int
    , Connection -> IORef (IO ())
delayedAckCancel :: IORef (IO ())
    , -- State
      Connection -> IORef Int
peerPacketNumber :: IORef PacketNumber -- for RTT1
    , Connection -> IORef StreamTable
streamTable :: IORef StreamTable
    , Connection -> TVar Concurrency
myStreamId :: TVar Concurrency -- C:0 S:1
    , Connection -> TVar Concurrency
myUniStreamId :: TVar Concurrency -- C:2 S:3
    , Connection -> IORef Concurrency
peerStreamId :: IORef Concurrency -- C:1 S:0
    , Connection -> IORef Concurrency
peerUniStreamId :: IORef Concurrency -- C:3 S:2
    , Connection -> TVar TxFlow
flowTx :: TVar TxFlow
    , Connection -> IORef RxFlow
flowRx :: IORef RxFlow
    , Connection -> TVar MigrationState
migrationState :: TVar MigrationState
    , Connection -> IORef Microseconds
minIdleTimeout :: IORef Microseconds
    , Connection -> TVar Int
bytesTx :: TVar Int -- TVar for anti amplification
    , Connection -> TVar Int
bytesRx :: TVar Int -- TVar for anti amplification
    , Connection -> TVar Bool
addressValidated :: TVar Bool
    , -- TLS
      Connection -> Array EncryptionLevel (TVar [ReceivedPacket])
pendingQ :: Array EncryptionLevel (TVar [ReceivedPacket])
    , Connection -> IOArray EncryptionLevel Cipher
ciphers :: IOArray EncryptionLevel Cipher
    , Connection -> IOArray EncryptionLevel Coder
coders :: IOArray EncryptionLevel Coder
    , Connection -> IOArray Bool Coder1RTT
coders1RTT :: IOArray Bool Coder1RTT
    , Connection -> IOArray EncryptionLevel Protector
protectors :: IOArray EncryptionLevel Protector
    , Connection -> IORef (Bool, Int)
currentKeyPhase :: IORef (Bool, PacketNumber)
    , Connection -> IORef Negotiated
negotiated :: IORef Negotiated
    , Connection -> IORef AuthCIDs
connMyAuthCIDs :: IORef AuthCIDs
    , Connection -> IORef AuthCIDs
connPeerAuthCIDs :: IORef AuthCIDs
    , -- Resources
      Connection -> IORef (IO ())
connResources :: IORef (IO ())
    , Connection -> Buffer
encodeBuf :: Buffer
    , Connection -> SizedBuffer
encryptRes :: SizedBuffer
    , Connection -> Buffer
decryptBuf :: Buffer
    , -- Recovery
      Connection -> LDCC
connLDCC :: LDCC
    }

instance KeepQlog Connection where
    keepQlog :: Connection -> QLogger
keepQlog Connection
conn = Connection -> QLogger
connQLog Connection
conn

instance Connector Connection where
    getRole :: Connection -> Role
getRole = ConnState -> Role
role (ConnState -> Role)
-> (Connection -> ConnState) -> Connection -> Role
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Connection -> ConnState
connState
    getEncryptionLevel :: Connection -> IO EncryptionLevel
getEncryptionLevel = TVar EncryptionLevel -> IO EncryptionLevel
forall a. TVar a -> IO a
readTVarIO (TVar EncryptionLevel -> IO EncryptionLevel)
-> (Connection -> TVar EncryptionLevel)
-> Connection
-> IO EncryptionLevel
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConnState -> TVar EncryptionLevel
encryptionLevel (ConnState -> TVar EncryptionLevel)
-> (Connection -> ConnState) -> Connection -> TVar EncryptionLevel
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Connection -> ConnState
connState
    getMaxPacketSize :: Connection -> IO Int
getMaxPacketSize = IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int)
-> (Connection -> IORef Int) -> Connection -> IO Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConnState -> IORef Int
maxPacketSize (ConnState -> IORef Int)
-> (Connection -> ConnState) -> Connection -> IORef Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Connection -> ConnState
connState
    getConnectionState :: Connection -> IO ConnectionState
getConnectionState = TVar ConnectionState -> IO ConnectionState
forall a. TVar a -> IO a
readTVarIO (TVar ConnectionState -> IO ConnectionState)
-> (Connection -> TVar ConnectionState)
-> Connection
-> IO ConnectionState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConnState -> TVar ConnectionState
connectionState (ConnState -> TVar ConnectionState)
-> (Connection -> ConnState) -> Connection -> TVar ConnectionState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Connection -> ConnState
connState
    getPacketNumber :: Connection -> IO Int
getPacketNumber = IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int)
-> (Connection -> IORef Int) -> Connection -> IO Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConnState -> IORef Int
packetNumber (ConnState -> IORef Int)
-> (Connection -> ConnState) -> Connection -> IORef Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Connection -> ConnState
connState
    getAlive :: Connection -> IO Bool
getAlive = IORef Bool -> IO Bool
forall a. IORef a -> IO a
readIORef (IORef Bool -> IO Bool)
-> (Connection -> IORef Bool) -> Connection -> IO Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConnState -> IORef Bool
connectionAlive (ConnState -> IORef Bool)
-> (Connection -> ConnState) -> Connection -> IORef Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Connection -> ConnState
connState

setDead :: Connection -> IO ()
setDead :: Connection -> IO ()
setDead Connection
conn = IORef Bool -> Bool -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ConnState -> IORef Bool
connectionAlive (ConnState -> IORef Bool) -> ConnState -> IORef Bool
forall a b. (a -> b) -> a -> b
$ Connection -> ConnState
connState Connection
conn) Bool
False

makePendingQ :: IO (Array EncryptionLevel (TVar [ReceivedPacket]))
makePendingQ :: IO (Array EncryptionLevel (TVar [ReceivedPacket]))
makePendingQ = do
    TVar [ReceivedPacket]
q1 <- [ReceivedPacket] -> IO (TVar [ReceivedPacket])
forall a. a -> IO (TVar a)
newTVarIO []
    TVar [ReceivedPacket]
q2 <- [ReceivedPacket] -> IO (TVar [ReceivedPacket])
forall a. a -> IO (TVar a)
newTVarIO []
    TVar [ReceivedPacket]
q3 <- [ReceivedPacket] -> IO (TVar [ReceivedPacket])
forall a. a -> IO (TVar a)
newTVarIO []
    let lst :: [(EncryptionLevel, TVar [ReceivedPacket])]
lst = [(EncryptionLevel
RTT0Level, TVar [ReceivedPacket]
q1), (EncryptionLevel
HandshakeLevel, TVar [ReceivedPacket]
q2), (EncryptionLevel
RTT1Level, TVar [ReceivedPacket]
q3)]
        arr :: Array EncryptionLevel (TVar [ReceivedPacket])
arr = (EncryptionLevel, EncryptionLevel)
-> [(EncryptionLevel, TVar [ReceivedPacket])]
-> Array EncryptionLevel (TVar [ReceivedPacket])
forall i e. Ix i => (i, i) -> [(i, e)] -> Array i e
array (EncryptionLevel
RTT0Level, EncryptionLevel
RTT1Level) [(EncryptionLevel, TVar [ReceivedPacket])]
lst
    Array EncryptionLevel (TVar [ReceivedPacket])
-> IO (Array EncryptionLevel (TVar [ReceivedPacket]))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Array EncryptionLevel (TVar [ReceivedPacket])
arr

newConnection
    :: Role
    -> Parameters
    -> VersionInfo
    -> AuthCIDs
    -> AuthCIDs
    -> DebugLogger
    -> QLogger
    -> Hooks
    -> IORef Socket
    -> IORef PeerInfo
    -> RecvQ
    -> Send
    -> Recv
    -> IO Connection
newConnection :: Role
-> Parameters
-> VersionInfo
-> AuthCIDs
-> AuthCIDs
-> DebugLogger
-> QLogger
-> Hooks
-> IORef Socket
-> IORef PeerInfo
-> RecvQ
-> Send
-> Recv
-> IO Connection
newConnection Role
rl Parameters
myparams VersionInfo
verInfo AuthCIDs
myAuthCIDs AuthCIDs
peerAuthCIDs DebugLogger
debugLog QLogger
qLog Hooks
hooks IORef Socket
sref IORef PeerInfo
piref RecvQ
recvQ ~Send
send ~Recv
recv = do
    -- ~ for testing
    OutputQ
outQ <- IO OutputQ
forall a. IO (TQueue a)
newTQueueIO
    let put :: PlainPacket -> IO ()
put PlainPacket
x = STM () -> IO ()
forall a. STM a -> IO a
atomically (STM () -> IO ()) -> STM () -> IO ()
forall a b. (a -> b) -> a -> b
$ OutputQ -> Output -> STM ()
forall a. TQueue a -> a -> STM ()
writeTQueue OutputQ
outQ (Output -> STM ()) -> Output -> STM ()
forall a b. (a -> b) -> a -> b
$ PlainPacket -> Output
OutRetrans PlainPacket
x
    ConnState
connstate <- Role -> IO ConnState
newConnState Role
rl
    let bufsiz :: Int
bufsiz = Int
maximumUdpPayloadSize
    Buffer
encBuf <- Int -> IO Buffer
forall a. Int -> IO (Ptr a)
mallocBytes Int
bufsiz
    Buffer
ecrptBuf <- Int -> IO Buffer
forall a. Int -> IO (Ptr a)
mallocBytes Int
bufsiz
    Buffer
dcrptBuf <- Int -> IO Buffer
forall a. Int -> IO (Ptr a)
mallocBytes Int
bufsiz
    ConnState
-> DebugLogger
-> QLogger
-> Hooks
-> Send
-> Recv
-> RecvQ
-> IORef Socket
-> IORef (IO ())
-> ThreadId
-> Rate
-> IORef RoleInfo
-> IORef VersionInfo
-> VersionInfo
-> Parameters
-> IORef CIDDB
-> IORef Parameters
-> TVar CIDDB
-> IORef PeerInfo
-> InputQ
-> CryptoQ
-> OutputQ
-> OutputQLim
-> MigrationQ
-> Shared
-> IORef Int
-> IORef (IO ())
-> IORef Int
-> IORef StreamTable
-> TVar Concurrency
-> TVar Concurrency
-> IORef Concurrency
-> IORef Concurrency
-> TVar TxFlow
-> IORef RxFlow
-> TVar MigrationState
-> IORef Microseconds
-> TVar Int
-> TVar Int
-> TVar Bool
-> Array EncryptionLevel (TVar [ReceivedPacket])
-> IOArray EncryptionLevel Cipher
-> IOArray EncryptionLevel Coder
-> IOArray Bool Coder1RTT
-> IOArray EncryptionLevel Protector
-> IORef (Bool, Int)
-> IORef Negotiated
-> IORef AuthCIDs
-> IORef AuthCIDs
-> IORef (IO ())
-> Buffer
-> SizedBuffer
-> Buffer
-> LDCC
-> Connection
Connection ConnState
connstate DebugLogger
debugLog QLogger
qLog Hooks
hooks Send
send Recv
recv RecvQ
recvQ IORef Socket
sref
        (IORef (IO ())
 -> ThreadId
 -> Rate
 -> IORef RoleInfo
 -> IORef VersionInfo
 -> VersionInfo
 -> Parameters
 -> IORef CIDDB
 -> IORef Parameters
 -> TVar CIDDB
 -> IORef PeerInfo
 -> InputQ
 -> CryptoQ
 -> OutputQ
 -> OutputQLim
 -> MigrationQ
 -> Shared
 -> IORef Int
 -> IORef (IO ())
 -> IORef Int
 -> IORef StreamTable
 -> TVar Concurrency
 -> TVar Concurrency
 -> IORef Concurrency
 -> IORef Concurrency
 -> TVar TxFlow
 -> IORef RxFlow
 -> TVar MigrationState
 -> IORef Microseconds
 -> TVar Int
 -> TVar Int
 -> TVar Bool
 -> Array EncryptionLevel (TVar [ReceivedPacket])
 -> IOArray EncryptionLevel Cipher
 -> IOArray EncryptionLevel Coder
 -> IOArray Bool Coder1RTT
 -> IOArray EncryptionLevel Protector
 -> IORef (Bool, Int)
 -> IORef Negotiated
 -> IORef AuthCIDs
 -> IORef AuthCIDs
 -> IORef (IO ())
 -> Buffer
 -> SizedBuffer
 -> Buffer
 -> LDCC
 -> Connection)
-> IO (IORef (IO ()))
-> IO
     (ThreadId
      -> Rate
      -> IORef RoleInfo
      -> IORef VersionInfo
      -> VersionInfo
      -> Parameters
      -> IORef CIDDB
      -> IORef Parameters
      -> TVar CIDDB
      -> IORef PeerInfo
      -> InputQ
      -> CryptoQ
      -> OutputQ
      -> OutputQLim
      -> MigrationQ
      -> Shared
      -> IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO () -> IO (IORef (IO ()))
forall a. a -> IO (IORef a)
newIORef (() -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ())
        IO
  (ThreadId
   -> Rate
   -> IORef RoleInfo
   -> IORef VersionInfo
   -> VersionInfo
   -> Parameters
   -> IORef CIDDB
   -> IORef Parameters
   -> TVar CIDDB
   -> IORef PeerInfo
   -> InputQ
   -> CryptoQ
   -> OutputQ
   -> OutputQLim
   -> MigrationQ
   -> Shared
   -> IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO ThreadId
-> IO
     (Rate
      -> IORef RoleInfo
      -> IORef VersionInfo
      -> VersionInfo
      -> Parameters
      -> IORef CIDDB
      -> IORef Parameters
      -> TVar CIDDB
      -> IORef PeerInfo
      -> InputQ
      -> CryptoQ
      -> OutputQ
      -> OutputQLim
      -> MigrationQ
      -> Shared
      -> IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IO ThreadId
myThreadId
        IO
  (Rate
   -> IORef RoleInfo
   -> IORef VersionInfo
   -> VersionInfo
   -> Parameters
   -> IORef CIDDB
   -> IORef Parameters
   -> TVar CIDDB
   -> IORef PeerInfo
   -> InputQ
   -> CryptoQ
   -> OutputQ
   -> OutputQLim
   -> MigrationQ
   -> Shared
   -> IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO Rate
-> IO
     (IORef RoleInfo
      -> IORef VersionInfo
      -> VersionInfo
      -> Parameters
      -> IORef CIDDB
      -> IORef Parameters
      -> TVar CIDDB
      -> IORef PeerInfo
      -> InputQ
      -> CryptoQ
      -> OutputQ
      -> OutputQLim
      -> MigrationQ
      -> Shared
      -> IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IO Rate
newRate
        -- Info
        IO
  (IORef RoleInfo
   -> IORef VersionInfo
   -> VersionInfo
   -> Parameters
   -> IORef CIDDB
   -> IORef Parameters
   -> TVar CIDDB
   -> IORef PeerInfo
   -> InputQ
   -> CryptoQ
   -> OutputQ
   -> OutputQLim
   -> MigrationQ
   -> Shared
   -> IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef RoleInfo)
-> IO
     (IORef VersionInfo
      -> VersionInfo
      -> Parameters
      -> IORef CIDDB
      -> IORef Parameters
      -> TVar CIDDB
      -> IORef PeerInfo
      -> InputQ
      -> CryptoQ
      -> OutputQ
      -> OutputQLim
      -> MigrationQ
      -> Shared
      -> IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RoleInfo -> IO (IORef RoleInfo)
forall a. a -> IO (IORef a)
newIORef RoleInfo
initialRoleInfo
        IO
  (IORef VersionInfo
   -> VersionInfo
   -> Parameters
   -> IORef CIDDB
   -> IORef Parameters
   -> TVar CIDDB
   -> IORef PeerInfo
   -> InputQ
   -> CryptoQ
   -> OutputQ
   -> OutputQLim
   -> MigrationQ
   -> Shared
   -> IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef VersionInfo)
-> IO
     (VersionInfo
      -> Parameters
      -> IORef CIDDB
      -> IORef Parameters
      -> TVar CIDDB
      -> IORef PeerInfo
      -> InputQ
      -> CryptoQ
      -> OutputQ
      -> OutputQLim
      -> MigrationQ
      -> Shared
      -> IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> VersionInfo -> IO (IORef VersionInfo)
forall a. a -> IO (IORef a)
newIORef VersionInfo
verInfo
        IO
  (VersionInfo
   -> Parameters
   -> IORef CIDDB
   -> IORef Parameters
   -> TVar CIDDB
   -> IORef PeerInfo
   -> InputQ
   -> CryptoQ
   -> OutputQ
   -> OutputQLim
   -> MigrationQ
   -> Shared
   -> IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO VersionInfo
-> IO
     (Parameters
      -> IORef CIDDB
      -> IORef Parameters
      -> TVar CIDDB
      -> IORef PeerInfo
      -> InputQ
      -> CryptoQ
      -> OutputQ
      -> OutputQLim
      -> MigrationQ
      -> Shared
      -> IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> VersionInfo -> IO VersionInfo
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return VersionInfo
verInfo
        -- Mine
        IO
  (Parameters
   -> IORef CIDDB
   -> IORef Parameters
   -> TVar CIDDB
   -> IORef PeerInfo
   -> InputQ
   -> CryptoQ
   -> OutputQ
   -> OutputQLim
   -> MigrationQ
   -> Shared
   -> IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO Parameters
-> IO
     (IORef CIDDB
      -> IORef Parameters
      -> TVar CIDDB
      -> IORef PeerInfo
      -> InputQ
      -> CryptoQ
      -> OutputQ
      -> OutputQLim
      -> MigrationQ
      -> Shared
      -> IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parameters -> IO Parameters
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Parameters
myparams
        IO
  (IORef CIDDB
   -> IORef Parameters
   -> TVar CIDDB
   -> IORef PeerInfo
   -> InputQ
   -> CryptoQ
   -> OutputQ
   -> OutputQLim
   -> MigrationQ
   -> Shared
   -> IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef CIDDB)
-> IO
     (IORef Parameters
      -> TVar CIDDB
      -> IORef PeerInfo
      -> InputQ
      -> CryptoQ
      -> OutputQ
      -> OutputQLim
      -> MigrationQ
      -> Shared
      -> IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CIDDB -> IO (IORef CIDDB)
forall a. a -> IO (IORef a)
newIORef (CID -> CIDDB
newCIDDB CID
myCID)
        -- Peer
        IO
  (IORef Parameters
   -> TVar CIDDB
   -> IORef PeerInfo
   -> InputQ
   -> CryptoQ
   -> OutputQ
   -> OutputQLim
   -> MigrationQ
   -> Shared
   -> IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef Parameters)
-> IO
     (TVar CIDDB
      -> IORef PeerInfo
      -> InputQ
      -> CryptoQ
      -> OutputQ
      -> OutputQLim
      -> MigrationQ
      -> Shared
      -> IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parameters -> IO (IORef Parameters)
forall a. a -> IO (IORef a)
newIORef Parameters
baseParameters
        IO
  (TVar CIDDB
   -> IORef PeerInfo
   -> InputQ
   -> CryptoQ
   -> OutputQ
   -> OutputQLim
   -> MigrationQ
   -> Shared
   -> IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (TVar CIDDB)
-> IO
     (IORef PeerInfo
      -> InputQ
      -> CryptoQ
      -> OutputQ
      -> OutputQLim
      -> MigrationQ
      -> Shared
      -> IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CIDDB -> IO (TVar CIDDB)
forall a. a -> IO (TVar a)
newTVarIO (CID -> CIDDB
newCIDDB CID
peerCID)
        IO
  (IORef PeerInfo
   -> InputQ
   -> CryptoQ
   -> OutputQ
   -> OutputQLim
   -> MigrationQ
   -> Shared
   -> IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef PeerInfo)
-> IO
     (InputQ
      -> CryptoQ
      -> OutputQ
      -> OutputQLim
      -> MigrationQ
      -> Shared
      -> IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IORef PeerInfo -> IO (IORef PeerInfo)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return IORef PeerInfo
piref
        -- Queues
        IO
  (InputQ
   -> CryptoQ
   -> OutputQ
   -> OutputQLim
   -> MigrationQ
   -> Shared
   -> IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO InputQ
-> IO
     (CryptoQ
      -> OutputQ
      -> OutputQLim
      -> MigrationQ
      -> Shared
      -> IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IO InputQ
forall a. IO (TQueue a)
newTQueueIO
        IO
  (CryptoQ
   -> OutputQ
   -> OutputQLim
   -> MigrationQ
   -> Shared
   -> IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO CryptoQ
-> IO
     (OutputQ
      -> OutputQLim
      -> MigrationQ
      -> Shared
      -> IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IO CryptoQ
forall a. IO (TQueue a)
newTQueueIO
        IO
  (OutputQ
   -> OutputQLim
   -> MigrationQ
   -> Shared
   -> IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO OutputQ
-> IO
     (OutputQLim
      -> MigrationQ
      -> Shared
      -> IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> OutputQ -> IO OutputQ
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return OutputQ
outQ
        IO
  (OutputQLim
   -> MigrationQ
   -> Shared
   -> IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO OutputQLim
-> IO
     (MigrationQ
      -> Shared
      -> IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Natural -> IO OutputQLim
forall a. Natural -> IO (TBQueue a)
newTBQueueIO Natural
1
        IO
  (MigrationQ
   -> Shared
   -> IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO MigrationQ
-> IO
     (Shared
      -> IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IO MigrationQ
forall a. IO (TQueue a)
newTQueueIO
        IO
  (Shared
   -> IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO Shared
-> IO
     (IORef Int
      -> IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IO Shared
newShared
        IO
  (IORef Int
   -> IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef Int)
-> IO
     (IORef (IO ())
      -> IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
        IO
  (IORef (IO ())
   -> IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef (IO ()))
-> IO
     (IORef Int
      -> IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IO () -> IO (IORef (IO ()))
forall a. a -> IO (IORef a)
newIORef (() -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ())
        -- State
        IO
  (IORef Int
   -> IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef Int)
-> IO
     (IORef StreamTable
      -> TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
        IO
  (IORef StreamTable
   -> TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef StreamTable)
-> IO
     (TVar Concurrency
      -> TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> StreamTable -> IO (IORef StreamTable)
forall a. a -> IO (IORef a)
newIORef StreamTable
emptyStreamTable
        IO
  (TVar Concurrency
   -> TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (TVar Concurrency)
-> IO
     (TVar Concurrency
      -> IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Concurrency -> IO (TVar Concurrency)
forall a. a -> IO (TVar a)
newTVarIO (Role -> Direction -> Int -> Concurrency
newConcurrency Role
rl Direction
Bidirectional Int
0)
        IO
  (TVar Concurrency
   -> IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (TVar Concurrency)
-> IO
     (IORef Concurrency
      -> IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Concurrency -> IO (TVar Concurrency)
forall a. a -> IO (TVar a)
newTVarIO (Role -> Direction -> Int -> Concurrency
newConcurrency Role
rl Direction
Unidirectional Int
0)
        IO
  (IORef Concurrency
   -> IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef Concurrency)
-> IO
     (IORef Concurrency
      -> TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Concurrency -> IO (IORef Concurrency)
forall a. a -> IO (IORef a)
newIORef Concurrency
peerConcurrency
        IO
  (IORef Concurrency
   -> TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef Concurrency)
-> IO
     (TVar TxFlow
      -> IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Concurrency -> IO (IORef Concurrency)
forall a. a -> IO (IORef a)
newIORef Concurrency
peerUniConcurrency
        IO
  (TVar TxFlow
   -> IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (TVar TxFlow)
-> IO
     (IORef RxFlow
      -> TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxFlow -> IO (TVar TxFlow)
forall a. a -> IO (TVar a)
newTVarIO (Int -> TxFlow
newTxFlow Int
0) -- limit is set in Handshake
        IO
  (IORef RxFlow
   -> TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef RxFlow)
-> IO
     (TVar MigrationState
      -> IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RxFlow -> IO (IORef RxFlow)
forall a. a -> IO (IORef a)
newIORef (Int -> RxFlow
newRxFlow (Int -> RxFlow) -> Int -> RxFlow
forall a b. (a -> b) -> a -> b
$ Parameters -> Int
initialMaxData Parameters
myparams)
        IO
  (TVar MigrationState
   -> IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (TVar MigrationState)
-> IO
     (IORef Microseconds
      -> TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> MigrationState -> IO (TVar MigrationState)
forall a. a -> IO (TVar a)
newTVarIO MigrationState
NonMigration
        IO
  (IORef Microseconds
   -> TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef Microseconds)
-> IO
     (TVar Int
      -> TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Microseconds -> IO (IORef Microseconds)
forall a. a -> IO (IORef a)
newIORef (Milliseconds -> Microseconds
milliToMicro (Milliseconds -> Microseconds) -> Milliseconds -> Microseconds
forall a b. (a -> b) -> a -> b
$ Parameters -> Milliseconds
maxIdleTimeout Parameters
myparams)
        IO
  (TVar Int
   -> TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (TVar Int)
-> IO
     (TVar Int
      -> TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> IO (TVar Int)
forall a. a -> IO (TVar a)
newTVarIO Int
0
        IO
  (TVar Int
   -> TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (TVar Int)
-> IO
     (TVar Bool
      -> Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> IO (TVar Int)
forall a. a -> IO (TVar a)
newTVarIO Int
0
        IO
  (TVar Bool
   -> Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (TVar Bool)
-> IO
     (Array EncryptionLevel (TVar [ReceivedPacket])
      -> IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> IO (TVar Bool)
forall a. a -> IO (TVar a)
newTVarIO Bool
False
        -- TLS
        IO
  (Array EncryptionLevel (TVar [ReceivedPacket])
   -> IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (Array EncryptionLevel (TVar [ReceivedPacket]))
-> IO
     (IOArray EncryptionLevel Cipher
      -> IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IO (Array EncryptionLevel (TVar [ReceivedPacket]))
makePendingQ
        IO
  (IOArray EncryptionLevel Cipher
   -> IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IOArray EncryptionLevel Cipher)
-> IO
     (IOArray EncryptionLevel Coder
      -> IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (EncryptionLevel, EncryptionLevel)
-> Cipher -> IO (IOArray EncryptionLevel Cipher)
forall i. Ix i => (i, i) -> Cipher -> IO (IOArray i Cipher)
forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
(i, i) -> e -> m (a i e)
newArray (EncryptionLevel
InitialLevel, EncryptionLevel
RTT1Level) Cipher
defaultCipher
        IO
  (IOArray EncryptionLevel Coder
   -> IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IOArray EncryptionLevel Coder)
-> IO
     (IOArray Bool Coder1RTT
      -> IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (EncryptionLevel, EncryptionLevel)
-> Coder -> IO (IOArray EncryptionLevel Coder)
forall i. Ix i => (i, i) -> Coder -> IO (IOArray i Coder)
forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
(i, i) -> e -> m (a i e)
newArray (EncryptionLevel
InitialLevel, EncryptionLevel
HandshakeLevel) Coder
initialCoder
        IO
  (IOArray Bool Coder1RTT
   -> IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IOArray Bool Coder1RTT)
-> IO
     (IOArray EncryptionLevel Protector
      -> IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Bool, Bool) -> Coder1RTT -> IO (IOArray Bool Coder1RTT)
forall i. Ix i => (i, i) -> Coder1RTT -> IO (IOArray i Coder1RTT)
forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
(i, i) -> e -> m (a i e)
newArray (Bool
False, Bool
True) Coder1RTT
initialCoder1RTT
        IO
  (IOArray EncryptionLevel Protector
   -> IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IOArray EncryptionLevel Protector)
-> IO
     (IORef (Bool, Int)
      -> IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (EncryptionLevel, EncryptionLevel)
-> Protector -> IO (IOArray EncryptionLevel Protector)
forall i. Ix i => (i, i) -> Protector -> IO (IOArray i Protector)
forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
(i, i) -> e -> m (a i e)
newArray (EncryptionLevel
InitialLevel, EncryptionLevel
RTT1Level) Protector
initialProtector
        IO
  (IORef (Bool, Int)
   -> IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef (Bool, Int))
-> IO
     (IORef Negotiated
      -> IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Bool, Int) -> IO (IORef (Bool, Int))
forall a. a -> IO (IORef a)
newIORef (Bool
False, Int
0)
        IO
  (IORef Negotiated
   -> IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef Negotiated)
-> IO
     (IORef AuthCIDs
      -> IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Negotiated -> IO (IORef Negotiated)
forall a. a -> IO (IORef a)
newIORef Negotiated
initialNegotiated
        IO
  (IORef AuthCIDs
   -> IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef AuthCIDs)
-> IO
     (IORef AuthCIDs
      -> IORef (IO ())
      -> Buffer
      -> SizedBuffer
      -> Buffer
      -> LDCC
      -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AuthCIDs -> IO (IORef AuthCIDs)
forall a. a -> IO (IORef a)
newIORef AuthCIDs
myAuthCIDs
        IO
  (IORef AuthCIDs
   -> IORef (IO ())
   -> Buffer
   -> SizedBuffer
   -> Buffer
   -> LDCC
   -> Connection)
-> IO (IORef AuthCIDs)
-> IO
     (IORef (IO ())
      -> Buffer -> SizedBuffer -> Buffer -> LDCC -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AuthCIDs -> IO (IORef AuthCIDs)
forall a. a -> IO (IORef a)
newIORef AuthCIDs
peerAuthCIDs
        -- Resources
        IO
  (IORef (IO ())
   -> Buffer -> SizedBuffer -> Buffer -> LDCC -> Connection)
-> IO (IORef (IO ()))
-> IO (Buffer -> SizedBuffer -> Buffer -> LDCC -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IO () -> IO (IORef (IO ()))
forall a. a -> IO (IORef a)
newIORef (Buffer -> IO ()
forall a. Ptr a -> IO ()
free Buffer
encBuf IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Buffer -> IO ()
forall a. Ptr a -> IO ()
free Buffer
ecrptBuf IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Buffer -> IO ()
forall a. Ptr a -> IO ()
free Buffer
dcrptBuf)
        IO (Buffer -> SizedBuffer -> Buffer -> LDCC -> Connection)
-> IO Buffer -> IO (SizedBuffer -> Buffer -> LDCC -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Buffer -> IO Buffer
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Buffer
encBuf -- used sender or closere
        IO (SizedBuffer -> Buffer -> LDCC -> Connection)
-> IO SizedBuffer -> IO (Buffer -> LDCC -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SizedBuffer -> IO SizedBuffer
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Buffer -> Int -> SizedBuffer
SizedBuffer Buffer
ecrptBuf Int
bufsiz) -- used sender
        IO (Buffer -> LDCC -> Connection)
-> IO Buffer -> IO (LDCC -> Connection)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Buffer -> IO Buffer
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Buffer
dcrptBuf -- used receiver
        -- Recovery
        IO (LDCC -> Connection) -> IO LDCC -> IO Connection
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ConnState -> QLogger -> (PlainPacket -> IO ()) -> IO LDCC
newLDCC ConnState
connstate QLogger
qLog PlainPacket -> IO ()
put
  where
    isclient :: Bool
isclient = Role
rl Role -> Role -> Bool
forall a. Eq a => a -> a -> Bool
== Role
Client
    initialRoleInfo :: RoleInfo
initialRoleInfo
        | Bool
isclient = RoleInfo
defaultClientRoleInfo
        | Bool
otherwise = RoleInfo
defaultServerRoleInfo
    myCID :: CID
myCID = Maybe CID -> CID
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe CID -> CID) -> Maybe CID -> CID
forall a b. (a -> b) -> a -> b
$ AuthCIDs -> Maybe CID
initSrcCID AuthCIDs
myAuthCIDs
    peerCID :: CID
peerCID = Maybe CID -> CID
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe CID -> CID) -> Maybe CID -> CID
forall a b. (a -> b) -> a -> b
$ AuthCIDs -> Maybe CID
initSrcCID AuthCIDs
peerAuthCIDs
    peer :: Role
peer
        | Bool
isclient = Role
Server
        | Bool
otherwise = Role
Client
    peerConcurrency :: Concurrency
peerConcurrency = Role -> Direction -> Int -> Concurrency
newConcurrency Role
peer Direction
Bidirectional (Parameters -> Int
initialMaxStreamsBidi Parameters
myparams)
    peerUniConcurrency :: Concurrency
peerUniConcurrency = Role -> Direction -> Int -> Concurrency
newConcurrency Role
peer Direction
Unidirectional (Parameters -> Int
initialMaxStreamsUni Parameters
myparams)

defaultTrafficSecrets :: (ClientTrafficSecret a, ServerTrafficSecret a)
defaultTrafficSecrets :: forall a. TrafficSecrets a
defaultTrafficSecrets = (ByteString -> ClientTrafficSecret a
forall a. ByteString -> ClientTrafficSecret a
ClientTrafficSecret ByteString
"", ByteString -> ServerTrafficSecret a
forall a. ByteString -> ServerTrafficSecret a
ServerTrafficSecret ByteString
"")

----------------------------------------------------------------

clientConnection
    :: ClientConfig
    -> VersionInfo
    -> AuthCIDs
    -> AuthCIDs
    -> DebugLogger
    -> QLogger
    -> Hooks
    -> IORef Socket
    -> IORef PeerInfo
    -> RecvQ
    -> Send
    -> Recv
    -> IO Connection
clientConnection :: ClientConfig
-> VersionInfo
-> AuthCIDs
-> AuthCIDs
-> DebugLogger
-> QLogger
-> Hooks
-> IORef Socket
-> IORef PeerInfo
-> RecvQ
-> Send
-> Recv
-> IO Connection
clientConnection ClientConfig{Bool
String
[Group]
[Cipher]
[Version]
Maybe Int
Maybe String
Credentials
ClientHooks
Version
ResumptionInfo
Parameters
Hooks
String -> IO ()
Version -> IO (Maybe [ByteString])
ccVersion :: Version
ccVersions :: [Version]
ccCiphers :: [Cipher]
ccGroups :: [Group]
ccParameters :: Parameters
ccKeyLog :: String -> IO ()
ccQLog :: Maybe String
ccCredentials :: Credentials
ccHooks :: Hooks
ccTlsHooks :: ClientHooks
ccUse0RTT :: Bool
ccServerName :: String
ccPortName :: String
ccALPN :: Version -> IO (Maybe [ByteString])
ccValidate :: Bool
ccResumption :: ResumptionInfo
ccPacketSize :: Maybe Int
ccDebugLog :: Bool
ccVersion :: ClientConfig -> Version
ccVersions :: ClientConfig -> [Version]
ccCiphers :: ClientConfig -> [Cipher]
ccGroups :: ClientConfig -> [Group]
ccParameters :: ClientConfig -> Parameters
ccKeyLog :: ClientConfig -> String -> IO ()
ccQLog :: ClientConfig -> Maybe String
ccCredentials :: ClientConfig -> Credentials
ccHooks :: ClientConfig -> Hooks
ccTlsHooks :: ClientConfig -> ClientHooks
ccUse0RTT :: ClientConfig -> Bool
ccServerName :: ClientConfig -> String
ccPortName :: ClientConfig -> String
ccALPN :: ClientConfig -> Version -> IO (Maybe [ByteString])
ccValidate :: ClientConfig -> Bool
ccResumption :: ClientConfig -> ResumptionInfo
ccPacketSize :: ClientConfig -> Maybe Int
ccDebugLog :: ClientConfig -> Bool
..} VersionInfo
verInfo AuthCIDs
myAuthCIDs AuthCIDs
peerAuthCIDs =
    Role
-> Parameters
-> VersionInfo
-> AuthCIDs
-> AuthCIDs
-> DebugLogger
-> QLogger
-> Hooks
-> IORef Socket
-> IORef PeerInfo
-> RecvQ
-> Send
-> Recv
-> IO Connection
newConnection Role
Client Parameters
ccParameters VersionInfo
verInfo AuthCIDs
myAuthCIDs AuthCIDs
peerAuthCIDs

serverConnection
    :: ServerConfig
    -> VersionInfo
    -> AuthCIDs
    -> AuthCIDs
    -> DebugLogger
    -> QLogger
    -> Hooks
    -> IORef Socket
    -> IORef PeerInfo
    -> RecvQ
    -> Send
    -> Recv
    -> IO Connection
serverConnection :: ServerConfig
-> VersionInfo
-> AuthCIDs
-> AuthCIDs
-> DebugLogger
-> QLogger
-> Hooks
-> IORef Socket
-> IORef PeerInfo
-> RecvQ
-> Send
-> Recv
-> IO Connection
serverConnection ServerConfig{Bool
Int
[(IP, PortNumber)]
[Group]
[Cipher]
[Version]
Maybe String
Maybe (Version -> [ByteString] -> IO ByteString)
SessionManager
Credentials
ServerHooks
Parameters
Hooks
String -> IO ()
scVersions :: [Version]
scCiphers :: [Cipher]
scGroups :: [Group]
scParameters :: Parameters
scKeyLog :: String -> IO ()
scQLog :: Maybe String
scCredentials :: Credentials
scHooks :: Hooks
scTlsHooks :: ServerHooks
scUse0RTT :: Bool
scAddresses :: [(IP, PortNumber)]
scALPN :: Maybe (Version -> [ByteString] -> IO ByteString)
scRequireRetry :: Bool
scSessionManager :: SessionManager
scDebugLog :: Maybe String
scTicketLifetime :: Int
scVersions :: ServerConfig -> [Version]
scCiphers :: ServerConfig -> [Cipher]
scGroups :: ServerConfig -> [Group]
scParameters :: ServerConfig -> Parameters
scKeyLog :: ServerConfig -> String -> IO ()
scQLog :: ServerConfig -> Maybe String
scCredentials :: ServerConfig -> Credentials
scHooks :: ServerConfig -> Hooks
scTlsHooks :: ServerConfig -> ServerHooks
scUse0RTT :: ServerConfig -> Bool
scAddresses :: ServerConfig -> [(IP, PortNumber)]
scALPN :: ServerConfig -> Maybe (Version -> [ByteString] -> IO ByteString)
scRequireRetry :: ServerConfig -> Bool
scSessionManager :: ServerConfig -> SessionManager
scDebugLog :: ServerConfig -> Maybe String
scTicketLifetime :: ServerConfig -> Int
..} VersionInfo
verInfo AuthCIDs
myAuthCIDs AuthCIDs
peerAuthCIDs =
    Role
-> Parameters
-> VersionInfo
-> AuthCIDs
-> AuthCIDs
-> DebugLogger
-> QLogger
-> Hooks
-> IORef Socket
-> IORef PeerInfo
-> RecvQ
-> Send
-> Recv
-> IO Connection
newConnection Role
Server Parameters
scParameters VersionInfo
verInfo AuthCIDs
myAuthCIDs AuthCIDs
peerAuthCIDs

----------------------------------------------------------------

newtype Input = InpStream Stream deriving (Int -> Input -> ShowS
[Input] -> ShowS
Input -> String
(Int -> Input -> ShowS)
-> (Input -> String) -> ([Input] -> ShowS) -> Show Input
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Input -> ShowS
showsPrec :: Int -> Input -> ShowS
$cshow :: Input -> String
show :: Input -> String
$cshowList :: [Input] -> ShowS
showList :: [Input] -> ShowS
Show)
data Crypto = InpHandshake EncryptionLevel ByteString deriving (Int -> Crypto -> ShowS
[Crypto] -> ShowS
Crypto -> String
(Int -> Crypto -> ShowS)
-> (Crypto -> String) -> ([Crypto] -> ShowS) -> Show Crypto
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Crypto -> ShowS
showsPrec :: Int -> Crypto -> ShowS
$cshow :: Crypto -> String
show :: Crypto -> String
$cshowList :: [Crypto] -> ShowS
showList :: [Crypto] -> ShowS
Show)

data Output
    = OutControl EncryptionLevel [Frame] (IO ())
    | OutHandshake [(EncryptionLevel, ByteString)]
    | OutRetrans PlainPacket

type InputQ = TQueue Input
type CryptoQ = TQueue Crypto
type OutputQ = TQueue Output
type OutputQLim = TBQueue Output
type MigrationQ = TQueue ReceivedPacket

----------------------------------------------------------------

type SendStreamQ = TQueue TxStreamData

data Shared = Shared
    { Shared -> IORef Bool
sharedCloseSent :: IORef Bool
    , Shared -> IORef Bool
sharedCloseReceived :: IORef Bool
    , Shared -> IORef Bool
shared1RTTReady :: IORef Bool
    , Shared -> SendStreamQ
sharedSendStreamQ :: SendStreamQ
    }

newShared :: IO Shared
newShared :: IO Shared
newShared =
    IORef Bool -> IORef Bool -> IORef Bool -> SendStreamQ -> Shared
Shared
        (IORef Bool -> IORef Bool -> IORef Bool -> SendStreamQ -> Shared)
-> IO (IORef Bool)
-> IO (IORef Bool -> IORef Bool -> SendStreamQ -> Shared)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> IO (IORef Bool)
forall a. a -> IO (IORef a)
newIORef Bool
False
        IO (IORef Bool -> IORef Bool -> SendStreamQ -> Shared)
-> IO (IORef Bool) -> IO (IORef Bool -> SendStreamQ -> Shared)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> IO (IORef Bool)
forall a. a -> IO (IORef a)
newIORef Bool
False
        IO (IORef Bool -> SendStreamQ -> Shared)
-> IO (IORef Bool) -> IO (SendStreamQ -> Shared)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> IO (IORef Bool)
forall a. a -> IO (IORef a)
newIORef Bool
False
        IO (SendStreamQ -> Shared) -> IO SendStreamQ -> IO Shared
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IO SendStreamQ
forall a. IO (TQueue a)
newTQueueIO