Skip to content

Commit

Permalink
cmd: allow to set the retrieval peerID, not just the retrieval multiaddr
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMure committed Feb 9, 2024
1 parent f6b2259 commit 93e5c41
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/provider/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions cmd/provider/internal/config/providerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions engine/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 93e5c41

Please sign in to comment.