How to use libp2p-mplex - 7 common examples

To help you get started, we’ve selected a few libp2p-mplex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github libp2p / js-libp2p / test / upgrading / upgrader.spec.js View on Github external
it('should fail if crypto fails', async () => {
    const { inbound, outbound } = mockMultiaddrConnPair({ addrs, remotePeer })

    const muxers = new Map([[Muxer.multicodec, Muxer]])
    sinon.stub(localUpgrader, 'muxers').value(muxers)
    sinon.stub(remoteUpgrader, 'muxers').value(muxers)

    const crypto = {
      tag: '/insecure',
      secureInbound: () => { throw new Error('Boom') },
      secureOutbound: () => { throw new Error('Boom') }
    }

    const cryptos = new Map([[crypto.tag, crypto]])
    sinon.stub(localUpgrader, 'cryptos').value(cryptos)
    sinon.stub(remoteUpgrader, 'cryptos').value(cryptos)

    // Wait for the results of each side of the connection
    const results = await pSettle([
      localUpgrader.upgradeOutbound(outbound),
github libp2p / js-libp2p / test / utils / mockConnection.js View on Github external
// Pipe all data through the muxer
  pipe(maConn, muxer, maConn)

  maConn.timeline.upgraded = Date.now()

  // Create the connection
  const connection = new Connection({
    localAddr: maConn.localAddr,
    remoteAddr: maConn.remoteAddr,
    localPeer: localPeer,
    remotePeer: remotePeer,
    stat: {
      direction,
      timeline: maConn.timeline,
      multiplexer: Muxer.multicodec,
      encryption: 'N/A'
    },
    newStream,
    getStreams: () => muxer.streams,
    close: err => maConn.close(err)
  })

  return connection
}
github libp2p / js-libp2p-switch / test / identify.node.js View on Github external
setTimeout(() => {
        const peerB = switchA._peerBook.get(switchB._peerInfo.id.toB58String())
        const peerA = switchB._peerBook.get(switchA._peerInfo.id.toB58String())
        expect(Array.from(peerB.protocols)).to.eql([
          multiplex.multicodec,
          identify.multicodec
        ])
        expect(Array.from(peerA.protocols)).to.eql([
          multiplex.multicodec,
          identify.multicodec,
          '/id-test/1.0.0'
        ])

        done()
      }, 500)
    })
github libp2p / js-libp2p / test / switch / identify.node.js View on Github external
setTimeout(() => {
        const peerB = switchA._peerBook.get(switchB._peerInfo.id.toB58String())
        const peerA = switchB._peerBook.get(switchA._peerInfo.id.toB58String())
        expect(Array.from(peerB.protocols)).to.eql([
          multiplex.multicodec,
          identify.multicodec
        ])
        expect(Array.from(peerA.protocols)).to.eql([
          multiplex.multicodec,
          identify.multicodec,
          '/id-test/1.0.0'
        ])

        done()
      }, 500)
    })
github libp2p / go-libp2p-webrtc-direct / examples / standalone / index.js View on Github external
const listener = direct.createListener({ config: {} }, (conn) => {
    console.log('[listener] Got connection')

    const muxer = mplex.listener(conn)

    muxer.on('stream', (stream) => {
      console.log('[listener] Got stream')
      pull(
      stream,
      pull.drain((data) => {
        console.log('[listener] Received:')
        console.log(data.toString())
      })
      )
    })
  })
github libp2p / go-libp2p-webrtc-direct / examples / standalone / index.js View on Github external
direct.dial(maddr, { config: {} }, (err, conn) => {
    if (err) {
      console.log(`[dialer] Failed to open connection: ${err}`)
    }
    console.log('[dialer] Opened connection')

    const muxer = mplex.dialer(conn)
    const stream = muxer.newStream((err) => {
      console.log('[dialer] Opened stream')
      if (err) throw err
    })

    pull(
      pull.values(['hey, how is it going. I am the dialer']),
      stream
    )
  })
}
github RTradeLtd / Temporal / vendor / gx / ipfs / QmWGQQ6Tz8AdUpxktLf3zgnVN9Vy8fcWVezZJSU3ZmiANj / go-mplex / interop / js / server.js View on Github external
const listener = tcp.createServer((socket) => {
  let muxer = mplex.listener(toPull.duplex(socket))
  muxer.on('stream', (stream) => {
    readWrite(stream)
  })
  for (let i = 0; i < 100; i++) {
    muxer.newStream((err, stream) => {
      if (err) {
        throw err
      }
      readWrite(stream)
    })
  }
  socket.on('close', () => {
    listener.close()
  })
})

libp2p-mplex

JavaScript implementation of https://github.com/libp2p/mplex

MIT
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis