hs-libp2p-0.2.0.0: Haskell implementation of the libp2p networking stack
Safe HaskellNone
LanguageGHC2021

LibP2P.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

Documentation

newSwitch :: PeerId -> KeyPair -> IO Switch Source #

Create a new Switch with the given local identity. All internal state is initialized empty.

newSwitchWithConfig :: SwitchConfig -> PeerId -> KeyPair -> IO Switch Source #

Like newSwitch, with an explicit configuration.

subscribeSwitchEvents :: Switch -> IO (TChan SwitchEvent) Source #

Subscribe independently to future per-connection events (no replay). Drop the channel to unsubscribe; unread channels retain queued events. Shutdown neither waits for subscribers nor signals end-of-stream.

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.

setConnectionGater :: Switch -> ConnectionGater -> IO () Source #

Set the admission policy used by future inbound and outbound connections. Configure this before starting listeners or dialing peers.

setStreamHandler :: Switch -> ProtocolId -> StreamHandler -> IO () Source #

Register a protocol stream handler. Overwrites any existing handler for the same protocol ID. The changed protocol set is pushed to connected peers via identify push (specs/identify) in the background.

removeStreamHandler :: Switch -> ProtocolId -> IO () Source #

Remove a protocol stream handler. The changed protocol set is pushed to connected peers via identify push (specs/identify) in the background.

lookupStreamHandler :: Switch -> ProtocolId -> IO (Maybe StreamHandler) Source #

Look up a registered stream handler by protocol ID.

registerSwitchShutdownAction :: Switch -> IO () -> IO () Source #

Register cleanup for a background service owned by the Switch. If shutdown has already begun, the action runs immediately instead.

switchClose :: Switch -> IO () Source #

Shut down the switch. Stops background services, cancels accept loops, closes listeners, and tears down all pooled connections.