fix: add transport manager to exports map and fix docs (#1182)

Addresses PR comments from #1172 - fixes syntax of examples in docs, adds the transport manager to the exports map and renames fault tolerance enum for consistency.
This commit is contained in:
Alex Potsides
2022-03-29 15:39:50 +01:00
committed by GitHub
parent 8cca8e4bfc
commit cc60cfde1a
9 changed files with 26 additions and 24 deletions

View File

@ -246,8 +246,8 @@ import { GossipSub } from 'libp2p-gossipsub'
const node = await createLibp2p({
transports: [
TCP,
new WS() // It can take instances too!
new TCP(),
new WS()
],
streamMuxers: [new Mplex()],
connectionEncryption: [new Noise()],
@ -697,8 +697,7 @@ import { createLibp2p } from 'libp2p'
import { TCP } from '@libp2p/tcp'
import { Mplex } from '@libp2p/mplex'
import { Noise } from '@chainsafe/libp2p-noise'
const { FaultTolerance } from 'libp2p/src/transport-manager')
import { FaultTolerance } from 'libp2p/transport-manager'
const node = await createLibp2p({
transports: [new TCP()],

View File

@ -22,7 +22,7 @@
Sometimes you may need to wrap an existing duplex stream in order to perform incoming and outgoing [transforms](#transform) on data. This type of wrapping is commonly used in stream encryption/decryption. Using [it-pair][it-pair] and [it-pipe][it-pipe], we can do this rather easily, given an existing [duplex iterable](#duplex).
```js
const duplexPair from 'it-pair/duplex')
import { duplexPair } from 'it-pair/duplex'
import { pipe } from 'it-pipe'
// Wrapper is what we will write and read from

View File

@ -49,13 +49,13 @@ Protocol registration is very similar to how it previously was, however, the han
**Before**
```js
const pull from 'pull-stream')
const pull = require('pull-stream')
libp2p.handle('/echo/1.0.0', (protocol, conn) => pull(conn, conn))
```
**After**
```js
const pipe from 'it-pipe')
const pipe = require('it-pipe')
libp2p.handle(['/echo/1.0.0'], ({ protocol, stream }) => pipe(stream, stream))
```
@ -65,7 +65,7 @@ libp2p.handle(['/echo/1.0.0'], ({ protocol, stream }) => pipe(stream, stream))
**Before**
```js
const pull from 'pull-stream')
const pull = require('pull-stream')
libp2p.dialProtocol(peerInfo, '/echo/1.0.0', (err, conn) => {
if (err) { throw err }
pull(
@ -82,7 +82,7 @@ libp2p.dialProtocol(peerInfo, '/echo/1.0.0', (err, conn) => {
**After**
```js
const pipe from 'it-pipe')
const pipe = require('it-pipe')
const { protocol, stream } = await libp2p.dialProtocol(peerInfo, '/echo/1.0.0')
await pipe(
['hey'],