mdns

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package mdns advertises the bridge on the local network as _onebit-bridge._tcp.local. so iOS clients can auto-discover on LAN.

mDNS only works on the same broadcast domain (no routing across the internet, unlikely to traverse Tailscale reliably). It's a LAN convenience — once paired, the iOS app stores the Tailscale IP or public hostname for remote access. The TXT records include the advertised protocolVersion so the iOS client can refuse incompatible versions before even attempting a TLS handshake.

Index

Constants

View Source
const Service = "_onebit-bridge._tcp"

Service is the Bonjour service type the bridge registers under. Underscore prefix is mandatory for DNS-SD service types.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advertiser

type Advertiser struct {
	// contains filtered or unexported fields
}

Advertiser wraps a running mDNS server. Close to stop advertising; safe for concurrent callers.

Internally manages a re-advertise goroutine that watches for network-interface changes and rebuilds the underlying mDNS server when the IP set drifts. The goroutine's lifetime is tied to Close().

func Advertise(cfg Config) (*Advertiser, error)

Advertise starts advertising Service with the given config. Returns an error if the underlying UDP sockets can't be opened (typically a permissions issue on Linux without cap_net_bind).

On success, spawns a background goroutine that polls the advertise-eligible interface set every defaultRebindInterval (60 s) and rebuilds the underlying mDNS server when the IP set drifts — hashicorp/mdns snapshots IPs at construction time and never re- binds, so without this loop a Wi-Fi roam / Ethernet plug / docking- station handoff silently kills discovery until process restart. Goroutine stops on Close().

func (*Advertiser) Close

func (a *Advertiser) Close() error

Close stops the advertisement and the rebind loop. Safe to call multiple times and from concurrent goroutines. hashicorp/mdns's Shutdown() tears down the UDP listeners but does NOT send TTL-0 "goodbye" packets, so clients may see a stale entry until the record's TTL expires.

type Config

type Config struct {
	// InstanceName is the human-friendly name shown in the iOS picker
	// (e.g. "Arsenie's 1-bit Bridge"). Spaces are allowed; control chars
	// and dots are stripped.
	InstanceName string

	// Port the bridge's HTTPS listener is bound to.
	Port int

	// Hostname advertised in the SRV record. If empty, os.Hostname is
	// used. Trailing dots stripped; ".local." appended for Bonjour
	// compliance.
	Hostname string

	// ProtocolVersion is advertised in the TXT record as "pv=<N>" so
	// clients can version-gate at discovery time.
	ProtocolVersion int

	// LibraryName is advertised in the TXT record as "library=<name>"
	// so the iOS picker can display it alongside the instance name.
	LibraryName string
}

Config controls what's advertised. InstanceName and Port are the only required fields; the rest are derived if empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL