Libp2p.SecureConn (libp2p_elixir v0.9.0)

Noise-secured connection wrapper.

This intentionally exposes a small interface; the Swarm/Connection process owns the socket and calls these helpers.

Summary

Functions

Decrypt as many complete Noise transport messages as are currently buffered.

Append raw encrypted bytes received from the socket.

Receive some plaintext bytes (one Noise transport message).

Types

cipher_state()

@type cipher_state() :: %{k: binary() | nil, n: non_neg_integer()}

t()

@type t() :: %Libp2p.SecureConn{
  cs_in: cipher_state(),
  cs_out: cipher_state(),
  recv_buf: binary(),
  socket: Libp2p.Transport.Tcp.socket()
}

Functions

drain(c)

@spec drain(t()) :: {[binary()], t()}

Decrypt as many complete Noise transport messages as are currently buffered.

Returns {plaintext_messages, conn2} where each plaintext message corresponds to one Noise transport message.

ingest(c, data)

@spec ingest(t(), binary()) :: t()

Append raw encrypted bytes received from the socket.

new(socket, cs_in, cs_out)

recv(c, timeout \\ 5000)

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

Receive some plaintext bytes (one Noise transport message).

Returns {bytes, conn2} where bytes may be empty only on protocol errors (raised).

send(c, bytes)

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