Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to serve index provider ads over http #1452

Merged
merged 10 commits into from
May 23, 2023
12 changes: 8 additions & 4 deletions node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,16 @@ func DefaultBoost() *Boost {
TopicName: "",
PurgeCacheOnStart: false,

HttpPublisher: IndexProviderHttpPublisherConfig{
Enabled: false,
PublicHostname: "",
Port: 3104,
Announce: IndexProviderAnnounceConfig{
AnnounceOverHttp: false,
DirectAnnounceURLs: []string{"https://cid.contact"},
},

HttpPublisher: IndexProviderHttpPublisherConfig{
Enabled: false,
PublicHostname: "",
Port: 3104,
},
},
}
return cfg
Expand Down
17 changes: 12 additions & 5 deletions node/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,21 @@ type IndexProviderConfig struct {
// datastore if any is present.
PurgeCacheOnStart bool

Announce IndexProviderAnnounceConfig

HttpPublisher IndexProviderHttpPublisherConfig
}

type IndexProviderAnnounceConfig struct {
// Make a direct announcement to a list of indexing nodes over http.
// Note that announcements are already made over pubsub regardless
// of this setting.
AnnounceOverHttp bool

// The list of URLs of indexing nodes to announce to.
DirectAnnounceURLs []string
}

type IndexProviderHttpPublisherConfig struct {
// If not enabled, requests are served over graphsync instead.
Enabled bool
Expand All @@ -321,11 +333,6 @@ type IndexProviderHttpPublisherConfig struct {
// Set the port on which to listen for index provider requests over HTTP.
// Note that this port must be open on the firewall.
Port int
// The HTTP publisher makes announcements directly to the indexing
// nodes (whereas the data transfer publisher publishes on gossipsub)
// DirectAnnounceURLs is the list of URLs of indexing nodes to
// announce to.
DirectAnnounceURLs []string
}

type FeeConfig struct {
Expand Down
35 changes: 20 additions & 15 deletions node/modules/storageminer_idxprov.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ func IndexProvider(cfg config.IndexProviderConfig) func(params IdxProv, marketHo
// If announcements to the network are enabled, then set options for the publisher.
var e *engine.Engine
if cfg.Enable {
// Join the indexer topic using the market's pubsub instance. Otherwise, the provider
// engine would create its own instance of pubsub down the line in go-legs, which has
// no validators by default.
t, err := ps.Join(topicName)
if err != nil {
llog.Errorw("Failed to join indexer topic", "err", err)
return nil, xerrors.Errorf("joining indexer topic %s: %w", topicName, err)
}

// Get the miner ID and set as extra gossip data.
// The extra data is required by the lotus-specific index-provider gossip message validators.
ma := address.Address(maddr)
opts = append(opts,
engine.WithTopic(t),
engine.WithExtraGossipData(ma.Bytes()),
)
if cfg.Announce.AnnounceOverHttp {
opts = append(opts, engine.WithDirectAnnounce(cfg.Announce.DirectAnnounceURLs...))
}

// Advertisements can be served over the data transfer protocol
// (on graphsync) or over HTTP
if cfg.HttpPublisher.Enabled {
dirkmc marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -94,29 +114,14 @@ func IndexProvider(cfg config.IndexProviderConfig) func(params IdxProv, marketHo
engine.WithPublisherKind(engine.HttpPublisher),
engine.WithHttpPublisherListenAddr(fmt.Sprintf("0.0.0.0:%d", cfg.HttpPublisher.Port)),
engine.WithHttpPublisherAnnounceAddr(announceAddr.String()),
engine.WithDirectAnnounce(cfg.HttpPublisher.DirectAnnounceURLs...),
)
llog = llog.With("publisher", "http", "announceAddr", announceAddr)
} else {
// Join the indexer topic using the market's pubsub instance. Otherwise, the provider
// engine would create its own instance of pubsub down the line in go-legs, which has
// no validators by default.
t, err := ps.Join(topicName)
if err != nil {
llog.Errorw("Failed to join indexer topic", "err", err)
return nil, xerrors.Errorf("joining indexer topic %s: %w", topicName, err)
}

// Get the miner ID and set as extra gossip data.
// The extra data is required by the lotus-specific index-provider gossip message validators.
ma := address.Address(maddr)
opts = append(opts,
engine.WithTopic(t),
engine.WithPublisherKind(engine.DataTransferPublisher),
engine.WithDataTransfer(dtV1ToIndexerDT(dt, func() ipld.LinkSystem {
return *e.LinkSystem()
})),
engine.WithExtraGossipData(ma.Bytes()),
)
llog = llog.With("extraGossipData", ma, "publisher", "data-transfer")
}
Expand Down