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

Commit

Permalink
fix: use default ws filters instead of connecting to everything (#4142)
Browse files Browse the repository at this point in the history
Fixes configuration regression, use the default websocket transport filters, e.g. only connect to wss and/or DNS addresses in the browser and anything goes in node.

Fixes: #4141
  • Loading branch information
achingbrain committed Jun 22, 2022
1 parent 0078aad commit 7be50bd
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/ipfs-core-config/package.json
Expand Up @@ -92,7 +92,7 @@
"datastore-level": "^8.0.0",
"err-code": "^3.0.1",
"hashlru": "^2.3.0",
"interface-datastore": "^6.0.2",
"interface-datastore": "^6.1.1",
"ipfs-repo": "^14.0.1",
"ipfs-utils": "^9.0.6",
"is-ipfs": "^6.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core-types/package.json
Expand Up @@ -47,7 +47,7 @@
"license": "(Apache-2.0 OR MIT)",
"dependencies": {
"@ipld/dag-pb": "^2.1.3",
"interface-datastore": "^6.0.2",
"interface-datastore": "^6.1.1",
"ipfs-unixfs": "^6.0.9",
"@multiformats/multiaddr": "^10.0.0",
"multiformats": "^9.5.1"
Expand Down
6 changes: 3 additions & 3 deletions packages/ipfs-core/package.json
Expand Up @@ -97,8 +97,8 @@
"err-code": "^3.0.1",
"hamt-sharding": "^2.0.1",
"hashlru": "^2.3.0",
"interface-blockstore": "^2.0.2",
"interface-datastore": "^6.0.2",
"interface-blockstore": "^2.0.3",
"interface-datastore": "^6.1.1",
"ipfs-bitswap": "^11.0.0",
"ipfs-core-config": "^0.4.0",
"ipfs-core-types": "^0.11.0",
Expand Down Expand Up @@ -143,7 +143,7 @@
"blockstore-datastore-adapter": "^2.0.2",
"delay": "^5.0.0",
"go-ipfs": "^0.12.1",
"interface-blockstore-tests": "^2.0.2",
"interface-blockstore-tests": "^2.0.4",
"interface-ipfs-core": "^0.155.0",
"ipfsd-ctl": "^11.0.0",
"iso-url": "^1.0.0",
Expand Down
16 changes: 10 additions & 6 deletions packages/ipfs-core/src/components/libp2p.js
Expand Up @@ -14,7 +14,6 @@ import { Bootstrap } from '@libp2p/bootstrap'
import { ipnsValidator } from 'ipns/validator'
import { ipnsSelector } from 'ipns/selector'
import { WebSockets } from '@libp2p/websockets'
import * as WebSocketsFilters from '@libp2p/websockets/filters'
import { Mplex } from '@libp2p/mplex'
import { NOISE } from '@chainsafe/libp2p-noise'

Expand Down Expand Up @@ -123,11 +122,7 @@ function getLibp2pOptions ({ options, config, datastore, keychainConfig, peerId,
contentRouters: [],
peerRouters: [],
peerDiscovery: [],
transports: [
new WebSockets({
filter: WebSocketsFilters.all
})
],
transports: [],
streamMuxers: [
new Mplex({
// temporary fix until we can limit streams on a per-protocol basis
Expand Down Expand Up @@ -221,5 +216,14 @@ function getLibp2pOptions ({ options, config, datastore, keychainConfig, peerId,
})
}

if (libp2pFinalConfig.transports == null) {
libp2pFinalConfig.transports = []
}

// add WebSocket transport if not overridden by user config
if (libp2pFinalConfig.transports.find(t => t[Symbol.toStringTag] === '@libp2p/websockets') == null) {
libp2pFinalConfig.transports.push(new WebSockets())
}

return libp2pFinalConfig
}
1 change: 1 addition & 0 deletions packages/ipfs/package.json
Expand Up @@ -75,6 +75,7 @@
},
"devDependencies": {
"@libp2p/webrtc-star-signalling-server": "^1.0.3",
"@libp2p/websockets": "^1.0.8",
"@types/semver": "^7.3.4",
"@types/update-notifier": "^5.0.0",
"aegir": "^37.0.11",
Expand Down
9 changes: 8 additions & 1 deletion packages/ipfs/test/utils/factory.js
Expand Up @@ -7,6 +7,8 @@ import * as ipfsModule from 'ipfs-core'
import goIpfs from 'go-ipfs'
import path, { dirname } from 'path'
import { fileURLToPath } from 'url'
import { WebSockets } from '@libp2p/websockets'
import { all as WebSocketsFiltersAll } from '@libp2p/websockets/filters'

const merge = mergeOpts.bind({ ignoreUndefined: true })
let __dirname = ''
Expand All @@ -25,7 +27,12 @@ const commonOptions = {
libp2p: {
dialer: {
dialTimeout: 60e3 // increase timeout because travis is slow
}
},
transports: [
new WebSockets({
filter: WebSocketsFiltersAll
})
]
}
},
endpoint: process.env.IPFSD_SERVER
Expand Down

0 comments on commit 7be50bd

Please sign in to comment.