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

refactor: remove duplicated code #1327

Merged
merged 1 commit into from
Apr 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 6 additions & 35 deletions src/cli/commands/stats/bitswap.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,8 @@
'use strict'

const CID = require('cids')
const print = require('../../utils').print

module.exports = {
command: 'bitswap',

describe: 'Show some diagnostic information on the bitswap agent.',

builder: {},

handler (argv) {
argv.ipfs.stats.bitswap((err, stats) => {
if (err) {
throw err
}

stats.wantlist = stats.wantlist || []
stats.wantlist = stats.wantlist.map((entry) => {
const buf = Buffer.from(entry.cid.hash.data)
const cid = new CID(entry.cid.version, entry.cid.codec, buf)
return cid.toBaseEncodedString()
})
stats.peers = stats.peers || []

print(`bitswap status
blocks received: ${stats.blocksReceived}
dup blocks received: ${stats.dupBlksReceived}
dup data received: ${stats.dupDataReceived}B
wantlist [${stats.wantlist.length} keys]
${stats.wantlist.join('\n ')}
partners [${stats.peers.length}]
${stats.peers.join('\n ')}`)
})
}
}
// This is an alias for `bitswap stat`.
const bitswapStats = require('../bitswap/stat.js')
// The command needs to be renamed, else it would be `stats stat` instead of
// `stats bitswap`
bitswapStats.command = 'bitswap'
module.exports = bitswapStats