From 93e5c41bd483a97ebb8a9449576cf51c37f8f2b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Fri, 9 Feb 2024 14:26:42 +0100 Subject: [PATCH] cmd: allow to set the retrieval peerID, not just the retrieval multiaddr --- cmd/provider/daemon.go | 1 + cmd/provider/internal/config/providerserver.go | 3 +++ engine/options.go | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/cmd/provider/daemon.go b/cmd/provider/daemon.go index e9007035..aec28b2e 100644 --- a/cmd/provider/daemon.go +++ b/cmd/provider/daemon.go @@ -160,6 +160,7 @@ func daemonCommand(cctx *cli.Context) error { engine.WithHttpPublisherAnnounceAddr(cfg.Ingest.HttpPublisher.AnnounceMultiaddr), engine.WithPubsubAnnounce(!cfg.DirectAnnounce.NoPubsubAnnounce), engine.WithSyncPolicy(syncPolicy), + engine.WithRetrievalPeerID(cfg.ProviderServer.RetrievalPeerID), engine.WithRetrievalAddrs(cfg.ProviderServer.RetrievalMultiaddrs...), ) if err != nil { diff --git a/cmd/provider/internal/config/providerserver.go b/cmd/provider/internal/config/providerserver.go index 3fab3669..de94c912 100644 --- a/cmd/provider/internal/config/providerserver.go +++ b/cmd/provider/internal/config/providerserver.go @@ -3,6 +3,9 @@ package config type ProviderServer struct { // ListenMultiaddr is the multiaddr string for the node's listen address ListenMultiaddr string + // RetrievalPeerID is the peer ID to advertise for data retrieval. + // Defaults to the provider's libp2p host peer ID. + RetrievalPeerID string // RetrievalMultiaddrs are the addresses to advertise for data retrieval. // Defaults to the provider's libp2p host listen addresses. RetrievalMultiaddrs []string diff --git a/engine/options.go b/engine/options.go index e7642d15..ddd932d5 100644 --- a/engine/options.go +++ b/engine/options.go @@ -372,6 +372,22 @@ func WithRetrievalAddrs(addrs ...string) Option { } } +// WithRetrievalPeerID sets the peerID of where to get the content corresponding to an indexing advertisement. +// If unspecified, the libp2p host peer ID are used. +// See: WithHost +func WithRetrievalPeerID(peerID string) Option { + return func(o *options) error { + if len(peerID) != 0 { + pId, err := peer.Decode(peerID) + if err != nil { + return fmt.Errorf("bad peer ID %q: %w", peerID, err) + } + o.provider.ID = pId + } + return nil + } +} + func WithSyncPolicy(syncPolicy *policy.Policy) Option { return func(o *options) error { o.syncPolicy = syncPolicy