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

feat: is multiaddr private and loopback #10

Merged
merged 5 commits into from
Oct 7, 2020

Conversation

vasco-santos
Copy link
Member

@vasco-santos vasco-santos commented Oct 6, 2020

This PR adds multiaddr isPrivate and isLoopback utilities that can be used for libp2p core and libp2p users to validate if a multiaddr address is a private/loopback network address. This will be useful for creating multiaddr sorters and filtering for dialling and advertising purposes.

Unfortunately, the already installed ip-address module does not support this for ipv4 and ipv6. As a consequence, the private-ip module was added. It has 706 Bytes minified and 312 Bytes minified and gzipped per bundlephobia, which is fine. A is-loopback-addr module was also created for a more specific check.

test/is-multiaddr-private.spec.js Outdated Show resolved Hide resolved
src/is-multiaddr-private.js Outdated Show resolved Hide resolved
@vasco-santos vasco-santos changed the title feat: is multiaddr private feat: is multiaddr private and loopback Oct 7, 2020
@vasco-santos
Copy link
Member Author

@jacobheun I created a module is-loopback-addr with a more specific check for verifying loopback addresses and added it. Also structured the utils as you suggested

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.

This looks good, just two things:

  1. Add the utilities to the README so they're easy to find.
  2. Can we add some tests for multiaddrs without IPs? (dns4, etc) Do these functions throw if there is no IP?

@vasco-santos
Copy link
Member Author

vasco-santos commented Oct 7, 2020

I added docs and more tests to both. I noticed other utils had no docs (nor jsdocs) and I will add them in a follow up PR.

Do these functions throw if there is no IP?

Yes, they throw if they are not a network address with /{ip4, ip6, dns4, dns6}/{address}/{tcp, udp}/{port} format. If other type of multiaddrs get here, they should not and I think we should throw

@vasco-santos vasco-santos mentioned this pull request Oct 7, 2020
1 task
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, the headers in the readme are off though.

README.md Outdated

Check if a given multiaddr is a loopback address.

##### Parameters
Copy link
Contributor

Choose a reason for hiding this comment

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

All the following headers are off (too many #'s)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, thanks for noticing! fixed it

@vasco-santos vasco-santos merged commit d7fa562 into master Oct 7, 2020
@vasco-santos vasco-santos deleted the feat/is-multiaddr-private branch October 7, 2020 15:02
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