Skip to content

Commit 3d82c0c

Browse files
committed
fix storeiface, publisher multiaddrs
1 parent 563f95c commit 3d82c0c

File tree

6 files changed

+95
-19
lines changed

6 files changed

+95
-19
lines changed

deps/config/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func DefaultCurioConfig() *CurioConfig {
7272
},
7373
Market: MarketConfig{
7474
HTTP: HTTPConfig{
75-
ListenAddress: "0.0.0.0:8888",
75+
ListenAddress: "0.0.0.0:12400",
7676
AnnounceAddresses: []string{},
7777
},
7878
StorageMarketConfig: StorageMarketConfig{
@@ -666,11 +666,11 @@ type IPNIConfig struct {
666666
}
667667

668668
type HTTPConfig struct {
669-
// ListenAddress is where HTTP server will be listening on
669+
// ListenAddress is where HTTP server will be listening on. Default is "0.0.0.0:12400"
670670
ListenAddress string
671671

672672
// AnnounceAddresses is a list of addresses clients can use to reach to the HTTP market node.
673673
// Curio allows running more than one node for HTTP server and thus all addressed can be announced
674-
// simultaneously to the client
674+
// simultaneously to the client. Example: ["https://mycurio.com", "http://myNewCurio:433/XYZ", "http://1.2.3.4:433"]
675675
AnnounceAddresses []string
676676
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ require (
320320
golang.org/x/crypto v0.26.0 // indirect
321321
golang.org/x/mod v0.20.0 // indirect
322322
golang.org/x/term v0.23.0 // indirect
323+
golang.org/x/time v0.5.0 // indirect
323324
gonum.org/v1/gonum v0.15.0 // indirect
324325
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
325326
google.golang.org/grpc v1.64.0 // indirect

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

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

14+
"github.com/filecoin-project/curio/lib/storiface"
15+
"github.com/filecoin-project/curio/lib/urltomultiaddr"
1416
"github.com/gorilla/mux"
1517
lru "github.com/hashicorp/golang-lru/v2"
1618
"github.com/ipfs/go-cid"
@@ -40,9 +42,9 @@ import (
4042
"github.com/filecoin-project/curio/lib/pieceprovider"
4143

4244
"github.com/filecoin-project/lotus/node/modules/dtypes"
43-
"github.com/filecoin-project/lotus/storage/sealer/storiface"
4445
)
4546

47+
const IPNIRoutePath = "/ipni-provider"
4648
const IPNIPath = "/ipni/v1/ad/"
4749
const ProviderPath = "/ipni-provider"
4850

@@ -141,7 +143,11 @@ func NewProvider(api ipniAPI, deps *deps.Deps) (*Provider, error) {
141143
var httpServerAddresses []multiaddr.Multiaddr
142144

143145
for _, a := range deps.Cfg.Market.HTTP.AnnounceAddresses {
144-
addr, err := multiaddr.NewMultiaddr(a)
146+
addr, err := urltomultiaddr.UrlToMultiaddr(a)
147+
if err != nil {
148+
return nil, err
149+
}
150+
addr, err = multiaddr.NewMultiaddr(addr.String() + IPNIRoutePath)
145151
if err != nil {
146152
return nil, err
147153
}
@@ -393,6 +399,9 @@ func (p *Provider) GetEntry(block cid.Cid, provider string) ([]byte, error) {
393399

394400
mis := make(index.MultihashIndexSorted)
395401
err = mis.Load(recs)
402+
if err != nil {
403+
return nil, xerrors.Errorf("failed to load indexed in multihash sorter: %w", err)
404+
}
396405

397406
// To avoid - Cannot assert pinter to interface
398407
idxF := func(sorted *index.MultihashIndexSorted) index.Index {
@@ -516,7 +525,7 @@ func contentRouter(r *mux.Router, p *Provider) {
516525
}
517526

518527
func Routes(r *mux.Router, p *Provider) {
519-
contentRouter(r.PathPrefix("/ipni-provider").Subrouter(), p)
528+
contentRouter(r.PathPrefix(IPNIRoutePath).Subrouter(), p)
520529
}
521530

522531
func (p *Provider) StartPublishing(ctx context.Context) {
@@ -572,6 +581,24 @@ func (p *Provider) publishhttp(ctx context.Context, adCid cid.Cid, peer string)
572581
return fmt.Errorf("cannot create http announce sender: %w", err)
573582
}
574583

584+
addrs, err := p.getHTTPAddressForPeer(peer)
585+
if err != nil {
586+
return fmt.Errorf("cannot create provider http addresses: %w", err)
587+
}
588+
575589
log.Infow("Announcing advertisements over HTTP", "urls", p.announceURLs)
576-
return announce.Send(ctx, adCid, p.httpServerAddresses, httpSender)
590+
return announce.Send(ctx, adCid, addrs, httpSender)
591+
}
592+
593+
func (p *Provider) getHTTPAddressForPeer(peer string) ([]multiaddr.Multiaddr, error) {
594+
var ret []multiaddr.Multiaddr
595+
for _, addr := range p.httpServerAddresses {
596+
a, err := multiaddr.NewMultiaddr(addr.String() + "/" + peer)
597+
if err != nil {
598+
return nil, err
599+
}
600+
ret = append(ret, a)
601+
}
602+
603+
return ret, nil
577604
}

lib/ipni/ipniculib/ipniculib.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
package ipniculib
22

33
import (
4-
"crypto/sha256"
5-
6-
"github.com/ipld/go-ipld-prime/codec/dagjson"
74
"github.com/ipld/go-ipld-prime/datamodel"
8-
"golang.org/x/xerrors"
5+
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
96
)
107

118
func NodeToLink(node datamodel.Node, lp datamodel.LinkPrototype) (datamodel.Link, error) {
12-
hasher := sha256.New()
13-
err := dagjson.Encode(node, hasher)
14-
if err != nil {
15-
return nil, xerrors.Errorf("failed to encode: %w", err)
16-
}
17-
return lp.BuildLink(hasher.Sum(nil)), nil
9+
linkSystem := cidlink.DefaultLinkSystem()
10+
return linkSystem.ComputeLink(lp, node)
1811
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package urltomultiaddr
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"net"
7+
"net/url"
8+
9+
"github.com/multiformats/go-multiaddr"
10+
)
11+
12+
const protocol = "tcp"
13+
14+
func UrlToMultiaddr(urlStr string) (multiaddr.Multiaddr, error) {
15+
// Parse the URL
16+
parsedURL, err := url.Parse(urlStr)
17+
if err != nil {
18+
return nil, err
19+
}
20+
21+
// Extract the host and port
22+
host := parsedURL.Hostname()
23+
port := parsedURL.Port()
24+
if port == "" {
25+
// Default port based on the scheme
26+
switch parsedURL.Scheme {
27+
case "https":
28+
port = "443"
29+
case "http":
30+
port = "80"
31+
default:
32+
return nil, errors.New("invalid URL scheme")
33+
}
34+
}
35+
36+
// Determine if the host is an IP address or a DNS name
37+
var addrStr string
38+
if ip := net.ParseIP(host); ip != nil {
39+
// It's an IP address, check if it's IPv4 or IPv6
40+
if ip.To4() != nil {
41+
// IPv4
42+
addrStr = fmt.Sprintf("/ip4/%s/%s/%s/%s", ip.String(), protocol, port, parsedURL.Scheme)
43+
} else {
44+
// IPv6
45+
addrStr = fmt.Sprintf("/ip6/%s/%s/%s/%s", ip.String(), protocol, port, parsedURL.Scheme)
46+
}
47+
} else {
48+
// It's a DNS name
49+
addrStr = fmt.Sprintf("/dns/%s/%s/%s/%s", host, protocol, port, parsedURL.Scheme)
50+
}
51+
52+
return multiaddr.NewMultiaddr(addrStr)
53+
}

tasks/indexing/task_ipni.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"time"
1111

12+
"github.com/filecoin-project/curio/lib/storiface"
1213
"github.com/ipfs/go-cid"
1314
logging "github.com/ipfs/go-log/v2"
1415
carv2 "github.com/ipld/go-car/v2"
@@ -32,8 +33,6 @@ import (
3233
"github.com/filecoin-project/curio/lib/ipni/ipniculib"
3334
"github.com/filecoin-project/curio/lib/passcall"
3435
"github.com/filecoin-project/curio/lib/pieceprovider"
35-
36-
"github.com/filecoin-project/lotus/storage/sealer/storiface"
3736
)
3837

3938
var ilog = logging.Logger("ipni")
@@ -145,6 +144,9 @@ func (I *IPNITask) Do(taskID harmonytask.TaskID, stillOwned func() bool) (done b
145144

146145
mis := make(index.MultihashIndexSorted)
147146
err = mis.Load(recs)
147+
if err != nil {
148+
return false, xerrors.Errorf("failed to load indexed in multihash sorter: %w", err)
149+
}
148150

149151
// To avoid - Cannot assert pinter to interface
150152
idxF := func(sorted *index.MultihashIndexSorted) index.Index {

0 commit comments

Comments
 (0)