forked from ipfs/js-ipfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat.js
38 lines (34 loc) · 1.16 KB
/
stat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict'
const { BigNumber } = require('bignumber.js')
const CID = require('cids')
const configure = require('../lib/configure')
const toUrlSearchParams = require('../lib/to-url-search-params')
module.exports = configure(api => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {import('../../../ipfs/src/core/components/bitswap/stat').Stat<import('..').HttpOptions>}
*/
async function stat (options = {}) {
const res = await api.post('bitswap/stat', {
searchParams: toUrlSearchParams(options),
timeout: options.timeout,
signal: options.signal,
headers: options.headers
})
return toCoreInterface(await res.json())
}
return stat
})
function toCoreInterface (res) {
return {
provideBufLen: res.ProvideBufLen,
wantlist: (res.Wantlist || []).map(k => new CID(k['/'])),
peers: (res.Peers || []),
blocksReceived: new BigNumber(res.BlocksReceived),
dataReceived: new BigNumber(res.DataReceived),
blocksSent: new BigNumber(res.BlocksSent),
dataSent: new BigNumber(res.DataSent),
dupBlksReceived: new BigNumber(res.DupBlksReceived),
dupDataReceived: new BigNumber(res.DupDataReceived)
}
}