diff --git a/api/api.go b/api/api.go index cc067d49c..6b803b8c6 100644 --- a/api/api.go +++ b/api/api.go @@ -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 diff --git a/api/proxy_gen.go b/api/proxy_gen.go index b51ec916a..5121b8212 100644 --- a/api/proxy_gen.go +++ b/api/proxy_gen.go @@ -69,6 +69,10 @@ type BoostStruct struct { BoostIndexerAnnounceAllDeals func(p0 context.Context) error `perm:"admin"` + BoostIndexerAnnounceLatest func(p0 context.Context) (cid.Cid, error) `perm:"admin"` + + BoostIndexerAnnounceLatestHttp func(p0 context.Context, p1 []string) (cid.Cid, error) `perm:"admin"` + BoostMakeDeal func(p0 context.Context, p1 smtypes.DealParams) (*ProviderDealRejectionInfo, error) `perm:"write"` BoostOfflineDealWithData func(p0 context.Context, p1 uuid.UUID, p2 string, p3 bool) (*ProviderDealRejectionInfo, error) `perm:"admin"` @@ -444,6 +448,28 @@ func (s *BoostStub) BoostIndexerAnnounceAllDeals(p0 context.Context) error { return ErrNotSupported } +func (s *BoostStruct) BoostIndexerAnnounceLatest(p0 context.Context) (cid.Cid, error) { + if s.Internal.BoostIndexerAnnounceLatest == nil { + return *new(cid.Cid), ErrNotSupported + } + return s.Internal.BoostIndexerAnnounceLatest(p0) +} + +func (s *BoostStub) BoostIndexerAnnounceLatest(p0 context.Context) (cid.Cid, error) { + return *new(cid.Cid), ErrNotSupported +} + +func (s *BoostStruct) BoostIndexerAnnounceLatestHttp(p0 context.Context, p1 []string) (cid.Cid, error) { + if s.Internal.BoostIndexerAnnounceLatestHttp == nil { + return *new(cid.Cid), ErrNotSupported + } + return s.Internal.BoostIndexerAnnounceLatestHttp(p0, p1) +} + +func (s *BoostStub) BoostIndexerAnnounceLatestHttp(p0 context.Context, p1 []string) (cid.Cid, error) { + return *new(cid.Cid), ErrNotSupported +} + func (s *BoostStruct) BoostMakeDeal(p0 context.Context, p1 smtypes.DealParams) (*ProviderDealRejectionInfo, error) { if s.Internal.BoostMakeDeal == nil { return nil, ErrNotSupported diff --git a/build/openrpc/boost.json.gz b/build/openrpc/boost.json.gz index 5bcd3ae20..0680625fe 100644 Binary files a/build/openrpc/boost.json.gz and b/build/openrpc/boost.json.gz differ diff --git a/cmd/boostd/index.go b/cmd/boostd/index.go index f4947d005..1fbeee504 100644 --- a/cmd/boostd/index.go +++ b/cmd/boostd/index.go @@ -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" @@ -11,6 +12,8 @@ var indexProvCmd = &cli.Command{ Usage: "Manage the index provider on Boost", Subcommands: []*cli.Command{ indexProvAnnounceAllCmd, + indexProvAnnounceLatest, + indexProvAnnounceLatestHttp, }, } @@ -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 + }, +} diff --git a/documentation/en/api-v1-methods.md b/documentation/en/api-v1-methods.md index d223d9b25..5e9a4991f 100644 --- a/documentation/en/api-v1-methods.md +++ b/documentation/en/api-v1-methods.md @@ -23,6 +23,8 @@ * [BoostDealBySignedProposalCid](#boostdealbysignedproposalcid) * [BoostDummyDeal](#boostdummydeal) * [BoostIndexerAnnounceAllDeals](#boostindexerannouncealldeals) + * [BoostIndexerAnnounceLatest](#boostindexerannouncelatest) + * [BoostIndexerAnnounceLatestHttp](#boostindexerannouncelatesthttp) * [BoostMakeDeal](#boostmakedeal) * [BoostOfflineDealWithData](#boostofflinedealwithdata) * [Deals](#deals) @@ -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 diff --git a/indexprovider/wrapper.go b/indexprovider/wrapper.go index e1840c5fa..fc25cb2c9 100644 --- a/indexprovider/wrapper.go +++ b/indexprovider/wrapper.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "math" + "net/url" "os" "path/filepath" @@ -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" @@ -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) + if !ok { + return cid.Undef, fmt.Errorf("index provider is disabled") + } + return e.PublishLatest(ctx) +} + +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 { diff --git a/node/config/def.go b/node/config/def.go index 9632c3c3c..b8a216a62 100644 --- a/node/config/def.go +++ b/node/config/def.go @@ -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{ diff --git a/node/impl/boost.go b/node/impl/boost.go index 5d2927966..736cb6c4c 100644 --- a/node/impl/boost.go +++ b/node/impl/boost.go @@ -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