You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
Copy file name to clipboardexpand all lines: SPEC/BLOCK.md
+16-9
Original file line number
Diff line number
Diff line change
@@ -5,9 +5,6 @@
5
5
*[block.rm](#blockrm)
6
6
*[block.stat](#blockstat)
7
7
8
-
### ⚠️ Note
9
-
Although not listed in the documentation, all the following APIs that actually return a **promise** can also accept a **final callback** parameter.
10
-
11
8
#### `block.get`
12
9
13
10
> Get a raw IPFS block.
@@ -114,22 +111,32 @@ A great source of [examples][] can be found in the tests for this API.
114
111
115
112
`options` is an Object that can contain the following properties:
116
113
117
-
- force (boolean): Ignores nonexistent blocks.
118
-
- quiet (boolean): write minimal output
114
+
-`force` (boolean): Ignores nonexistent blocks.
115
+
-`quiet` (boolean): write minimal output
119
116
120
117
**Returns**
121
118
122
119
| Type | Description |
123
120
| -------- | -------- |
124
-
|`Promise<Array>`| An array of objects containing hash and (potentially) error strings |
121
+
|`AsyncIterable<Object>`| An async iterable that yields objects containing hash and (potentially) error strings |
125
122
126
-
Note: If an error string is present for a given object in the returned array, the block with that hash was not removed and the string will contain the reason why, for example if the block was pinned.
123
+
Each object yielded is of the form:
124
+
125
+
```js
126
+
{
127
+
hash: string,
128
+
error: string
129
+
}
130
+
```
131
+
132
+
Note: If an error string is present for a given object, the block with that hash was not removed and the string will contain the reason why, for example if the block was pinned.
127
133
128
134
**Example:**
129
135
130
136
```JavaScript
131
-
constresult=awaitipfs.block.rm(cid)
132
-
console.log(result[0].hash)
137
+
forawait (constresultofipfs.block.rm(cid)) {
138
+
console.log(result.hash)
139
+
}
133
140
```
134
141
135
142
A great source of [examples][] can be found in the tests for this API.
Copy file name to clipboardexpand all lines: SPEC/DHT.md
+139-50
Original file line number
Diff line number
Diff line change
@@ -7,79 +7,80 @@
7
7
*[dht.put](#dhtput)
8
8
*[dht.query](#dhtquery)
9
9
10
-
### ⚠️ Note
11
-
Although not listed in the documentation, all the following APIs that actually return a **promise** can also accept a **final callback** parameter.
12
-
13
10
#### `dht.findPeer`
14
11
15
-
> Retrieve the Peer Info of a reachable node in the network.
12
+
> Find the multiaddresses associated with a Peer ID
16
13
17
14
##### `ipfs.dht.findPeer(peerId)`
18
15
19
-
Where `peerId` is a IPFS/libp2p Id from [PeerId](https://github.com/libp2p/js-peer-id)type.
16
+
Where `peerId` is a Peer ID in `String`, [`CID`](https://github.com/multiformats/js-cid) or [`PeerId`](https://github.com/libp2p/js-peer-id)format.
20
17
21
18
**Returns**
22
19
23
20
| Type | Description |
24
21
| -------- | -------- |
25
-
|`Promise<PeerInfo>`|An object type [`PeerInfo`](https://github.com/libp2p/js-peer-info)|
22
+
|`Promise<{ id: CID, addrs: Multiaddr[] }>`|A promise that resolves to an object with `id` and `addrs`. `id` is a [`CID`](https://github.com/multiformats/js-cid) - the peer's ID and `addrs` is an array of [Multiaddr](https://github.com/multiformats/js-multiaddr/) - addresses for the peer.|
26
23
27
24
**Example:**
28
25
29
26
```JavaScript
30
-
var id =PeerId.create()
31
-
32
-
constpeerInfo=awaitipfs.dht.findPeer(id)
33
-
// peerInfo will contain the multiaddrs of that peer
A great source of [examples][] can be found in the tests for this API.
39
45
40
46
#### `dht.findProvs`
41
47
42
-
> Retrieve the providers for content that is addressed by an hash.
48
+
> Find peers that can provide a specific value, given a CID.
43
49
44
-
##### `ipfs.dht.findProvs(hash, [options])`
50
+
##### `ipfs.dht.findProvs(cid, [options])`
45
51
46
-
Where `hash` is a multihash.
52
+
Where `cid` is a CID as a `String`, `Buffer` or [`CID`](https://github.com/multiformats/js-cid) instance.
47
53
48
-
`options` an optional object with the following properties
49
-
-`timeout` - a maximum timeout in milliseconds
50
-
-`maxNumProviders` - a maximum number of providers to find
54
+
`options` an optional object with the following properties:
55
+
-`numProviders` - the number of providers to find. Default: 20
56
+
57
+
Note that if `options.numProviders` are not found an error will be thrown.
51
58
52
59
**Returns**
53
60
54
61
| Type | Description |
55
62
| -------- | -------- |
56
-
|`Promise<Array>`| An array of type [`PeerInfo`](https://github.com/libp2p/js-peer-info)|
57
-
58
-
each entry of the returned array is composed by the peerId, as well as an array with its adresses.
63
+
|`AsyncIterable<{ id: CID, addrs: Multiaddr[] }>`| A async iterable that yields objects with `id` and `addrs`. `id` is a [`CID`](https://github.com/multiformats/js-cid) - the peer's ID and `addrs` is an array of [Multiaddr](https://github.com/multiformats/js-multiaddr/) - addresses for the peer. |
Alternatively you can simply "consume" the iterable:
204
+
205
+
```js
206
+
const { consume } =require('streaming-iterables')
207
+
awaitconsume(ipfs.dht.put(key, value))
138
208
```
139
209
140
210
A great source of [examples][] can be found in the tests for this API.
141
211
142
212
#### `dht.query`
143
213
144
-
> Queries the network for the 'closest peers' to a given key. 'closest' is defined by the rules of the underlying Peer Routing mechanism.
214
+
> Find the closest Peer IDs to a given Peer ID by querying the DHT.
145
215
146
216
##### `ipfs.dht.query(peerId)`
147
217
148
-
Where `peerId` is a IPFS/libp2p Id of type [PeerId](https://github.com/libp2p/js-peer-id).
218
+
Where `peerId` is a Peer ID in `String`, [`CID`](https://github.com/multiformats/js-cid) or [`PeerId`](https://github.com/libp2p/js-peer-id) format.
149
219
150
220
**Returns**
151
221
152
222
| Type | Description |
153
223
| -------- | -------- |
154
-
|`Promise<Array>`|An array of objects of type [PeerInfo](https://github.com/libp2p/js-peer-info)|
224
+
|`AsyncIterable<Object>`|DHT query messages. See example below for structure.|
0 commit comments