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

Network.LibP2P.Switch.ConnPool

Description

STM-based connection pool for the Switch.

Tracks active connections per peer. All operations are STM-safe for concurrent access from dial, listen, and cleanup threads.

Connection identity uses TVar pointer equality (connState field) since Connection contains function fields that prevent deriving Eq.

Synopsis

Documentation

newConnPool :: IO (TVar (Map PeerId [Connection])) Source #

Create a new empty connection pool.

lookupConn :: TVar (Map PeerId [Connection]) -> PeerId -> STM (Maybe Connection) Source #

Look up the first Open connection for a peer. Returns Nothing if no connection exists or none are in ConnOpen state.

lookupAllConns :: TVar (Map PeerId [Connection]) -> PeerId -> STM [Connection] Source #

Look up all connections for a peer (any state).

addConn :: TVar (Map PeerId [Connection]) -> Connection -> STM () Source #

Add a connection to the pool, keyed by its peer ID.

removeConn :: TVar (Map PeerId [Connection]) -> Connection -> STM () Source #

Remove a specific connection from the pool. Uses TVar reference equality (connState) to identify the connection. Removes empty entries from the map to prevent memory leaks.

allConns :: TVar (Map PeerId [Connection]) -> STM [Connection] Source #

Get all connections across all peers.