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 addresses and hosts for mdns connections, and listen only on ip4 #69

Closed
gmaclennan opened this issue Feb 2, 2023 · 2 comments
Closed
Assignees

Comments

@gmaclennan
Copy link
Member

The way we lookup server addresses and socket addresses is not quite correct, and we should only listen on ip4. It means that although everything works on localhost, and works in tests, I do not think that everything will work as expected on a real network.

server.address() as used here returns the address that the server is bound to by the OS. Since we create the server with no options, this will default to 0.0.0.0 on ip4 and :: on ip6. On an OS that supports ip6 (my Mac for instance) server.address().address will be ::. We are using this as the host name that we are advertising on mdns.

We should not pass a hostname to mdns, and instead rely on the mdns module to create a correct hostname (which will be a .local address) for the mdns record. In addition we should probably specify server.listen({ host: '0.0.0.0', port: 0 }) to force the server to only listen on ip4, but to listen on all addresses (e.g. local and non-local).

For connecting to a peer when discovering a service via mdns, we use the service.host property. This will be hostname.local. normally, but since we are specifying host when we advertise the service it will be either :: or 0.0.0.0. This will work in tests (since connecting to this will work locally) it will not work on a real network. We should use the addresses property of the resolved service record. This will always have at least one entry, and any of the entries should work for connecting.

For the address of an incoming connection from a peer, we use socket.address(). This will not be the address of the peer, but rather be the locally bound address - the same same as returned by server.address(). To get the address of the incoming connection we need socket.remoteAddress and socket.remotePort.

@tomasciccola
Copy link
Contributor

I think solving #68 will solve this, so I can assign it to myself.

@gmaclennan
Copy link
Member Author

This should be fixed in the latest implementation

@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Mapeo - Sprint 2023 (Archived) Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

3 participants