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
BREAKING CHANGE: all API methods with peer-info parameters or return values were changed. You can check the API.md document, in order to check the new values to use
|[options.datastore]|`object`| must implement [ipfs/interface-datastore](https://github.com/ipfs/interface-datastore) (in memory datastore will be used if not provided) |
|[options.peerInfo]|[`PeerInfo`][peer-info]|peerInfo instance (it will be created if not provided) |
69
+
|[options.peerId]|[`PeerId`][peer-id]|peerId instance (it will be created if not provided) |
69
70
70
71
For Libp2p configurations and modules details read the [Configuration Document](./CONFIGURATION.md).
71
72
@@ -87,7 +88,7 @@ const options = {}
87
88
constlibp2p=awaitLibp2p.create(options)
88
89
```
89
90
90
-
Note: The [`PeerInfo`][peer-info] option is not required and will be generated if it is not provided.
91
+
Note: The [`PeerId`][peer-id] option is not required and will be generated if it is not provided.
91
92
92
93
<details><summary>Alternative</summary>
93
94
As an alternative, it is possible to create a Libp2p instance with the constructor:
@@ -106,7 +107,7 @@ const libp2p = new Libp2p(options)
106
107
107
108
Required keys in the `options` object:
108
109
109
-
-`peerInfo`: instance of [`PeerInfo`][peer-info] that contains the [`PeerId`][peer-id], Keys and [multiaddrs][multiaddr] of the libp2p Node (optional when using `.create`).
110
+
-`peerId`: instance of [`PeerId`][peer-id] that contains the peer Keys (optional when using `.create`).
110
111
-`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).
A Getter that returns a Map of the current Connections libp2p has to other peers.
@@ -194,10 +199,12 @@ for (const [peerId, connections] of libp2p.connections) {
194
199
195
200
| Name | Type | Description |
196
201
|------|------|-------------|
197
-
| 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|
202
+
| peer |[`PeerId`][peer-id]\|[`Multiaddr`][multiaddr]\|`string`| The peer to dial. |
198
203
|[options]|`object`| dial options |
199
204
|[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 |
200
205
206
+
**Note:** If a [`Multiaddr`][multiaddr] or its string is provided, it **must** include the peer id. Moreover, if a [`PeerId`][peer-id] is given, the peer will need to have known multiaddrs for it in the PeerStore.
207
+
201
208
#### Returns
202
209
203
210
| Type | Description |
@@ -208,7 +215,7 @@ for (const [peerId, connections] of libp2p.connections) {
@@ -229,11 +236,13 @@ Dials to another peer in the network and selects a protocol to communicate with
229
236
230
237
| Name | Type | Description |
231
238
|------|------|-------------|
232
-
| 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|
239
+
| peer |[`PeerId`][peer-id]\|[`Multiaddr`][multiaddr]\|`string`| The peer to dial. |
233
240
| 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') |
234
241
|[options]|`object`| dial options |
235
242
|[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 |
236
243
244
+
**Note:** If a [`Multiaddr`][multiaddr] or its string is provided, it **must** include the peer id. Moreover, if a [`PeerId`][peer-id] is given, the peer will need to have known multiaddrs for it in the PeerStore.
245
+
237
246
#### Returns
238
247
239
248
| Type | Description |
@@ -246,7 +255,7 @@ Dials to another peer in the network and selects a protocol to communicate with
@@ -851,15 +859,13 @@ Get all the stored information of every peer.
851
859
852
860
| Type | Description |
853
861
|------|-------------|
854
-
|`Map<string, PeerInfo>`| Peer information of every peer |
855
-
856
-
TODO: change when `peer-info` is deprecated to new pointer (breaking change)
862
+
|`Map<string, { id: PeerId, multiaddrInfos: Array<MultiaddrInfo>, protocols: Array<string> }>`| Peer data of every peer known |
857
863
858
864
#### Example
859
865
860
866
```js
861
-
for (let [peerIdString, peerInfo] ofpeerStore.peers.entries()) {
862
-
//peerInfo instance
867
+
for (let [peerIdString, peerData] ofpeerStore.peers.entries()) {
868
+
//peerData
863
869
}
864
870
```
865
871
@@ -1070,7 +1076,7 @@ Returns the [`Stats`](#stats) object for a given [`PeerId`][peer-id] if it is be
1070
1076
#### Example
1071
1077
1072
1078
```js
1073
-
constpeerStats=libp2p.metrics.forPeer(peerInfo)
1079
+
constpeerStats=libp2p.metrics.forPeer(peerId)
1074
1080
console.log(peerStats.toJSON())
1075
1081
```
1076
1082
@@ -1118,23 +1124,23 @@ Once you have a libp2p instance, you can listen to several events it emits, so t
1118
1124
If `autoDial` option is `true`, applications should **not** attempt to connect to the peer
1119
1125
unless they are performing a specific action. See [peer discovery and auto dial](./PEER_DISCOVERY.md) for more information.
1120
1126
1121
-
-`peer`: instance of [`PeerInfo`][peer-info]
1127
+
-`peer`: instance of [`PeerId`][peer-id]
1122
1128
1123
1129
#### A new connection to a peer has been opened
1124
1130
1125
1131
This event will be triggered anytime a new Connection is established to another peer.
1126
1132
1127
1133
`libp2p.on('peer:connect', (peer) => {})`
1128
1134
1129
-
-`peer`: instance of [`PeerInfo`][peer-info]
1135
+
-`peer`: instance of [`PeerId`][peer-id]
1130
1136
1131
1137
#### An existing connection to a peer has been closed
1132
1138
1133
1139
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.
1134
1140
1135
1141
`libp2p.on('peer:disconnect', (peer) => {})`
1136
1142
1137
-
-`peer`: instance of [`PeerInfo`][peer-info]
1143
+
-`peer`: instance of [`PeerId`][peer-id]
1138
1144
1139
1145
### libp2p.peerStore
1140
1146
@@ -1183,4 +1189,3 @@ This event will be triggered anytime we are disconnected from another peer, rega
0 commit comments