Skip to content

Commit 5d4d94e

Browse files
committed
docs: finish API documentation
1 parent a4b97b9 commit 5d4d94e

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

README.md

+59-3
Original file line numberDiff line numberDiff line change
@@ -107,29 +107,78 @@ class Node extends libp2p {
107107

108108
### API
109109

110-
#### Create a Node - `new libp2p.Node()`
110+
#### Create a Node - `new libp2p.Node([peerInfo, peerBook, options])`
111+
112+
> Creates an instance of the libp2p.Node.
113+
114+
- `peerInfo`: instance of [PeerInfo][] that contains the [PeerId][], Keys and [multiaddrs][multiaddr] of the libp2p Node. Optional.
115+
- `peerBook`: instance of [PeerBook][] that contains the [PeerInfo][] of known peers. Optional.
116+
- `options`: Object containing custom options for the bundle.
111117

112118
#### `libp2p.start(callback)`
113119

120+
> Start the libp2p Node.
121+
122+
`callback` is a function with the following `function (err) {}` signature, where `err` is an Error in case starting the node fails.
123+
114124
#### `libp2p.stop(callback)`
115125

126+
> Stop the libp2p Node.
127+
128+
`callback` is a function with the following `function (err) {}` signature, where `err` is an Error in case stopping the node fails.
129+
116130
#### `libp2p.dial(peer [, protocol, callback])`
117131

132+
> Dials to another peer in the network.
133+
134+
- `peer`: can be an instance of [PeerInfo][], [PeerId][] or [multiaddr][]
135+
- `protocol`: String that defines the protocol (e.g '/ipfs/bitswap/1.1.0')
136+
137+
`callback` is a function with the following `function (err, conn) {}` signature, where `err` is an Error in of failure to dial the connection and `conn` is a [Connection][] instance in case of a protocol selected, if not it is undefined.
138+
118139
#### `libp2p.hangUp(peer, callback)
119140

141+
> Closes an open connection with a peer, graciously.
142+
143+
- `peer`: can be an instance of [PeerInfo][], [PeerId][] or [multiaddr][]
144+
145+
`callback` is a function with the following `function (err) {}` signature, where `err` is an Error in case stopping the node fails.
146+
120147
#### `libp2p.handle(protocol, handlerFunc [, matchFunc])`
121148

149+
> Handle new protocol
150+
151+
- `protocol`: String that defines the protocol (e.g '/ipfs/bitswap/1.1.0')
152+
- `handlerFunc`: Function with signature `function (protocol, conn) {}`
153+
- `matchFunc`: Function for matching on protocol (exact matching, semver, etc). Default to exact match.
154+
122155
#### `libp2p.unhandle(protocol)
123156

157+
> Stop handling protocol
158+
159+
- `protocol`: String that defines the protocol (e.g '/ipfs/bitswap/1.1.0')
160+
124161
#### `libp2p.on('peer', (peer) => {})`
125162

163+
> Peer has been discovered.
164+
165+
- `peer`: instance of [PeerInfo][]
166+
126167
#### `libp2p.isOn()`
127168

128-
#### `libp2p.peers`
169+
> Check if libp2p is started
170+
171+
#### `libp2p.peerBook`
172+
173+
> PeerBook instance of the node
174+
175+
#### `libp2p.peerInfo`
176+
177+
> PeerInfo instance of the node
129178
130179
---------------------
131180

132-
`FUTURE`
181+
`SOON`
133182

134183
#### `libp2p.findPeers`
135184

@@ -139,6 +188,13 @@ class Node extends libp2p {
139188

140189
#### `libp2p.record.get`
141190

191+
[PeerInfo]: https://github.com/libp2p/js-peer-info
192+
[PeerId]: https://github.com/libp2p/js-peer-id
193+
[PeerBook]: https://github.com/libp2p/js-peer-book
194+
[multiaddr]: https://github.com/multiformats/js-multiaddr
195+
[Connection]: https://github.com/libp2p/interface-connection
196+
197+
142198
### Packages
143199

144200
List of packages currently in existence for libp2p

0 commit comments

Comments
 (0)