Skip to main content

multiaddr_to_ws_url

Function multiaddr_to_ws_url 

Source
pub fn multiaddr_to_ws_url(addr: &str) -> Result<String, String>
Expand description

Normalize a peer address to a WebSocket URL the relay can dial.

Accepts:

  • a libp2p multiaddr: /ip4/H/tcp/P, /ip6/H/tcp/P, /dns4/H/tcp/P (also /dns, /dns6, /dnsaddr), with an optional /ws or /wss transport suffix (default ws) and an optional trailing /p2p/<id> (ignored — the relay addresses by host:port, not peer id);
  • a raw ws://… or wss://… URL, returned unchanged.

IPv6 literals are bracketed (/ip6/::1/tcp/9944ws://[::1]:9944).

Returns Err with a human message on anything it cannot map.