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

chore: throw error no swarm on multiaddrs using websocket-star #3051

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions packages/ipfs/src/core/components/start.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
'use strict'

const log = require('debug')('ipfs:components:start')
const Bitswap = require('ipfs-bitswap')
const multiaddr = require('multiaddr')
const get = require('dlv')
const defer = require('p-defer')
const errCode = require('err-code')
const IPNS = require('../ipns')
const routingConfig = require('../ipns/routing/config')
const { AlreadyInitializedError, NotEnabledError } = require('../errors')
const Components = require('./')
const createMfsPreload = require('../mfs-preload')
const { withTimeoutOption } = require('../utils')

const WEBSOCKET_STAR_PROTO_CODE = 479

module.exports = ({
apiManager,
options: constructorOptions,
Expand All @@ -26,6 +30,8 @@ module.exports = ({
repo
}) => withTimeoutOption(async function start () {
const startPromise = defer()
startPromise.promise.catch((err) => log(err))

const { cancel } = apiManager.update({ start: () => startPromise.promise })

try {
Expand All @@ -41,6 +47,12 @@ module.exports = ({
config.Addresses.Swarm.forEach(addr => {
let ma = multiaddr(addr)

// Temporary error for users migrating using websocket-star multiaddrs for listenning on libp2p
// websocket-star support was removed from ipfs and libp2p
if (ma.protoCodes().includes(WEBSOCKET_STAR_PROTO_CODE)) {
throw errCode(new Error('websocket-star swarm addresses are not supported. See https://github.com/ipfs/js-ipfs/issues/2779'), 'ERR_WEBSOCKET_STAR_SWARM_ADDR_NOT_SUPPORTED')
}

// multiaddrs that go via a signalling server or other intermediary (e.g. stardust,
// webrtc-star) can have the intermediary's peer ID in the address, so append our
// peer ID to the end of it
Expand Down
17 changes: 17 additions & 0 deletions packages/ipfs/test/core/create-node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,21 @@ describe('create node', function () {

await node.stop()
})

it('should error when receiving websocket-star swarm addresses', async () => {
const node = await IPFS.create({
repo: tempRepo,
init: { bits: 512 },
start: false,
config: {
Addresses: {
Swarm: ['/ip4/127.0.0.1/tcp/13579/wss/p2p-websocket-star']
},
Bootstrap: []
},
preload: { enabled: false }
})

await expect(node.start()).to.eventually.be.rejected().with.property('code', 'ERR_WEBSOCKET_STAR_SWARM_ADDR_NOT_SUPPORTED')
})
})