Skip to content

Commit

Permalink
chore: apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-Authored-By: Jacob Heun <[email protected]>
  • Loading branch information
vasco-santos and jacobheun committed Apr 2, 2020
1 parent eb27b8d commit d645b63
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ Dials to another peer in the network and selects a protocol to communicate with
| Name | Type | Description |
|------|------|-------------|
| peer | [`PeerInfo`][peer-info]\|[`PeerId`][peer-id]\|[`Multiaddr`][multiaddr]\|`string` | The peer to dial. If a [`Multiaddr`][multiaddr] or its string is provided, it **must** include the peer id |
| protocols | `String|Array<String>` | A list of protocols (or single protocol) to negotiate with. Protocols are attempted in order until a match is made. (e.g '/ipfs/bitswap/1.1.0') |
| protocols | `string|Array<string>` | A list of protocols (or single protocol) to negotiate with. Protocols are attempted in order until a match is made. (e.g '/ipfs/bitswap/1.1.0') |
| [options] | `Object` | dial options |
| [options.signal] | [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) | An `AbortSignal` instance obtained from an [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) that can be used to abort the connection before it completes |

Expand Down Expand Up @@ -286,7 +286,7 @@ In the event of a new handler for the same protocol being added, the first one i

| Name | Type | Description |
|------|------|-------------|
| protocols | `Array<String>|String` | protocols to register |
| protocols | `Array<string>|string` | protocols to register |
| handler | `function({ connection:*, stream:*, protocol:string })` | handler to call |


Expand All @@ -311,7 +311,7 @@ Unregisters all handlers with the given protocols

| Name | Type | Description |
|------|------|-------------|
| protocols | `Array<String>|String` | protocols to unregister |
| protocols | `Array<string>|string` | protocols to unregister |

#### Example

Expand Down Expand Up @@ -438,7 +438,7 @@ Writes a value to a key in the DHT.

| Name | Type | Description |
|------|------|-------------|
| key | `String` | key to add to the dht |
| key | `string` | key to add to the dht |
| value | `Buffer` | value to add to the dht |
| [options] | `Object` | put options |
| [options.minPeers] | `number` | minimum number of peers required to successfully put (default: closestPeers.length) |
Expand Down Expand Up @@ -469,7 +469,7 @@ Queries the DHT for a value stored for a given key.

| Name | Type | Description |
|------|------|-------------|
| key | `String` | key to get from the dht |
| key | `string` | key to get from the dht |
| [options] | `Object` | get options |
| [options.timeout] | `number` | maximum time the query should run |

Expand Down Expand Up @@ -498,7 +498,7 @@ Queries the DHT for the n values stored for the given key (without sorting).

| Name | Type | Description |
|------|------|-------------|
| key | `String` | key to get from the dht |
| key | `string` | key to get from the dht |
| nvals | `number` | number of values aimed |
| [options] | `Object` | get options |
| [options.timeout] | `number` | maximum time the query should run |
Expand Down Expand Up @@ -528,7 +528,7 @@ Delete the provided peer from the book.

| Name | Type | Description |
|------|------|-------------|
| peerId | `peerid` | peerId to remove |
| peerId | [`PeerId`][peer-id] | peerId to remove |

#### Returns

Expand Down Expand Up @@ -556,7 +556,7 @@ Get the known `multiaddrInfos` of a provided peer.

| Name | Type | Description |
|------|------|-------------|
| peerId | `peerid` | peerId to get |
| peerId | [`PeerId`][peer-id] | peerId to get |

#### Returns

Expand All @@ -569,7 +569,7 @@ Get the known `multiaddrInfos` of a provided peer.
```js
peerStore.addressBook.get(peerId)
// undefined
peerStore.addressBook.set(peerId, discoveredMultiaddr)
peerStore.addressBook.set(peerId, multiaddr)
peerStore.addressBook.get(peerId)
// [
// {
Expand All @@ -593,20 +593,20 @@ Get the known `multiaddr` of a provided peer. All returned multiaddrs will inclu

| Name | Type | Description |
|------|------|-------------|
| peerId | `peerid` | peerId to get |
| peerId | [`PeerId`][peer-id] | peerId to get |

#### Returns

| Type | Description |
|------|-------------|
| `Array<multiaddr>` | Array of peer's multiaddr |
| `Array<Multiaddr>` | Array of peer's multiaddr |

#### Example

```js
peerStore.addressBook.getMultiaddrsForPeer(peerId)
// undefined
peerStore.addressBook.set(peerId, discoveredMultiaddr)
peerStore.addressBook.set(peerId, multiaddr)
peerStore.addressBook.getMultiaddrsForPeer(peerId)
// [
// /ip4/140.10.2.1/tcp/8000/p2p/QmW8rAgaaA6sRydK1k6vonShQME47aDxaFidbtMevWs73t
Expand All @@ -624,9 +624,9 @@ Set known `multiaddrs` of a given peer.

| Name | Type | Description |
|------|------|-------------|
| peerId | `peerid` | peerId to set |
| multiaddrs | `multiaddr|Array<multiaddr>` | multiaddrs to store |
| [options] | `object` | options to set |
| peerId | [`PeerId`][peer-id] | peerId to set |
| multiaddrs | `Multiaddr|Array<Multiaddr>` | multiaddrs to store |
| [options] | `Object` | options to set |
| [options.replace] | `Object` | replace stored data (if exists) or unique union (default: true) |

#### Returns
Expand All @@ -638,7 +638,7 @@ Set known `multiaddrs` of a given peer.
#### Example

```js
peerStore.addressBook.set(peerId, discoveredMultiaddr)
peerStore.addressBook.set(peerId, multiaddr)
// [
// {
// multiaddr: /ip4/140.10.2.1/tcp/8000,
Expand All @@ -661,7 +661,7 @@ Delete the provided peer from the book.

| Name | Type | Description |
|------|------|-------------|
| peerId | `peerid` | peerId to remove |
| peerId | [`PeerId`][peer-id] | peerId to remove |

#### Returns

Expand All @@ -674,7 +674,7 @@ Delete the provided peer from the book.
```js
peerStore.protoBook.delete(peerId)
// false
peerStore.protoBook.set(peerId, supportedProtocols)
peerStore.protoBook.set(peerId, protocols)
peerStore.protoBook.delete(peerId)
// true
```
Expand All @@ -689,7 +689,7 @@ Get the known `protocols` of a provided peer.

| Name | Type | Description |
|------|------|-------------|
| peerId | `peerid` | peerId to get |
| peerId | [`PeerId`][peer-id] | peerId to get |

#### Returns

Expand All @@ -702,7 +702,7 @@ Get the known `protocols` of a provided peer.
```js
peerStore.protoBook.get(peerId)
// undefined
peerStore.protoBook.set(peerId, supportedProtocols)
peerStore.protoBook.set(peerId, [ '/proto/1.0.0', '/proto/1.1.0' ])
peerStore.protoBook.get(peerId)
// [ '/proto/1.0.0', '/proto/1.1.0' ]
```
Expand All @@ -717,9 +717,9 @@ Set known `protocols` of a given peer.

| Name | Type | Description |
|------|------|-------------|
| peerId | `peerid` | peerId to set |
| peerId | [`PeerId`][peer-id] | peerId to set |
| protocols | `string|Array<string>` | protocols to store |
| [options] | `object` | options to set |
| [options] | `Object` | options to set |
| [options.replace] | `Object` | replace stored data (if exists) or unique union (default: true) |

#### Returns
Expand All @@ -745,7 +745,7 @@ Verify if the provided peer supports the given `protocols`.

| Name | Type | Description |
|------|------|-------------|
| peerId | `peerid` | peerId to get |
| peerId | [`PeerId`][peer-id] | peerId to get |
| protocols | `string|Array<string>` | protocols to verify |

#### Returns
Expand Down Expand Up @@ -779,7 +779,7 @@ Delete the provided peer from every book.

| Name | Type | Description |
|------|------|-------------|
| peerId | `peerid` | peerId to remove |
| peerId | [`PeerId`][peer-id] | peerId to remove |

#### Returns

Expand Down Expand Up @@ -813,7 +813,7 @@ Find the stored information of a given peer.

| Name | Type | Description |
|------|------|-------------|
| peerId | `peerid` | peerId to find |
| peerId | [`PeerId`][peer-id] | peerId to find |

#### Returns

Expand Down Expand Up @@ -852,7 +852,7 @@ TODO: change when `peer-info` is deprecated (breaking change)
#### Example

```js
for (peer of peerStore.peers().values()) {
for (let [peerIdString, peerInfo] of peerStore.peers.entries()) {
// peerInfo instance
}
```
Expand All @@ -873,7 +873,7 @@ Gets a list of the peer-ids that are subscribed to one topic.

| Type | Description |
|------|-------------|
| `Array<String>` | peer-id subscribed to the topic |
| `Array<string>` | peer-id subscribed to the topic |

#### Example

Expand All @@ -891,7 +891,7 @@ Gets a list of topics the node is subscribed to.

| Type | Description |
|------|-------------|
| `Array<String>` | topics the node is subscribed to |
| `Array<string>` | topics the node is subscribed to |

#### Example

Expand Down Expand Up @@ -938,7 +938,7 @@ Subscribes the given handler to a pubsub topic.
| Name | Type | Description |
|------|------|-------------|
| topic | `string` | topic to subscribe |
| handler | `function({ from: String, data: Buffer, seqno: Buffer, topicIDs: Array<String>, signature: Buffer, key: Buffer })` | handler for new data on topic |
| handler | `function({ from: string, data: Buffer, seqno: Buffer, topicIDs: Array<string>, signature: Buffer, key: Buffer })` | handler for new data on topic |

#### Returns

Expand Down Expand Up @@ -967,7 +967,7 @@ Unsubscribes the given handler from a pubsub topic. If no handler is provided, a

| Name | Type | Description |
|------|------|-------------|
| topic | `string` | topic to unsubscribe |
| topic | `String` | topic to unsubscribe |
| handler | `function(<Object>)` | handler subscribed |

#### Returns
Expand Down

0 comments on commit d645b63

Please sign in to comment.