| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
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
- closeConnection :: Switch -> Connection -> IO ()
- closeAllConnections :: Switch -> IO ()
- newStream :: Switch -> Connection -> IO (Either StreamOpenError StreamIO)
- newStreamAllowingLimited :: Switch -> Connection -> IO (Either StreamOpenError StreamIO)
- data StreamOpenError
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 StreamOpenError 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).
Refuses a relay-limited connection. Protocols that must run over a
relay circuit (Identify, Ping, DCUtR) use newStreamAllowingLimited.
newStreamAllowingLimited :: Switch -> Connection -> IO (Either StreamOpenError StreamIO) Source #
Like newStream, but allows a relay-limited connection.
The circuit still dies when its budget is exhausted
(RelayCircuitExhausted). Opt in only for a
short exchange that can tolerate that.
data StreamOpenError Source #
Failure to open an outbound stream.
Constructors
| StreamResourceLimit !ResourceError | Peer or connection stream budget is exhausted |
| StreamLimitedConnection | The connection is a relay circuit with an active budget, and the caller did not opt in. No stream slot is reserved. |
Instances
| Exception StreamOpenError Source # | |
Defined in LibP2P.Switch.Connection Methods toException :: StreamOpenError -> SomeException # fromException :: SomeException -> Maybe StreamOpenError # displayException :: StreamOpenError -> String # backtraceDesired :: StreamOpenError -> Bool # | |
| Show StreamOpenError Source # | |
Defined in LibP2P.Switch.Connection Methods showsPrec :: Int -> StreamOpenError -> ShowS # show :: StreamOpenError -> String # showList :: [StreamOpenError] -> ShowS # | |
| Eq StreamOpenError Source # | |
Defined in LibP2P.Switch.Connection Methods (==) :: StreamOpenError -> StreamOpenError -> Bool # (/=) :: StreamOpenError -> StreamOpenError -> Bool # | |