| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Network.LibP2P.Switch.Switch
Description
Switch core operations.
The Switch is the central coordinator of the libp2p stack. This module provides construction, transport management, protocol handler registration, and shutdown.
Synopsis
- newSwitch :: PeerId -> KeyPair -> IO Switch
- addTransport :: Switch -> Transport -> IO ()
- selectTransport :: Switch -> Multiaddr -> IO (Maybe Transport)
- setStreamHandler :: Switch -> ProtocolId -> StreamHandler -> IO ()
- removeStreamHandler :: Switch -> ProtocolId -> IO ()
- lookupStreamHandler :: Switch -> ProtocolId -> IO (Maybe StreamHandler)
- switchClose :: Switch -> IO ()
Documentation
newSwitch :: PeerId -> KeyPair -> IO Switch Source #
Create a new Switch with the given local identity. All internal state is initialized empty.
addTransport :: Switch -> Transport -> IO () Source #
Register a transport with the switch. Appends to the list of transports; order matters for selectTransport.
selectTransport :: Switch -> Multiaddr -> IO (Maybe Transport) Source #
Find the first registered transport that can dial the given multiaddr.
setStreamHandler :: Switch -> ProtocolId -> StreamHandler -> IO () Source #
Register a protocol stream handler. Overwrites any existing handler for the same protocol ID.
removeStreamHandler :: Switch -> ProtocolId -> IO () Source #
Remove a protocol stream handler.
lookupStreamHandler :: Switch -> ProtocolId -> IO (Maybe StreamHandler) Source #
Look up a registered stream handler by protocol ID.
switchClose :: Switch -> IO () Source #
Shut down the switch. Cancels all accept loop threads, closes all listeners, then sets the closed flag.