mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-13 01:01:23 +00:00
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:
@ -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()],
|
||||
|
@ -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
|
||||
|
@ -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'],
|
||||
|
Reference in New Issue
Block a user