Libp2p.Connection (libp2p_elixir v0.9.0)

One libp2p connection process.

Owns:

Exposes basic stream send/recv primitives used by higher-level protocol handlers.

Summary

Functions

Block until the connection has completed the upgrade pipeline.

Returns a specification to start this module under a supervisor.

Open a new outbound yamux stream.

Return the remote peer id (from Noise) once ready.

Set the process that will receive stream events.

Close (FIN) a yamux stream.

Receive bytes for a yamux stream (may return partial data).

Send bytes on a yamux stream.

Types

t()

@type t() :: pid()

Functions

await_ready(conn, timeout \\ 20000)

@spec await_ready(t(), timeout()) :: :ok | {:error, term()}

Block until the connection has completed the upgrade pipeline.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

open_stream(conn)

@spec open_stream(t()) :: {:ok, non_neg_integer()} | {:error, term()}

Open a new outbound yamux stream.

peer_store(conn)

@spec peer_store(t()) :: term()

remote_peer_id(conn)

@spec remote_peer_id(t()) :: {:ok, binary()} | {:error, term()}

Return the remote peer id (from Noise) once ready.

set_stream_handler(conn, stream_id, pid)

@spec set_stream_handler(t(), non_neg_integer(), pid()) :: :ok

Set the process that will receive stream events.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

stream_close(conn, stream_id)

@spec stream_close(t(), non_neg_integer()) :: :ok | {:error, term()}

Close (FIN) a yamux stream.

stream_recv(conn, stream_id, timeout \\ 5000)

@spec stream_recv(t(), non_neg_integer(), timeout()) ::
  {:ok, binary()} | {:error, term()}

Receive bytes for a yamux stream (may return partial data).

stream_send(conn, stream_id, data)

@spec stream_send(t(), non_neg_integer(), binary()) :: :ok | {:error, term()}

Send bytes on a yamux stream.