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
References
Context
PR #1284 adds an
ObservedAddrManagerand integrates externally observed addresses intoBasicHost.get_addrs()when noannounce_addrsargument is provided (fixes #1250). Whenannounce_addrsis provided, it is now treated as a static-listAddrsFactory— mirroring go-libp2p'sapplyAddrsFactorybehaviour — so observed addresses are still recorded by the manager (forget_nat_type, future AutoNAT consumers, etc.) but not advertised viaget_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/AddrsFactorygo-libp2p exposes
AddrsFactoryas a function([]ma.Multiaddr) -> []ma.Multiaddr(seeoptions.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 composelisten + observed + extrasthemselves 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 dedicatedaddrs_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:The current py-libp2p implementation always records observations (even when
announce_addrsis set). Users who never want Identify-driven address discovery — either for privacy reasons or to eliminate the memory / CPU footprint ofObservedAddrManager— currently have no clean way to opt out.A
disable_identify_address_discovery: bool = Falseknob (or an equivalent no-opObservedAddrManager/Nonesentinel onBasicHost) would match go-libp2p's API surface.Acceptance criteria
announce_addrs/ a newaddrs_factory=kwarg onBasicHost, with semantics matching go-libp2p'sAddrsFactory.BasicHost._identify_peerfrom callingObservedAddrManager.record_observationwhen enabled.docs/libp2p.host.rstanddocs/examples.announce_addrs.rstcovering both options.get_nat_type()when discovery is disabled.References
announce_addrs.ObservedAddrManager, documented the static-list-as-AddrsFactory semantics.options.go—AddrsFactory,DisableIdentifyAddressDiscovery.p2p/host/basic/addrs_manager.go—updateAddrspipeline,applyAddrsFactory,appendObservedAddrs.