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

Commit

Permalink
refactor: remove duplicated code
Browse files Browse the repository at this point in the history
The `stats bitswap` command is an alias of `bitswap stat`. That should
also be reflected in the code.
  • Loading branch information
vmx authored and daviddias committed Apr 26, 2018
1 parent d6ac355 commit e7b91ff
Showing 1 changed file with 6 additions and 35 deletions.
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

0 comments on commit e7b91ff

Please sign in to comment.