Libp2p.Swarm (libp2p_elixir v0.9.0)

Minimal Swarm runtime for the libp2p subset we implement.

Responsibilities:

  • start/stop TCP listeners
  • dial peers
  • supervise connections (each connection owns its socket + yamux session)
  • notify on inbound streams for protocol routing

Protocol routing is implemented in later steps (Identify/Gossipsub/ReqResp).

Summary

Functions

Returns a specification to start this module under a supervisor.

Dial a peer at {ip, port}.

Start listening on {ip, port}.

Types

t()

@type t() :: pid() | atom()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

dial(swarm, ip, port)

@spec dial(t(), :inet.ip_address(), :inet.port_number()) ::
  {:ok, pid()} | {:error, term()}

Dial a peer at {ip, port}.

dial(swarm, ip, port, opts)

@spec dial(t(), :inet.ip_address(), :inet.port_number(), keyword()) ::
  {:ok, pid()} | {:error, term()}

listen(swarm, ip, port)

@spec listen(t(), :inet.ip_address(), :inet.port_number()) ::
  {:ok, Libp2p.Transport.Tcp.socket()} | {:error, term()}

Start listening on {ip, port}.

start_link(opts)

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