• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ipfs/js-ipfs-bitswap: JavaScript implementation of Bitswap 'data exchange&#3 ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

ipfs/js-ipfs-bitswap

开源软件地址:

https://github.com/ipfs/js-ipfs-bitswap

开源编程语言:

JavaScript 98.7%

开源软件介绍:

ipfs-bitswap

Build Status

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

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 { createBitswap } from '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




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap