ipfs.bitswap.wantlist([options])
ipfs.bitswap.wantlistForPeer(peerId, [options])
ipfs.bitswap.unwant(cids, [options])
ipfs.bitswap.stat([options])
Returns the wantlist for your node
None
An optional object which may have the following keys:
Name | Type | Default | Description |
---|---|---|---|
timeout | Number |
undefined |
A timeout in ms |
signal | AbortSignal | undefined |
Can be used to cancel any long running requests started as a result of this call |
Type | Description |
---|---|
Promise<CID[]> |
An array of CIDs currently in the wantlist |
const list = await ipfs.bitswap.wantlist()
console.log(list)
// [ CID('QmHash') ]
A great source of examples can be found in the tests for this API.
Returns the wantlist for a connected peer
Name | Type | Default | Description |
---|---|---|---|
peerId | PeerId | A peer ID to return the wantlist for |
An optional object which may have the following keys:
Name | Type | Default | Description |
---|---|---|---|
timeout | Number |
undefined |
A timeout in ms |
signal | AbortSignal | undefined |
Can be used to cancel any long running requests started as a result of this call |
Type | Description |
---|---|
Promise<CID[]> |
An array of CIDs currently in the wantlist |
const list = await ipfs.bitswap.wantlistForPeer(peerId)
console.log(list)
// [ CID('QmHash') ]
A great source of examples can be found in the tests for this API.
Removes one or more CIDs from the wantlist
Name | Type | Description |
---|---|---|
cids | A CID or Array of CIDs | The CIDs to remove from the wantlist |
An optional object which may have the following keys:
Name | Type | Default | Description |
---|---|---|---|
timeout | Number |
undefined |
A timeout in ms |
signal | AbortSignal | undefined |
Can be used to cancel any long running requests started as a result of this call |
Type | Description |
---|---|
Promise<void> |
A promise that resolves once the request is complete |
let list = await ipfs.bitswap.wantlist()
console.log(list)
// [ CID('QmHash') ]
await ipfs.bitswap.unwant(cid)
list = await ipfs.bitswap.wantlist()
console.log(list)
// []
A great source of examples can be found in the tests for this API.
Show diagnostic information on the bitswap agent.
Note: bitswap.stat
and stats.bitswap
can be used interchangeably.
None
An optional object which may have the following keys:
Name | Type | Default | Description |
---|---|---|---|
timeout | Number |
undefined |
A timeout in ms |
signal | AbortSignal | undefined |
Can be used to cancel any long running requests started as a result of this call |
Type | Description |
---|---|
Promise<Object> |
An object that contains information about the bitswap agent |
The returned object contains the following keys:
provideBufLen
is an integer.wantlist
(array of CIDs)peers
(array of PeerIds)blocksReceived
is a BigIntdataReceived
is a BigIntblocksSent
is a BigIntdataSent
is a BigIntdupBlksReceived
is a BigIntdupDataReceived
is a BigInt
const stats = await ipfs.bitswap.stat()
console.log(stats)
// {
// provideBufLen: 0,
// wantlist: [ CID('QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM') ],
// peers:
// [ 'QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
// 'QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
// 'QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd' ],
// blocksReceived: 0,
// dataReceived: 0,
// blocksSent: 0,
// dataSent: 0,
// dupBlksReceived: 0,
// dupDataReceived: 0
// }
A great source of examples can be found in the tests for this API.