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

Commit

Permalink
chore: update libp2p to 0.30 (#3427)
Browse files Browse the repository at this point in the history
Integrates `[email protected]` release.

BREAKING CHANGE: The websocket transport will only dial DNS+WSS addresses - see https://github.com/libp2p/js-libp2p-websockets/releases/tag/v0.15.0

Co-authored-by: Hugo Dias <[email protected]>
  • Loading branch information
vasco-santos and hugomrdias authored Jan 15, 2021
1 parent c5f0bc5 commit a39e6fb
Show file tree
Hide file tree
Showing 37 changed files with 141 additions and 87 deletions.
1 change: 1 addition & 0 deletions examples/browser-exchange-files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"ipfs": "^0.52.2",
"it-all": "^1.0.4",
"libp2p-websockets": "^0.15.0",
"rimraf": "^3.0.2",
"test-ipfs-example": "^2.0.3"
},
Expand Down
16 changes: 16 additions & 0 deletions examples/browser-exchange-files/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
'use strict'

const IPFS = require('ipfs')
const WS = require('libp2p-websockets')
const filters = require('libp2p-websockets/src/filters')
const transportKey = WS.prototype[Symbol.toStringTag]

const all = require('it-all')
const uint8ArrayConcat = require('uint8arrays/concat')
const uint8ArrayFromString = require('uint8arrays/from-string')
Expand Down Expand Up @@ -59,6 +63,18 @@ async function start () {
},
// If you want to connect to the public bootstrap nodes, remove the next line
Bootstrap: []
},
libp2p: {
config: {
transport: {
// This is added for local demo!
// In a production environment the default filter should be used
// where only DNS + WSS addresses will be dialed by websockets in the browser.
[transportKey]: {
filter: filters.all
}
}
}
}
})

Expand Down
1 change: 1 addition & 0 deletions examples/circuit-relaying/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"delay": "^4.4.0",
"ipfs": "^0.52.2",
"ipfs-pubsub-room": "^2.0.1",
"libp2p-websockets": "^0.15.0",
"uint8arrays": "^1.1.0"
},
"devDependencies": {
Expand Down
15 changes: 15 additions & 0 deletions examples/circuit-relaying/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
'use strict'

const IPFS = require('ipfs')
const WS = require('libp2p-websockets')
const filters = require('libp2p-websockets/src/filters')
const transportKey = WS.prototype[Symbol.toStringTag]
const Helpers = require('./helpers')

document.addEventListener('DOMContentLoaded', async () => {
Expand Down Expand Up @@ -38,6 +41,18 @@ document.addEventListener('DOMContentLoaded', async () => {
},
config: {
Bootstrap: []
},
libp2p: {
config: {
transport: {
// This is added for local demo!
// In a production environment the default filter should be used
// where only DNS + WSS addresses will be dialed by websockets in the browser.
[transportKey]: {
filter: filters.all
}
}
}
}
})

Expand Down
1 change: 1 addition & 0 deletions packages/interface-ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"it-map": "^1.0.4",
"it-pushable": "^1.4.0",
"libp2p-crypto": "^0.18.0",
"libp2p-websockets": "^0.15.0",
"multiaddr": "^8.0.0",
"multibase": "^3.0.0",
"multihashing-async": "^2.0.1",
Expand Down
8 changes: 5 additions & 3 deletions packages/interface-ipfs-core/src/bitswap/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const { nanoid } = require('nanoid')
const uint8ArrayFromString = require('uint8arrays/from-string')
const pmap = require('p-map')
const multihashing = require('multihashing-async')
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')

const makeBlock = async () => {
const d = uint8ArrayFromString(`IPFS is awesome ${nanoid()}`)
Expand All @@ -25,6 +26,7 @@ const makeBlock = async () => {
* @param {Object} options
*/
module.exports = (factory, options) => {
const ipfsOptions = getIpfsOptions()
const describe = getDescribe(options)
const it = getIt(options)

Expand All @@ -37,7 +39,7 @@ module.exports = (factory, options) => {
it('2 peers', async function () {
// webworkers are not dialable because webrtc is not available
const remote = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api
const local = (await factory.spawn()).api
const local = (await factory.spawn({ type: 'proc', ipfsOptions })).api
await local.swarm.connect(remote.peerId.addresses[0])
const block = await makeBlock()

Expand All @@ -51,7 +53,7 @@ module.exports = (factory, options) => {
const blocks = await Promise.all([...Array(6).keys()].map(() => makeBlock()))
const remote1 = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api
const remote2 = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api
const local = (await factory.spawn()).api
const local = (await factory.spawn({ type: 'proc', ipfsOptions })).api
await local.swarm.connect(remote1.peerId.addresses[0])
await local.swarm.connect(remote2.peerId.addresses[0])
await remote1.swarm.connect(remote2.peerId.addresses[0])
Expand All @@ -75,7 +77,7 @@ module.exports = (factory, options) => {
it('2 peers', async () => {
const content = randomBytes(1024 * 1024 * 10)
const remote = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api
const local = (await factory.spawn()).api
const local = (await factory.spawn({ type: 'proc', ipfsOptions })).api
local.swarm.connect(remote.peerId.addresses[0])

const file = await remote.add({ path: 'awesome.txt', content })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ const { getDescribe, getIt } = require('../utils/mocha')
const { waitForWantlistKey } = require('./utils')
const { isWebWorker } = require('ipfs-utils/src/env')
const testTimeout = require('../utils/test-timeout')
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const ipfsOptions = getIpfsOptions()
const describe = getDescribe(options)
const it = getIt(options)

Expand All @@ -23,7 +25,7 @@ module.exports = (common, options) => {
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'

before(async () => {
ipfsA = (await common.spawn()).api
ipfsA = (await common.spawn({ type: 'proc', ipfsOptions })).api
// webworkers are not dialable because webrtc is not available
ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
// Add key to the wantlist for ipfsB
Expand Down
4 changes: 3 additions & 1 deletion packages/interface-ipfs-core/src/bitswap/wantlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ const testTimeout = require('../utils/test-timeout')
const AbortController = require('native-abort-controller')
const CID = require('cids')
const delay = require('delay')
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const ipfsOptions = getIpfsOptions()
const describe = getDescribe(options)
const it = getIt(options)

Expand All @@ -26,7 +28,7 @@ module.exports = (common, options) => {
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'

before(async () => {
ipfsA = (await common.spawn()).api
ipfsA = (await common.spawn({ type: 'proc', ipfsOptions })).api
// webworkers are not dialable because webrtc is not available
ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
// Add key to the wantlist for ipfsB
Expand Down
4 changes: 3 additions & 1 deletion packages/interface-ipfs-core/src/miscellaneous/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ const { getDescribe, getIt, expect } = require('../utils/mocha')
const all = require('it-all')
const { isWebWorker } = require('ipfs-utils/src/env')
const testTimeout = require('../utils/test-timeout')
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const ipfsOptions = getIpfsOptions()
const describe = getDescribe(options)
const it = getIt(options)

Expand All @@ -25,7 +27,7 @@ module.exports = (common, options) => {
let ipfs

before(async () => {
ipfs = (await common.spawn()).api
ipfs = (await common.spawn({ type: 'proc', ipfsOptions })).api
})

after(() => common.clean())
Expand Down
4 changes: 3 additions & 1 deletion packages/interface-ipfs-core/src/ping/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ const all = require('it-all')
const drain = require('it-drain')
const { isWebWorker } = require('ipfs-utils/src/env')
const testTimeout = require('../utils/test-timeout')
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const ipfsOptions = getIpfsOptions()
const describe = getDescribe(options)
const it = getIt(options)

Expand All @@ -24,7 +26,7 @@ module.exports = (common, options) => {
let ipfsB

before(async () => {
ipfsA = (await common.spawn()).api
ipfsA = (await common.spawn({ type: 'proc', ipfsOptions })).api
// webworkers are not dialable because webrtc is not available
ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
await ipfsA.swarm.connect(ipfsB.peerId.addresses[0])
Expand Down
4 changes: 3 additions & 1 deletion packages/interface-ipfs-core/src/pubsub/peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ const { getDescribe, getIt, expect } = require('../utils/mocha')
const delay = require('delay')
const { isWebWorker } = require('ipfs-utils/src/env')
const testTimeout = require('../utils/test-timeout')
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const ipfsOptions = getIpfsOptions()
const describe = getDescribe(options)
const it = getIt(options)

Expand All @@ -25,7 +27,7 @@ module.exports = (common, options) => {
let subscribedTopics = []

before(async () => {
ipfs1 = (await common.spawn()).api
ipfs1 = (await common.spawn({ type: 'proc', ipfsOptions })).api
// webworkers are not dialable because webrtc is not available
ipfs2 = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
ipfs3 = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
Expand Down
4 changes: 3 additions & 1 deletion packages/interface-ipfs-core/src/pubsub/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ const { getDescribe, getIt, expect } = require('../utils/mocha')
const delay = require('delay')
const AbortController = require('native-abort-controller')
const { isWebWorker, isNode } = require('ipfs-utils/src/env')
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const ipfsOptions = getIpfsOptions()
const describe = getDescribe(options)
const it = getIt(options)

Expand All @@ -30,7 +32,7 @@ module.exports = (common, options) => {
let subscribedTopics = []

before(async () => {
ipfs1 = (await common.spawn()).api
ipfs1 = (await common.spawn({ type: 'proc', ipfsOptions })).api
// TODO 'multiple connected nodes' tests fails with go in Firefox
// and JS is flaky everywhere

Expand Down
4 changes: 3 additions & 1 deletion packages/interface-ipfs-core/src/swarm/addrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ const Multiaddr = require('multiaddr')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { isWebWorker } = require('ipfs-utils/src/env')
const testTimeout = require('../utils/test-timeout')
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const ipfsOptions = getIpfsOptions()
const describe = getDescribe(options)
const it = getIt(options)

Expand All @@ -23,7 +25,7 @@ module.exports = (common, options) => {
let ipfsB

before(async () => {
ipfsA = (await common.spawn()).api
ipfsA = (await common.spawn({ type: 'proc', ipfsOptions })).api
// webworkers are not dialable because webrtc is not available
ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
await ipfsA.swarm.connect(ipfsB.peerId.addresses[0])
Expand Down
4 changes: 3 additions & 1 deletion packages/interface-ipfs-core/src/swarm/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { isWebWorker } = require('ipfs-utils/src/env')
const testTimeout = require('../utils/test-timeout')
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const ipfsOptions = getIpfsOptions()
const describe = getDescribe(options)
const it = getIt(options)

Expand All @@ -20,7 +22,7 @@ module.exports = (common, options) => {
let ipfsB

before(async () => {
ipfsA = (await common.spawn()).api
ipfsA = (await common.spawn({ type: 'proc', ipfsOptions })).api
// webworkers are not dialable because webrtc is not available
ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
})
Expand Down
4 changes: 3 additions & 1 deletion packages/interface-ipfs-core/src/swarm/disconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { isWebWorker } = require('ipfs-utils/src/env')
const testTimeout = require('../utils/test-timeout')
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const ipfsOptions = getIpfsOptions()
const describe = getDescribe(options)
const it = getIt(options)

Expand All @@ -21,7 +23,7 @@ module.exports = (common, options) => {
let ipfsB

before(async () => {
ipfsA = (await common.spawn()).api
ipfsA = (await common.spawn({ type: 'proc', ipfsOptions })).api
// webworkers are not dialable because webrtc is not available
ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
})
Expand Down
Loading

0 comments on commit a39e6fb

Please sign in to comment.