The AddressManager provides an interface for managing peer addresses in libp2p. It supports handling multiple types of addresses, verifying their validity, and storing mappings between internal and external addresses.

interface AddressManager {
    addDNSMapping(domain, ipAddresses): void;
    addObservedAddr(addr): void;
    addPublicAddressMapping(internalIp, internalPort, externalIp, externalPort?, protocol?): void;
    confirmObservedAddr(addr, options?): void;
    getAddresses(): Multiaddr[];
    getAddressesWithMetadata(): NodeAddress[];
    getAnnounceAddrs(): Multiaddr[];
    getListenAddrs(): Multiaddr[];
    getObservedAddrs(): Multiaddr[];
    removeDNSMapping(domain): void;
    removeObservedAddr(addr): void;
    removePublicAddressMapping(internalIp, internalPort, externalIp, externalPort?, protocol?): void;
}

Methods

  • Adds a mapping between one or more IP addresses and a domain name - when getAddresses is invoked, where the IP addresses are present in a multiaddr, an additional multiaddr will be added with ip4 and ip6 tuples replaced with dns4 and `dns6 ones respectively.

    Parameters

    • domain: string

      The domain name to map.

    • ipAddresses: string[]

      The associated IP addresses.

    Returns void

  • Add peer observed addresses. These will then appear in the output of getObservedAddrs but not getAddresses() until their dialability has been confirmed via a call to confirmObservedAddr.

    Parameters

    Returns void

  • Add a publicly routable address/port/protocol tuple that this node is reachable on. Where this node listens on a link-local (e.g. LAN) address with the same protocol for any transport, an additional listen address will be added with the IP and port replaced with this IP and port.

    It's possible to add a IPv6 address here and have it added to the address list, this is for the case when a router has an external IPv6 address with port forwarding configured, but it does IPv6 -> IPv4 NAT.

    Parameters

    • internalIp: string

      The internal IP address.

    • internalPort: number

      The internal port number.

    • externalIp: string

      The external IP address.

    • Optional externalPort: number

      The external port number (optional).

    • Optional protocol: "tcp" | "udp"

      The transport protocol (tcp or udp).

    Returns void

  • Remove a publicly routable address that this node is no longer reachable on

    Parameters

    • internalIp: string

      The internal IP address.

    • internalPort: number

      The internal port number.

    • externalIp: string

      The external IP address.

    • Optional externalPort: number

      The external port number (optional).

    • Optional protocol: "tcp" | "udp"

      The transport protocol (tcp or udp).

    Returns void