-
Notifications
You must be signed in to change notification settings - Fork 1.2k
chore: make IPFS API static (remove api-manager) #3365
Changes from all commits
084b213
8e1d141
ac85e55
90f18fc
015fcfc
d321353
e42b9d7
877c620
f8dc797
e757d58
417abf7
8e63ab4
7816a7e
7c1bdac
8b386cb
caca4b9
f5e0e85
4fbd20b
fa7c2c1
a911154
b242530
9064688
4b6d668
eb66f38
d2c013d
26e4b80
a857bb7
8d736ab
7fe8d76
dcef0d3
e67525f
b3d0e23
d1e3e02
bec98c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict' | ||
|
||
const createWantlist = require('./wantlist') | ||
const createWantlistForPeer = require('./wantlist-for-peer') | ||
const createUnwant = require('./unwant') | ||
const createStat = require('./stat') | ||
|
||
class BitswapAPI { | ||
/** | ||
* @param {Object} config | ||
Gozala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @param {NetworkService} config.network | ||
*/ | ||
constructor ({ network }) { | ||
this.wantlist = createWantlist({ network }) | ||
this.wantlistForPeer = createWantlistForPeer({ network }) | ||
this.unwant = createUnwant({ network }) | ||
this.stat = createStat({ network }) | ||
} | ||
} | ||
module.exports = BitswapAPI | ||
|
||
/** | ||
* @typedef {import('..').NetworkService} NetworkService | ||
Gozala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @typedef {import('..').PeerId} PeerId | ||
* @typedef {import('..').CID} CID | ||
* @typedef {import('..').AbortOptions} AbortOptions | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,16 +6,13 @@ const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option') | |
|
||
/** | ||
* @param {Object} config | ||
* @param {import('..').IPFSBitSwap} config.bitswap | ||
* @param {import('.').NetworkService} config.network | ||
*/ | ||
module.exports = ({ bitswap }) => { | ||
module.exports = ({ network }) => { | ||
/** | ||
* Show diagnostic information on the bitswap agent. | ||
* Note: `bitswap.stat` and `stats.bitswap` can be used interchangeably. | ||
* | ||
* @param {import('../../utils').AbortOptions} [_options] | ||
* @returns {Promise<BitswapStats>} | ||
* | ||
* @example | ||
* ```js | ||
* const stats = await ipfs.bitswap.stat() | ||
|
@@ -35,8 +32,11 @@ module.exports = ({ bitswap }) => { | |
* // dupDataReceived: 0 | ||
* // } | ||
* ``` | ||
* @param {import('.').AbortOptions} [options] | ||
* @returns {Promise<BitswapStats>} | ||
*/ | ||
async function stat (_options) { // eslint-disable-line require-await | ||
async function stat (options) { | ||
const { bitswap } = await network.use(options) | ||
const snapshot = bitswap.stat().snapshot | ||
|
||
return { | ||
|
@@ -59,13 +59,11 @@ module.exports = ({ bitswap }) => { | |
* @typedef {object} BitswapStats - An object that contains information about the bitswap agent | ||
* @property {number} provideBufLen - an integer | ||
* @property {CID[]} wantlist | ||
* @property {string[]} peers - array of peer IDs as Strings | ||
* @property {CID[]} peers - array of peer IDs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See docs comment, peer IDs should be strings consistent with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Current implementation is not and docs / types were incorrect. And I have submitted #3389 to address that separately. |
||
* @property {Big} blocksReceived | ||
* @property {Big} dataReceived | ||
* @property {Big} blocksSent | ||
* @property {Big} dataSent | ||
* @property {Big} dupBlksReceived | ||
* @property {Big} dupDataReceived | ||
* | ||
* @typedef {import('..').CID} CID | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,24 +5,26 @@ const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option') | |
|
||
/** | ||
* @param {Object} config | ||
* @param {import('..').IPFSBitSwap} config.bitswap | ||
* @param {import('.').NetworkService} config.network | ||
*/ | ||
module.exports = ({ bitswap }) => { | ||
module.exports = ({ network }) => { | ||
/** | ||
* Returns the wantlist for a connected peer | ||
* | ||
* @param {PeerId | CID | string | Uint8Array} peerId - A peer ID to return the wantlist for\ | ||
* @param {AbortOptions} [options] | ||
* @returns {Promise<CID[]>} - An array of CIDs currently in the wantlist | ||
* | ||
* @example | ||
* ```js | ||
* const list = await ipfs.bitswap.wantlistForPeer(peerId) | ||
* console.log(list) | ||
* // [ CID('QmHash') ] | ||
* ``` | ||
* | ||
* @param {PeerId | CID | string | Uint8Array} peerId - A peer ID to return the wantlist for\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think better alternative would be accept I think we already have couple of places with Either way can we deal with trickling types into separate packages as a followup work ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created a followup here libp2p/js-peer-id#133 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have several I think this would be nice to have, I would just go with |
||
* @param {AbortOptions} [options] | ||
* @returns {Promise<CID[]>} - An array of CIDs currently in the wantlist | ||
* | ||
*/ | ||
async function wantlistForPeer (peerId, options = {}) { // eslint-disable-line require-await | ||
async function wantlistForPeer (peerId, options = {}) { | ||
const { bitswap } = await network.use(options) | ||
const list = bitswap.wantlistForPeer(PeerId.createFromCID(peerId), options) | ||
|
||
return Array.from(list).map(e => e[1].cid) | ||
|
@@ -32,9 +34,9 @@ module.exports = ({ bitswap }) => { | |
} | ||
|
||
/** | ||
* @typedef {import('../../utils').AbortOptions} AbortOptions | ||
* @typedef {import('..').CID} CID | ||
* @typedef {import('..').PeerId} PeerId | ||
* @typedef {import('.').AbortOptions} AbortOptions | ||
* @typedef {import('.').CID} CID | ||
* @typedef {import('.').PeerId} PeerId | ||
*/ | ||
|
||
/** | ||
|
Uh oh!
There was an error while loading. Please reload this page.