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 (#3051)
Browse files Browse the repository at this point in the history
On `[email protected]`, we removed the `websocket-star` module from the libp2p default configuration for browser nodes in `js-ipfs`. We removed it because this module was not refactored during #1670, since the libp2p goal is to [sunset the star protocols](libp2p/js-libp2p#385) and we preferred to use the time refactoring `websocket-star` into improving the browser support.

In the refactor, the `webrtc-star` module was refactored so that browser users could discover other peers in the network. In addition, `circuit-relay` may be used for establishing connections between browser nodes using `websockets`.

However, this migration has not been smooth for `js-ipfs` users. Users previously using `websocket-star` swarm addresses, did not have enough visibility of this change, since the removal of `websocket-star` was transparent for them and on the default `js-ipfs` release and not technically a programmable breaking change. 

With the above in mind, once `js-ipfs` users updated they started getting errors from `js-libp2p` in scenarios where they were providing only `websocket-star` swarm addresses. When `js-libp2p` receives listening multiaddrs, it throws an error if it cannot use any to listen on the configured transports, which was the case here (For instance #2779).

In `js-libp2p`, we added an option to tolerate these errors [libp2p/js-libp2p#643](libp2p/js-libp2p#643), which was also mentioned for some other cases earlier.

After syncing about this issue, we decided to temporarily throw an error when `js-ipfs` receives `websocket-star` multiaddrs. This aims to help users who still need to migrate to identify the problem faster.
  • Loading branch information
vasco-santos authored Jun 22, 2020
1 parent a93d6d9 commit b9db5d4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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')
})
})

0 comments on commit b9db5d4

Please sign in to comment.