Skip to content

Announce-address API parity with go-libp2p: callable AddrsFactory + DisableIdentifyAddressDiscovery #1311

@acul71

Description

@acul71

Context

PR #1284 adds an ObservedAddrManager and integrates externally observed addresses into BasicHost.get_addrs() when no announce_addrs argument is provided (fixes #1250). When announce_addrs is provided, it is now treated as a static-list AddrsFactory — mirroring go-libp2p's applyAddrsFactory behaviour — so observed addresses are still recorded by the manager (for get_nat_type, future AutoNAT consumers, etc.) but not advertised via get_addrs.

This covers the common "NAT / EC2 auto-discovery" case (#1250) and the "I know my exact public addresses" case (#1268), but there are two follow-up gaps versus go-libp2p that are deliberately out of scope for #1284.

Gap 1 — Callable announce_addrs / AddrsFactory

go-libp2p exposes AddrsFactory as a function ([]ma.Multiaddr) -> []ma.Multiaddr (see options.go:259-268). The factory receives the full live list (listen + interface + NAT + observed) and returns whatever the user wants to advertise. That lets users compose listen + observed + extras themselves without having to pick one or the other.

py-libp2p currently only accepts a static announce_addrs: Sequence[Multiaddr] | None. A callable form (e.g. announce_addrs: Sequence[Multiaddr] | Callable[[list[Multiaddr]], list[Multiaddr]] | None, or a dedicated addrs_factory= kwarg) would close this gap.

Gap 2 — Public opt-out to stop recording observations (DisableIdentifyAddressDiscovery)

go-libp2p also exposes DisableIdentifyAddressDiscovery() (options.go:601-610), whose docstring reads:

If you know your public addresses upfront, the recommended way is to use AddressFactory to provide the external address to the host and use this option to disable discovery from identify.

The current py-libp2p implementation always records observations (even when announce_addrs is set). Users who never want Identify-driven address discovery — either for privacy reasons or to eliminate the memory / CPU footprint of ObservedAddrManager — currently have no clean way to opt out.

A disable_identify_address_discovery: bool = False knob (or an equivalent no-op ObservedAddrManager / None sentinel on BasicHost) would match go-libp2p's API surface.

Acceptance criteria

  • Callable form of announce_addrs / a new addrs_factory= kwarg on BasicHost, with semantics matching go-libp2p's AddrsFactory.
  • Public opt-out that stops BasicHost._identify_peer from calling ObservedAddrManager.record_observation when enabled.
  • Docs update in docs/libp2p.host.rst and docs/examples.announce_addrs.rst covering both options.
  • Unit tests for both knobs, including the interaction with get_nat_type() when discovery is disabled.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions