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

Commit

Permalink
chore: throw error no swarm on multiaddrs using websocket-star
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed May 27, 2020
1 parent 80c6fdf commit 3ac8b48
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/ipfs/src/core/components/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const Components = require('./')
const createMfsPreload = require('../mfs-preload')
const { withTimeoutOption } = require('../utils')

const WEBSOCKET_STAR_PROTO_CODE = 479

module.exports = ({
apiManager,
options: constructorOptions,
Expand Down Expand Up @@ -40,6 +42,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 new Error('websocket-star swarm addresses are not supported. See https://github.com/ipfs/js-ipfs/issues/2779')
}

// 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 Expand Up @@ -130,7 +138,6 @@ module.exports = ({
apiManager.update(api, () => undefined)
} catch (err) {
cancel()
startPromise.reject(err)
throw err
}

Expand Down
24 changes: 24 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,28 @@ 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 }
})

try {
await node.start()
} catch (err) {
expect(err).to.exist()
return
}

throw new Error('should error when receiving websocket-star swarm addresses')
})
})

0 comments on commit 3ac8b48

Please sign in to comment.