MatrixAI / js-mdns

Multicast DNS Stack for TypeScript/JavaScript Applications
https://matrixai.github.io/js-mdns/
Apache License 2.0
0 stars 0 forks source link

React to network topology changes #12

Open amydevs opened 1 year ago

amydevs commented 1 year ago

Specification

We should react to the adding or removing network interfaces. This will mean we need to close and open sockets and manage our resource record cache accordingly

Additional context

The RFC provides guidelines on what to do for topology changes https://datatracker.ietf.org/doc/html/rfc6762#section-10.3

Tasks

  1. [ ] Create and close sockets based on connected/disconnected network interfaces. - 2 days
CMCDragonkai commented 1 year ago

How does one detect changes to the network? Would it just be a matter of polling the os.networkInterfaces()?

Actually a trick question, because we had worked on this problem a long time ago in Matrix OS. The most efficient way is to make use of netlink sockets to subscribe to OS network changes. However that's not portable and is specific to Linux ecosystem.

We had worked on a netlink interface in Haskell before but didn't get very far... I can see that there's https://github.com/mildsunrise/node_netlink which seems maintained, but it would have to be an entirely different library if we were to wrap it ourselves.

CMCDragonkai commented 1 year ago

Again such a thing would be platform-specific again. So that would have to be relegated to a later date. The easiest solution for now is just to poll os.networkInterfaces() every second.