Libp2p.Multiaddr (libp2p_elixir v0.9.0)
Minimal Multiaddr implementation (binary codec + a small parser).
Ethereum consensus clients mostly need /ip4|ip6/.../tcp/... (and often see
additional components like /p2p/..., /udp/.../quic-v1, /tls, /ws in peer
advertisements). We implement enough of the multiaddr table to:
- encode/decode common addresses seen in the wild
- extract a
:inettuple + port for TCP dialing/listening
Summary
Functions
Parse a multiaddr string like /ip4/1.2.3.4/tcp/9000(/p2p/<peerid>).
Best-effort conversion to a multiaddr string. Unknown/unsupported protos are not represented.
Extract a TCP socket address from a multiaddr (first ip4/ip6 + tcp).
Returns {:ok, {ip, port}} or {:error, reason}.
Types
@type proto() :: {:ip4, :inet.ip4_address()} | {:ip6, :inet.ip6_address()} | {:tcp, :inet.port_number()} | {:udp, :inet.port_number()} | {:dns, binary()} | {:dns4, binary()} | {:dns6, binary()} | {:dnsaddr, binary()} | {:p2p, binary()} | {:quic, nil} | {:quic_v1, nil} | {:webtransport, nil} | {:tls, nil} | {:ws, nil} | {:wss, nil} | {:certhash, binary()}
Functions
Parse a multiaddr string like /ip4/1.2.3.4/tcp/9000(/p2p/<peerid>).
@spec from_tcp_socketaddr(:inet.ip_address(), :inet.port_number()) :: t()
Best-effort conversion to a multiaddr string. Unknown/unsupported protos are not represented.
@spec to_tcp_socketaddr(t()) :: {:ok, {:inet.ip_address(), :inet.port_number()}} | {:error, term()}
Extract a TCP socket address from a multiaddr (first ip4/ip6 + tcp).
Returns {:ok, {ip, port}} or {:error, reason}.