# All files / src/server swarm.js

100% Statements 17/17
100% Branches 0/0
100% Functions 9/9
100% Lines 17/17

    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
    481x
    1x
    1x
    1x
    1x

    23x

    6x
    6x
    21x
    21x
    21x

    2x
    2x

    2x
    2x

    14x

    2x

     import { expose } from 'postmsg-rpc'
    import { pre, post } from 'prepost'
    import { peerInfoToJson } from '../serialization/peer'
    import { preMultiaddrFromJson, multiaddrToJson } from '../serialization/multiaddr'
    import { preBufferFromJson } from '../serialization/buffer'

    export default function (getIpfs, opts) {
      return {
        peers: expose('ipfs.swarm.peers', pre(
          opts.pre('swarm.peers'),
          post(
            (...args) => getIpfs().swarm.peers(...args),
            (res) => res.map((item) => {
              item.addr = multiaddrToJson(item.addr)
              item.peer = peerInfoToJson(item.peer)
              return item
            })
          )
        ), opts),
        addrs: expose('ipfs.swarm.addrs', pre(
          opts.pre('swarm.addrs'),
          post(
            () => getIpfs().swarm.addrs(),
            (res) => res.map(peerInfoToJson)
          )
        ), opts),
        localAddrs: expose('ipfs.swarm.localAddrs', pre(
          opts.pre('swarm.localAddrs'),
          post(
            () => getIpfs().swarm.localAddrs(),
            (res) => res.map(multiaddrToJson)
          )
        ), opts),
        connect: expose('ipfs.swarm.connect', pre(
          preBufferFromJson(0),
          preMultiaddrFromJson(0),
          opts.pre('swarm.connect'),
          (...args) => getIpfs().swarm.connect(...args)
        ), opts),
        disconnect: expose('ipfs.swarm.disconnect', pre(
          preBufferFromJson(0),
          preMultiaddrFromJson(0),
          opts.pre('swarm.disconnect'),
          (...args) => getIpfs().swarm.disconnect(...args)
        ), opts)
      }
    }