libp2p / go-libp2p

libp2p implementation in Go
MIT License
6.1k stars 1.07k forks source link

Bug: autorelay: enabling autorelay overrides custom AddrFactory #2964

Closed burdiyan closed 1 month ago

burdiyan commented 2 months ago

In this line, autorelay overwrites the AddrFactory on the basic host: https://github.com/libp2p/go-libp2p/blob/921cc71072229344a78c7d794e3571c3cbf058e3/p2p/host/autorelay/autorelay.go#L54

It supposedly "caches" the original AddrFactory here: https://github.com/libp2p/go-libp2p/blob/921cc71072229344a78c7d794e3571c3cbf058e3/p2p/host/autorelay/autorelay.go#L41

but it seems like this happens before the custom libp2p.AddrFactory option is being applied on the libp2p host. I presume that NewAutorelay function is being passed a partially built instance of the basic host, which is probably due to some of the fx dependency injection magic.

In my custom AddrFactory option I add a public IP address that I discovery via STUN manually, and it's not being returned by calling host.Addrs() method unless I disable AutoRelay option.