# All files / src/server dht.js

76.47% Statements 13/17
33.33% Branches 2/6
63.64% Functions 7/11
80% Lines 12/15

    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
    45
    46
    47
    48
    491x
    1x
    1x
    1x
    1x

    23x

    2x

    1x
    1x

    1x

    1x
    2x

     import { expose } from 'postmsg-rpc'
    import { pre, post } from 'prepost'
    import { preCidFromJson } from '../serialization/cid'
    import { prePeerIdFromJson, peerInfoToJson, isPeerInfo } from '../serialization/peer'
    import { preBufferFromJson } from '../serialization/buffer'

    export default function (getIpfs, opts) {
      return {
        put: expose('ipfs.dht.put', pre(
          opts.pre('dht.put'),
          (...args) => getIpfs().dht.put(...args)
        ), opts),
        get: expose('ipfs.dht.get', pre(
          opts.pre('dht.get'),
          (...args) => getIpfs().dht.get(...args)
        ), opts),
        findprovs: expose('ipfs.dht.findprovs', pre(
          preBufferFromJson(0),
          opts.pre('dht.findprovs'),
          post(
            (...args) => getIpfs().dht.findprovs(...args),
            (res) => res.map((item) => isPeerInfo(item) ? peerInfoToJson(item) : item)
          )
        ), opts),
        findpeer: expose('ipfs.dht.findpeer', pre(
          prePeerIdFromJson(0),
          opts.pre('dht.findpeer'),
          post(
            (...args) => getIpfs().dht.findpeer(...args),
            (res) => isPeerInfo(res) ? peerInfoToJson(res) : res
          )
        ), opts),
        provide: expose('ipfs.dht.provide', pre(
          preBufferFromJson(0),
          preCidFromJson(0),
          opts.pre('dht.provide'),
          (...args) => getIpfs().dht.provide(...args)
        ), opts),
        query: expose('ipfs.dht.query', pre(
          prePeerIdFromJson(0),
          opts.pre('dht.query'),
          post(
            (...args) => getIpfs().dht.query(...args),
            (res) => res.map((item) => isPeerInfo(item) ? peerInfoToJson(item) : item)
          )
        ), opts)
      }
    }