Skip to content

Commit

Permalink
docs: fix api link formatting (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
wemeetagain authored and jacobheun committed Jan 28, 2020
1 parent 33cef10 commit c6592c5
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Creates an instance of Libp2p.
| [options.datastore] | `Object` | must implement [ipfs/interface-datastore](https://github.com/ipfs/interface-datastore) (in memory datastore will be used if not provided) |
| [options.dialer] | `Object` | libp2p Dialer configuration
| [options.metrics] | `Object` | libp2p Metrics configuration
| [options.peerInfo] | [PeerInfo](https://github.com/libp2p/js-peer-info) | peerInfo instance (it will be created if not provided) |
| [options.peerInfo] | [`PeerInfo`][peer-info] | peerInfo instance (it will be created if not provided) |

For Libp2p configurations and modules details read the [Configuration Document](./CONFIGURATION.md).

Expand All @@ -73,7 +73,7 @@ const options = {}
const libp2p = await Libp2p.create(options)
```

Note: The `PeerInfo` option is not required and will be generated if it is not provided.
Note: The [`PeerInfo`][peer-info] option is not required and will be generated if it is not provided.

<details><summary>Alternative</summary>
As an alternative, it is possible to create a Libp2p instance with the constructor:
Expand All @@ -92,7 +92,7 @@ const libp2p = new Libp2p(options)

Required keys in the `options` object:

- `peerInfo`: instance of [PeerInfo][] that contains the [PeerId][], Keys and [multiaddrs][multiaddr] of the libp2p Node (optional when using `.create`).
- `peerInfo`: instance of [`PeerInfo`][peer-info] that contains the [`PeerId`][peer-id], Keys and [multiaddrs][multiaddr] of the libp2p Node (optional when using `.create`).
- `modules.transport`: An array that must include at least 1 compliant transport. See [modules that implement the transport interface](https://github.com/libp2p/js-interfaces/tree/master/src/transport#modules-that-implement-the-interface).

</details>
Expand Down Expand Up @@ -182,7 +182,7 @@ Dials to another peer in the network and establishes the connection.

| Name | Type | Description |
|------|------|-------------|
| peer | [PeerInfo](https://github.com/libp2p/js-peer-info), [PeerId][peer-id], [multiaddr](https://github.com/multiformats/js-multiaddr), `string` | peer to dial |
| peer | [`PeerInfo`][peer-info]\|[`PeerId`][peer-id]\|[`Multiaddr`][multiaddr]\|`string` | peer to dial |
| [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 @@ -217,7 +217,7 @@ Dials to another peer in the network and selects a protocol to communicate with

| Name | Type | Description |
|------|------|-------------|
| peer | [PeerInfo](https://github.com/libp2p/js-peer-info), [PeerId][peer-id], [multiaddr](https://github.com/multiformats/js-multiaddr), `string` | peer to dial |
| peer | [`PeerInfo`][peer-info]\|[`PeerId`][peer-id]\|[`Multiaddr`][multiaddr]\|`string` | peer to dial |
| 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 @@ -250,7 +250,7 @@ Attempts to gracefully close an open connection to the given peer. If the connec

| Name | Type | Description |
|------|------|-------------|
| peer | [PeerInfo](https://github.com/libp2p/js-peer-info), [PeerId][peer-id], [multiaddr](https://github.com/multiformats/js-multiaddr), `string` | peer to hang up |
| peer | [`PeerInfo`][peer-info]\|[`PeerId`][peer-id]\|[`Multiaddr`][multiaddr]\|`string` | peer to hang up |

#### Returns

Expand Down Expand Up @@ -321,7 +321,7 @@ Pings a given peer and get the operation's latency.

| Name | Type | Description |
|------|------|-------------|
| peer | `PeerInfo|PeerId|Multiaddr|string` | peer to ping |
| peer | [`PeerInfo`][peer-info]\|[`PeerId`][peer-id]\|[`Multiaddr`][multiaddr]\|`string` | peer to ping |

#### Returns

Expand Down Expand Up @@ -374,7 +374,7 @@ Once a content router succeeds, the iteration will stop. If the DHT is enabled,

| Name | Type | Description |
|------|------|-------------|
| cid | [`CID`](https://github.com/multiformats/js-cid) | cid to find |
| cid | [`CID`][cid] | cid to find |
| options | `Object` | operation options |
| options.timeout | `number` | maximum time the query should run |
| options.maxNumProviders | `number` | maximum number of providers to find |
Expand All @@ -383,7 +383,7 @@ Once a content router succeeds, the iteration will stop. If the DHT is enabled,

| Type | Description |
|------|-------------|
| `AsyncIterator<PeerInfo>` | Async iterator for [`PeerInfo`](https://github.com/libp2p/js-peer-info) |
| `AsyncIterator<PeerInfo>` | Async iterator for [`PeerInfo`][peer-info] |

#### Example

Expand All @@ -404,7 +404,7 @@ Iterates over all content routers in parallel, in order to notify it is a provid

| Name | Type | Description |
|------|------|-------------|
| cid | [`CID`](https://github.com/multiformats/js-cid) | cid to provide |
| cid | [`CID`][cid] | cid to provide |

#### Returns

Expand Down Expand Up @@ -649,7 +649,7 @@ Enables users to change the value of certain peers in a range of 0 to 1. Peers w

| Name | Type | Description |
|------|------|-------------|
| peerId | `PeerId` | The peer to set the value for |
| peerId | [`PeerId`][peer-id] | The peer to set the value for |
| value | `number` | The value of the peer from 0 to 1 |

#### Returns
Expand Down Expand Up @@ -677,7 +677,7 @@ const peerIdStrings = libp2p.metrics.peers

### metrics.peers

An array of `PeerId` strings of each peer currently being tracked.
An array of [`PeerId`][peer-id] strings of each peer currently being tracked.

#### Example

Expand All @@ -697,15 +697,15 @@ const protocols = libp2p.metrics.protocols

### metrics.forPeer

Returns the [`Stats`](#stats) object for a given `PeerId` if it is being tracked.
Returns the [`Stats`](#stats) object for a given [`PeerId`][peer-id] if it is being tracked.

`libp2p.metrics.forPeer(peerId)`

#### Parameters

| Name | Type | Description |
|------|------|-------------|
| peerId | `PeerId` | The peer to get stats for |
| peerId | [`PeerId`][peer-id] | The peer to get stats for |

#### Returns

Expand Down Expand Up @@ -762,23 +762,23 @@ Once you have a libp2p instance, you can listen to several events it emits, so t
If `autoDial` option is `true`, applications should **not** attempt to connect to the peer
unless they are performing a specific action. See [peer discovery and auto dial](./PEER_DISCOVERY.md) for more information.

- `peer`: instance of [PeerInfo][https://github.com/libp2p/js-peer-info]
- `peer`: instance of [`PeerInfo`][peer-info]

#### A new connection to a peer has been opened

This event will be triggered anytime a new Connection is established to another peer.

`libp2p.on('peer:connect', (peer) => {})`

- `peer`: instance of [PeerInfo][https://github.com/libp2p/js-peer-info]
- `peer`: instance of [`PeerInfo`][peer-info]

#### An existing connection to a peer has been closed

This event will be triggered anytime we are disconnected from another peer, regardless of the circumstances of that disconnection. If we happen to have multiple connections to a peer, this event will **only** be triggered when the last connection is closed.

`libp2p.on('peer:disconnect', (peer) => {})`

- `peer`: instance of [PeerInfo][https://github.com/libp2p/js-peer-info]
- `peer`: instance of [`PeerInfo`][peer-info]

## Types

Expand All @@ -800,5 +800,8 @@ This event will be triggered anytime we are disconnected from another peer, rega
- `['300000']<MovingAverage>`: The [MovingAverage](https://www.npmjs.com/package/moving-averages) at a 5 minute interval.
- `['900000']<MovingAverage>`: The [MovingAverage](https://www.npmjs.com/package/moving-averages) at a 15 minute interval.

[cid]: https://github.com/multiformats/js-cid
[connection]: https://github.com/libp2p/js-interfaces/tree/master/src/connection
[multiaddr]: https://github.com/multiformats/js-multiaddr
[peer-id]: https://github.com/libp2p/js-peer-id
[peer-info]: https://github.com/libp2p/js-peer-info

0 comments on commit c6592c5

Please sign in to comment.