Skip to content

Commit 65f3f47

Browse files
committed
apply suggestions
1 parent b4dabfc commit 65f3f47

File tree

6 files changed

+91
-85
lines changed

6 files changed

+91
-85
lines changed

deps/config/doc_gen.go

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

deps/config/types.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ func DefaultCurioConfig() *CurioConfig {
9090
ExpectedSnapSealDuration: Duration(2 * time.Hour),
9191
},
9292
IPNI: IPNIConfig{
93-
Enable: true,
94-
TopicName: "",
95-
WebHost: "https://cid.contact",
96-
DirectAnnounceURLs: []string{"https://cid.contact/ingest/announce"},
93+
EntriesCacheCapacity: 4096,
94+
WebHost: "https://cid.contact",
95+
DirectAnnounceURLs: []string{"https://cid.contact/ingest/announce"},
9796
},
9897
},
9998
},
@@ -648,17 +647,20 @@ type Libp2pConfig struct {
648647
}
649648

650649
type IPNIConfig struct {
651-
// Enable set whether to enable indexing announcement to the network and expose endpoints that
652-
// allow indexer nodes to process announcements. Enabled by default.
653-
Enable bool
654-
655-
// TopicName sets the topic name on which the changes to the advertised content are announced.
656-
// If not explicitly specified, the topic name is automatically inferred from the network name
657-
// in following format: '/indexer/ingest/<network-name>'
658-
// Defaults to empty, which implies the topic name is inferred from network name.
659-
TopicName string
650+
// Disable set whether to disable indexing announcement to the network and expose endpoints that
651+
// allow indexer nodes to process announcements. Default: False
652+
Disable bool
653+
654+
// EntriesCacheCapacity sets the maximum capacity to use for caching the indexing advertisement
655+
// entries. Defaults to 4096 if not specified. The cache is evicted using LRU policy. The
656+
// maximum storage used by the cache is a factor of EntriesCacheCapacity, EntriesChunkSize(16384) and
657+
// the length of multihashes being advertised. For example, advertising 128-bit long multihashes
658+
// with the default EntriesCacheCapacity, and EntriesChunkSize(16384) means the cache size can grow to
659+
// 1GiB when full.
660+
EntriesCacheCapacity int
660661

661662
// The network indexer host that the web UI should link to for published announcements
663+
// TODO: should we use this for checking published heas before publishing? Later commit
662664
WebHost string
663665

664666
// The list of URLs of indexing nodes to announce to.

documentation/en/configuration/default-curio-configuration.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -407,21 +407,24 @@ description: The default curio configuration
407407
#InsertConcurrency = 8
408408

409409
[Market.StorageMarketConfig.IPNI]
410-
# Enable set whether to enable indexing announcement to the network and expose endpoints that
411-
# allow indexer nodes to process announcements. Enabled by default.
410+
# Disable set whether to disable indexing announcement to the network and expose endpoints that
411+
# allow indexer nodes to process announcements. Default: False
412412
#
413413
# type: bool
414-
#Enable = true
415-
416-
# TopicName sets the topic name on which the changes to the advertised content are announced.
417-
# If not explicitly specified, the topic name is automatically inferred from the network name
418-
# in following format: '/indexer/ingest/<network-name>'
419-
# Defaults to empty, which implies the topic name is inferred from network name.
414+
#Disable = false
415+
416+
# EntriesCacheCapacity sets the maximum capacity to use for caching the indexing advertisement
417+
# entries. Defaults to 4096 if not specified. The cache is evicted using LRU policy. The
418+
# maximum storage used by the cache is a factor of EntriesCacheCapacity, EntriesChunkSize(16384) and
419+
# the length of multihashes being advertised. For example, advertising 128-bit long multihashes
420+
# with the default EntriesCacheCapacity, and EntriesChunkSize(16384) means the cache size can grow to
421+
# 1GiB when full.
420422
#
421-
# type: string
422-
#TopicName = ""
423+
# type: int
424+
#EntriesCacheCapacity = 4096
423425

424426
# The network indexer host that the web UI should link to for published announcements
427+
# TODO: should we use this for checking published heas before publishing? Later commit
425428
#
426429
# type: string
427430
#WebHost = "https://cid.contact"
@@ -477,14 +480,14 @@ description: The default curio configuration
477480
#SkipCommP = false
478481

479482
[Market.HTTP]
480-
# ListenAddress is where HTTP server will be listening on
483+
# ListenAddress is where HTTP server will be listening on. Default is "0.0.0.0:12400"
481484
#
482485
# type: string
483-
#ListenAddress = "0.0.0.0:8888"
486+
#ListenAddress = "0.0.0.0:12400"
484487

485488
# AnnounceAddresses is a list of addresses clients can use to reach to the HTTP market node.
486489
# Curio allows running more than one node for HTTP server and thus all addressed can be announced
487-
# simultaneously to the client
490+
# simultaneously to the client. Example: ["https://mycurio.com", "http://myNewCurio:433/XYZ", "http://1.2.3.4:433"]
488491
#
489492
# type: []string
490493
#AnnounceAddresses = []

lib/ipni/chunker/chunker.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ import (
2020

2121
var log = logging.Logger("chunker")
2222

23-
const EntriesChunkSize = 16384
24-
const EntriesCacheCapacity = 4096
23+
const entriesChunkSize = 16384
2524

2625
// Chunker chunks advertisement entries as a chained series of schema.EntryChunk nodes.
2726
// See: NewChunker
@@ -36,13 +35,10 @@ type Chunker struct {
3635
//
3736
// See: schema.EntryChunk.
3837
func NewChunker(cache *lru.Cache[ipld.Link, datamodel.Node]) *Chunker {
39-
chunker := &Chunker{
40-
chunkSize: EntriesChunkSize,
38+
return &Chunker{
39+
chunkSize: entriesChunkSize,
40+
cache: cache,
4141
}
42-
if cache != nil {
43-
chunker.cache = cache
44-
}
45-
return chunker
4642
}
4743

4844
// Chunk chunks all the mulithashes returned by the given iterator into a chain of schema.EntryChunk
@@ -63,7 +59,6 @@ func (ls *Chunker) Chunk(mhi SliceMhIterator) (ipld.Link, error) {
6359
return nil, err
6460
}
6561
mhs = append(mhs, mh)
66-
mhCount++
6762
if len(mhs) >= ls.chunkSize {
6863
cNode, err := newEntriesChunkNode(mhs, next)
6964
if err != nil {
@@ -77,6 +72,7 @@ func (ls *Chunker) Chunk(mhi SliceMhIterator) (ipld.Link, error) {
7772
ls.cache.Add(next, cNode)
7873
}
7974
chunkCount++
75+
mhCount += len(mhs)
8076
// NewLinkedListOfMhs makes it own copy, so safe to reuse mhs
8177
mhs = mhs[:0]
8278
}
@@ -91,6 +87,7 @@ func (ls *Chunker) Chunk(mhi SliceMhIterator) (ipld.Link, error) {
9187
return nil, err
9288
}
9389
chunkCount++
90+
mhCount += len(mhs)
9491
}
9592

9693
log.Infow("Generated linked chunks of multihashes", "totalMhCount", mhCount, "chunkCount", chunkCount)

lib/ipni/ipni-provider/ipni-provider.go

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"strings"
1212
"time"
1313

14-
"github.com/filecoin-project/curio/lib/storiface"
15-
"github.com/filecoin-project/curio/lib/urltomultiaddr"
1614
"github.com/gorilla/mux"
1715
lru "github.com/hashicorp/golang-lru/v2"
1816
"github.com/ipfs/go-cid"
@@ -40,13 +38,16 @@ import (
4038
"github.com/filecoin-project/curio/lib/ipni/chunker"
4139
"github.com/filecoin-project/curio/lib/ipni/ipniculib"
4240
"github.com/filecoin-project/curio/lib/pieceprovider"
41+
"github.com/filecoin-project/curio/lib/storiface"
42+
"github.com/filecoin-project/curio/lib/urltomultiaddr"
4343

4444
"github.com/filecoin-project/lotus/node/modules/dtypes"
4545
)
4646

4747
const IPNIRoutePath = "/ipni-provider"
4848
const IPNIPath = "/ipni/v1/ad/"
4949
const ProviderPath = "/ipni-provider"
50+
const publishInterval = 10 * time.Minute
5051

5152
var (
5253
log = logging.Logger("ipni-provider")
@@ -68,7 +69,6 @@ type Provider struct {
6869
pieceProvider *pieceprovider.PieceProvider
6970
entriesChunker *chunker.Chunker
7071
cache *lru.Cache[ipld.Link, datamodel.Node]
71-
topic string
7272
httpPrefix string
7373
keys map[string]*peerInfo // map[peerID String]Private_Key
7474
// announceURLs enables sending direct announcements via HTTP. This is
@@ -78,7 +78,7 @@ type Provider struct {
7878
}
7979

8080
func NewProvider(api ipniAPI, deps *deps.Deps) (*Provider, error) {
81-
c, err := lru.New[ipld.Link, datamodel.Node](chunker.EntriesCacheCapacity)
81+
c, err := lru.New[ipld.Link, datamodel.Node](deps.Cfg.Market.StorageMarketConfig.IPNI.EntriesCacheCapacity)
8282
if err != nil {
8383
return nil, xerrors.Errorf("creating new cache: %w", err)
8484
}
@@ -121,30 +121,19 @@ func NewProvider(api ipniAPI, deps *deps.Deps) (*Provider, error) {
121121
return nil, err
122122
}
123123

124-
nn, err := api.StateNetworkName(ctx)
125-
if err != nil {
126-
return nil, err
127-
}
128-
129-
topic := "/indexer/ingest/" + string(nn)
130-
131-
if deps.Cfg.Market.StorageMarketConfig.IPNI.TopicName != "" {
132-
topic = deps.Cfg.Market.StorageMarketConfig.IPNI.TopicName
133-
}
134-
135-
var announceURLs []*url.URL
124+
announceURLs := make([]*url.URL, 0, len(deps.Cfg.Market.StorageMarketConfig.IPNI.DirectAnnounceURLs))
136125

137-
for _, us := range deps.Cfg.Market.StorageMarketConfig.IPNI.DirectAnnounceURLs {
126+
for i, us := range deps.Cfg.Market.StorageMarketConfig.IPNI.DirectAnnounceURLs {
138127
u, err := url.Parse(us)
139128
if err != nil {
140129
return nil, err
141130
}
142-
announceURLs = append(announceURLs, u)
131+
announceURLs[i] = u
143132
}
144133

145-
var httpServerAddresses []multiaddr.Multiaddr
134+
httpServerAddresses := make([]multiaddr.Multiaddr, 0, len(deps.Cfg.Market.HTTP.AnnounceAddresses))
146135

147-
for _, a := range deps.Cfg.Market.HTTP.AnnounceAddresses {
136+
for i, a := range deps.Cfg.Market.HTTP.AnnounceAddresses {
148137
addr, err := urltomultiaddr.UrlToMultiaddr(a)
149138
if err != nil {
150139
return nil, err
@@ -153,7 +142,7 @@ func NewProvider(api ipniAPI, deps *deps.Deps) (*Provider, error) {
153142
if err != nil {
154143
return nil, err
155144
}
156-
httpServerAddresses = append(httpServerAddresses, addr)
145+
httpServerAddresses[i] = addr
157146
}
158147

159148
return &Provider{
@@ -162,7 +151,6 @@ func NewProvider(api ipniAPI, deps *deps.Deps) (*Provider, error) {
162151
pieceProvider: deps.PieceProvider,
163152
cache: c,
164153
keys: keyMap,
165-
topic: topic,
166154
announceURLs: announceURLs,
167155
httpServerAddresses: httpServerAddresses,
168156
}, nil
@@ -179,9 +167,17 @@ func (p *Provider) getAd(ctx context.Context, ad cid.Cid, provider string) (sche
179167
IsRm bool
180168
}
181169

182-
err := p.db.Select(ctx, &ads, `SELECT context_id,
183-
is_rm, previous, provider, addresses,
184-
signature, entries FROM ipni WHERE ad_cid = $1 AND provider = $2`, ad.String(), provider)
170+
err := p.db.Select(ctx, &ads, `SELECT
171+
context_id,
172+
is_rm,
173+
previous,
174+
provider,
175+
addresses,
176+
signature,
177+
entries
178+
FROM ipni
179+
WHERE ad_cid = $1
180+
AND provider = $2`, ad.String(), provider)
185181

186182
if err != nil {
187183
return schema.Advertisement{}, xerrors.Errorf("getting ad from DB: %w", err)
@@ -256,7 +252,7 @@ func (p *Provider) getHead(ctx context.Context, provider string) ([]byte, error)
256252
return nil, err
257253
}
258254

259-
signedHead, err := head.NewSignedHead(lnk.(cidlink.Link).Cid, p.topic, p.keys[provider].Key)
255+
signedHead, err := head.NewSignedHead(lnk.(cidlink.Link).Cid, "", p.keys[provider].Key)
260256
if err != nil {
261257
return nil, xerrors.Errorf("failed to generate signed head for peer %s: %w", provider, err)
262258
}
@@ -461,7 +457,7 @@ func (p *Provider) handleGet(w http.ResponseWriter, r *http.Request) {
461457
return
462458
}
463459
log.Errorf("failed to get signed head for peer %s: %w", providerID, err)
464-
http.Error(w, err.Error(), http.StatusInternalServerError)
460+
http.Error(w, "", http.StatusInternalServerError)
465461
}
466462
w.WriteHeader(http.StatusOK)
467463
_, err = w.Write(sh)
@@ -487,7 +483,7 @@ func (p *Provider) handleGet(w http.ResponseWriter, r *http.Request) {
487483
return
488484
}
489485
log.Errorf("failed to get entry %s for peer %s: %w", b.String(), providerID, err)
490-
http.Error(w, err.Error(), http.StatusInternalServerError)
486+
http.Error(w, "", http.StatusInternalServerError)
491487
return
492488
}
493489
w.WriteHeader(http.StatusOK)
@@ -498,21 +494,21 @@ func (p *Provider) handleGet(w http.ResponseWriter, r *http.Request) {
498494
return
499495
}
500496
log.Errorf("failed to get ad %s for peer %s: %w", b.String(), providerID, err)
501-
http.Error(w, err.Error(), http.StatusInternalServerError)
497+
http.Error(w, "", http.StatusInternalServerError)
502498
return
503499
}
504500
adn, err := ad.ToNode()
505501
if err != nil {
506502
log.Errorf("failed to convert ad %s for peer %s to IPLD node: %w", b.String(), providerID, err)
507-
http.Error(w, err.Error(), http.StatusInternalServerError)
503+
http.Error(w, "", http.StatusInternalServerError)
508504
return
509505
}
510506
// Use local buffer for better error handing
511507
resp := new(bytes.Buffer)
512508
err = dagjson.Encode(adn, resp)
513509
if err != nil {
514510
log.Errorf("failed to encode ad %s for peer %s: %w", b.String(), providerID, err)
515-
http.Error(w, err.Error(), http.StatusInternalServerError)
511+
http.Error(w, "", http.StatusInternalServerError)
516512
return
517513
}
518514
w.WriteHeader(http.StatusOK)
@@ -535,7 +531,7 @@ func Routes(r *mux.Router, p *Provider) {
535531
func (p *Provider) StartPublishing(ctx context.Context) {
536532
// A poller which publishes head for each provider
537533
// every 10 minutes
538-
ticker := time.NewTicker(10 * time.Minute)
534+
ticker := time.NewTicker(publishInterval)
539535
go func() {
540536
for {
541537
select {

0 commit comments

Comments
 (0)