Repository Documentation Index: docs/README.md
This document describes the configuration options for the mDNS service discovery module.
The mDNS module supports various configuration options for service broadcasting and discovery.
Configure the mDNS server in code:
type ServerConfig struct {
DeviceID string // Stable device ID
Name string // Device name
Version string // Software version
Port int // API port (default 18800)
Iface *net.Interface // Network interface to bind (optional)
}- Type:
string - Required: Yes
- Description: Stable, unique identifier for the device
The DeviceID should be:
- Persistent across restarts
- Unique within the network
- Typically a UUID or hash of hardware identifiers
Example:
DeviceID: "moonhub-abc123def456"- Type:
string - Required: Yes
- Description: Human-readable device name displayed during discovery
Example:
Name: "Living Room MoonHub"- Type:
string - Required: Yes
- Description: Software version for compatibility checking
Example:
Version: "1.0.0"- Type:
int - Default:
18800 - Description: TCP port for the API server
The API port must:
- Match the actual HTTP server port
- Be accessible on the local network
- Not conflict with other services
Example:
Port: 18800- Type:
*net.Interface - Default:
nil(all interfaces) - Description: Specific network interface to bind
Use this to:
- Bind to a specific network adapter
- Avoid broadcasting on unwanted interfaces
- Support multi-homed systems
Example:
// Bind to specific interface
iface, _ := net.InterfaceByName("eth0")
Iface: ifaceThe service broadcasts the following TXT records:
| Key | Type | Description |
|---|---|---|
id |
string | Device ID (matches DeviceID) |
name |
string | Device name (matches Name) |
version |
string | Software version (matches Version) |
TXT records are used for:
- Device identification without connection
- Version compatibility checking
- Displaying device info in discovery UI
The mDNS client uses timeout-based discovery:
type ClientConfig struct {
Timeout time.Duration // Discovery timeout
ServiceName string // Service to discover (default: _moonhub._tcp)
}- Type:
time.Duration - Default:
5 * time.Second - Description: Maximum time to wait for discovery
Longer timeouts:
- Find more devices on larger networks
- Increase user wait time
- May be needed for slow networks
Example:
client := mdns.NewClient(10 * time.Second)| Port | Protocol | Usage |
|---|---|---|
| 5353 | UDP | mDNS multicast |
| 18800 | TCP | API server |
- IPv4:
224.0.0.251 - IPv6:
ff02::fb
Ensure the following are allowed:
- UDP port 5353 for mDNS
- TCP port 18800 for API access
server := mdns.NewServer(mdns.ServerConfig{
DeviceID: generateDeviceID(),
Name: "My MoonHub",
Version: "1.0.0",
Port: 18800,
})
server.Start(context.Background())// Get WiFi interface
wifiIface, _ := net.InterfaceByName("wlan0")
server := mdns.NewServer(mdns.ServerConfig{
DeviceID: deviceID,
Name: "My MoonHub",
Version: "1.0.0",
Port: 18800,
Iface: wifiIface,
})// 10 second timeout for larger networks
client := mdns.NewClient(10 * time.Second)
devices, err := client.Discover(context.Background())- Check firewall allows UDP 5353
- Verify devices are on same subnet
- Try increasing discovery timeout
- Check mDNS service running with
dns-sd -B _moonhub._tcp local.
- Verify server started without error
- Check port 18800 is available
- Verify network interface is up
- Check logs for mDNS errors
- mDNS works only on local network (same subnet)
- Device discovery may take up to the configured timeout
- Service broadcast continues until server is stopped
- Multiple MoonHub instances on same network are supported