module Network.LibP2P.Switch.Types
( ConnState (..)
, Direction (..)
, MuxerSession (..)
, Connection (..)
, SwitchEvent (..)
, StreamHandler
, Switch (..)
, DialError (..)
, BackoffEntry (..)
, ResourceError (..)
, ActiveListener (..)
) where
import Control.Concurrent.Async (Async)
import Control.Concurrent.STM (TChan, TMVar, TVar)
import Data.Map.Strict (Map)
import Data.Time.Clock (UTCTime)
import Network.LibP2P.Crypto.Key (KeyPair)
import Network.LibP2P.Crypto.PeerId (PeerId)
import Network.LibP2P.Multiaddr.Multiaddr (Multiaddr)
import Network.LibP2P.MultistreamSelect.Negotiation (ProtocolId, StreamIO)
import Network.LibP2P.Protocol.Identify.Message (IdentifyInfo)
import Network.LibP2P.Switch.ResourceManager (Direction (..), ResourceError (..), ResourceManager)
import Network.LibP2P.Transport.Transport (Listener, Transport)
data ConnState
= Connecting
| ConnOpen
| Closing
| ConnClosed
deriving (Int -> ConnState -> ShowS
[ConnState] -> ShowS
ConnState -> String
(Int -> ConnState -> ShowS)
-> (ConnState -> String)
-> ([ConnState] -> ShowS)
-> Show ConnState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ConnState -> ShowS
showsPrec :: Int -> ConnState -> ShowS
$cshow :: ConnState -> String
show :: ConnState -> String
$cshowList :: [ConnState] -> ShowS
showList :: [ConnState] -> ShowS
Show, ConnState -> ConnState -> Bool
(ConnState -> ConnState -> Bool)
-> (ConnState -> ConnState -> Bool) -> Eq ConnState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ConnState -> ConnState -> Bool
== :: ConnState -> ConnState -> Bool
$c/= :: ConnState -> ConnState -> Bool
/= :: ConnState -> ConnState -> Bool
Eq)
data MuxerSession = MuxerSession
{ MuxerSession -> IO StreamIO
muxOpenStream :: !(IO StreamIO)
, MuxerSession -> IO StreamIO
muxAcceptStream :: !(IO StreamIO)
, MuxerSession -> IO ()
muxClose :: !(IO ())
}
data Connection = Connection
{ Connection -> PeerId
connPeerId :: !PeerId
, Connection -> Direction
connDirection :: !Direction
, Connection -> Multiaddr
connLocalAddr :: !Multiaddr
, Connection -> Multiaddr
connRemoteAddr :: !Multiaddr
, Connection -> ProtocolId
connSecurity :: !ProtocolId
, Connection -> ProtocolId
connMuxer :: !ProtocolId
, Connection -> MuxerSession
connSession :: !MuxerSession
, Connection -> TVar ConnState
connState :: !(TVar ConnState)
}
type StreamHandler = StreamIO -> PeerId -> IO ()
data SwitchEvent
= Connected !PeerId !Direction !Multiaddr
| Disconnected !PeerId !Direction !Multiaddr
deriving (Int -> SwitchEvent -> ShowS
[SwitchEvent] -> ShowS
SwitchEvent -> String
(Int -> SwitchEvent -> ShowS)
-> (SwitchEvent -> String)
-> ([SwitchEvent] -> ShowS)
-> Show SwitchEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SwitchEvent -> ShowS
showsPrec :: Int -> SwitchEvent -> ShowS
$cshow :: SwitchEvent -> String
show :: SwitchEvent -> String
$cshowList :: [SwitchEvent] -> ShowS
showList :: [SwitchEvent] -> ShowS
Show, SwitchEvent -> SwitchEvent -> Bool
(SwitchEvent -> SwitchEvent -> Bool)
-> (SwitchEvent -> SwitchEvent -> Bool) -> Eq SwitchEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SwitchEvent -> SwitchEvent -> Bool
== :: SwitchEvent -> SwitchEvent -> Bool
$c/= :: SwitchEvent -> SwitchEvent -> Bool
/= :: SwitchEvent -> SwitchEvent -> Bool
Eq)
data DialError
= DialBackoff
| DialNoAddresses
| DialNoTransport !Multiaddr
| DialAllFailed ![String]
| DialUpgradeFailed !String
| DialSwitchClosed
| DialResourceLimit !ResourceError
| DialPeerIdMismatch !PeerId !PeerId
deriving (Int -> DialError -> ShowS
[DialError] -> ShowS
DialError -> String
(Int -> DialError -> ShowS)
-> (DialError -> String)
-> ([DialError] -> ShowS)
-> Show DialError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DialError -> ShowS
showsPrec :: Int -> DialError -> ShowS
$cshow :: DialError -> String
show :: DialError -> String
$cshowList :: [DialError] -> ShowS
showList :: [DialError] -> ShowS
Show, DialError -> DialError -> Bool
(DialError -> DialError -> Bool)
-> (DialError -> DialError -> Bool) -> Eq DialError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DialError -> DialError -> Bool
== :: DialError -> DialError -> Bool
$c/= :: DialError -> DialError -> Bool
/= :: DialError -> DialError -> Bool
Eq)
data BackoffEntry = BackoffEntry
{ BackoffEntry -> UTCTime
beExpiry :: !UTCTime
, BackoffEntry -> Int
beAttempts :: !Int
} deriving (Int -> BackoffEntry -> ShowS
[BackoffEntry] -> ShowS
BackoffEntry -> String
(Int -> BackoffEntry -> ShowS)
-> (BackoffEntry -> String)
-> ([BackoffEntry] -> ShowS)
-> Show BackoffEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BackoffEntry -> ShowS
showsPrec :: Int -> BackoffEntry -> ShowS
$cshow :: BackoffEntry -> String
show :: BackoffEntry -> String
$cshowList :: [BackoffEntry] -> ShowS
showList :: [BackoffEntry] -> ShowS
Show, BackoffEntry -> BackoffEntry -> Bool
(BackoffEntry -> BackoffEntry -> Bool)
-> (BackoffEntry -> BackoffEntry -> Bool) -> Eq BackoffEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BackoffEntry -> BackoffEntry -> Bool
== :: BackoffEntry -> BackoffEntry -> Bool
$c/= :: BackoffEntry -> BackoffEntry -> Bool
/= :: BackoffEntry -> BackoffEntry -> Bool
Eq)
data ActiveListener = ActiveListener
{ ActiveListener -> Listener
alListener :: !Listener
, ActiveListener -> Async ()
alAcceptLoop :: !(Async ())
, ActiveListener -> Multiaddr
alAddress :: !Multiaddr
}
data Switch = Switch
{ Switch -> PeerId
swLocalPeerId :: !PeerId
, Switch -> KeyPair
swIdentityKey :: !KeyPair
, Switch -> TVar [Transport]
swTransports :: !(TVar [Transport])
, Switch -> TVar (Map PeerId [Connection])
swConnPool :: !(TVar (Map PeerId [Connection]))
, Switch -> TVar (Map ProtocolId StreamHandler)
swProtocols :: !(TVar (Map ProtocolId StreamHandler))
, Switch -> TChan SwitchEvent
swEvents :: !(TChan SwitchEvent)
, Switch -> TVar Bool
swClosed :: !(TVar Bool)
, Switch -> TVar (Map PeerId BackoffEntry)
swDialBackoffs :: !(TVar (Map PeerId BackoffEntry))
, Switch -> TVar (Map PeerId (TMVar (Either DialError Connection)))
swPendingDials :: !(TVar (Map PeerId (TMVar (Either DialError Connection))))
, Switch -> ResourceManager
swResourceMgr :: !ResourceManager
, Switch -> TVar (Map PeerId IdentifyInfo)
swPeerStore :: !(TVar (Map PeerId IdentifyInfo))
, Switch -> TVar [Connection -> IO ()]
swNotifiers :: !(TVar [Connection -> IO ()])
, Switch -> TVar [ActiveListener]
swListeners :: !(TVar [ActiveListener])
}