| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Network.LibP2P.Switch.Types
Description
Core types for the libp2p Switch (central coordinator).
Defines connection states, direction, muxer session abstraction, connection records, switch events, and the Switch itself. See docs/08-switch.md for the full specification.
Synopsis
- data ConnState
- data Direction
- data MuxerSession = MuxerSession {
- muxOpenStream :: !(IO StreamIO)
- muxAcceptStream :: !(IO StreamIO)
- muxClose :: !(IO ())
- data Connection = Connection {
- connPeerId :: !PeerId
- connDirection :: !Direction
- connLocalAddr :: !Multiaddr
- connRemoteAddr :: !Multiaddr
- connSecurity :: !ProtocolId
- connMuxer :: !ProtocolId
- connSession :: !MuxerSession
- connState :: !(TVar ConnState)
- data SwitchEvent
- type StreamHandler = StreamIO -> PeerId -> IO ()
- data Switch = Switch {
- swLocalPeerId :: !PeerId
- swIdentityKey :: !KeyPair
- swTransports :: !(TVar [Transport])
- swConnPool :: !(TVar (Map PeerId [Connection]))
- swProtocols :: !(TVar (Map ProtocolId StreamHandler))
- swEvents :: !(TChan SwitchEvent)
- swClosed :: !(TVar Bool)
- swDialBackoffs :: !(TVar (Map PeerId BackoffEntry))
- swPendingDials :: !(TVar (Map PeerId (TMVar (Either DialError Connection))))
- swResourceMgr :: !ResourceManager
- swPeerStore :: !(TVar (Map PeerId IdentifyInfo))
- swNotifiers :: !(TVar [Connection -> IO ()])
- swListeners :: !(TVar [ActiveListener])
- data DialError
- data BackoffEntry = BackoffEntry {
- beExpiry :: !UTCTime
- beAttempts :: !Int
- data ResourceError = ResourceLimitExceeded !ScopeName !String
- data ActiveListener = ActiveListener {
- alListener :: !Listener
- alAcceptLoop :: !(Async ())
- alAddress :: !Multiaddr
Documentation
Connection state machine (docs/08-switch.md §Connection States).
Connecting → ConnOpen → Closing → Closed
Constructors
| Connecting | Raw transport established, upgrade in progress |
| ConnOpen | Fully upgraded, streams can be opened/accepted |
| Closing | Go Away sent/received, draining existing streams |
| ConnClosed | Transport connection closed, resources freed |
Direction of a connection relative to this node. Defined here to avoid circular dependency with Switch.Types.
data MuxerSession Source #
Abstract muxer session interface.
Decouples Switch from a specific muxer (Yamux, mplex, etc.). Each muxer implementation provides a MuxerSession adapter.
Constructors
| MuxerSession | |
Fields
| |
data Connection Source #
An upgraded (secure + multiplexed) connection to a remote peer.
Constructors
| Connection | |
Fields
| |
data SwitchEvent Source #
Events emitted by the Switch for observability.
Constructors
| Connected !PeerId !Direction !Multiaddr | Connection fully upgraded |
| Disconnected !PeerId !Direction !Multiaddr | Connection closed |
Instances
| Show SwitchEvent Source # | |
Defined in Network.LibP2P.Switch.Types Methods showsPrec :: Int -> SwitchEvent -> ShowS # show :: SwitchEvent -> String # showList :: [SwitchEvent] -> ShowS # | |
| Eq SwitchEvent Source # | |
Defined in Network.LibP2P.Switch.Types | |
type StreamHandler = StreamIO -> PeerId -> IO () Source #
A protocol stream handler.
Receives the stream I/O and the remote peer's identity.
The Switch: central coordinator of the libp2p networking stack.
Manages transports, connection pool, protocol handlers, and events. All mutable state is STM-based for safe concurrent access.
Constructors
| Switch | |
Fields
| |
Errors that can occur during a dial operation (docs/08-switch.md §Dialing).
Constructors
| DialBackoff | Peer is in backoff period (recently failed) |
| DialNoAddresses | No addresses provided for dialing |
| DialNoTransport !Multiaddr | No registered transport can handle this address |
| DialAllFailed ![String] | All dial attempts failed |
| DialUpgradeFailed !String | Connection upgrade pipeline failed |
| DialSwitchClosed | Switch has been shut down |
| DialResourceLimit !ResourceError | Resource limit exceeded |
| DialPeerIdMismatch !PeerId !PeerId | Expected vs actual remote PeerId |
data BackoffEntry Source #
Per-peer dial backoff state (docs/08-switch.md §Dial Backoff).
After a failed dial, subsequent dials are rejected until the backoff expires. Duration doubles on each consecutive failure up to 300s max.
Constructors
| BackoffEntry | |
Fields
| |
Instances
| Show BackoffEntry Source # | |
Defined in Network.LibP2P.Switch.Types Methods showsPrec :: Int -> BackoffEntry -> ShowS # show :: BackoffEntry -> String # showList :: [BackoffEntry] -> ShowS # | |
| Eq BackoffEntry Source # | |
Defined in Network.LibP2P.Switch.Types | |
data ResourceError Source #
Resource limit violation error.
Constructors
| ResourceLimitExceeded !ScopeName !String |
Instances
| Show ResourceError Source # | |
Defined in Network.LibP2P.Switch.ResourceManager Methods showsPrec :: Int -> ResourceError -> ShowS # show :: ResourceError -> String # showList :: [ResourceError] -> ShowS # | |
| Eq ResourceError Source # | |
Defined in Network.LibP2P.Switch.ResourceManager Methods (==) :: ResourceError -> ResourceError -> Bool # (/=) :: ResourceError -> ResourceError -> Bool # | |
data ActiveListener Source #
An active listener bound to an address with its accept loop thread.
Constructors
| ActiveListener | |
Fields
| |