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

MacOS multicast bound socket is unable to receive multicast packets, so MacOS hosts can only facilitate local same-device discovery #29

Open
amydevs opened this issue Oct 19, 2023 · 1 comment
Labels
bug Something isn't working r&d:polykey:core activity 4 End to End Networking behind Consumer NAT Devices

Comments

@amydevs
Copy link
Contributor

amydevs commented Oct 19, 2023

Describe the bug

The sockets on MacOS binded to ::0 and 0.0.0.0 are not able to receive incoming multicast packets despite having addMembership called. Despite this, these sockets are still able to receive the multicast packets sent on the same interface with IP_MULTICAST_LOOP enabled.

This behavior is not exhibited with Linux hosts.

The MacOS system dns-sd command is able to find registered services from other devices made by our MDNS stack. This means that the only explanation our MDNS stack on a MacOS host not finding the registered service is that the the socket.addMembership is silently failing, or we are passing it incorrect parameters on MacOS specifically.

If this is not fixed, js-mdns on MacOS would only be able to facilitate discovery on the same device

To Reproduce

import type { Hostname, Port } from '@/types';
import * as events from '@/events';
import MDNS from '@/MDNS';

describe(MDNS.name, () => {
  let mdns1: MDNS;
  let mdns2: MDNS;

  beforeEach(async () => {
    mdns1 = new MDNS();
    mdns2 = new MDNS();
  });
  afterEach(async () => {
    await mdns1.stop();
    await mdns2.stop();
  });
  test('register', async () => {
    const mdnsPort = 5353 as Port;
    const mdns2Hostname = 'polykey2' as Hostname;
    await mdns2.start({ hostname: mdns2Hostname, port: mdnsPort, groups: ['224.0.0.251'] });
    const service = {
      name: 'test2',
      port: mdnsPort,
      protocol: 'udp',
      type: 'polykey',
    } as Parameters<typeof MDNS.prototype.registerService>[0];
    mdns2.registerService(service);
    await new Promise(() => {})
  });
  test('query', async () => {
    const mdnsPort = 5353 as Port;
    const mdns1Hostname = 'polykey2' as Hostname;
    await mdns1.start({
      hostname: mdns1Hostname,
      port: mdnsPort,
      advertise: false,
    });
    mdns1.startQuery({
      protocol: 'udp',
      type: 'polykey',
    });
    await new Promise((resolve) => {
      mdns1.addEventListener(
        events.EventMDNSService.name,
        (e: events.EventMDNSService) => {
          console.log(e);
          resolve(null);
        },
      );
    });
  });
});

Run npm run test -- -t 'register' on a non-MacOS system.
Run npm run test -- -t 'query' on a MacOS system.

The expectation is that an event will be logged on the MacOS system for the service being discovered. A console.log can also be put after handleSocketMessage under if (packet.id === this._id) return; to show that no incoming multicast packets have been received. (must be placed after this statement, so that packets sent by the MacOS host itself are filtered out)

Expected behavior

Incoming multicast packets should be correctly received by the the multicast sockets bound by MDNS.

Screenshots

Platform (please complete the following information)

  • Device: Macmini9,1
  • OS: MacOS 13.1 (Build 22C65)
  • Version: v20.5.1

Additional context

Notify maintainers

@amydevs

@amydevs amydevs added the bug Something isn't working label Oct 19, 2023
@CMCDragonkai
Copy link
Member

Check if ciao has the same problem.

@amydevs amydevs changed the title MacOS multicast bound socket is unable to receive multicast packets MacOS multicast bound socket is unable to receive multicast packets, so MacOS hosts can only facilitate local same-device discovery Oct 23, 2023
@CMCDragonkai CMCDragonkai added the r&d:polykey:core activity 4 End to End Networking behind Consumer NAT Devices label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working r&d:polykey:core activity 4 End to End Networking behind Consumer NAT Devices
Development

No branches or pull requests

2 participants