Skip to content

Replace Embedded Functionality with mdns library (written in C) #45

Description

@CMCDragonkai

Specification

Migrate the existing embedded MDNS functionality in js-mdns to use the lightweight, portable C library mjansson/mdns via Rust FFI bindings. Implement a hybrid discovery model:

  1. Prefer OS-native MDNS stacks (Avahi on Linux, Bonjour on macOS, etc.) when available.
  2. Fallback to embedded mjansson/mdns when OS-native stacks are unavailable (e.g., Docker containers, minimal OS environments).

The MDNS class must:

  • Manage all multicast group lifecycle state explicitly when using the embedded library.
  • Remain stateless when delegating to OS-native stacks (rely on their managed state).
  • Support cross-platform multicast discovery (IPv4/IPv6) on Linux, macOS, and Windows.

Additional Context

Tasks

  1. Create Rust FFI bindings for mjansson/mdns:

  2. Integrate Rust module with Node.js:

    • Use napi-rs or similar to expose functionality via Node.js N-API.
    • Design JS API mirroring current js-mdns interface for backward compatibility.
  3. Implement OS-native stack detection:

    • Linux: Check for Avahi DBus service (dbus-send or socket presence).
    • macOS: Verify Bonjour/mDNSResponder availability via dns-sd CLI or headers.
    • Windows: Validate Bonjour SDK installation/registry entries.
    • Return detection status to JS layer.
  4. Implement hybrid mode:

    • If OS-native stack detected:
      • Delegate advertisement/discovery to native APIs (Avahi/Bonjour bindings).
    • Else:
      • Use embedded mjansson/mdns via Rust bindings.
      • Explicitly manage multicast group joins/leaves per interface.
      • Handle TXT record serialization/parsing in Rust.
  5. State management for embedded mode:

    • MDNS class to track:
      • Active multicast sockets per interface.
      • Service advertisement TTLs.
      • Discovery query intervals.
    • Ensure resource cleanup (socket closure, group leaves) on shutdown.
  6. Testing & CI/CD:

    • Add cross-platform tests for hybrid mode:
      • Native stack available (Linux host).
      • Embedded fallback (Docker bridge network).
    • Verify Windows firewall allows multicast traffic during tests.
    • Build ARM binaries for container/embedded use.
  7. Documentation:

    • Update README with hybrid mode explanation.
    • Add troubleshooting guide for multicast firewall rules.
    • Note Docker-specific considerations (e.g., --network host vs. bridge).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions