coreapi: split the interface into multiple files
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Mar 10, 2018 at 18:46 UTC
f218b69e470568078c7338ed56c6c2edb9f89cc5
12 files changed
+454
-384
core/coreapi/interface/block.go
new
+49
@@ -0,0 +1,49 @@
1
+package iface
2
+
3
+import (
4
+ "context"
5
+ "io"
6
+
7
+ options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
8
+)
9
+
10
+// BlockStat contains information about a block
11
+type BlockStat interface {
12
+ // Size is the size of a block
13
+ Size() int
14
+
15
+ // Path returns path to the block
16
+ Path() Path
17
+}
18
+
19
+// BlockAPI specifies the interface to the block layer
20
+type BlockAPI interface {
21
+ // Put imports raw block data, hashing it using specified settings.
22
+ Put(context.Context, io.Reader, ...options.BlockPutOption) (Path, error)
23
+
24
+ // WithFormat is an option for Put which specifies the multicodec to use to
25
+ // serialize the object. Default is "v0"
26
+ WithFormat(codec string) options.BlockPutOption
27
+
28
+ // WithHash is an option for Put which specifies the multihash settings to use
29
+ // when hashing the object. Default is mh.SHA2_256 (0x12).
30
+ // If mhLen is set to -1, default length for the hash will be used
31
+ WithHash(mhType uint64, mhLen int) options.BlockPutOption
32
+
33
+ // Get attempts to resolve the path and return a reader for data in the block
34
+ Get(context.Context, Path) (io.Reader, error)
35
+
36
+ // Rm removes the block specified by the path from local blockstore.
37
+ // By default an error will be returned if the block can't be found locally.
38
+ //
39
+ // NOTE: If the specified block is pinned it won't be removed and no error
40
+ // will be returned
41
+ Rm(context.Context, Path, ...options.BlockRmOption) error
42
+
43
+ // WithForce is an option for Rm which, when set to true, will ignore
44
+ // non-existing blocks
45
+ WithForce(force bool) options.BlockRmOption
46
+
47
+ // Stat returns information on
48
+ Stat(context.Context, Path) (BlockStat, error)
49
+}
core/coreapi/interface/coreapi.go
new
+38
@@ -0,0 +1,38 @@
1
+// Package iface defines IPFS Core API which is a set of interfaces used to
2
+// interact with IPFS nodes.
3
+package iface
4
+
5
+import (
6
+ "context"
7
+
8
+ ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
9
+)
10
+
11
+// CoreAPI defines an unified interface to IPFS for Go programs.
12
+type CoreAPI interface {
13
+ // Unixfs returns an implementation of Unixfs API.
14
+ Unixfs() UnixfsAPI
15
+
16
+ // Block returns an implementation of Block API.
17
+ Block() BlockAPI
18
+
19
+ // Dag returns an implementation of Dag API.
20
+ Dag() DagAPI
21
+
22
+ // Name returns an implementation of Name API.
23
+ Name() NameAPI
24
+
25
+ // Key returns an implementation of Key API.
26
+ Key() KeyAPI
27
+ Pin() PinAPI
28
+
29
+ // ObjectAPI returns an implementation of Object API
30
+ Object() ObjectAPI
31
+
32
+ // ResolvePath resolves the path using Unixfs resolver
33
+ ResolvePath(context.Context, Path) (Path, error)
34
+
35
+ // ResolveNode resolves the path (if not resolved already) using Unixfs
36
+ // resolver, gets and returns the resolved Node
37
+ ResolveNode(context.Context, Path) (ipld.Node, error)
38
+}
core/coreapi/interface/dag.go
new
+42
@@ -0,0 +1,42 @@
1
+package iface
2
+
3
+import (
4
+ "context"
5
+ "io"
6
+
7
+ options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
8
+
9
+ ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
10
+)
11
+
12
+// DagAPI specifies the interface to IPLD
13
+type DagAPI interface {
14
+ // Put inserts data using specified format and input encoding.
15
+ // Unless used with WithCodec or WithHash, the defaults "dag-cbor" and
16
+ // "sha256" are used.
17
+ Put(ctx context.Context, src io.Reader, opts ...options.DagPutOption) (Path, error)
18
+
19
+ // WithInputEnc is an option for Put which specifies the input encoding of the
20
+ // data. Default is "json", most formats/codecs support "raw"
21
+ WithInputEnc(enc string) options.DagPutOption
22
+
23
+ // WithCodec is an option for Put which specifies the multicodec to use to
24
+ // serialize the object. Default is cid.DagCBOR (0x71)
25
+ WithCodec(codec uint64) options.DagPutOption
26
+
27
+ // WithHash is an option for Put which specifies the multihash settings to use
28
+ // when hashing the object. Default is based on the codec used
29
+ // (mh.SHA2_256 (0x12) for DagCBOR). If mhLen is set to -1, default length for
30
+ // the hash will be used
31
+ WithHash(mhType uint64, mhLen int) options.DagPutOption
32
+
33
+ // Get attempts to resolve and get the node specified by the path
34
+ Get(ctx context.Context, path Path) (ipld.Node, error)
35
+
36
+ // Tree returns list of paths within a node specified by the path.
37
+ Tree(ctx context.Context, path Path, opts ...options.DagTreeOption) ([]Path, error)
38
+
39
+ // WithDepth is an option for Tree which specifies maximum depth of the
40
+ // returned tree. Default is -1 (no depth limit)
41
+ WithDepth(depth int) options.DagTreeOption
42
+}
core/coreapi/interface/errors.go
new
+6
@@ -0,0 +1,6 @@
1
+package iface
2
+
3
+import "errors"
4
+
5
+var ErrIsDir = errors.New("object is a directory")
6
+var ErrOffline = errors.New("can't resolve, ipfs node is offline")
core/coreapi/interface/interface.go
deleted
-384
@@ -1,384 +0,0 @@
1
-// Package iface defines IPFS Core API which is a set of interfaces used to
2
-// interact with IPFS nodes.
3
-package iface
4
-
5
-import (
6
- "context"
7
- "errors"
8
- "io"
9
- "time"
10
-
11
- options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
12
-
13
- cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
14
- ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
15
-)
16
-
17
-var ErrIsDir = errors.New("object is a directory")
18
-var ErrOffline = errors.New("can't resolve, ipfs node is offline")
19
-
20
-// Path is a generic wrapper for paths used in the API. A path can be resolved
21
-// to a CID using one of Resolve functions in the API.
22
-type Path interface {
23
- // String returns the path as a string.
24
- String() string
25
- // Cid returns cid referred to by path
26
- Cid() *cid.Cid
27
- // Root returns cid of root path
28
- Root() *cid.Cid
29
- // Resolved returns whether path has been fully resolved
30
- Resolved() bool
31
-}
32
-
33
-type Reader interface {
34
- io.ReadSeeker
35
- io.Closer
36
-}
37
-
38
-// IpnsEntry specifies the interface to IpnsEntries
39
-type IpnsEntry interface {
40
- // Name returns IpnsEntry name
41
- Name() string
42
- // Value returns IpnsEntry value
43
- Value() Path
44
-}
45
-
46
-// Key specifies the interface to Keys in KeyAPI Keystore
47
-type Key interface {
48
- // Key returns key name
49
- Name() string
50
- // Path returns key path
51
- Path() Path
52
-}
53
-
54
-type BlockStat interface {
55
- Size() int
56
- Path() Path
57
-}
58
-
59
-// Pin holds information about pinned resource
60
-type Pin interface {
61
- // Path to the pinned object
62
- Path() Path
63
-
64
- // Type of the pin
65
- Type() string
66
-}
67
-
68
-// PinStatus holds information about pin health
69
-type PinStatus interface {
70
- // Ok indicates whether the pin has been verified to be correct
71
- Ok() bool
72
-
73
- // BadNodes returns any bad (usually missing) nodes from the pin
74
- BadNodes() []BadPinNode
75
-}
76
-
77
-// BadPinNode is a node that has been marked as bad by Pin.Verify
78
-type BadPinNode interface {
79
- // Path is the path of the node
80
- Path() Path
81
-
82
- // Err is the reason why the node has been marked as bad
83
- Err() error
84
-}
85
-
86
-// CoreAPI defines an unified interface to IPFS for Go programs.
87
-type CoreAPI interface {
88
- // Unixfs returns an implementation of Unixfs API.
89
- Unixfs() UnixfsAPI
90
-
91
- // Block returns an implementation of Block API.
92
- Block() BlockAPI
93
-
94
- // Dag returns an implementation of Dag API.
95
- Dag() DagAPI
96
-
97
- // Name returns an implementation of Name API.
98
- Name() NameAPI
99
-
100
- // Key returns an implementation of Key API.
101
- Key() KeyAPI
102
- Pin() PinAPI
103
-
104
- // ObjectAPI returns an implementation of Object API
105
- Object() ObjectAPI
106
-
107
- // ResolvePath resolves the path using Unixfs resolver
108
- ResolvePath(context.Context, Path) (Path, error)
109
-
110
- // ResolveNode resolves the path (if not resolved already) using Unixfs
111
- // resolver, gets and returns the resolved Node
112
- ResolveNode(context.Context, Path) (ipld.Node, error)
113
-}
114
-
115
-// UnixfsAPI is the basic interface to immutable files in IPFS
116
-type UnixfsAPI interface {
117
- // Add imports the data from the reader into merkledag file
118
- Add(context.Context, io.Reader) (Path, error)
119
-
120
- // Cat returns a reader for the file
121
- Cat(context.Context, Path) (Reader, error)
122
-
123
- // Ls returns the list of links in a directory
124
- Ls(context.Context, Path) ([]*ipld.Link, error)
125
-}
126
-
127
-// BlockAPI specifies the interface to the block layer
128
-type BlockAPI interface {
129
- // Put imports raw block data, hashing it using specified settings.
130
- Put(context.Context, io.Reader, ...options.BlockPutOption) (Path, error)
131
-
132
- // WithFormat is an option for Put which specifies the multicodec to use to
133
- // serialize the object. Default is "v0"
134
- WithFormat(codec string) options.BlockPutOption
135
-
136
- // WithHash is an option for Put which specifies the multihash settings to use
137
- // when hashing the object. Default is mh.SHA2_256 (0x12).
138
- // If mhLen is set to -1, default length for the hash will be used
139
- WithHash(mhType uint64, mhLen int) options.BlockPutOption
140
-
141
- // Get attempts to resolve the path and return a reader for data in the block
142
- Get(context.Context, Path) (io.Reader, error)
143
-
144
- // Rm removes the block specified by the path from local blockstore.
145
- // By default an error will be returned if the block can't be found locally.
146
- //
147
- // NOTE: If the specified block is pinned it won't be removed and no error
148
- // will be returned
149
- Rm(context.Context, Path, ...options.BlockRmOption) error
150
-
151
- // WithForce is an option for Rm which, when set to true, will ignore
152
- // non-existing blocks
153
- WithForce(force bool) options.BlockRmOption
154
-
155
- // Stat returns information on
156
- Stat(context.Context, Path) (BlockStat, error)
157
-}
158
-
159
-// DagAPI specifies the interface to IPLD
160
-type DagAPI interface {
161
- // Put inserts data using specified format and input encoding.
162
- // Unless used with WithCodec or WithHash, the defaults "dag-cbor" and
163
- // "sha256" are used.
164
- Put(ctx context.Context, src io.Reader, opts ...options.DagPutOption) (Path, error)
165
-
166
- // WithInputEnc is an option for Put which specifies the input encoding of the
167
- // data. Default is "json", most formats/codecs support "raw"
168
- WithInputEnc(enc string) options.DagPutOption
169
-
170
- // WithCodec is an option for Put which specifies the multicodec to use to
171
- // serialize the object. Default is cid.DagCBOR (0x71)
172
- WithCodec(codec uint64) options.DagPutOption
173
-
174
- // WithHash is an option for Put which specifies the multihash settings to use
175
- // when hashing the object. Default is based on the codec used
176
- // (mh.SHA2_256 (0x12) for DagCBOR). If mhLen is set to -1, default length for
177
- // the hash will be used
178
- WithHash(mhType uint64, mhLen int) options.DagPutOption
179
-
180
- // Get attempts to resolve and get the node specified by the path
181
- Get(ctx context.Context, path Path) (ipld.Node, error)
182
-
183
- // Tree returns list of paths within a node specified by the path.
184
- Tree(ctx context.Context, path Path, opts ...options.DagTreeOption) ([]Path, error)
185
-
186
- // WithDepth is an option for Tree which specifies maximum depth of the
187
- // returned tree. Default is -1 (no depth limit)
188
- WithDepth(depth int) options.DagTreeOption
189
-}
190
-
191
-// NameAPI specifies the interface to IPNS.
192
-//
193
-// IPNS is a PKI namespace, where names are the hashes of public keys, and the
194
-// private key enables publishing new (signed) values. In both publish and
195
-// resolve, the default name used is the node's own PeerID, which is the hash of
196
-// its public key.
197
-//
198
-// You can use .Key API to list and generate more names and their respective keys.
199
-type NameAPI interface {
200
- // Publish announces new IPNS name
201
- Publish(ctx context.Context, path Path, opts ...options.NamePublishOption) (IpnsEntry, error)
202
-
203
- // WithValidTime is an option for Publish which specifies for how long the
204
- // entry will remain valid. Default value is 24h
205
- WithValidTime(validTime time.Duration) options.NamePublishOption
206
-
207
- // WithKey is an option for Publish which specifies the key to use for
208
- // publishing. Default value is "self" which is the node's own PeerID.
209
- // The key parameter must be either PeerID or keystore key alias.
210
- //
211
- // You can use KeyAPI to list and generate more names and their respective keys.
212
- WithKey(key string) options.NamePublishOption
213
-
214
- // Resolve attempts to resolve the newest version of the specified name
215
- Resolve(ctx context.Context, name string, opts ...options.NameResolveOption) (Path, error)
216
-
217
- // WithRecursive is an option for Resolve which specifies whether to perform a
218
- // recursive lookup. Default value is false
219
- WithRecursive(recursive bool) options.NameResolveOption
220
-
221
- // WithLocal is an option for Resolve which specifies if the lookup should be
222
- // offline. Default value is false
223
- WithLocal(local bool) options.NameResolveOption
224
-
225
- // WithCache is an option for Resolve which specifies if cache should be used.
226
- // Default value is true
227
- WithCache(cache bool) options.NameResolveOption
228
-}
229
-
230
-// KeyAPI specifies the interface to Keystore
231
-type KeyAPI interface {
232
- // Generate generates new key, stores it in the keystore under the specified
233
- // name and returns a base58 encoded multihash of it's public key
234
- Generate(ctx context.Context, name string, opts ...options.KeyGenerateOption) (Key, error)
235
-
236
- // WithType is an option for Generate which specifies which algorithm
237
- // should be used for the key. Default is options.RSAKey
238
- //
239
- // Supported key types:
240
- // * options.RSAKey
241
- // * options.Ed25519Key
242
- WithType(algorithm string) options.KeyGenerateOption
243
-
244
- // WithSize is an option for Generate which specifies the size of the key to
245
- // generated. Default is -1
246
- //
247
- // value of -1 means 'use default size for key type':
248
- // * 2048 for RSA
249
- WithSize(size int) options.KeyGenerateOption
250
-
251
- // Rename renames oldName key to newName. Returns the key and whether another
252
- // key was overwritten, or an error
253
- Rename(ctx context.Context, oldName string, newName string, opts ...options.KeyRenameOption) (Key, bool, error)
254
-
255
- // WithForce is an option for Rename which specifies whether to allow to
256
- // replace existing keys.
257
- WithForce(force bool) options.KeyRenameOption
258
-
259
- // List lists keys stored in keystore
260
- List(ctx context.Context) ([]Key, error)
261
-
262
- // Remove removes keys from keystore. Returns ipns path of the removed key
263
- Remove(ctx context.Context, name string) (Path, error)
264
-}
265
-
266
-// ObjectAPI specifies the interface to MerkleDAG and contains useful utilities
267
-// for manipulating MerkleDAG data structures.
268
-type ObjectAPI interface {
269
- // New creates new, empty (by default) dag-node.
270
- New(context.Context, ...options.ObjectNewOption) (ipld.Node, error)
271
-
272
- // WithType is an option for New which allows to change the type of created
273
- // dag node.
274
- //
275
- // Supported types:
276
- // * 'empty' - Empty node
277
- // * 'unixfs-dir' - Empty UnixFS directory
278
- WithType(string) options.ObjectNewOption
279
-
280
- // Put imports the data into merkledag
281
- Put(context.Context, io.Reader, ...options.ObjectPutOption) (Path, error)
282
-
283
- // WithInputEnc is an option for Put which specifies the input encoding of the
284
- // data. Default is "json".
285
- //
286
- // Supported encodings:
287
- // * "protobuf"
288
- // * "json"
289
- WithInputEnc(e string) options.ObjectPutOption
290
-
291
- // WithDataType specifies the encoding of data field when using Josn or XML
292
- // input encoding.
293
- //
294
- // Supported types:
295
- // * "text" (default)
296
- // * "base64"
297
- WithDataType(t string) options.ObjectPutOption
298
-
299
- // Get returns the node for the path
300
- Get(context.Context, Path) (ipld.Node, error)
301
-
302
- // Data returns reader for data of the node
303
- Data(context.Context, Path) (io.Reader, error)
304
-
305
- // Links returns lint or links the node contains
306
- Links(context.Context, Path) ([]*ipld.Link, error)
307
-
308
- // Stat returns information about the node
309
- Stat(context.Context, Path) (*ObjectStat, error)
310
-
311
- // AddLink adds a link under the specified path. child path can point to a
312
- // subdirectory within the patent which must be present (can be overridden
313
- // with WithCreate option).
314
- AddLink(ctx context.Context, base Path, name string, child Path, opts ...options.ObjectAddLinkOption) (Path, error)
315
-
316
- // WithCreate is an option for AddLink which specifies whether create required
317
- // directories for the child
318
- WithCreate(create bool) options.ObjectAddLinkOption
319
-
320
- // RmLink removes a link from the node
321
- RmLink(ctx context.Context, base Path, link string) (Path, error)
322
-
323
- // AppendData appends data to the node
324
- AppendData(context.Context, Path, io.Reader) (Path, error)
325
-
326
- // SetData sets the data contained in the node
327
- SetData(context.Context, Path, io.Reader) (Path, error)
328
-}
329
-
330
-// ObjectStat provides information about dag nodes
331
-type ObjectStat struct {
332
- // Cid is the CID of the node
333
- Cid *cid.Cid
334
-
335
- // NumLinks is number of links the node contains
336
- NumLinks int
337
-
338
- // BlockSize is size of the raw serialized node
339
- BlockSize int
340
-
341
- // LinksSize is size of the links block section
342
- LinksSize int
343
-
344
- // DataSize is the size of data block section
345
- DataSize int
346
-
347
- // CumulativeSize is size of the tree (BlockSize + link sizes)
348
- CumulativeSize int
349
-}
350
-
351
-// PinAPI specifies the interface to pining
352
-type PinAPI interface {
353
- // Add creates new pin, be default recursive - pinning the whole referenced
354
- // tree
355
- Add(context.Context, Path, ...options.PinAddOption) error
356
-
357
- // WithRecursive is an option for Add which specifies whether to pin an entire
358
- // object tree or just one object. Default: true
359
- WithRecursive(bool) options.PinAddOption
360
-
361
- // Ls returns list of pinned objects on this node
362
- Ls(context.Context, ...options.PinLsOption) ([]Pin, error)
363
-
364
- // WithType is an option for Ls which allows to specify which pin types should
365
- // be returned
366
- //
367
- // Supported values:
368
- // * "direct" - directly pinned objects
369
- // * "recursive" - roots of recursive pins
370
- // * "indirect" - indirectly pinned objects (referenced by recursively pinned
371
- // objects)
372
- // * "all" - all pinned objects (default)
373
- WithType(string) options.PinLsOption
374
-
375
- // Rm removes pin for object specified by the path
376
- Rm(context.Context, Path) error
377
-
378
- // Update changes one pin to another, skipping checks for matching paths in
379
- // the old tree
380
- Update(ctx context.Context, from Path, to Path, opts ...options.PinUpdateOption) error
381
-
382
- // Verify verifies the integrity of pinned objects
383
- Verify(context.Context) (<-chan PinStatus, error)
384
-}
core/coreapi/interface/key.go
new
+51
@@ -0,0 +1,51 @@
1
+package iface
2
+
3
+import (
4
+ "context"
5
+
6
+ options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
7
+)
8
+
9
+// Key specifies the interface to Keys in KeyAPI Keystore
10
+type Key interface {
11
+ // Key returns key name
12
+ Name() string
13
+ // Path returns key path
14
+ Path() Path
15
+}
16
+
17
+// KeyAPI specifies the interface to Keystore
18
+type KeyAPI interface {
19
+ // Generate generates new key, stores it in the keystore under the specified
20
+ // name and returns a base58 encoded multihash of it's public key
21
+ Generate(ctx context.Context, name string, opts ...options.KeyGenerateOption) (Key, error)
22
+
23
+ // WithType is an option for Generate which specifies which algorithm
24
+ // should be used for the key. Default is options.RSAKey
25
+ //
26
+ // Supported key types:
27
+ // * options.RSAKey
28
+ // * options.Ed25519Key
29
+ WithType(algorithm string) options.KeyGenerateOption
30
+
31
+ // WithSize is an option for Generate which specifies the size of the key to
32
+ // generated. Default is -1
33
+ //
34
+ // value of -1 means 'use default size for key type':
35
+ // * 2048 for RSA
36
+ WithSize(size int) options.KeyGenerateOption
37
+
38
+ // Rename renames oldName key to newName. Returns the key and whether another
39
+ // key was overwritten, or an error
40
+ Rename(ctx context.Context, oldName string, newName string, opts ...options.KeyRenameOption) (Key, bool, error)
41
+
42
+ // WithForce is an option for Rename which specifies whether to allow to
43
+ // replace existing keys.
44
+ WithForce(force bool) options.KeyRenameOption
45
+
46
+ // List lists keys stored in keystore
47
+ List(ctx context.Context) ([]Key, error)
48
+
49
+ // Remove removes keys from keystore. Returns ipns path of the removed key
50
+ Remove(ctx context.Context, name string) (Path, error)
51
+}
core/coreapi/interface/name.go
new
+55
@@ -0,0 +1,55 @@
1
+package iface
2
+
3
+import (
4
+ "context"
5
+ "time"
6
+
7
+ options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
8
+)
9
+
10
+// IpnsEntry specifies the interface to IpnsEntries
11
+type IpnsEntry interface {
12
+ // Name returns IpnsEntry name
13
+ Name() string
14
+ // Value returns IpnsEntry value
15
+ Value() Path
16
+}
17
+
18
+// NameAPI specifies the interface to IPNS.
19
+//
20
+// IPNS is a PKI namespace, where names are the hashes of public keys, and the
21
+// private key enables publishing new (signed) values. In both publish and
22
+// resolve, the default name used is the node's own PeerID, which is the hash of
23
+// its public key.
24
+//
25
+// You can use .Key API to list and generate more names and their respective keys.
26
+type NameAPI interface {
27
+ // Publish announces new IPNS name
28
+ Publish(ctx context.Context, path Path, opts ...options.NamePublishOption) (IpnsEntry, error)
29
+
30
+ // WithValidTime is an option for Publish which specifies for how long the
31
+ // entry will remain valid. Default value is 24h
32
+ WithValidTime(validTime time.Duration) options.NamePublishOption
33
+
34
+ // WithKey is an option for Publish which specifies the key to use for
35
+ // publishing. Default value is "self" which is the node's own PeerID.
36
+ // The key parameter must be either PeerID or keystore key alias.
37
+ //
38
+ // You can use KeyAPI to list and generate more names and their respective keys.
39
+ WithKey(key string) options.NamePublishOption
40
+
41
+ // Resolve attempts to resolve the newest version of the specified name
42
+ Resolve(ctx context.Context, name string, opts ...options.NameResolveOption) (Path, error)
43
+
44
+ // WithRecursive is an option for Resolve which specifies whether to perform a
45
+ // recursive lookup. Default value is false
46
+ WithRecursive(recursive bool) options.NameResolveOption
47
+
48
+ // WithLocal is an option for Resolve which specifies if the lookup should be
49
+ // offline. Default value is false
50
+ WithLocal(local bool) options.NameResolveOption
51
+
52
+ // WithCache is an option for Resolve which specifies if cache should be used.
53
+ // Default value is true
54
+ WithCache(cache bool) options.NameResolveOption
55
+}
core/coreapi/interface/object.go
new
+96
@@ -0,0 +1,96 @@
1
+package iface
2
+
3
+import (
4
+ "context"
5
+ "io"
6
+
7
+ options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
8
+
9
+ cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
10
+ ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
11
+)
12
+
13
+// ObjectStat provides information about dag nodes
14
+type ObjectStat struct {
15
+ // Cid is the CID of the node
16
+ Cid *cid.Cid
17
+
18
+ // NumLinks is number of links the node contains
19
+ NumLinks int
20
+
21
+ // BlockSize is size of the raw serialized node
22
+ BlockSize int
23
+
24
+ // LinksSize is size of the links block section
25
+ LinksSize int
26
+
27
+ // DataSize is the size of data block section
28
+ DataSize int
29
+
30
+ // CumulativeSize is size of the tree (BlockSize + link sizes)
31
+ CumulativeSize int
32
+}
33
+
34
+// ObjectAPI specifies the interface to MerkleDAG and contains useful utilities
35
+// for manipulating MerkleDAG data structures.
36
+type ObjectAPI interface {
37
+ // New creates new, empty (by default) dag-node.
38
+ New(context.Context, ...options.ObjectNewOption) (ipld.Node, error)
39
+
40
+ // WithType is an option for New which allows to change the type of created
41
+ // dag node.
42
+ //
43
+ // Supported types:
44
+ // * 'empty' - Empty node
45
+ // * 'unixfs-dir' - Empty UnixFS directory
46
+ WithType(string) options.ObjectNewOption
47
+
48
+ // Put imports the data into merkledag
49
+ Put(context.Context, io.Reader, ...options.ObjectPutOption) (Path, error)
50
+
51
+ // WithInputEnc is an option for Put which specifies the input encoding of the
52
+ // data. Default is "json".
53
+ //
54
+ // Supported encodings:
55
+ // * "protobuf"
56
+ // * "json"
57
+ WithInputEnc(e string) options.ObjectPutOption
58
+
59
+ // WithDataType specifies the encoding of data field when using Josn or XML
60
+ // input encoding.
61
+ //
62
+ // Supported types:
63
+ // * "text" (default)
64
+ // * "base64"
65
+ WithDataType(t string) options.ObjectPutOption
66
+
67
+ // Get returns the node for the path
68
+ Get(context.Context, Path) (ipld.Node, error)
69
+
70
+ // Data returns reader for data of the node
71
+ Data(context.Context, Path) (io.Reader, error)
72
+
73
+ // Links returns lint or links the node contains
74
+ Links(context.Context, Path) ([]*ipld.Link, error)
75
+
76
+ // Stat returns information about the node
77
+ Stat(context.Context, Path) (*ObjectStat, error)
78
+
79
+ // AddLink adds a link under the specified path. child path can point to a
80
+ // subdirectory within the patent which must be present (can be overridden
81
+ // with WithCreate option).
82
+ AddLink(ctx context.Context, base Path, name string, child Path, opts ...options.ObjectAddLinkOption) (Path, error)
83
+
84
+ // WithCreate is an option for AddLink which specifies whether create required
85
+ // directories for the child
86
+ WithCreate(create bool) options.ObjectAddLinkOption
87
+
88
+ // RmLink removes a link from the node
89
+ RmLink(ctx context.Context, base Path, link string) (Path, error)
90
+
91
+ // AppendData appends data to the node
92
+ AppendData(context.Context, Path, io.Reader) (Path, error)
93
+
94
+ // SetData sets the data contained in the node
95
+ SetData(context.Context, Path, io.Reader) (Path, error)
96
+}
core/coreapi/interface/path.go
new
+18
@@ -0,0 +1,18 @@
1
+package iface
2
+
3
+import (
4
+ cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
5
+)
6
+
7
+// Path is a generic wrapper for paths used in the API. A path can be resolved
8
+// to a CID using one of Resolve functions in the API.
9
+type Path interface {
10
+ // String returns the path as a string.
11
+ String() string
12
+ // Cid returns cid referred to by path
13
+ Cid() *cid.Cid
14
+ // Root returns cid of root path
15
+ Root() *cid.Cid
16
+ // Resolved returns whether path has been fully resolved
17
+ Resolved() bool
18
+}
core/coreapi/interface/pin.go
new
+69
@@ -0,0 +1,69 @@
1
+package iface
2
+
3
+import (
4
+ "context"
5
+
6
+ options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
7
+)
8
+
9
+// Pin holds information about pinned resource
10
+type Pin interface {
11
+ // Path to the pinned object
12
+ Path() Path
13
+
14
+ // Type of the pin
15
+ Type() string
16
+}
17
+
18
+// PinStatus holds information about pin health
19
+type PinStatus interface {
20
+ // Ok indicates whether the pin has been verified to be correct
21
+ Ok() bool
22
+
23
+ // BadNodes returns any bad (usually missing) nodes from the pin
24
+ BadNodes() []BadPinNode
25
+}
26
+
27
+// BadPinNode is a node that has been marked as bad by Pin.Verify
28
+type BadPinNode interface {
29
+ // Path is the path of the node
30
+ Path() Path
31
+
32
+ // Err is the reason why the node has been marked as bad
33
+ Err() error
34
+}
35
+
36
+// PinAPI specifies the interface to pining
37
+type PinAPI interface {
38
+ // Add creates new pin, be default recursive - pinning the whole referenced
39
+ // tree
40
+ Add(context.Context, Path, ...options.PinAddOption) error
41
+
42
+ // WithRecursive is an option for Add which specifies whether to pin an entire
43
+ // object tree or just one object. Default: true
44
+ WithRecursive(bool) options.PinAddOption
45
+
46
+ // Ls returns list of pinned objects on this node
47
+ Ls(context.Context, ...options.PinLsOption) ([]Pin, error)
48
+
49
+ // WithType is an option for Ls which allows to specify which pin types should
50
+ // be returned
51
+ //
52
+ // Supported values:
53
+ // * "direct" - directly pinned objects
54
+ // * "recursive" - roots of recursive pins
55
+ // * "indirect" - indirectly pinned objects (referenced by recursively pinned
56
+ // objects)
57
+ // * "all" - all pinned objects (default)
58
+ WithType(string) options.PinLsOption
59
+
60
+ // Rm removes pin for object specified by the path
61
+ Rm(context.Context, Path) error
62
+
63
+ // Update changes one pin to another, skipping checks for matching paths in
64
+ // the old tree
65
+ Update(ctx context.Context, from Path, to Path, opts ...options.PinUpdateOption) error
66
+
67
+ // Verify verifies the integrity of pinned objects
68
+ Verify(context.Context) (<-chan PinStatus, error)
69
+}
core/coreapi/interface/unixfs.go
new
+20
@@ -0,0 +1,20 @@
1
+package iface
2
+
3
+import (
4
+ "context"
5
+ "io"
6
+
7
+ ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
8
+)
9
+
10
+// UnixfsAPI is the basic interface to immutable files in IPFS
11
+type UnixfsAPI interface {
12
+ // Add imports the data from the reader into merkledag file
13
+ Add(context.Context, io.Reader) (Path, error)
14
+
15
+ // Cat returns a reader for the file
16
+ Cat(context.Context, Path) (Reader, error)
17
+
18
+ // Ls returns the list of links in a directory
19
+ Ls(context.Context, Path) ([]*ipld.Link, error)
20
+}
core/coreapi/interface/util.go
new
+10
@@ -0,0 +1,10 @@
1
+package iface
2
+
3
+import (
4
+ "io"
5
+)
6
+
7
+type Reader interface {
8
+ io.ReadSeeker
9
+ io.Closer
10
+}