Skip to content

Commit 1d9428f

Browse files
committed
remove unnecssary go-dagwriter. switch to using separate ipld and unix fetchers and constructing resolvers on demand.
1 parent 5801c34 commit 1d9428f

File tree

9 files changed

+53
-59
lines changed

9 files changed

+53
-59
lines changed

core/core.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
ipld "github.com/ipfs/go-ipld-format"
2626
logging "github.com/ipfs/go-log"
2727
mfs "github.com/ipfs/go-mfs"
28-
resolver "github.com/ipfs/go-path/resolver"
2928
goprocess "github.com/jbenet/goprocess"
3029
connmgr "github.com/libp2p/go-libp2p-core/connmgr"
3130
ic "github.com/libp2p/go-libp2p-core/crypto"
@@ -71,19 +70,19 @@ type IpfsNode struct {
7170
PNetFingerprint libp2p.PNetFingerprint `optional:"true"` // fingerprint of private network
7271

7372
// Services
74-
Peerstore pstore.Peerstore `optional:"true"` // storage for other Peer instances
75-
Blockstore bstore.GCBlockstore // the block store (lower level)
76-
Filestore *filestore.Filestore `optional:"true"` // the filestore blockstore
77-
BaseBlocks node.BaseBlocks // the raw blockstore, no filestore wrapping
78-
GCLocker bstore.GCLocker // the locker used to protect the blockstore during gc
79-
Blocks bserv.BlockService // the block service, get/add blocks.
80-
DAG ipld.DAGService // the merkle dag service, get/add objects.
81-
Resolver *resolver.Resolver // the path resolution system
82-
FetcherFactory fetcher.Factory // an implementation of the fetcher
83-
Reporter *metrics.BandwidthCounter `optional:"true"`
84-
Discovery discovery.Service `optional:"true"`
85-
FilesRoot *mfs.Root
86-
RecordValidator record.Validator
73+
Peerstore pstore.Peerstore `optional:"true"` // storage for other Peer instances
74+
Blockstore bstore.GCBlockstore // the block store (lower level)
75+
Filestore *filestore.Filestore `optional:"true"` // the filestore blockstore
76+
BaseBlocks node.BaseBlocks // the raw blockstore, no filestore wrapping
77+
GCLocker bstore.GCLocker // the locker used to protect the blockstore during gc
78+
Blocks bserv.BlockService // the block service, get/add blocks.
79+
DAG ipld.DAGService // the merkle dag service, get/add objects.
80+
IPLDFetcherFactory fetcher.Factory `name:"ipldFetcher"` // fetcher that paths over the IPLD data model
81+
UnixFSFetcherFactory fetcher.Factory `name:"unixfsFetcher"` // fetcher that interprets UnixFS data
82+
Reporter *metrics.BandwidthCounter `optional:"true"`
83+
Discovery discovery.Service `optional:"true"`
84+
FilesRoot *mfs.Root
85+
RecordValidator record.Validator
8786

8887
// Online
8988
PeerHost p2phost.Host `optional:"true"` // the network host (server+client)

core/coreapi/coreapi.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
"fmt"
2020

2121
bserv "github.com/ipfs/go-blockservice"
22-
"github.com/ipfs/go-dagwriter"
23-
bsdagwriter "github.com/ipfs/go-dagwriter/impl/blockservice"
2422
"github.com/ipfs/go-fetcher"
2523
blockstore "github.com/ipfs/go-ipfs-blockstore"
2624
exchange "github.com/ipfs/go-ipfs-exchange-interface"
@@ -30,7 +28,6 @@ import (
3028
offlineroute "github.com/ipfs/go-ipfs-routing/offline"
3129
ipld "github.com/ipfs/go-ipld-format"
3230
dag "github.com/ipfs/go-merkledag"
33-
"github.com/ipfs/go-path/resolver"
3431
coreiface "github.com/ipfs/interface-go-ipfs-core"
3532
"github.com/ipfs/interface-go-ipfs-core/options"
3633
ci "github.com/libp2p/go-libp2p-core/crypto"
@@ -59,15 +56,14 @@ type CoreAPI struct {
5956
baseBlocks blockstore.Blockstore
6057
pinning pin.Pinner
6158

62-
blocks bserv.BlockService
63-
dag ipld.DAGService
64-
fetcherFactory fetcher.Factory
65-
dagWriter dagwriter.DagWritingService
66-
resolver *resolver.Resolver
67-
peerstore pstore.Peerstore
68-
peerHost p2phost.Host
69-
recordValidator record.Validator
70-
exchange exchange.Interface
59+
blocks bserv.BlockService
60+
dag ipld.DAGService
61+
ipldFetcherFactory fetcher.Factory
62+
unixFSFetcherFactory fetcher.Factory
63+
peerstore pstore.Peerstore
64+
peerHost p2phost.Host
65+
recordValidator record.Validator
66+
exchange exchange.Interface
7167

7268
namesys namesys.NameSystem
7369
routing routing.Routing
@@ -173,10 +169,10 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e
173169
baseBlocks: n.BaseBlocks,
174170
pinning: n.Pinning,
175171

176-
blocks: n.Blocks,
177-
dag: n.DAG,
178-
resolver: n.Resolver,
179-
fetcherFactory: n.FetcherFactory,
172+
blocks: n.Blocks,
173+
dag: n.DAG,
174+
ipldFetcherFactory: n.IPLDFetcherFactory,
175+
unixFSFetcherFactory: n.UnixFSFetcherFactory,
180176

181177
peerstore: n.Peerstore,
182178
peerHost: n.PeerHost,
@@ -194,8 +190,6 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e
194190
parentOpts: settings,
195191
}
196192

197-
subApi.dagWriter = bsdagwriter.NewDagWriter(subApi.blocks)
198-
199193
subApi.checkOnline = func(allowOffline bool) error {
200194
if !n.IsOnline && !allowOffline {
201195
return coreiface.ErrOffline

core/coreapi/path.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
"github.com/ipfs/go-fetcher"
1212
ipld "github.com/ipfs/go-ipld-format"
1313
ipfspath "github.com/ipfs/go-path"
14+
ipfspathresolver "github.com/ipfs/go-path/resolver"
1415
coreiface "github.com/ipfs/interface-go-ipfs-core"
1516
path "github.com/ipfs/interface-go-ipfs-core/path"
16-
ipldprime "github.com/ipld/go-ipld-prime"
1717
)
1818

1919
// ResolveNode resolves the path `p` using Unixfs resolver, gets and returns the
@@ -52,15 +52,14 @@ func (api *CoreAPI) ResolvePath(ctx context.Context, p path.Path) (path.Resolved
5252
if ipath.Segments()[0] != "ipfs" && ipath.Segments()[0] != "ipld" {
5353
return nil, fmt.Errorf("unsupported path namespace: %s", p.Namespace())
5454
}
55-
resolver := *api.resolver
55+
56+
var dataFetcher fetcher.Factory
5657
if ipath.Segments()[0] == "ipld" {
57-
type reifiable interface {
58-
WithReifier(nr ipldprime.NodeReifier) fetcher.Factory
59-
}
60-
if bsf, ok := resolver.FetcherFactory.(reifiable); ok {
61-
resolver.FetcherFactory = bsf.WithReifier(nil)
62-
}
58+
dataFetcher = api.ipldFetcherFactory
59+
} else {
60+
dataFetcher = api.unixFSFetcherFactory
6361
}
62+
resolver := ipfspathresolver.NewBasicResolver(dataFetcher)
6463

6564
node, rest, err := resolver.ResolveToLastNode(ctx, ipath)
6665
if err != nil {

core/node/core.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package node
33
import (
44
"context"
55
"fmt"
6-
76
"github.com/ipfs/go-bitswap"
87
"github.com/ipfs/go-bitswap/network"
98
"github.com/ipfs/go-blockservice"
@@ -19,7 +18,6 @@ import (
1918
format "github.com/ipfs/go-ipld-format"
2019
"github.com/ipfs/go-merkledag"
2120
"github.com/ipfs/go-mfs"
22-
"github.com/ipfs/go-path/resolver"
2321
"github.com/ipfs/go-unixfs"
2422
"github.com/ipfs/go-unixfsnode"
2523
dagpb "github.com/ipld/go-codec-dagpb"
@@ -88,22 +86,24 @@ func (s *syncDagService) Session(ctx context.Context) format.NodeGetter {
8886
return merkledag.NewSession(ctx, s.DAGService)
8987
}
9088

89+
type fetchersOut struct {
90+
fx.Out
91+
IPLDFetcher fetcher.Factory `name:"ipldFetcher"`
92+
UnixfsFetcher fetcher.Factory `name:"unixfsFetcher"`
93+
}
94+
9195
// FetcherConfig returns a fetcher config that can build new fetcher instances
92-
func FetcherConfig(bs blockservice.BlockService) fetcher.Factory {
93-
fc := bsfetcher.NewFetcherConfig(bs)
94-
fc.NodeReifier = unixfsnode.Reify
95-
fc.PrototypeChooser = dagpb.AddSupportToChooser(func(lnk ipld.Link, lnkCtx ipld.LinkContext) (ipld.NodePrototype, error) {
96+
func FetcherConfig(bs blockservice.BlockService) fetchersOut {
97+
ipldFetcher := bsfetcher.NewFetcherConfig(bs)
98+
ipldFetcher.PrototypeChooser = dagpb.AddSupportToChooser(func(lnk ipld.Link, lnkCtx ipld.LinkContext) (ipld.NodePrototype, error) {
9699
if tlnkNd, ok := lnkCtx.LinkNode.(schema.TypedLinkNode); ok {
97100
return tlnkNd.LinkTargetNodePrototype(), nil
98101
}
99102
return basicnode.Prototype.Any, nil
100103
})
101-
return fc
102-
}
103104

104-
// Resolver returns a resolver that's configured to look up unixfs paths
105-
func Resolver(fetcherFactory fetcher.Factory) *resolver.Resolver {
106-
return resolver.NewBasicResolver(fetcherFactory)
105+
unixFSFetcher := ipldFetcher.WithReifier(unixfsnode.Reify)
106+
return fetchersOut{IPLDFetcher: ipldFetcher, UnixfsFetcher: unixFSFetcher}
107107
}
108108

109109
// Dag creates new DAGService

core/node/groups.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ var Core = fx.Options(
294294
fx.Provide(BlockService),
295295
fx.Provide(Dag),
296296
fx.Provide(FetcherConfig),
297-
fx.Provide(Resolver),
298297
fx.Provide(Pinning),
299298
fx.Provide(Files),
300299
)

core/node/provider.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import (
55
"fmt"
66
"time"
77

8+
"github.com/ipfs/go-fetcher"
89
"github.com/ipfs/go-ipfs-pinner"
910
"github.com/ipfs/go-ipfs-provider"
1011
"github.com/ipfs/go-ipfs-provider/batched"
1112
q "github.com/ipfs/go-ipfs-provider/queue"
1213
"github.com/ipfs/go-ipfs-provider/simple"
13-
ipld "github.com/ipfs/go-ipld-format"
1414
"github.com/libp2p/go-libp2p-core/routing"
1515
"github.com/multiformats/go-multihash"
1616
"go.uber.org/fx"
@@ -172,7 +172,12 @@ func SimpleProviders(reprovideStrategy string, reprovideInterval string) fx.Opti
172172
}
173173

174174
func pinnedProviderStrategy(onlyRoots bool) interface{} {
175-
return func(pinner pin.Pinner, dag ipld.DAGService) simple.KeyChanFunc {
176-
return simple.NewPinnedProvider(onlyRoots, pinner, dag)
175+
type input struct {
176+
fx.In
177+
Pinner pin.Pinner
178+
IPLDFetcher fetcher.Factory `name:"ipldFetcher"`
179+
}
180+
return func(in input) simple.KeyChanFunc {
181+
return simple.NewPinnedProvider(onlyRoots, in.Pinner, in.IPLDFetcher)
177182
}
178183
}

fuse/readonly/readonly_unix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
logging "github.com/ipfs/go-log"
1919
mdag "github.com/ipfs/go-merkledag"
2020
path "github.com/ipfs/go-path"
21+
"github.com/ipfs/go-path/resolver"
2122
ft "github.com/ipfs/go-unixfs"
2223
uio "github.com/ipfs/go-unixfs/io"
2324
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
@@ -66,7 +67,7 @@ func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) {
6667
return nil, fuse.ENOENT
6768
}
6869

69-
nd, ndLnk, err := s.Ipfs.Resolver.ResolvePath(ctx, p)
70+
nd, ndLnk, err := resolver.NewBasicResolver(s.Ipfs.UnixFSFetcherFactory).ResolvePath(ctx, p)
7071
if err != nil {
7172
// todo: make this error more versatile.
7273
return nil, fuse.ENOENT

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ require (
1717
github.com/ipfs/go-blockservice v0.1.7
1818
github.com/ipfs/go-cid v0.0.7
1919
github.com/ipfs/go-cidutil v0.0.2
20-
github.com/ipfs/go-dagwriter v1.0.0
2120
github.com/ipfs/go-datastore v0.4.5
2221
github.com/ipfs/go-detect-race v0.0.1
2322
github.com/ipfs/go-ds-badger v0.2.7

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,6 @@ github.com/ipfs/go-cid v0.0.7 h1:ysQJVJA3fNDF1qigJbsSQOdjhVLsOEoPdh0+R97k3jY=
370370
github.com/ipfs/go-cid v0.0.7/go.mod h1:6Ux9z5e+HpkQdckYoX1PG/6xqKspzlEIR5SDmgqgC/I=
371371
github.com/ipfs/go-cidutil v0.0.2 h1:CNOboQf1t7Qp0nuNh8QMmhJs0+Q//bRL1axtCnIB1Yo=
372372
github.com/ipfs/go-cidutil v0.0.2/go.mod h1:ewllrvrxG6AMYStla3GD7Cqn+XYSLqjK0vc+086tB6s=
373-
github.com/ipfs/go-dagwriter v1.0.0 h1:fMwjI4e+dhAguyycxXjshnZsqWlS4ko2KgTpWd6Kfxk=
374-
github.com/ipfs/go-dagwriter v1.0.0/go.mod h1:rytn1TKuQ3zg9oMJxoVsSUt7BXonIRWxChvDR6LkG98=
375373
github.com/ipfs/go-datastore v0.0.1/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE=
376374
github.com/ipfs/go-datastore v0.0.5/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE=
377375
github.com/ipfs/go-datastore v0.1.0/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE=

0 commit comments

Comments
 (0)