在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ipfs/js-ipfs-bitswap开源软件地址:https://github.com/ipfs/js-ipfs-bitswap开源编程语言:JavaScript 98.7%开源软件介绍:ipfs-bitswap
Table of ContentsInstallnpm> npm install ipfs-bitswap Use in Node.js or in the browser with browserify, webpack or any other bundlerconst { createBitswap } from 'ipfs-bitswap' Use in a browser using a script tagLoading this module through a script tag will make the <script src="https://unpkg.com/ipfs-bitswap/dist/index.min.js"></script>
<!-- OR -->
<script src="https://unpkg.com/ipfs-bitswap/dist/index.js"></script> APISee https://ipfs.github.io/js-ipfs-bitswap Statsconst 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:
const dataReceivedMovingAverages = movingAverages.dataReceived Each one of these will contain one key per interval (miliseconds), being the default intervals defined:
You can then select one of them const oneMinuteDataReceivedMovingAverages = dataReceivedMovingAverages[60000] This object will be a movingAverage instance. DevelopmentStructure» 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 testsYou can run performance tests like this:
ProfilingYou 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. ContributeFeel free to join in. All welcome. Open an issue! This repository falls under the IPFS Code of Conduct. License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论