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

LibP2P.Switch.Connection

Description

Connection lifecycle for the Switch.

Provides the single teardown path for upgraded connections and a resource-accounted outbound stream opener. Teardown fires from the stream accept loop exit (remote disconnect or session death), from explicit closeConnection calls, and from switchClose via closeAllConnections.

Synopsis

Documentation

closeConnection :: Switch -> Connection -> IO () Source #

Tear down a connection: remove it from the pool, release its resource reservation, publish a Disconnected event, run the disconnect notifiers, and close the muxer session together with the underlying transport.

Idempotent: the state transition to ConnClosed is atomic, so concurrent calls (accept loop exit, explicit close, switchClose) perform the teardown exactly once, and the notifiers run once.

Notifiers run synchronously, after the pool removal has committed and before the muxer is closed, so a notifier that asks whether the peer still has a live connection (Circuit Relay v2 reservation cleanup) never sees the connection being torn down. Each is isolated so a failing notifier cannot abort the teardown.

closeAllConnections :: Switch -> IO () Source #

Tear down every pooled connection (used by switchClose).

newStream :: Switch -> Connection -> IO (Either ResourceError StreamIO) Source #

Open an outbound stream on a connection, reserving a stream slot against the peer's resource scope. The slot is released when the returned stream is closed (exactly once, even on double close).