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

Commit a39e6fb

Browse files
chore: update libp2p to 0.30 (#3427)
Integrates `libp2p@0.30` 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 <hugomrdias@gmail.com>
1 parent c5f0bc5 commit a39e6fb

37 files changed

+141
-87
lines changed

examples/browser-exchange-files/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"dependencies": {
2121
"ipfs": "^0.52.2",
2222
"it-all": "^1.0.4",
23+
"libp2p-websockets": "^0.15.0",
2324
"rimraf": "^3.0.2",
2425
"test-ipfs-example": "^2.0.3"
2526
},

examples/browser-exchange-files/public/app.js

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
'use strict'
33

44
const IPFS = require('ipfs')
5+
const WS = require('libp2p-websockets')
6+
const filters = require('libp2p-websockets/src/filters')
7+
const transportKey = WS.prototype[Symbol.toStringTag]
8+
59
const all = require('it-all')
610
const uint8ArrayConcat = require('uint8arrays/concat')
711
const uint8ArrayFromString = require('uint8arrays/from-string')
@@ -59,6 +63,18 @@ async function start () {
5963
},
6064
// If you want to connect to the public bootstrap nodes, remove the next line
6165
Bootstrap: []
66+
},
67+
libp2p: {
68+
config: {
69+
transport: {
70+
// This is added for local demo!
71+
// In a production environment the default filter should be used
72+
// where only DNS + WSS addresses will be dialed by websockets in the browser.
73+
[transportKey]: {
74+
filter: filters.all
75+
}
76+
}
77+
}
6278
}
6379
})
6480

examples/circuit-relaying/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"delay": "^4.4.0",
1818
"ipfs": "^0.52.2",
1919
"ipfs-pubsub-room": "^2.0.1",
20+
"libp2p-websockets": "^0.15.0",
2021
"uint8arrays": "^1.1.0"
2122
},
2223
"devDependencies": {

examples/circuit-relaying/src/app.js

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
'use strict'
33

44
const IPFS = require('ipfs')
5+
const WS = require('libp2p-websockets')
6+
const filters = require('libp2p-websockets/src/filters')
7+
const transportKey = WS.prototype[Symbol.toStringTag]
58
const Helpers = require('./helpers')
69

710
document.addEventListener('DOMContentLoaded', async () => {
@@ -38,6 +41,18 @@ document.addEventListener('DOMContentLoaded', async () => {
3841
},
3942
config: {
4043
Bootstrap: []
44+
},
45+
libp2p: {
46+
config: {
47+
transport: {
48+
// This is added for local demo!
49+
// In a production environment the default filter should be used
50+
// where only DNS + WSS addresses will be dialed by websockets in the browser.
51+
[transportKey]: {
52+
filter: filters.all
53+
}
54+
}
55+
}
4156
}
4257
})
4358

packages/interface-ipfs-core/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"it-map": "^1.0.4",
5656
"it-pushable": "^1.4.0",
5757
"libp2p-crypto": "^0.18.0",
58+
"libp2p-websockets": "^0.15.0",
5859
"multiaddr": "^8.0.0",
5960
"multibase": "^3.0.0",
6061
"multihashing-async": "^2.0.1",

packages/interface-ipfs-core/src/bitswap/transfer.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const { nanoid } = require('nanoid')
1111
const uint8ArrayFromString = require('uint8arrays/from-string')
1212
const pmap = require('p-map')
1313
const multihashing = require('multihashing-async')
14+
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')
1415

1516
const makeBlock = async () => {
1617
const d = uint8ArrayFromString(`IPFS is awesome ${nanoid()}`)
@@ -25,6 +26,7 @@ const makeBlock = async () => {
2526
* @param {Object} options
2627
*/
2728
module.exports = (factory, options) => {
29+
const ipfsOptions = getIpfsOptions()
2830
const describe = getDescribe(options)
2931
const it = getIt(options)
3032

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

@@ -51,7 +53,7 @@ module.exports = (factory, options) => {
5153
const blocks = await Promise.all([...Array(6).keys()].map(() => makeBlock()))
5254
const remote1 = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api
5355
const remote2 = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api
54-
const local = (await factory.spawn()).api
56+
const local = (await factory.spawn({ type: 'proc', ipfsOptions })).api
5557
await local.swarm.connect(remote1.peerId.addresses[0])
5658
await local.swarm.connect(remote2.peerId.addresses[0])
5759
await remote1.swarm.connect(remote2.peerId.addresses[0])
@@ -75,7 +77,7 @@ module.exports = (factory, options) => {
7577
it('2 peers', async () => {
7678
const content = randomBytes(1024 * 1024 * 10)
7779
const remote = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api
78-
const local = (await factory.spawn()).api
80+
const local = (await factory.spawn({ type: 'proc', ipfsOptions })).api
7981
local.swarm.connect(remote.peerId.addresses[0])
8082

8183
const file = await remote.add({ path: 'awesome.txt', content })

packages/interface-ipfs-core/src/bitswap/wantlist-for-peer.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ const { getDescribe, getIt } = require('../utils/mocha')
55
const { waitForWantlistKey } = require('./utils')
66
const { isWebWorker } = require('ipfs-utils/src/env')
77
const testTimeout = require('../utils/test-timeout')
8+
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')
89

910
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
1011
/**
1112
* @param {Factory} common
1213
* @param {Object} options
1314
*/
1415
module.exports = (common, options) => {
16+
const ipfsOptions = getIpfsOptions()
1517
const describe = getDescribe(options)
1618
const it = getIt(options)
1719

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

2527
before(async () => {
26-
ipfsA = (await common.spawn()).api
28+
ipfsA = (await common.spawn({ type: 'proc', ipfsOptions })).api
2729
// webworkers are not dialable because webrtc is not available
2830
ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
2931
// Add key to the wantlist for ipfsB

packages/interface-ipfs-core/src/bitswap/wantlist.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ const testTimeout = require('../utils/test-timeout')
88
const AbortController = require('native-abort-controller')
99
const CID = require('cids')
1010
const delay = require('delay')
11+
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')
1112

1213
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
1314
/**
1415
* @param {Factory} common
1516
* @param {Object} options
1617
*/
1718
module.exports = (common, options) => {
19+
const ipfsOptions = getIpfsOptions()
1820
const describe = getDescribe(options)
1921
const it = getIt(options)
2022

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

2830
before(async () => {
29-
ipfsA = (await common.spawn()).api
31+
ipfsA = (await common.spawn({ type: 'proc', ipfsOptions })).api
3032
// webworkers are not dialable because webrtc is not available
3133
ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
3234
// Add key to the wantlist for ipfsB

packages/interface-ipfs-core/src/miscellaneous/resolve.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ const { getDescribe, getIt, expect } = require('../utils/mocha')
1010
const all = require('it-all')
1111
const { isWebWorker } = require('ipfs-utils/src/env')
1212
const testTimeout = require('../utils/test-timeout')
13+
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')
1314

1415
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
1516
/**
1617
* @param {Factory} common
1718
* @param {Object} options
1819
*/
1920
module.exports = (common, options) => {
21+
const ipfsOptions = getIpfsOptions()
2022
const describe = getDescribe(options)
2123
const it = getIt(options)
2224

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

2729
before(async () => {
28-
ipfs = (await common.spawn()).api
30+
ipfs = (await common.spawn({ type: 'proc', ipfsOptions })).api
2931
})
3032

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

packages/interface-ipfs-core/src/ping/ping.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ const all = require('it-all')
77
const drain = require('it-drain')
88
const { isWebWorker } = require('ipfs-utils/src/env')
99
const testTimeout = require('../utils/test-timeout')
10+
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')
1011

1112
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
1213
/**
1314
* @param {Factory} common
1415
* @param {Object} options
1516
*/
1617
module.exports = (common, options) => {
18+
const ipfsOptions = getIpfsOptions()
1719
const describe = getDescribe(options)
1820
const it = getIt(options)
1921

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

2628
before(async () => {
27-
ipfsA = (await common.spawn()).api
29+
ipfsA = (await common.spawn({ type: 'proc', ipfsOptions })).api
2830
// webworkers are not dialable because webrtc is not available
2931
ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
3032
await ipfsA.swarm.connect(ipfsB.peerId.addresses[0])

packages/interface-ipfs-core/src/pubsub/peers.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ const { getDescribe, getIt, expect } = require('../utils/mocha')
66
const delay = require('delay')
77
const { isWebWorker } = require('ipfs-utils/src/env')
88
const testTimeout = require('../utils/test-timeout')
9+
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')
910

1011
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
1112
/**
1213
* @param {Factory} common
1314
* @param {Object} options
1415
*/
1516
module.exports = (common, options) => {
17+
const ipfsOptions = getIpfsOptions()
1618
const describe = getDescribe(options)
1719
const it = getIt(options)
1820

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

2729
before(async () => {
28-
ipfs1 = (await common.spawn()).api
30+
ipfs1 = (await common.spawn({ type: 'proc', ipfsOptions })).api
2931
// webworkers are not dialable because webrtc is not available
3032
ipfs2 = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
3133
ipfs3 = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api

packages/interface-ipfs-core/src/pubsub/subscribe.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ const { getDescribe, getIt, expect } = require('../utils/mocha')
1111
const delay = require('delay')
1212
const AbortController = require('native-abort-controller')
1313
const { isWebWorker, isNode } = require('ipfs-utils/src/env')
14+
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')
1415

1516
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
1617
/**
1718
* @param {Factory} common
1819
* @param {Object} options
1920
*/
2021
module.exports = (common, options) => {
22+
const ipfsOptions = getIpfsOptions()
2123
const describe = getDescribe(options)
2224
const it = getIt(options)
2325

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

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

packages/interface-ipfs-core/src/swarm/addrs.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ const Multiaddr = require('multiaddr')
66
const { getDescribe, getIt, expect } = require('../utils/mocha')
77
const { isWebWorker } = require('ipfs-utils/src/env')
88
const testTimeout = require('../utils/test-timeout')
9+
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')
910

1011
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
1112
/**
1213
* @param {Factory} common
1314
* @param {Object} options
1415
*/
1516
module.exports = (common, options) => {
17+
const ipfsOptions = getIpfsOptions()
1618
const describe = getDescribe(options)
1719
const it = getIt(options)
1820

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

2527
before(async () => {
26-
ipfsA = (await common.spawn()).api
28+
ipfsA = (await common.spawn({ type: 'proc', ipfsOptions })).api
2729
// webworkers are not dialable because webrtc is not available
2830
ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
2931
await ipfsA.swarm.connect(ipfsB.peerId.addresses[0])

packages/interface-ipfs-core/src/swarm/connect.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
const { getDescribe, getIt, expect } = require('../utils/mocha')
55
const { isWebWorker } = require('ipfs-utils/src/env')
66
const testTimeout = require('../utils/test-timeout')
7+
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')
78

89
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
910
/**
1011
* @param {Factory} common
1112
* @param {Object} options
1213
*/
1314
module.exports = (common, options) => {
15+
const ipfsOptions = getIpfsOptions()
1416
const describe = getDescribe(options)
1517
const it = getIt(options)
1618

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

2224
before(async () => {
23-
ipfsA = (await common.spawn()).api
25+
ipfsA = (await common.spawn({ type: 'proc', ipfsOptions })).api
2426
// webworkers are not dialable because webrtc is not available
2527
ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
2628
})

packages/interface-ipfs-core/src/swarm/disconnect.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
const { getDescribe, getIt, expect } = require('../utils/mocha')
55
const { isWebWorker } = require('ipfs-utils/src/env')
66
const testTimeout = require('../utils/test-timeout')
7+
const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all')
78

89
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
910
/**
1011
* @param {Factory} common
1112
* @param {Object} options
1213
*/
1314
module.exports = (common, options) => {
15+
const ipfsOptions = getIpfsOptions()
1416
const describe = getDescribe(options)
1517
const it = getIt(options)
1618

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

2325
before(async () => {
24-
ipfsA = (await common.spawn()).api
26+
ipfsA = (await common.spawn({ type: 'proc', ipfsOptions })).api
2527
// webworkers are not dialable because webrtc is not available
2628
ipfsB = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
2729
})

0 commit comments

Comments
 (0)