Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

chore: make IPFS API static (remove api-manager) #3365

Merged
merged 34 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
084b213
chore: make IPFS api static
Gozala Oct 31, 2020
8e1d141
fix: initalization regressions
Gozala Oct 31, 2020
ac85e55
fix: rebase mistakes
Gozala Nov 1, 2020
90f18fc
fix: documentation missmatch
Gozala Nov 1, 2020
015fcfc
chore: remove unnecessary change
Gozala Nov 1, 2020
d321353
chore: undo accidental changes
Gozala Nov 1, 2020
e42b9d7
fix: lint issues
Gozala Nov 1, 2020
877c620
fix: ipns API regression
Gozala Nov 1, 2020
f8dc797
fix: dag put regression
Gozala Nov 1, 2020
e757d58
chore: use patched ipfsd-ctl
Gozala Nov 1, 2020
417abf7
fix: remove duplicate param annoation
Gozala Nov 1, 2020
8e63ab4
fix: init.bits should be a number
Gozala Nov 2, 2020
7816a7e
fix: issues with ipld wiring
Gozala Nov 2, 2020
7c1bdac
Merge remote-tracking branch 'upstream/master' into chore/kill-api-ma…
Gozala Nov 2, 2020
8b386cb
fix: handle optionals differently
Gozala Nov 2, 2020
caca4b9
chroe: inverse property name to reflect it meaning
Gozala Nov 2, 2020
f5e0e85
fix: incorrectly defined getter
Gozala Nov 2, 2020
4fbd20b
chroe: mark init deprecated
Gozala Nov 2, 2020
fa7c2c1
fix: stop libp2p when node is stopped
Gozala Nov 2, 2020
a911154
Apply suggestions from code review
Gozala Nov 13, 2020
b242530
fix: identation
Gozala Nov 13, 2020
9064688
chore: rename core to root
Gozala Nov 13, 2020
4b6d668
Address review comments
Gozala Nov 13, 2020
eb66f38
Update packages/ipfs-core/src/components/dag/index.js
Gozala Nov 13, 2020
d2c013d
Update packages/ipfs-core/src/components/storage.js
Gozala Nov 13, 2020
26e4b80
chore: merge master
Gozala Nov 25, 2020
a857bb7
chore: update git urls
Gozala Nov 25, 2020
8d736ab
fix: types for withTimeoutOptions
Gozala Nov 26, 2020
7fe8d76
fix: regressions introduced by a merge
Gozala Nov 26, 2020
dcef0d3
Merge remote-tracking branch 'upstream/chore/kill-api-manager' into c…
Gozala Nov 26, 2020
e67525f
chore: remove unused p-defer
Gozala Nov 27, 2020
b3d0e23
Merge remote-tracking branch 'upstream/master' into chore/kill-api-ma…
Gozala Nov 27, 2020
d1e3e02
chore: remove gh url
achingbrain Dec 4, 2020
bec98c2
Merge remote-tracking branch 'origin/master' into chore/kill-api-manager
achingbrain Dec 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/interface-ipfs-core/src/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = (common, options) => {

after(() => common.clean())

it('should respect timeout option when adding files', () => {
it('should respect timeout option when adding file', () => {
Gozala marked this conversation as resolved.
Show resolved Hide resolved
return testTimeout(() => ipfs.add('Hello', {
timeout: 1
}))
Expand Down
31 changes: 15 additions & 16 deletions packages/ipfs-cli/src/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module.exports = {
type: 'number',
alias: 'b',
default: '2048',
describe: 'Number of bits to use in the generated RSA private key (defaults to 2048)'
describe: 'Number of bits to use in the generated RSA private key (defaults to 2048)',
coerce: Number
})
.option('empty-repo', {
alias: 'e',
Expand Down Expand Up @@ -69,22 +70,20 @@ module.exports = {
const IPFS = require('ipfs-core')
const Repo = require('ipfs-repo')

const node = await IPFS.create({
repo: new Repo(repoPath),
init: false,
start: false,
config
})

try {
await node.init({
algorithm: argv.algorithm,
bits: argv.bits,
privateKey: argv.privateKey,
emptyRepo: argv.emptyRepo,
profiles: argv.profile,
pass: argv.pass,
log: print
await IPFS.create({
repo: new Repo(repoPath),
init: {
algorithm: argv.algorithm,
bits: argv.bits,
privateKey: argv.privateKey,
emptyRepo: argv.emptyRepo,
profiles: argv.profile,
pass: argv.pass
Gozala marked this conversation as resolved.
Show resolved Hide resolved
},
start: false,
// @ts-ignore - Expects more than {}
Gozala marked this conversation as resolved.
Show resolved Hide resolved
config
})
} catch (err) {
if (err.code === 'EACCES') {
Expand Down
43 changes: 0 additions & 43 deletions packages/ipfs-core/src/api-manager.js

This file was deleted.

9 changes: 6 additions & 3 deletions packages/ipfs-core/src/components/add-all/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const mergeOptions = require('merge-options').bind({ ignoreUndefined: true })
* @param {import('..').GCLock} config.gcLock
* @param {import('..').Preload} config.preload
* @param {import('..').Pin} config.pin
* @param {import('../init').ConstructorOptions<any, boolean>} config.options
* @param {ShardingOptions} [config.options]
*/
module.exports = ({ block, gcLock, preload, pin, options: constructorOptions }) => {
const isShardingEnabled = constructorOptions.EXPERIMENTAL && constructorOptions.EXPERIMENTAL.sharding
module.exports = ({ block, gcLock, preload, pin, options }) => {
const isShardingEnabled = options && options.sharding
Gozala marked this conversation as resolved.
Show resolved Hide resolved
/**
* Import multiple files and data into IPFS.
*
Expand Down Expand Up @@ -178,4 +178,7 @@ function pinFile (pin, opts) {
* @typedef {import('../../utils').MTime} MTime
* @typedef {import('../../utils').AbortOptions} AbortOptions
* @typedef {import('..').CID} CID
*
* @typedef {Object} ShardingOptions
Gozala marked this conversation as resolved.
Show resolved Hide resolved
* @property {boolean} [sharding]
*/
27 changes: 27 additions & 0 deletions packages/ipfs-core/src/components/bitswap/index.js
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
*/
16 changes: 7 additions & 9 deletions packages/ipfs-core/src/components/bitswap/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ const { withTimeoutOption } = require('../../utils')

/**
* @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()
Expand All @@ -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 {
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See docs comment, peer IDs should be strings consistent with ipfs.swarm.peers

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
*/
18 changes: 10 additions & 8 deletions packages/ipfs-core/src/components/bitswap/unwant.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ const { withTimeoutOption } = require('../../utils')

/**
* @param {Object} config
* @param {import('..').IPFSBitSwap} config.bitswap
* @param {import('.').NetworkService} config.network
*/
module.exports = ({ bitswap }) => {
module.exports = ({ network }) => {
/**
* Removes one or more CIDs from the wantlist
*
* @param {CID | CID[]} cids - The CIDs to remove from the wantlist
* @param {AbortOptions} [options]
* @returns {Promise<void>} - A promise that resolves once the request is complete
* @example
* ```JavaScript
* let list = await ipfs.bitswap.wantlist()
Expand All @@ -27,8 +24,14 @@ module.exports = ({ bitswap }) => {
* console.log(list)
* // []
* ```
*
* @param {CID | CID[]} cids - The CIDs to remove from the wantlist
* @param {AbortOptions} [options]
vasco-santos marked this conversation as resolved.
Show resolved Hide resolved
* @returns {Promise<void>} - A promise that resolves once the request is complete
*/
async function unwant (cids, options) { // eslint-disable-line require-await
async function unwant (cids, options) {
const { bitswap } = await network.use(options)

if (!Array.isArray(cids)) {
cids = [cids]
}
Expand All @@ -46,6 +49,5 @@ module.exports = ({ bitswap }) => {
}

/**
* @typedef {import('..').CID} CID
* @typedef {import('../../utils').AbortOptions} AbortOptions
* @typedef {import('.').AbortOptions} AbortOptions
*/
22 changes: 12 additions & 10 deletions packages/ipfs-core/src/components/bitswap/wantlist-for-peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@ const { withTimeoutOption } = require('../../utils')

/**
* @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\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a PeerIdLike exported from the peerId package ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think better alternative would be accept PeerId here and let the user of the API do the conversion. That said if we were to add a type to peer-id I think it should be ToPeerId and there should be PeerId.from(thing:ToPeerId):PeerId function.

I think we already have couple of places with ToThing pattern.

Either way can we deal with trickling types into separate packages as a followup work ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a followup here libp2p/js-peer-id#133

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have several createFrom* functions in peer-id, but they are targeted to a specific type https://github.com/libp2p/js-peer-id#import

I think this would be nice to have, I would just go with PeerId.createFrom(param: ToPeerId) to be consistent with what we already have.

* @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)
Expand All @@ -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
*/

/**
Expand Down
Loading