Skip to content

Commit 1a7b193

Browse files
authored
Add option to serve index provider ads over http (#1452)
* feat: option to serve index provider ads over http * fix: config naming, hostname parsing * fix: update docsgen * fix: log announce address * feat: add config for indexer direct announce urls * refactor: always announce over pubsub * fix: docsgen * test: add test case for empty announce address hostname * Add `boostd index announce-latest` command (#1456) * feat: boostd index announce-latest * feat: add announce-latest-http command * fix: default direct announce url * feat: update to index-provider v0.11.2
1 parent a4b95bb commit 1a7b193

File tree

16 files changed

+436
-15
lines changed

16 files changed

+436
-15
lines changed

api/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ type Boost interface {
3535

3636
// MethodGroup: Boost
3737
BoostIndexerAnnounceAllDeals(ctx context.Context) error //perm:admin
38+
BoostIndexerAnnounceLatest(ctx context.Context) (cid.Cid, error) //perm:admin
39+
BoostIndexerAnnounceLatestHttp(ctx context.Context, urls []string) (cid.Cid, error) //perm:admin
3840
BoostOfflineDealWithData(ctx context.Context, dealUuid uuid.UUID, filePath string, delAfterImport bool) (*ProviderDealRejectionInfo, error) //perm:admin
3941
BoostDeal(ctx context.Context, dealUuid uuid.UUID) (*smtypes.ProviderDealState, error) //perm:admin
4042
BoostDealBySignedProposalCid(ctx context.Context, proposalCid cid.Cid) (*smtypes.ProviderDealState, error) //perm:admin

api/proxy_gen.go

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/openrpc/boost.json.gz

116 Bytes
Binary file not shown.

cmd/boostd/index.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
bcli "github.com/filecoin-project/boost/cli"
56
lcli "github.com/filecoin-project/lotus/cli"
67
"github.com/urfave/cli/v2"
@@ -11,6 +12,8 @@ var indexProvCmd = &cli.Command{
1112
Usage: "Manage the index provider on Boost",
1213
Subcommands: []*cli.Command{
1314
indexProvAnnounceAllCmd,
15+
indexProvAnnounceLatest,
16+
indexProvAnnounceLatestHttp,
1417
},
1518
}
1619

@@ -31,3 +34,54 @@ var indexProvAnnounceAllCmd = &cli.Command{
3134
return napi.BoostIndexerAnnounceAllDeals(ctx)
3235
},
3336
}
37+
38+
var indexProvAnnounceLatest = &cli.Command{
39+
Name: "announce-latest",
40+
Usage: "Re-publish the latest existing advertisement to pubsub",
41+
Action: func(cctx *cli.Context) error {
42+
ctx := lcli.ReqContext(cctx)
43+
44+
napi, closer, err := bcli.GetBoostAPI(cctx)
45+
if err != nil {
46+
return err
47+
}
48+
defer closer()
49+
50+
c, err := napi.BoostIndexerAnnounceLatest(ctx)
51+
if err != nil {
52+
return err
53+
}
54+
55+
fmt.Printf("Announced advertisement with cid %s\n", c)
56+
return nil
57+
},
58+
}
59+
60+
var indexProvAnnounceLatestHttp = &cli.Command{
61+
Name: "announce-latest-http",
62+
Usage: "Re-publish the latest existing advertisement to specific indexers over http",
63+
Flags: []cli.Flag{
64+
&cli.StringSliceFlag{
65+
Name: "announce-url",
66+
Usage: "The url(s) to announce to. If not specified, announces to the http urls in config",
67+
Required: false,
68+
},
69+
},
70+
Action: func(cctx *cli.Context) error {
71+
ctx := lcli.ReqContext(cctx)
72+
73+
napi, closer, err := bcli.GetBoostAPI(cctx)
74+
if err != nil {
75+
return err
76+
}
77+
defer closer()
78+
79+
c, err := napi.BoostIndexerAnnounceLatestHttp(ctx, cctx.StringSlice("announce-url"))
80+
if err != nil {
81+
return err
82+
}
83+
84+
fmt.Printf("Announced advertisement to indexers over http with cid %s\n", c)
85+
return nil
86+
},
87+
}

cmd/boostd/init.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,13 @@ func migrateMarketsConfig(cctx *cli.Context, mktsRepo lotus_repo.LockedRepo, boo
493493
// Clear the DAG store root dir config, because the DAG store is no longer configurable in Boost
494494
// (it is always at <repo path>/dagstore
495495
rcfg.DAGStore.RootDir = ""
496-
rcfg.IndexProvider = mktsCfg.IndexProvider
496+
rcfg.IndexProvider = config.IndexProviderConfig{
497+
Enable: mktsCfg.IndexProvider.Enable,
498+
EntriesCacheCapacity: mktsCfg.IndexProvider.EntriesCacheCapacity,
499+
EntriesChunkSize: mktsCfg.IndexProvider.EntriesChunkSize,
500+
TopicName: mktsCfg.IndexProvider.TopicName,
501+
PurgeCacheOnStart: mktsCfg.IndexProvider.PurgeCacheOnStart,
502+
}
497503
rcfg.IndexProvider.Enable = true // Enable index provider in Boost by default
498504

499505
if fromMonolith {

documentation/en/api-v1-methods.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
* [BoostDealBySignedProposalCid](#boostdealbysignedproposalcid)
2424
* [BoostDummyDeal](#boostdummydeal)
2525
* [BoostIndexerAnnounceAllDeals](#boostindexerannouncealldeals)
26+
* [BoostIndexerAnnounceLatest](#boostindexerannouncelatest)
27+
* [BoostIndexerAnnounceLatestHttp](#boostindexerannouncelatesthttp)
2628
* [BoostMakeDeal](#boostmakedeal)
2729
* [BoostOfflineDealWithData](#boostofflinedealwithdata)
2830
* [Deals](#deals)
@@ -563,6 +565,41 @@ Inputs: `null`
563565

564566
Response: `{}`
565567

568+
### BoostIndexerAnnounceLatest
569+
570+
571+
Perms: admin
572+
573+
Inputs: `null`
574+
575+
Response:
576+
```json
577+
{
578+
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
579+
}
580+
```
581+
582+
### BoostIndexerAnnounceLatestHttp
583+
584+
585+
Perms: admin
586+
587+
Inputs:
588+
```json
589+
[
590+
[
591+
"string value"
592+
]
593+
]
594+
```
595+
596+
Response:
597+
```json
598+
{
599+
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
600+
}
601+
```
602+
566603
### BoostMakeDeal
567604

568605

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ require (
7676
github.com/ipld/go-car/v2 v2.7.0
7777
github.com/ipld/go-ipld-prime v0.20.0
7878
github.com/ipld/go-ipld-selector-text-lite v0.0.1
79-
github.com/ipni/index-provider v0.11.1
79+
github.com/ipni/index-provider v0.11.2
8080
github.com/ipni/storetheindex v0.5.10
8181
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c
8282
github.com/jpillora/backoff v1.0.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,8 @@ github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20211210234204-ce2a1c70cd
951951
github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20230102063945-1a409dc236dd h1:gMlw/MhNr2Wtp5RwGdsW23cs+yCuj9k2ON7i9MiJlRo=
952952
github.com/ipld/go-ipld-selector-text-lite v0.0.1 h1:lNqFsQpBHc3p5xHob2KvEg/iM5dIFn6iw4L/Hh+kS1Y=
953953
github.com/ipld/go-ipld-selector-text-lite v0.0.1/go.mod h1:U2CQmFb+uWzfIEF3I1arrDa5rwtj00PrpiwwCO+k1RM=
954-
github.com/ipni/index-provider v0.11.1 h1:viNfSBvZA9G+Qe6/FGqfZtavnu4tTSfGUoWEECavqoI=
955-
github.com/ipni/index-provider v0.11.1/go.mod h1:gB/wN4Mdz4MzikQubjyRRV97iS5BkD4FKB0U/bF/dY4=
954+
github.com/ipni/index-provider v0.11.2 h1:nvykWK+/ncPTqHiuiJdXp/O0UF0V7iWesjHGKX//NYc=
955+
github.com/ipni/index-provider v0.11.2/go.mod h1:gB/wN4Mdz4MzikQubjyRRV97iS5BkD4FKB0U/bF/dY4=
956956
github.com/ipni/storetheindex v0.5.10 h1:r97jIZsXPuwQvePJQuStu2a/kn+Zn8X4MAdA0rU2Pu4=
957957
github.com/ipni/storetheindex v0.5.10/go.mod h1:SJKFCnSx4X/4ekQuZvq8pVU/7tmxkEv632Qmgu3m2bQ=
958958
github.com/ipsn/go-secp256k1 v0.0.0-20180726113642-9d62b9f0bc52 h1:QG4CGBqCeuBo6aZlGAamSkxWdgWfZGeE49eUOWJPA4c=

indexprovider/wrapper.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"math"
8+
"net/url"
89
"os"
910
"path/filepath"
1011

@@ -22,6 +23,7 @@ import (
2223
"github.com/ipfs/go-cid"
2324
logging "github.com/ipfs/go-log/v2"
2425
provider "github.com/ipni/index-provider"
26+
"github.com/ipni/index-provider/engine"
2527
"github.com/ipni/index-provider/engine/xproviders"
2628
"github.com/ipni/index-provider/metadata"
2729
"github.com/libp2p/go-libp2p/core/crypto"
@@ -262,6 +264,35 @@ func (w *Wrapper) IndexerAnnounceAllDeals(ctx context.Context) error {
262264
return merr
263265
}
264266

267+
func (w *Wrapper) IndexerAnnounceLatest(ctx context.Context) (cid.Cid, error) {
268+
e, ok := w.prov.(*engine.Engine)
269+
if !ok {
270+
return cid.Undef, fmt.Errorf("index provider is disabled")
271+
}
272+
return e.PublishLatest(ctx)
273+
}
274+
275+
func (w *Wrapper) IndexerAnnounceLatestHttp(ctx context.Context, announceUrls []string) (cid.Cid, error) {
276+
e, ok := w.prov.(*engine.Engine)
277+
if !ok {
278+
return cid.Undef, fmt.Errorf("index provider is disabled")
279+
}
280+
281+
if len(announceUrls) == 0 {
282+
announceUrls = w.cfg.IndexProvider.Announce.DirectAnnounceURLs
283+
}
284+
285+
urls := make([]*url.URL, 0, len(announceUrls))
286+
for _, us := range announceUrls {
287+
u, err := url.Parse(us)
288+
if err != nil {
289+
return cid.Undef, fmt.Errorf("parsing url %s: %w", us, err)
290+
}
291+
urls = append(urls, u)
292+
}
293+
return e.PublishLatestHTTP(ctx, urls...)
294+
}
295+
265296
func (w *Wrapper) Start(ctx context.Context) {
266297
// re-init dagstore shards for Boost deals if needed
267298
if _, err := w.DagstoreReinitBoostDeals(ctx); err != nil {

node/config/def.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,25 @@ func DefaultBoost() *Boost {
171171
MaxConcurrencyStorageCalls: 100,
172172
GCInterval: lotus_config.Duration(1 * time.Minute),
173173
},
174-
IndexProvider: lotus_config.IndexProviderConfig{
174+
IndexProvider: IndexProviderConfig{
175175
Enable: true,
176176
EntriesCacheCapacity: 1024,
177177
EntriesChunkSize: 16384,
178178
// The default empty TopicName means it is inferred from network name, in the following
179179
// format: "/indexer/ingest/<network-name>"
180180
TopicName: "",
181181
PurgeCacheOnStart: false,
182+
183+
Announce: IndexProviderAnnounceConfig{
184+
AnnounceOverHttp: false,
185+
DirectAnnounceURLs: []string{"https://cid.contact/ingest/announce"},
186+
},
187+
188+
HttpPublisher: IndexProviderHttpPublisherConfig{
189+
Enabled: false,
190+
PublicHostname: "",
191+
Port: 3104,
192+
},
182193
},
183194
}
184195
return cfg

node/config/doc_gen.go

Lines changed: 97 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)