How to use pull-length-prefixed - 10 common examples

To help you get started, we’ve selected a few pull-length-prefixed 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 validitylabs / hopr / src / network / natTraversal / signalling / index.js View on Github external
type: Type.RESPONSE,
                                status: Status.FAIL
                            })
                        )
                        return false
                    }
                }

                pull(
                    pull.once(
                        Message.encode({
                            type: Type.RESPONSE,
                            status: Status.FAIL
                        })
                    ),
                    lp.encode(),
                    conn
                )

                // Cancel stream by returning false
                return false
        }
    }
github libp2p / js-libp2p / test / circuit / hop.spec.js View on Github external
it('should create circuit', (done) => {
        pull(
          values([proto.CircuitRelay.encode({
            type: proto.CircuitRelay.Type.STATUS,
            code: proto.CircuitRelay.Status.SUCCESS
          })]),
          lp.encode(),
          collect((err, encoded) => {
            expect(err).to.not.exist()

            encoded.forEach((e) => dstShake.write(e))
            pull(
              values([Buffer.from('hello')]),
              lp.encode(),
              collect((err, encoded) => {
                expect(err).to.not.exist()

                encoded.forEach((e) => srcShake.write(e))
                lp.decodeFromReader(
                  dstShake,
                  (err, _msg) => {
                    expect(err).to.not.exist()
                    expect(_msg.toString()).to.equal('hello')
github libp2p / js-libp2p / test / identify / dialer.spec.js View on Github external
original.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/5002'))
    original.protocols.add('/echo/1.0.0')
    original.protocols.add('/ping/1.0.0')

    const input = msg.encode({
      protocolVersion: 'ipfs/0.1.0',
      agentVersion: 'na',
      publicKey: original.id.pubKey.bytes,
      listenAddrs: [multiaddr('/ip4/127.0.0.1/tcp/5002').buffer],
      observedAddr: multiaddr('/ip4/127.0.0.1/tcp/5001').buffer,
      protocols: Array.from(original.protocols)
    })

    pull(
      values([input]),
      lp.encode(),
      p[0]
    )

    identify.dialer(p[1], (err, info, observedAddrs) => {
      expect(err).to.not.exist()
      expect(info.id.pubKey.bytes)
        .to.eql(original.id.pubKey.bytes)

      expect(info.multiaddrs.has(original.multiaddrs.toArray()[0]))
        .to.eql(true)

      expect(multiaddr('/ip4/127.0.0.1/tcp/5001').equals(observedAddrs[0]))
        .to.eql(true)

      expect(info.protocols).to.eql(original.protocols)
github libp2p / js-libp2p-identify / test / dialer.spec.js View on Github external
original.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/5002'))
    original.protocols.add('/echo/1.0.0')
    original.protocols.add('/ping/1.0.0')

    const input = msg.encode({
      protocolVersion: 'ipfs/0.1.0',
      agentVersion: 'na',
      publicKey: original.id.pubKey.bytes,
      listenAddrs: [multiaddr('/ip4/127.0.0.1/tcp/5002').buffer],
      observedAddr: multiaddr('/ip4/127.0.0.1/tcp/5001').buffer,
      protocols: Array.from(original.protocols)
    })

    pull(
      values([input]),
      lp.encode(),
      p[0]
    )

    identify.dialer(p[1], (err, info, observedAddrs) => {
      expect(err).to.not.exist()
      expect(info.id.pubKey.bytes)
        .to.eql(original.id.pubKey.bytes)

      expect(info.multiaddrs.toArray())
        .to.eql(original.multiaddrs.toArray())

      expect(observedAddrs)
        .to.eql([multiaddr('/ip4/127.0.0.1/tcp/5001')])

      expect(info.protocols).to.eql(original.protocols)
github libp2p / js-libp2p / test / circuit / listener.spec.js View on Github external
listener.hopHandler.handle = (message, conn) => {
        expect(message.type).to.equal(proto.CircuitRelay.Type.HOP)

        expect(message.srcPeer.id.toString()).to.equal(relayMsg.srcPeer.id)
        expect(message.srcPeer.addrs[0].toString()).to.equal(relayMsg.srcPeer.addrs[0])

        expect(message.dstPeer.id.toString()).to.equal(relayMsg.dstPeer.id)
        expect(message.dstPeer.addrs[0].toString()).to.equal(relayMsg.dstPeer.addrs[0])

        done()
      }

      pull(
        values([proto.CircuitRelay.encode(relayMsg)]),
        lp.encode(),
        collect((err, encoded) => {
          expect(err).to.not.exist()
          encoded.forEach((e) => shake.write(e))
        })
      )
    })
github daviddias / js-ethereum-libp2p / src / ethereum-node.js View on Github external
libp2pNode.handle('/eth/block/sync/1.0.0', (conn) => {
      pull(
        pull.values(blocks),
        lp.encode(),
        conn
      )
    })
  }
github mediachain / aleph / src / peer / util.js View on Github external
function protoStreamEncode (codec: ProtoCodec): PullStreamThrough {
  return pull(
    pull.map(codec.encode),
    lp.encode()
  )
}
github validitylabs / hopr / src / handlers / deliverPubKey.js View on Github external
module.exports = (node) => node.handle(PROTOCOL_DELIVER_PUBKEY, (protocol, conn) => {
    pull(
        pull.once(node.peerInfo.id.pubKey.marshal()),
        lp.encode(),
        conn
    )
})
github validitylabs / hopr / src / handlers / packet / forward.js View on Github external
(conn, cb) => {
                pull(
                    pull.once(
                        Acknowledgement.create(
                            packet.oldChallenge,
                            packet.header.derivedSecret,
                            node.peerInfo.id
                        ).toBuffer()
                    ),
                    lp.encode(),
                    conn
                )
                cb()
            }
        ], cb)
github validitylabs / hopr / src / paymentChannels / handlers / open.js View on Github external
node.handle(PROTOCOL_PAYMENT_CHANNEL, (protocol, conn) =>
        pull(
            conn,
            lp.decode({
                maxLength: Transaction.SIZE
            }),
            paramap(handleOpeningRequest, null, false),
            lp.encode(),
            conn
        )
    )

pull-length-prefixed

Streaming length prefixed buffers with pull-streams

MIT
Latest version published 6 years ago

Package Health Score

42 / 100
Full package analysis

Popular pull-length-prefixed functions