ipfs-bitswap
0.25.1

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

Bitswap

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

Parameters

  1. libp2p: Libp2p:  
  2. blockstore: Blockstore:  
  3. options: any:  

instance

Bitswap.prototype.wantlistForPeer

wantlistForPeer(peerId: PeerId): Wantlist

Return the current wantlist for a given peerId

Parameters

  1. peerId: PeerId:  

Returns

Wantlist

Bitswap.prototype.ledgerForPeer

ledgerForPeer(peerId: PeerId): Object?

Return ledger information for a given peerId

Parameters

  1. peerId: PeerId:  

Returns

Bitswap.prototype.get

get(cid: CID, callback: function (Error, Block)): void

Fetch a given block by cid. If the block is in the local blockstore it is returned, otherwise the block is added to the wantlist and returned once another node sends it to us.

Parameters

  1. cid: CID:  
  2. callback: function (Error, Block):  

Returns

void

Bitswap.prototype.getMany

getMany(cids: Array<CID>, callback: function (Error, Blocks)): void

Fetch a a list of blocks by cid. If the blocks are in the local blockstore they are returned, otherwise the blocks are added to the wantlist and returned once another node sends them to us.

Parameters

  1. cids: Array<CID>:  
  2. callback: function (Error, Blocks):  

Returns

void

Bitswap.prototype.put

put(block: Block, callback: function (Error)): void

Put the given block to the underlying blockstore and send it to nodes that have it in their wantlist.

Parameters

  1. block: Block:  
  2. callback: function (Error):  

Returns

void

Bitswap.prototype.putMany

putMany(blocks: Array<Block>, callback: function (Error)): void

Put the given blocks to the underlying blockstore and send it to nodes that have it them their wantlist.

Parameters

  1. blocks: Array<Block>:  
  2. callback: function (Error):  

Returns

void

Bitswap.prototype.getWantlist

getWantlist(): Iterator<WantlistEntry>

Get the current list of wants.

Returns

Iterator<WantlistEntry>

Bitswap.prototype.peers

peers(): Array<PeerId>

Get the current list of partners.

Returns

Array<PeerId>

Bitswap.prototype.stat

stat(): Object

Get stats about the bitswap node.

Returns

Bitswap.prototype.start

start(callback: function (Error)): void

Start the bitswap node.

Parameters

  1. callback: function (Error):  

Returns

void

Bitswap.prototype.stop

stop(callback: function (Error)): void

Stop the bitswap node.

Parameters

  1. callback: function (Error):  

Returns

void