holepunchto / hyperswarm

A distributed networking stack for connecting peers.
https://docs.holepunch.to
MIT License
1.06k stars 85 forks source link

Expose IP and port of connected peers #97

Open gmaclennan opened 2 years ago

gmaclennan commented 2 years ago

Currently neither the socket or peerInfo objects returned from swarm.on('connection') expose the IP or port of the connected peer. This is a feature request to expose this information.

Our use-case is to use to IP to determine if the peer is local (e.g. if the IP is in a private range 10.0.0.0, 172.16.0.0, 192.168.0.0).

It would also be really great to expose this to opts.firewall, so that we could auto-reject non-local connections if we want to ensure that nothing connects online.

@mafintosh

smoyer64 commented 2 years ago

Reference for those unfamiliar with private network space (I've had so many problems when these networks collide within an organization): https://datatracker.ietf.org/doc/html/rfc1918

mafintosh commented 2 years ago

We already know internally if it's a local connection, so we should prob bubble that up additionally vs just the ip - the ip is fine as well, but a user shouldn't be required to analyse that i think.

smoyer64 commented 2 years ago

@mafintosh - I haven't looked at the v3 code as much be in v2 didn't it consider a loopback IP address local?

gmaclennan commented 2 years ago

We already know internally if it's a local connection, so we should prob bubble that up additionally vs just the ip - the ip is fine as well, but a user shouldn't be required to analyse that i think.

For our use-case, just knowing if it is a local connection would be all the information we need. We don't need the IP.

mafintosh commented 2 years ago

@smoyer64 it uses this https://github.com/mafintosh/bogon/blob/master/index.js to map how to holepunch to people

mafintosh commented 2 years ago

Tracking issue here: https://github.com/hyperswarm/dht/issues/76