# All files / server bitswap.js

17.39% Statements 4/23
0% Branches 0/14
0% Functions 0/6
17.39% Lines 4/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    39
    40
    41
    42
    43
    44
    451x
    1x
    1x

    1x

     import { expose } from 'postmsg-rpc'
    import { post } from 'prepost'
    import { isBig, bigToJson } from '../serialization/big'

    export default function (getIpfs, opts) {
      return {
        ledger: expose('ipfs.bitswap.ledger', (...args) => getIpfs().bitswap.ledger(...args), opts),
        reprovide: expose('ipfs.bitswap.reprovide', (...args) => getIpfs().bitswap.reprovide(...args), opts),
        stat: expose('ipfs.bitswap.stat', post(
          (...args) => getIpfs().bitswap.stat(...args),
          (stats) => {
            if (stats) {
              if (isBig(stats.blocksReceived)) {
                stats.blocksReceived = bigToJson(stats.blocksReceived)
              }

              if (isBig(stats.dataReceived)) {
                stats.dataReceived = bigToJson(stats.dataReceived)
              }

              if (isBig(stats.blocksSent)) {
                stats.blocksSent = bigToJson(stats.blocksSent)
              }

              if (isBig(stats.dataSent)) {
                stats.dataSent = bigToJson(stats.dataSent)
              }

              if (isBig(stats.dupBlksReceived)) {
                stats.dupBlksReceived = bigToJson(stats.dupBlksReceived)
              }

              if (isBig(stats.dupDataReceived)) {
                stats.dupDataReceived = bigToJson(stats.dupDataReceived)
              }
            }

            return stats
          }
        ), opts),
        unwant: expose('ipfs.bitswap.unwant', (...args) => getIpfs().bitswap.unwant(...args), opts),
        wantlist: expose('ipfs.bitswap.wantlist', (...args) => getIpfs().bitswap.wantlist(...args), opts)
      }
    }