npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@compendia/ipfs-bitswap-commonjs

v4.0.2

Published

Node.js implementation of the Bitswap data exchange protocol used by IPFS

Downloads

5

Readme

ipfs-bitswap

Travis CI

JavaScript implementation of the Bitswap 'data exchange' protocol used by IPFS

Lead Maintainer

Dirk McCormick

Table of Contents

Install

npm

> npm install ipfs-bitswap

Use in Node.js or in the browser with browserify, webpack or any other bundler

const Bitswap = require('ipfs-bitswap')

Use in a browser using a script tag

Loading this module through a script tag will make the IpfsBitswap object available in the global namespace.

<script src="https://unpkg.com/ipfs-bitswap/dist/index.min.js"></script>
<!-- OR -->
<script src="https://unpkg.com/ipfs-bitswap/dist/index.js"></script>

API

See https://ipfs.github.io/js-ipfs-bitswap

Stats

const bitswapNode = // ...

const stats = bitswapNode.stat()

Stats contains a snapshot accessor, a moving average acessor and a peer accessor.

Besides that, it emits "update" events every time it is updated.

stats.on('update', (stats) => {
  console.log('latest stats snapshot: %j', stats)
})

Peer accessor:

You can get the stats for a specific peer by doing:

const peerStats = stats.forPeer(peerId)

The returned object behaves like the root stats accessor (has a snapshot, a moving average accessors and is an event emitter).

Global snapshot accessor:

const snapshot = stats.snapshot
console.log('stats: %j', snapshot)

the snapshot will contain the following keys, with the values being bignumber.js instances:

// stats: {
//   "dataReceived":"96",
//   "blocksReceived":"2",
//   "dataReceived":"96",
//   "dupBlksReceived":"0",
//   "dupDataReceived":"0",
//   "blocksSent":"0",
//   "dataSent":"0",
//   "providesBufferLength":"0",
//   "wantListLength":"0",
//   "peerCount":"1"
// }

Moving average accessor:

const movingAverages = stats.movingAverages

This object contains these properties:

  • 'blocksReceived',
  • 'dataReceived',
  • 'dupBlksReceived',
  • 'dupDataReceived',
  • 'blocksSent',
  • 'dataSent',
  • 'providesBufferLength',
  • 'wantListLength',
  • 'peerCount'
const dataReceivedMovingAverages = movingAverages.dataReceived

Each one of these will contain one key per interval (miliseconds), being the default intervals defined:

  • 60000 (1 minute)
  • 300000 (5 minutes)
  • 900000 (15 minutes)

You can then select one of them

const oneMinuteDataReceivedMovingAverages = dataReceivedMovingAverages[60000]

This object will be a movingAverage instance.

Development

Structure

» tree src
src
├── constants.js
├── decision-engine
│   ├── index.js
│   └── ledger.js
├── index.js
├── network.js             # Handles peerSet and open new conns
├── notifications.js       # Handles tracking of incomning blocks and wants/unwants.
├─── want-manager          # Keeps track of all blocks the peer (self) wants
│   ├── index.js
│   └── msg-queue.js       # Messages to send queue, one per peer
└─── types
    ├── message            # (Type) message that is put in the wire
    │   ├── entry.js
    │   ├── index.js
    │   └── message.proto.js
    └── wantlist           # (Type) track wanted blocks
        ├── entry.js
        └── index.js

Performance tests

You can run performance tests like this:

$ npm run benchmarks

Profiling

You can run each of the individual performance tests with a profiler like 0x.

To do that, you need to install 0x:

$ npm install 0x --global

And then run the test:

$ 0x test/benchmarks/get-many

This will output a flame graph and print the location for it. Use the browser Chrome to open and inspect the generated graph.

Flame graph

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

License

MIT