@@ -3,14 +3,6 @@ package coreapi
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "sync"
7
-
8
- "github.com/ipfs/kubo/core"
9
- "github.com/ipfs/kubo/tracing"
10
- "go.opentelemetry.io/otel/attribute"
11
- "go.opentelemetry.io/otel/trace"
12
-
13
- "github.com/ipfs/kubo/core/coreunix"
14
6
15
7
blockservice "github.com/ipfs/boxo/blockservice"
16
8
bstore "github.com/ipfs/boxo/blockstore"
@@ -21,41 +13,23 @@ import (
21
13
ft "github.com/ipfs/boxo/ipld/unixfs"
22
14
unixfile "github.com/ipfs/boxo/ipld/unixfs/file"
23
15
uio "github.com/ipfs/boxo/ipld/unixfs/io"
24
- mfs "github.com/ipfs/boxo/mfs"
16
+ "github.com/ipfs/boxo/mfs"
25
17
"github.com/ipfs/boxo/path"
26
18
cid "github.com/ipfs/go-cid"
27
19
cidutil "github.com/ipfs/go-cidutil"
20
+ ds "github.com/ipfs/go-datastore"
21
+ dssync "github.com/ipfs/go-datastore/sync"
28
22
ipld "github.com/ipfs/go-ipld-format"
29
23
coreiface "github.com/ipfs/kubo/core/coreiface"
30
24
options "github.com/ipfs/kubo/core/coreiface/options"
25
+ "github.com/ipfs/kubo/core/coreunix"
26
+ "github.com/ipfs/kubo/tracing"
27
+ "go.opentelemetry.io/otel/attribute"
28
+ "go.opentelemetry.io/otel/trace"
31
29
)
32
30
33
31
type UnixfsAPI CoreAPI
34
32
35
- var (
36
- nilNode * core.IpfsNode
37
- once sync.Once
38
- )
39
-
40
- func getOrCreateNilNode () (* core.IpfsNode , error ) {
41
- once .Do (func () {
42
- if nilNode != nil {
43
- return
44
- }
45
- node , err := core .NewNode (context .Background (), & core.BuildCfg {
46
- // TODO: need this to be true or all files
47
- // hashed will be stored in memory!
48
- NilRepo : true ,
49
- })
50
- if err != nil {
51
- panic (err )
52
- }
53
- nilNode = node
54
- })
55
-
56
- return nilNode , nil
57
- }
58
-
59
33
// Add builds a merkledag node from a reader, adds it to the blockstore,
60
34
// and returns the key representing that node.
61
35
func (api * UnixfsAPI ) Add (ctx context.Context , files files.Node , opts ... options.UnixfsAddOption ) (path.ImmutablePath , error ) {
@@ -108,13 +82,12 @@ func (api *UnixfsAPI) Add(ctx context.Context, files files.Node, opts ...options
108
82
pinning := api .pinning
109
83
110
84
if settings .OnlyHash {
111
- node , err := getOrCreateNilNode ()
112
- if err != nil {
113
- return path.ImmutablePath {}, err
114
- }
115
- addblockstore = node .Blockstore
116
- exch = node .Exchange
117
- pinning = node .Pinning
85
+ // setup a /dev/null pipeline to simulate adding the data
86
+ dstore := dssync .MutexWrap (ds .NewNullDatastore ())
87
+ bs := bstore .NewBlockstore (dstore , bstore .WriteThrough ())
88
+ addblockstore = bstore .NewGCBlockstore (bs , nil ) // gclocker will never be used
89
+ exch = nil // exchange will never be used
90
+ pinning = nil // pinner will never be used
118
91
}
119
92
120
93
bserv := blockservice .New (addblockstore , exch ) // hash security 001
@@ -133,11 +106,11 @@ func (api *UnixfsAPI) Add(ctx context.Context, files files.Node, opts ...options
133
106
syncDserv = & syncDagService {
134
107
DAGService : dserv ,
135
108
syncFn : func () error {
136
- ds := api .repo .Datastore ()
137
- if err := ds .Sync (ctx , bstore .BlockPrefix ); err != nil {
109
+ rds := api .repo .Datastore ()
110
+ if err := rds .Sync (ctx , bstore .BlockPrefix ); err != nil {
138
111
return err
139
112
}
140
- return ds .Sync (ctx , filestore .FilestorePrefix )
113
+ return rds .Sync (ctx , filestore .FilestorePrefix )
141
114
},
142
115
}
143
116
}
0 commit comments