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

Commit

Permalink
chore: use 0.30 rc
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Dec 10, 2020
1 parent 7430d80 commit ad978f0
Show file tree
Hide file tree
Showing 18 changed files with 381 additions and 297 deletions.
590 changes: 336 additions & 254 deletions package.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"it-first": "^1.0.4",
"it-last": "^1.0.4",
"it-pipe": "^1.1.0",
"libp2p": "libp2p/js-libp2p#0.30.x",
"libp2p": "libp2p/js-libp2p#fix/types-with-dist",
"libp2p-bootstrap": "^0.12.1",
"libp2p-crypto": "^0.18.0",
"libp2p-floodsub": "^0.24.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/ipfs-core/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class IPFS {
})
const dns = createDNSAPI()
const isOnline = createIsOnlineAPI({ network })
// @ts-ignore This type check fails as options.
// libp2p can be a function, while IPNS router config expects libp2p config
const ipns = new IPNSAPI(options)
const dagReader = DagAPI.reader({ ipld, preload })

Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core/src/components/is-online.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ module.exports = ({ network }) =>
*/
() => {
const net = network.try()
return net != null && net.libp2p.isStarted()
return net != null && Boolean(net.libp2p.isStarted())
}
5 changes: 2 additions & 3 deletions packages/ipfs-core/src/components/key/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ module.exports = ({ keychain }) => {
* ```
* @param {string} name - The name of the key to export
* @param {string} password - Password to set on the PEM output
* @param {import('.').AbortOptions} options
* @returns {Promise<string>} - The string representation of the key
*/
const exportKey = (name, password, options) =>
keychain.exportKey(name, password, options)
const exportKey = (name, password) =>
keychain.exportKey(name, password)

return withTimeoutOption(exportKey)
}
5 changes: 2 additions & 3 deletions packages/ipfs-core/src/components/key/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ module.exports = ({ keychain }) => {
* @param {string} name - The name of the key to import
* @param {string} pem - The PEM encoded key
* @param {string} password - The password that protects the PEM key
* @param {import('.').AbortOptions} options
* @returns {Promise<import('.').Key>} - An object that describes the new key
*/
const importKey = (name, pem, password, options) => {
return keychain.importKey(name, pem, password, options)
const importKey = (name, pem, password) => {
return keychain.importKey(name, pem, password)
}

return withTimeoutOption(importKey)
Expand Down
3 changes: 1 addition & 2 deletions packages/ipfs-core/src/components/key/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option')
module.exports = ({ keychain }) => {
/**
* @param {string} name
* @param {AbortOptions} [options]
* @returns {Promise<Key>}
*/
const info = (name, options = {}) => keychain.findKeyByName(name, options)
const info = (name) => keychain.findKeyByName(name)

return withTimeoutOption(info)
}
Expand Down
13 changes: 2 additions & 11 deletions packages/ipfs-core/src/components/key/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,9 @@ module.exports = ({ keychain }) => {
* // ]
* ```
*
* @param {AbortOptions} [options]
* @returns {Promise<KeyEntry[]>}
* @returns {Promise<import('libp2p/src/keychain').KeyInfo[]>}
*/
const list = (options = {}) => keychain.listKeys(options)
const list = () => keychain.listKeys()

return withTimeoutOption(list)
}

/**
* @typedef {Object} KeyEntry
* @property {string} name - The name of the key
* @property {string} hash - The hash of the key
*
* @typedef {import('.').AbortOptions} AbortOptions
*/
6 changes: 3 additions & 3 deletions packages/ipfs-core/src/components/key/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ module.exports = ({ keychain }) => {
* ```
* @param {string} oldName - The current key name
* @param {string} newName - The desired key name
* @param {AbortOptions} [options]
* @returns {Promise<RenamedKey>}
*/
const rename = async (oldName, newName, options = {}) => {
const key = await keychain.renameKey(oldName, newName, options)
const rename = async (oldName, newName) => {
const key = await keychain.renameKey(oldName, newName)

return {
was: oldName,
now: key.name,
Expand Down
3 changes: 1 addition & 2 deletions packages/ipfs-core/src/components/key/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ module.exports = ({ keychain }) => {
* ```
*
* @param {string} name - The name of the key to remove
* @param {import('.').AbortOptions} options
* @returns {Promise<RemovedKey>} - An object that describes the removed key
*/
const rm = (name, options) => keychain.removeKey(name, options)
const rm = (name) => keychain.removeKey(name)

return withTimeoutOption(rm)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core/src/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,6 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p
* @typedef {import('.').PeerId} PeerId
* @typedef {import('.').Options} IPFSOptions
* @typedef {import('libp2p')} LibP2P
* @typedef {import('libp2p').Options} Options
* @typedef {import('libp2p').Libp2pOptions} Options
* @typedef {import('.').IPFSConfig} IPFSConfig
*/
17 changes: 12 additions & 5 deletions packages/ipfs-core/src/components/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,28 @@ module.exports = ({ network }) => {
peerId = PeerId.createFromCID(peerId)
}

let peer = libp2p.peerStore.get(peerId)
const storedPeer = libp2p.peerStore.get(peerId)
let id = storedPeer && storedPeer.id

if (!peer) {
if (!id) {
yield { ...basePacket, text: `Looking up peer ${peerId}` }
peer = await libp2p.peerRouting.findPeer(peerId)
const remotePeer = await libp2p.peerRouting.findPeer(peerId)

id = remotePeer && remotePeer.id
}

if (!id) {
throw new Error('Peer was not found')
}

yield { ...basePacket, text: `PING ${peer.id.toB58String()}` }
yield { ...basePacket, text: `PING ${id.toB58String()}` }

let packetCount = 0
let totalTime = 0

for (let i = 0; i < options.count; i++) {
try {
const time = await libp2p.ping(peer.id)
const time = await libp2p.ping(id)
totalTime += time
packetCount++
yield { ...basePacket, time }
Expand Down
6 changes: 4 additions & 2 deletions packages/ipfs-core/src/components/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = ({ network, config }) => {
*/
async function subscribe (topic, handler, options) {
const { libp2p } = await network.use(options)
// @ts-ignore Libp2p Pubsub is deprecating the handler, using the EventEmitter
return libp2p.pubsub.subscribe(topic, handler, options)
}

Expand Down Expand Up @@ -75,6 +76,7 @@ module.exports = ({ network, config }) => {
*/
async function unsubscribe (topic, handler, options) {
const { libp2p } = await network.use(options)
// @ts-ignore Libp2p Pubsub is deprecating the handler, using the EventEmitter
libp2p.pubsub.unsubscribe(topic, handler, options)
}

Expand Down Expand Up @@ -111,7 +113,7 @@ module.exports = ({ network, config }) => {
*/
async function ls (options) {
const { libp2p } = await network.use(options)
return libp2p.pubsub.getTopics(options)
return libp2p.pubsub.getTopics()
}

/**
Expand All @@ -131,7 +133,7 @@ module.exports = ({ network, config }) => {
*/
async function peers (topic, options) {
const { libp2p } = await network.use(options)
return libp2p.pubsub.getSubscribers(topic, options)
return libp2p.pubsub.getSubscribers(topic)
}
}

Expand Down
6 changes: 4 additions & 2 deletions packages/ipfs-core/src/components/stats/bw.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option')
function getBandwidthStats (libp2p, opts) {
let stats

if (opts.peer) {
if (!libp2p.metrics) {
stats = undefined
} else if (opts.peer) {
stats = libp2p.metrics.forPeer(opts.peer)
} else if (opts.proto) {
stats = libp2p.metrics.forProtocol(opts.proto)
Expand Down Expand Up @@ -85,7 +87,7 @@ module.exports = ({ network }) => {

/**
* @typedef {Object} BWOptions
* @property {PeerId|CID|string} [peer] - Specifies a peer to print bandwidth for
* @property {PeerId} [peer] - Specifies a peer to print bandwidth for
* @property {string} [proto] - Specifies a protocol to print bandwidth for
* @property {boolean} [poll] - Is used to yield bandwidth info at an interval
* @property {number|string} [interval=1000] - The time interval to wait between updating output, if `poll` is `true`.
Expand Down
10 changes: 6 additions & 4 deletions packages/ipfs-core/src/components/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Storage {

const { peerId, keychain, isNew } = await loadRepo(repo, options)

// TODO: throw error?
// @ts-ignore On start, keychain will always be available
return new Storage(peerId, keychain, repo, print, isNew)
}
}
Expand All @@ -52,7 +54,7 @@ module.exports = Storage
*
* @param {Repo} repo
* @param {RepoOptions & InitOptions} options
* @returns {Promise<{peerId: PeerId, keychain:Keychain, isNew:boolean }>}
* @returns {Promise<{peerId: PeerId, keychain: Keychain | undefined, isNew:boolean }>}
*/
const loadRepo = async (repo, options) => {
const openError = await openRepo(repo)
Expand Down Expand Up @@ -96,7 +98,7 @@ const openRepo = async (repo) => {
/**
* @param {Repo} repo
* @param {RepoOptions & InitOptions} options
* @returns {Promise<{peerId: PeerId, keychain:Keychain}>}
* @returns {Promise<{peerId: PeerId, keychain: Keychain | undefined}>}
*/
const initRepo = async (repo, options) => {
// 1. Verify that repo does not exist yet (if it does and we could not
Expand Down Expand Up @@ -197,7 +199,7 @@ const peerIdToIdentity = (peerId) => ({
*
* @param {Repo} repo
* @param {ConfigureOptions} options
* @returns {Promise<{peerId: PeerId, keychain:Keychain}>}
* @returns {Promise<{peerId: PeerId, keychain: Keychain | undefined}>}
*/
const configureRepo = async (repo, { config, profiles, pass }) => {
const original = await repo.config.getAll()
Expand Down Expand Up @@ -297,5 +299,5 @@ const applyProfiles = (config, profiles) => {
* @typedef {import('.').IPFSConfig} IPFSConfig
* @typedef {import('../interface/repo').Repo<IPFSConfig>} Repo
* @typedef {import('libp2p-crypto').KeyType} KeyType
* @typedef {import('libp2p').LibP2PKeychain} Keychain
* @typedef {import('libp2p/src/keychain')} Keychain
*/
2 changes: 1 addition & 1 deletion packages/ipfs-core/src/components/swarm/addrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = ({ network }) => {
async function addrs (options) { // eslint-disable-line require-await
const peers = []
const { libp2p } = await network.use(options)
for (const [peerId, peer] of libp2p.peerStore.peers.entries(options)) {
for (const [peerId, peer] of libp2p.peerStore.peers.entries()) {
peers.push({
id: peerId,
addrs: peer.addresses.map((mi) => mi.multiaddr)
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core/src/components/swarm/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = ({ network }) => {
*/
async function connect (addr, options) {
const { libp2p } = await network.use(options)
return libp2p.dial(addr, options)
await libp2p.dial(addr, options)
}

return withTimeoutOption(connect)
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core/src/components/swarm/disconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = ({ network }) => {
*/
async function disconnect (addr, options) {
const { libp2p } = await network.use(options)
return libp2p.hangUp(addr, options)
return libp2p.hangUp(addr)
}

return withTimeoutOption(disconnect)
Expand Down

0 comments on commit ad978f0

Please sign in to comment.