Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

feat: custom address filter #116

Merged
merged 3 commits into from
Nov 24, 2020

Conversation

vasco-santos
Copy link
Member

This PR adds a custom address filter to websockets. Long story short, libp2p-websockets has allowed TCP and DNS addresses, both with ws or wss.

Considering libp2p/js-libp2p#796 . Taking into account security (and browser policies), we should be restricting addresses to DNS only (unless in development), as well as supporting wss only in the browser (Node.js still permits ws).

This PR aims to set the defaults as specified above, but also adding support for a custom address filter. This is super useful for development, but also if anyone wants to connect to a local TCP loopback peer.

This PR also makes some filters available for users and the dependencies were updated. Libp2p will be able to custom this via its config per transport.

BREAKING CHANGE: Only DNS addresses are now returned on filter by default. WSS when in the browser and WS+WSS for Node.js. This can be overriden by the filter option.

BREAKING CHANGE: Only DNS addresses are now returned on filter by default. WSS when in the browser and WS+WSS for Node.js. This can be overritten by the filter option.
@@ -35,7 +35,25 @@
> npm i libp2p-websockets
```

### Example
### Constructor properties
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this is a good time to just replace this example with how to use it in a libp2p configuration with the passed options. That's likely much more useful than the existing examples as most people won't use this standalone.

README.md Outdated
const WS = require('libp2p-websockets')
const filters = require('libp2p-websockets/src/filters')

const ws = new WS({ upgrader, filter: filters.all })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think the libp2p transport configuration example will be ideal here, https://github.com/libp2p/js-libp2p/blob/master/doc/CONFIGURATION.md#customizing-transports.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the libp2p usage example, but kept the other. They could still be relevant, but the Readme might get too noisy. What's your opinion?

src/index.js Outdated
return filters.dnsWss(multiaddrs)
}

return filters.dnsWsOrWss(multiaddrs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably be all in Node, because a TCP dial on ws is valid. We don't need crypto because we use Noise.

We might need to double check that node doesn't block this though. I think our tests are only using loopback addresses right now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a non loopback addr test to a local addr

Copy link
Contributor

@jacobheun jacobheun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a small correction and some recommendations.

README.md Outdated
const transportKey = Websockets.prototype[Symbol.toStringTag]
const node = await Libp2p.create({
modules: {
transport: [WebRTCStar],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
transport: [WebRTCStar],
transport: [Websockets],

README.md Outdated
const node = await Libp2p.create({
modules: {
transport: [WebRTCStar],
// ... other mandatory modules
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just add NOISE and mplex in here. There aren't other options right now, so having a config people can just use would be helpful imo.

README.md Outdated

For more information see [libp2p/js-libp2p/doc/CONFIGURATION.md#customizing-transports](https://github.com/libp2p/js-libp2p/blob/master/doc/CONFIGURATION.md#customizing-transports).

## Base Example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just delete this whole section, nobody should use it like this.

@vasco-santos vasco-santos merged commit 711c721 into master Nov 24, 2020
@vasco-santos vasco-santos deleted the feat/custom-address-filter-for-transport branch November 24, 2020 09:14
@vasco-santos
Copy link
Member Author

Released this with beta tag until libp2p@0.30

beta: 0.15.0
latest: 0.14.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants