Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@libp2p/utils): switch to @chainsafe/is-ip #1957

Merged
merged 2 commits into from
Aug 13, 2023

Conversation

achingbrain
Copy link
Member

@achingbrain achingbrain commented Aug 11, 2023

The @achingbrain/ip-address module is a fork of ip-address which seems to have dependencies on older modules that break modern runtimes like react native.

@Chainsafe/is-ip does not have these limitations so switch to that.

Fixes #1926

…ddress

The `@achingbrain/ip-address` module is a fork of `ip-address` which
seems to have dependencies on older modules that break modern runtimes
like react native.

`@Chainsafe/is-ip` does not have these limitations so switch to that.

Fixes #1926
@@ -19,7 +19,7 @@ describe('IP and port to Multiaddr', () => {
it('creates multiaddr from valid IPv4 in IPv6 IP and port', () => {
const ip = '0:0:0:0:0:0:101.45.75.219'
const port = '9090'
expect(ipPortToMultiaddr(ip, port).toString()).to.equal(`/ip4/101.45.75.219/tcp/${port}`)
expect(ipPortToMultiaddr(ip, port).toString()).to.equal(`/ip6/::652d:4bdb/tcp/${port}`)
Copy link
Member Author

Choose a reason for hiding this comment

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

@chainsafe/is-ip doesn't support detecting IPv4 in IPv6 addresses so we lose support for returning an IPv4 address in this case.

Node.js recognises these sorts of addresses as IPv6 so I don't know if this is a problem or not.

E.g.:

% node
Welcome to Node.js v18.14.0.
Type ".help" for more information.
> const net = require('net')
undefined
> net.isIP('0:0:0:0:0:0:101.45.75.219')
6

Copy link
Member

Choose a reason for hiding this comment

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

We should be able to detect dual ipv6 addresses by simply testing for octects (or their delimiter, a period)

Copy link
Member

Choose a reason for hiding this comment

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

I need to test the browser usecase. if this is showing as ipv6, we should be able to just wrap in brackets for URL construction.

Copy link
Member

Choose a reason for hiding this comment

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

> new URL('http://[::101.45.75.219]')
URL {
  href: 'http://[::652d:4bdb]/',
  origin: 'http://[::652d:4bdb]',
  protocol: 'http:',
  username: '',
  password: '',
  host: '[::652d:4bdb]',
  hostname: '[::652d:4bdb]',
  port: '',
  pathname: '/',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

Copy link
Member

@SgtPooki SgtPooki Aug 11, 2023

Choose a reason for hiding this comment

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

> new URL('http://[0:0:0:0:0:0:101.45.75.219]')
URL {
  href: 'http://[::652d:4bdb]/',
  origin: 'http://[::652d:4bdb]',
  protocol: 'http:',
  username: '',
  password: '',
  host: '[::652d:4bdb]',
  hostname: '[::652d:4bdb]',
  port: '',
  pathname: '/',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

seems like it should be fine

@achingbrain achingbrain changed the title fix(@libp2p/utils): use @chainsafe/is-ip instead of @achingbrain/ip-a… fix(@libp2p/utils): switch to @chainsafe/is-ip Aug 11, 2023
Copy link
Member

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

Need to confirm dualIpv6 support in browser before approving

Comment on lines +38 to +40
const errMsg = `invalid ip:port for creating a multiaddr: ${ip}:${port}`
log.error(errMsg)
throw new CodeError(errMsg, Errors.ERR_INVALID_IP)
Copy link
Member

Choose a reason for hiding this comment

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

This is so much cleaner than the previous code

@@ -19,7 +19,7 @@ describe('IP and port to Multiaddr', () => {
it('creates multiaddr from valid IPv4 in IPv6 IP and port', () => {
const ip = '0:0:0:0:0:0:101.45.75.219'
const port = '9090'
expect(ipPortToMultiaddr(ip, port).toString()).to.equal(`/ip4/101.45.75.219/tcp/${port}`)
expect(ipPortToMultiaddr(ip, port).toString()).to.equal(`/ip6/::652d:4bdb/tcp/${port}`)
Copy link
Member

Choose a reason for hiding this comment

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

We should be able to detect dual ipv6 addresses by simply testing for octects (or their delimiter, a period)

@@ -19,7 +19,7 @@ describe('IP and port to Multiaddr', () => {
it('creates multiaddr from valid IPv4 in IPv6 IP and port', () => {
const ip = '0:0:0:0:0:0:101.45.75.219'
const port = '9090'
expect(ipPortToMultiaddr(ip, port).toString()).to.equal(`/ip4/101.45.75.219/tcp/${port}`)
expect(ipPortToMultiaddr(ip, port).toString()).to.equal(`/ip6/::652d:4bdb/tcp/${port}`)
Copy link
Member

Choose a reason for hiding this comment

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

I need to test the browser usecase. if this is showing as ipv6, we should be able to just wrap in brackets for URL construction.

@SgtPooki
Copy link
Member

I gave approval, but I expect this will break one scenario: consumers of dualIpv6 addresses that don't support ipv6 used to get an ipv4 multiaddr they could use; they won't anymore.

@achingbrain
Copy link
Member Author

It seems weird to me that we’d accept a v6 address and return a v4 one, not what I would expect.

@achingbrain achingbrain merged commit 18567b7 into master Aug 13, 2023
19 checks passed
@achingbrain achingbrain deleted the fix/use-chainsafe-is-ip branch August 13, 2023 07:11
This was referenced Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

switch to @chainsafe/is-ip (away from @achingbrain/ip-address)
2 participants