Skip to content

Add mDNS Peer Discovery Capability#23

Merged
mikelsr merged 6 commits intomasterfrom
feat/mdns-discovery
Sep 18, 2025
Merged

Add mDNS Peer Discovery Capability#23
mikelsr merged 6 commits intomasterfrom
feat/mdns-discovery

Conversation

@lthibault
Copy link
Copy Markdown
Contributor

This PR adds mDNS (multicast DNS) peer discovery capability to Wetware, allowing nodes to automatically discover and connect to other Wetware instances on the local network without manual configuration.

Features

  • --with-mdns capability flag - Enables mDNS peer discovery in both ww shell and ww run commands
  • Automatic peer discovery - Discovers other Wetware nodes on the local network using mDNS
  • Peer management - Automatically adds discovered peers to the libp2p peerstore
  • Conditional initialization - mDNS service only starts when the capability flag is enabled
  • Proper lifecycle management - Clean startup and shutdown of mDNS services

Implementation Details

Dependencies

  • Updated libp2p to v0.43.0 for mDNS support
  • Added libp2p/zeroconf/v2 for mDNS implementation
  • Updated related dependencies for compatibility

Core Changes

1. Capability Flag (cmd/internal/flags/flags.go)

&cli.BoolFlag{
    Name:     "with-mdns",
    Category: "CAPABILITIES", 
    Usage:    "grant mDNS peer discovery capability",
    EnvVars:  []string{"WW_WITH_MDNS"},
}

2. mDNS Implementation (cmd/ww/run/env.go)

  • Added MDNS field to EnvConfig and Env structs
  • Implemented MDNSPeerHandler to manage discovered peers
  • Added conditional mDNS service initialization in EnvConfig.New()
  • Integrated mDNS service lifecycle with environment cleanup

3. Command Integration

  • Run command: Passes --with-mdns flag to EnvConfig
  • Shell command: Forwards --with-mdns flag to run subprocess

Usage

Enable mDNS in Shell Mode

ww shell --with-mdns

Enable mDNS in Run Mode

ww run --with-mdns /path/to/binary

Enable All Capabilities (including mDNS)

ww shell --with-all

Testing

The implementation has been tested to ensure:

  • ✅ mDNS service only starts when --with-mdns flag is used
  • ✅ No mDNS service created when flag is not provided
  • ✅ Proper logging when mDNS service starts
  • ✅ Clean integration with existing capability system
  • ✅ Both shell and run commands work correctly

Architecture

The mDNS discovery is implemented in the run process environment, following the existing pattern where:

  1. The shell command spawns a run subprocess
  2. The run process manages the libp2p host and mDNS service
  3. Capability flags are passed from shell to run process
  4. mDNS service automatically discovers peers and adds them to the peerstore

Backward Compatibility

  • No breaking changes to existing functionality
  • mDNS is opt-in via capability flag
  • Existing commands work unchanged without the flag

- Update libp2p to v0.43.0 for mDNS support
- Add libp2p/zeroconf/v2 for mDNS implementation
- Update related dependencies for compatibility
Add mDNS peer discovery capability flag to the capability flags list.
This allows users to enable mDNS discovery when running wetware commands.
- Add MDNS field to EnvConfig and Env structs
- Implement MDNSPeerHandler to manage discovered peers
- Add conditional mDNS service initialization in EnvConfig.New()
- Integrate mDNS service lifecycle with environment cleanup
- Add proper logging for mDNS service startup and peer discovery

The mDNS service automatically discovers peers on the local network
and adds them to the libp2p peerstore for connection.
- Update run command to pass MDNS flag to EnvConfig
- Update shell command to pass --with-mdns flag to run subprocess
- Enable mDNS discovery when --with-mdns or --with-all flags are used

This allows users to enable mDNS peer discovery in both run and shell
modes by using the --with-mdns capability flag.
@lthibault lthibault requested a review from mikelsr September 18, 2025 04:32
@lthibault lthibault self-assigned this Sep 18, 2025
@lthibault lthibault added the enhancement New feature or request label Sep 18, 2025
@mikelsr
Copy link
Copy Markdown
Member

mikelsr commented Sep 18, 2025

In merging #21 and #22 I seem to have caused merge conflicts

@mikelsr
Copy link
Copy Markdown
Member

mikelsr commented Sep 18, 2025

Solved!

@mikelsr mikelsr merged commit 65ca914 into master Sep 18, 2025
0 of 2 checks passed
@mikelsr mikelsr deleted the feat/mdns-discovery branch September 19, 2025 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants