# All files / lib/server dht.js

78.95% Statements 15/19
33.33% Branches 2/6
66.67% Functions 8/12
78.95% Lines 15/19

    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
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60

    1x

    1x
    19x

    2x

    1x

    1x

    1x

    1x

    1x
    2x

    1x

    1x

    1x

    1x

    1x'use strict';

    Object.defineProperty(exports, "__esModule", {
      value: true
    });

    exports.default = function (getIpfs, opts) {
      return {
        put: (0, _postmsgRpc.expose)('ipfs.dht.put', (0, _prepost.pre)(opts.pre['dht.put'], function () {
          var _getIpfs$dht;

          return (_getIpfs$dht = getIpfs().dht).put.apply(_getIpfs$dht, arguments);
        }), opts),
        get: (0, _postmsgRpc.expose)('ipfs.dht.get', (0, _prepost.pre)(opts.pre['dht.get'], function () {
          var _getIpfs$dht2;

          return (_getIpfs$dht2 = getIpfs().dht).get.apply(_getIpfs$dht2, arguments);
        }), opts),
        findprovs: (0, _postmsgRpc.expose)('ipfs.dht.findprovs', (0, _prepost.pre)((0, _buffer.preBufferFromJson)(0), opts.pre['dht.findprovs'], (0, _prepost.post)(function () {
          var _getIpfs$dht3;

          return (_getIpfs$dht3 = getIpfs().dht).findprovs.apply(_getIpfs$dht3, arguments);
        }, function (res) {
          return res.map(function (item) {
            return (0, _peer.isPeerInfo)(item) ? (0, _peer.peerInfoToJson)(item) : item;
          });
        })), opts),
        findpeer: (0, _postmsgRpc.expose)('ipfs.dht.findpeer', (0, _prepost.pre)((0, _peer.prePeerIdFromJson)(0), opts.pre['dht.findpeer'], (0, _prepost.post)(function () {
          var _getIpfs$dht4;

          return (_getIpfs$dht4 = getIpfs().dht).findpeer.apply(_getIpfs$dht4, arguments);
        }, function (res) {
          return (0, _peer.isPeerInfo)(res) ? (0, _peer.peerInfoToJson)(res) : res;
        })), opts),
        provide: (0, _postmsgRpc.expose)('ipfs.dht.provide', (0, _prepost.pre)((0, _buffer.preBufferFromJson)(0), (0, _cid.preCidFromJson)(0), opts.pre['dht.provide'], function () {
          var _getIpfs$dht5;

          return (_getIpfs$dht5 = getIpfs().dht).provide.apply(_getIpfs$dht5, arguments);
        }), opts),
        query: (0, _postmsgRpc.expose)('ipfs.dht.query', (0, _prepost.pre)((0, _peer.prePeerIdFromJson)(0), opts.pre['dht.query'], (0, _prepost.post)(function () {
          var _getIpfs$dht6;

          return (_getIpfs$dht6 = getIpfs().dht).query.apply(_getIpfs$dht6, arguments);
        }, function (res) {
          return res.map(function (item) {
            return (0, _peer.isPeerInfo)(item) ? (0, _peer.peerInfoToJson)(item) : item;
          });
        })), opts)
      };
    };

    var _postmsgRpc = require('postmsg-rpc');

    var _prepost = require('prepost');

    var _cid = require('../serialization/cid');

    var _peer = require('../serialization/peer');

    var _buffer = require('../serialization/buffer');