Libp2p.ConnectionV2 (libp2p_elixir v0.9.0)
Manages a secure, multiplexed Libp2p connection.
This module encapsulates the state machine for a single peer connection, handling the transition from a raw transport socket to a fully functional application session.
Connection Lifecycle
The connection process follows the standard Libp2p upgrade path:
- Transport Establishment: A raw TCP connection is established (either via Dial or Listen).
- Multistream-select (Security): The peers negotiate the security protocol.
Only
/noiseis currently supported. - Secure Handshake: The peers perform a Noise XX handshake to authenticate each other
and establish shared encryption keys. See
Libp2p.Noisefor details. - Multistream-select (Muxer): Over the now-encrypted channel, the peers negotiate a
stream multiplexer. Only
/yamux/1.0.0is currently supported. - Multiplexing (Yamux): The process enters the Yamux session mode. It acts as the controller for the session, parsing incoming frames and routing them to logical streams.
Stream Management
Once established, this process manages multiple concurrent logical streams (Libp2p.InboundStream
or task-based handlers). It handles:
- Opening new outbound streams.
- Accepting inbound streams and negotiating protocols.
- Flow control (Yamux window updates).
- Connection teardown (GoAway frames).
Summary
Functions
Returns a specification to start this module under a supervisor.
Reset (RST) a yamux stream.
Set the process that will receive stream events.
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec close_stream(pid(), non_neg_integer()) :: :ok | {:error, term()}
@spec open_stream(pid()) :: {:ok, non_neg_integer()} | {:error, term()}
@spec open_stream(pid(), binary()) :: {:ok, non_neg_integer()} | {:error, term()}
@spec reset_stream(pid() | atom(), non_neg_integer()) :: :ok | {:error, term()}
Reset (RST) a yamux stream.
@spec send_stream(pid(), non_neg_integer(), binary()) :: :ok | {:error, term()}
@spec set_stream_handler(pid(), non_neg_integer(), pid()) :: :ok
Set the process that will receive stream events.
@spec start_link(keyword()) :: GenServer.on_start()