Skip to content

Commit

Permalink
feat(retrievalprovider): prioritize announce addresses over host addr…
Browse files Browse the repository at this point in the history
…esses

If announce addresses are configured, the retrieval provider now prioritizes
these over the addresses directly obtained from the host. This allows fora more controlled announcement of addresses in libp2p networks.
  • Loading branch information
yanzq committed Jul 24, 2024
1 parent 59102cb commit 91e4b44
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions retrievalprovider/transports.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,22 @@ func NewTransportsListener(h host.Host, cfg *config.MarketConfig) (*TransportsLi
var protos []types.Protocol

// Get the libp2p addresses from the Host
if len(h.Addrs()) > 0 {
protos = append(protos, types.Protocol{
Name: "libp2p",
Addresses: h.Addrs(),
})
var maddrs []multiaddr.Multiaddr
switch {
case len(cfg.Libp2p.AnnounceAddresses) > 0:
for i, _ := range cfg.Libp2p.AnnounceAddresses {
maddr, err := multiaddr.NewMultiaddr(cfg.Libp2p.AnnounceAddresses[i])
if err == nil {
maddrs = append(maddrs, maddr)
}
}
case len(h.Addrs()) > 0:
maddrs = h.Addrs()
}
protos = append(protos, types.Protocol{
Name: "libp2p",
Addresses: maddrs,
})

// If there's an http retrieval address specified, add HTTP to the list
// of supported protocols
Expand Down

0 comments on commit 91e4b44

Please sign in to comment.