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

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

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.