Intro

Installable via npm install --save ipfs-bitswap, it can also be used directly in the browser.

Download

The source is available for download from GitHub. Alternatively, you can install using npm:

$ npm install --save ipfs-bitswap

You can then require() ipfs-bitswap as normal:

const ipfsBitswap = require('ipfs-bitswap')

In the Browser

Ipfs-bitswap should work in any ES2015 environment out of the box.

Usage:

<script type="text/javascript" src="index.js"></script>

The portable versions of ipfs-bitswap, including index.js and index.min.js, are included in the /dist folder. Ipfs-bitswap can also be found on unpkg.com under

JavaScript implementation of the Bitswap 'data exchange' protocol used by IPFS.

new Bitswap(libp2p: Libp2p, blockstore: Blockstore, options: Object)
Parameters
libp2p (Libp2p)
blockstore (Blockstore)
options (Object)
Instance Members
enableStats()
disableStats()
wantlistForPeer(peerId)
ledgerForPeer(peerId)
get(cid)
getMany(cids)
unwant(cids)
cancelWants(cids)
put(block)
putMany(blocks)
getWantlist()
peers()
stat()
start()
stop()

findProviders

src/network.js

Find providers given a cid.

findProviders(cid: CID, maxProviders: number): Promise<Result<Array>>
Parameters
cid (CID)
maxProviders (number)
Returns
Promise<Result<Array>>:

findAndConnect

src/network.js

Find the providers of a given cid and connect to them.

findAndConnect(cid: CID): void
Parameters
cid (CID)
Returns
void:

Connects to another peer

connectTo(peer: (PeerInfo | PeerId | Multiaddr)): Promise<Connection>
Parameters
peer ((PeerInfo | PeerId | Multiaddr))
Returns
Promise<Connection>:

isMapEqual

src/utils.js

Is equal for Maps of BitswapMessageEntry or Blocks

isMapEqual
Parameters
a (Map)
b (Map)
Returns
boolean: