Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit e223888

Browse files
pgtedaviddias
authored andcommitted
fix: use new bitswap stats (#1151)
* fix: bitswap stats: use new bitswap stats, but keep the old interface (for now) * fix: bitswap stat tests * chore: using latest ipfs-bitswap version
1 parent 34f28ef commit e223888

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"hapi-set-header": "^1.0.2",
109109
"hoek": "^5.0.2",
110110
"ipfs-api": "^17.2.4",
111-
"ipfs-bitswap": "~0.17.4",
111+
"ipfs-bitswap": "~0.18.0",
112112
"ipfs-block": "~0.6.1",
113113
"ipfs-block-service": "~0.13.0",
114114
"ipfs-multipart": "~0.1.0",

src/core/components/bitswap.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ module.exports = function bitswap (self) {
2121
throw new Error(OFFLINE_ERROR)
2222
}
2323

24-
const stats = self._bitswap.stat()
25-
stats.wantlist = formatWantlist(stats.wantlist)
26-
stats.peers = stats.peers.map((id) => id.toB58String())
27-
28-
return stats
24+
return Object.assign({}, self._bitswap.stat().snapshot, {
25+
wantlist: formatWantlist(self._bitswap.getWantlist()),
26+
peers: self._bitswap.peers().map((id) => id.toB58String())
27+
})
2928
},
3029
unwant: (key) => {
3130
if (!self.isOnline()) {

test/core/bitswap.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,14 @@ describe('bitswap', function () {
261261

262262
expect(stats).to.have.keys([
263263
'blocksReceived',
264+
'blocksSent',
265+
'dataReceived',
266+
'dataSent',
267+
'wantListLength',
264268
'wantlist',
269+
'peerCount',
265270
'peers',
271+
'providesBufferLength',
266272
'dupDataReceived',
267273
'dupBlksReceived'
268274
])

0 commit comments

Comments
 (0)