| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
LibP2P.Multiaddr
Description
A multiaddr is a binary-encoded, composable network address that describes the entire protocol stack needed to reach a peer.
Synopsis
- newtype Multiaddr = Multiaddr [Protocol]
- fromText :: Text -> Either String Multiaddr
- toText :: Multiaddr -> Text
- fromBytes :: ByteString -> Either String Multiaddr
- toBytes :: Multiaddr -> ByteString
- encapsulate :: Multiaddr -> Multiaddr -> Multiaddr
- decapsulate :: Multiaddr -> Multiaddr -> Multiaddr
- protocols :: Multiaddr -> [Protocol]
- splitP2P :: Multiaddr -> Maybe (Multiaddr, PeerId)
- isPublicAddr :: Multiaddr -> Bool
- isRelayedAddr :: Multiaddr -> Bool
Documentation
A multiaddr is a list of protocol components.
fromText :: Text -> Either String Multiaddr Source #
Parse a multiaddr from its text representation (e.g. "ip4127.0.0.1tcp4001").
toBytes :: Multiaddr -> ByteString Source #
Encode a multiaddr to binary format.
encapsulate :: Multiaddr -> Multiaddr -> Multiaddr Source #
Encapsulate: append another multiaddr's protocols.
decapsulate :: Multiaddr -> Multiaddr -> Multiaddr Source #
Decapsulate: remove the last occurrence of the given suffix multiaddr
and everything after it (specs/addressing). Returns the original
multiaddr unchanged when the suffix does not occur. Decapsulating the
empty multiaddr is a no-op, making decapsulate a left inverse of
encapsulate: decapsulate (encapsulate a b) b == a for non-empty b.
splitP2P :: Multiaddr -> Maybe (Multiaddr, PeerId) Source #
Split off the trailing p2ppeerId component from a multiaddr. Returns the transport address and the peer ID, or Nothing if the multiaddr does not end with a p2p component.
isPublicAddr :: Multiaddr -> Bool Source #
Whether the address is publicly routable.
Mirrors go-multiaddr's manet.IsPublicAddr (net/private.go), which
the DCUtR unilateral-upgrade check depends on: a peer is only worth
dialling directly if it advertises an address that can be reached.
IPv4 is classified by exclusion (anything outside the private and unroutable ranges is public); IPv6 by inclusion (only the global unicast allocation, minus documentation and multicast, plus the NAT64 prefixes). A DNS name is public unless it is a special-use domain. An address with no IP or DNS component is not public.
isRelayedAddr :: Multiaddr -> Bool Source #
Whether the address goes through a circuit relay, i.e. contains a
/p2p-circuit component.