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

LibP2P.Switch.ResourceManager

Description

Hierarchical resource management for the Switch.

Resources are owned by a System -> Peer -> Connection -> Stream scope tree. Reservations walk from the owning scope to the system scope in one STM transaction, so a failed ancestor check never leaves partial usage behind.

Synopsis

Documentation

data Direction Source #

Direction of a resource relative to this node.

Constructors

Inbound 
Outbound 

Instances

Instances details
Show Direction Source # 
Instance details

Defined in LibP2P.Switch.ResourceManager

Eq Direction Source # 
Instance details

Defined in LibP2P.Switch.ResourceManager

data ResourceUsage Source #

Tracked usage aggregated at a scope.

data ResourceScope Source #

A node in the resource ownership tree.

data ScopeName Source #

Stable names make sibling connection and stream scopes distinguishable.

data MemoryAccount Source #

Generic memory hooks used by buffering layers without exposing the tree.

Constructors

MemoryAccount 

Fields

reserveConnection :: ResourceManager -> PeerId -> Direction -> STM (Either ResourceError ResourceScope) Source #

Create and reserve one connection scope.

releaseConnection :: ResourceManager -> ResourceScope -> STM () Source #

Close a connection and every stream it owns. Idempotent.

reserveStream :: ResourceManager -> ResourceScope -> Direction -> STM (Either ResourceError ResourceScope) Source #

Create and reserve one stream below a connection scope.

releaseStream :: ResourceManager -> ResourceScope -> STM () Source #

Close a stream and release all usage it still owns. Idempotent.

unlimitedMemoryAccount :: MemoryAccount Source #

An account for standalone protocol use where no manager is installed.