@libp2p/webrtc 5.2.9 → 5.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -230,6 +230,60 @@ await pipe(
230
230
  )
231
231
  ```
232
232
 
233
+ ## WebRTC Direct certificate hashes
234
+
235
+ WebRTC Direct listeners publish the hash of their TLS certificate as part of
236
+ the listening multiaddr.
237
+
238
+ By default these certificates are generated at start up using an ephemeral
239
+ keypair that only exists while the node is running.
240
+
241
+ This means that the certificate hashes change when the node is restarted,
242
+ which can be undesirable if multiaddrs are intended to be long lived (e.g.
243
+ if the node is used as a network bootstrapper).
244
+
245
+ To reuse the same certificate and keypair, configure a persistent datastore
246
+ and the [@libp2p/keychain](https://www.npmjs.com/package/@libp2p/keychain)
247
+ service as part of your service map:
248
+
249
+ ## Example - Reuse TLS certificates after restart
250
+
251
+ ```ts
252
+ import { LevelDatastore } from 'datastore-level'
253
+ import { webRTCDirect } from '@libp2p/webrtc'
254
+ import { keychain } from '@libp2p/keychain'
255
+ import { createLibp2p } from 'libp2p'
256
+
257
+ // store data on disk between restarts
258
+ const datastore = new LevelDatastore('/path/to/store')
259
+
260
+ const listener = await createLibp2p({
261
+ addresses: {
262
+ listen: [
263
+ '/ip4/0.0.0.0/udp/0/webrtc-direct'
264
+ ]
265
+ },
266
+ datastore,
267
+ transports: [
268
+ webRTCDirect()
269
+ ],
270
+ services: {
271
+ keychain: keychain()
272
+ }
273
+ })
274
+
275
+ await listener.start()
276
+
277
+ console.info(listener.getMultiaddrs())
278
+ // /ip4/...../udp/../webrtc-direct/certhash/foo
279
+
280
+ await listener.stop()
281
+ await listener.start()
282
+
283
+ console.info(listener.getMultiaddrs())
284
+ // /ip4/...../udp/../webrtc-direct/certhash/foo
285
+ ```
286
+
233
287
  # Install
234
288
 
235
289
  ```console