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 boostd index announce-latest command #1456

Merged
merged 3 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type Boost interface {

// MethodGroup: Boost
BoostIndexerAnnounceAllDeals(ctx context.Context) error //perm:admin
BoostIndexerAnnounceLatest(ctx context.Context) (cid.Cid, error) //perm:admin
BoostIndexerAnnounceLatestHttp(ctx context.Context, urls []string) (cid.Cid, error) //perm:admin
BoostOfflineDealWithData(ctx context.Context, dealUuid uuid.UUID, filePath string, delAfterImport bool) (*ProviderDealRejectionInfo, error) //perm:admin
BoostDeal(ctx context.Context, dealUuid uuid.UUID) (*smtypes.ProviderDealState, error) //perm:admin
BoostDealBySignedProposalCid(ctx context.Context, proposalCid cid.Cid) (*smtypes.ProviderDealState, error) //perm:admin
Expand Down
26 changes: 26 additions & 0 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified build/openrpc/boost.json.gz
Binary file not shown.
54 changes: 54 additions & 0 deletions cmd/boostd/index.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
bcli "github.com/filecoin-project/boost/cli"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/urfave/cli/v2"
Expand All @@ -11,6 +12,8 @@ var indexProvCmd = &cli.Command{
Usage: "Manage the index provider on Boost",
Subcommands: []*cli.Command{
indexProvAnnounceAllCmd,
indexProvAnnounceLatest,
indexProvAnnounceLatestHttp,
},
}

Expand All @@ -31,3 +34,54 @@ var indexProvAnnounceAllCmd = &cli.Command{
return napi.BoostIndexerAnnounceAllDeals(ctx)
},
}

var indexProvAnnounceLatest = &cli.Command{
Name: "announce-latest",
Usage: "Re-publish the latest existing advertisement to pubsub",
Action: func(cctx *cli.Context) error {
ctx := lcli.ReqContext(cctx)

napi, closer, err := bcli.GetBoostAPI(cctx)
if err != nil {
return err
}
defer closer()

c, err := napi.BoostIndexerAnnounceLatest(ctx)
if err != nil {
return err
}

fmt.Printf("Announced advertisement with cid %s\n", c)
return nil
},
}

var indexProvAnnounceLatestHttp = &cli.Command{
Name: "announce-latest-http",
Usage: "Re-publish the latest existing advertisement to specific indexers over http",
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "announce-url",
Usage: "The url(s) to announce to. If not specified, announces to the http urls in config",
Required: false,
},
},
Action: func(cctx *cli.Context) error {
ctx := lcli.ReqContext(cctx)

napi, closer, err := bcli.GetBoostAPI(cctx)
if err != nil {
return err
}
defer closer()

c, err := napi.BoostIndexerAnnounceLatestHttp(ctx, cctx.StringSlice("announce-url"))
if err != nil {
return err
}

fmt.Printf("Announced advertisement to indexers over http with cid %s\n", c)
return nil
},
}
37 changes: 37 additions & 0 deletions documentation/en/api-v1-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* [BoostDealBySignedProposalCid](#boostdealbysignedproposalcid)
* [BoostDummyDeal](#boostdummydeal)
* [BoostIndexerAnnounceAllDeals](#boostindexerannouncealldeals)
* [BoostIndexerAnnounceLatest](#boostindexerannouncelatest)
* [BoostIndexerAnnounceLatestHttp](#boostindexerannouncelatesthttp)
* [BoostMakeDeal](#boostmakedeal)
* [BoostOfflineDealWithData](#boostofflinedealwithdata)
* [Deals](#deals)
Expand Down Expand Up @@ -563,6 +565,41 @@ Inputs: `null`

Response: `{}`

### BoostIndexerAnnounceLatest


Perms: admin

Inputs: `null`

Response:
```json
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
}
```

### BoostIndexerAnnounceLatestHttp


Perms: admin

Inputs:
```json
[
[
"string value"
]
]
```

Response:
```json
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
}
```

### BoostMakeDeal


Expand Down
31 changes: 31 additions & 0 deletions indexprovider/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math"
"net/url"
"os"
"path/filepath"

Expand All @@ -22,6 +23,7 @@ import (
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
provider "github.com/ipni/index-provider"
"github.com/ipni/index-provider/engine"
"github.com/ipni/index-provider/engine/xproviders"
"github.com/ipni/index-provider/metadata"
"github.com/libp2p/go-libp2p/core/crypto"
Expand Down Expand Up @@ -262,6 +264,35 @@ func (w *Wrapper) IndexerAnnounceAllDeals(ctx context.Context) error {
return merr
}

func (w *Wrapper) IndexerAnnounceLatest(ctx context.Context) (cid.Cid, error) {
e, ok := w.prov.(*engine.Engine)
masih marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
return cid.Undef, fmt.Errorf("index provider is disabled")
}
return e.PublishLatest(ctx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a separate function for direct announce over HTTP. Should we check if direct announce is enabled and call that as well as this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting.. I guess that could be a separate cli command so that we can debug both explicitly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or --direct flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I will add a separate command because you also have the option to explicitly specify the url

}

func (w *Wrapper) IndexerAnnounceLatestHttp(ctx context.Context, announceUrls []string) (cid.Cid, error) {
e, ok := w.prov.(*engine.Engine)
if !ok {
return cid.Undef, fmt.Errorf("index provider is disabled")
}

if len(announceUrls) == 0 {
announceUrls = w.cfg.IndexProvider.Announce.DirectAnnounceURLs
}

urls := make([]*url.URL, 0, len(announceUrls))
for _, us := range announceUrls {
u, err := url.Parse(us)
if err != nil {
return cid.Undef, fmt.Errorf("parsing url %s: %w", us, err)
}
urls = append(urls, u)
}
return e.PublishLatestHTTP(ctx, urls...)
}

func (w *Wrapper) Start(ctx context.Context) {
// re-init dagstore shards for Boost deals if needed
if _, err := w.DagstoreReinitBoostDeals(ctx); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func DefaultBoost() *Boost {

Announce: IndexProviderAnnounceConfig{
AnnounceOverHttp: false,
DirectAnnounceURLs: []string{"https://cid.contact"},
DirectAnnounceURLs: []string{"https://cid.contact/ingest/announce"},
},

HttpPublisher: IndexProviderHttpPublisherConfig{
Expand Down
8 changes: 8 additions & 0 deletions node/impl/boost.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ func (sm *BoostAPI) BoostIndexerAnnounceAllDeals(ctx context.Context) error {
return sm.IndexProvider.IndexerAnnounceAllDeals(ctx)
}

func (sm *BoostAPI) BoostIndexerAnnounceLatest(ctx context.Context) (cid.Cid, error) {
return sm.IndexProvider.IndexerAnnounceLatest(ctx)
}

func (sm *BoostAPI) BoostIndexerAnnounceLatestHttp(ctx context.Context, announceUrls []string) (cid.Cid, error) {
return sm.IndexProvider.IndexerAnnounceLatestHttp(ctx, announceUrls)
}

func (sm *BoostAPI) BoostOfflineDealWithData(ctx context.Context, dealUuid uuid.UUID, filePath string, delAfterImport bool) (*api.ProviderDealRejectionInfo, error) {
res, err := sm.StorageProvider.ImportOfflineDealData(ctx, dealUuid, filePath, delAfterImport)
return res, err
Expand Down