Documentation
¶
Overview ¶
Package lan finds RemoHop hosts on the local network without a rendezvous server and without typing an address. A running host answers multicast DNS (mDNS, RFC 6762) questions for the DNS-SD (RFC 6763) service type _remohop._udp; `remohop lan` and the desktop app ask that question and list who answers.
What a host says about itself is a hint, never a credential: its device name, the UDP port of its QUIC listener, its 9-digit ID when it has one, and the fingerprint of its identity key. Connecting to the address runs the full session handshake, which checks the host's key like any other connection does. Nothing secret is announced.
Only what discovery needs is implemented, with the standard library and golang.org/x/net (dnsmessage for the DNS messages, ipv4 for the multicast socket options); RemoHop links no mDNS library:
- The host only answers (see Serve). It does not probe, announce itself unasked or say goodbye. It answers a question only when it came from an address on one of the host's own subnets and, where the system tells, was sent to the mDNS group; it answers by unicast to the asker, with the addresses it has on the asker's subnet, a few times a second at most.
- The browser (see Browse) asks from an ephemeral port, which makes its questions "legacy unicast" ones (RFC 6762, section 6.7): every responder answers them by unicast to that port, so the browser needs neither port 5353 nor group membership.
- IPv4 only.
Everything read from the network is bounded in size and number, and checked for form; names are cleaned of control characters.
Index ¶
Constants ¶
const ( // Service is the DNS-SD service type, in the .local domain. Service = "_remohop._udp.local." // Version is the version of the TXT record's format (its "v" key). // A later format that old browsers must not read gets a new number; // new keys alone do not need one. Version = 1 )
const DefaultWait = 2 * time.Second
DefaultWait is how long Browse listens for answers when not told.
const Setting = "lan-discovery"
Setting is the config key that turns the host's answers off. REMOHOP_LAN_DISCOVERY=0 overrides it to off.
Variables ¶
This section is empty.
Functions ¶
func Allowed ¶
Allowed reports whether a host whose config file holds values may answer discovery: unless REMOHOP_LAN_DISCOVERY says off, or the setting does.
func Serve ¶
Serve answers discovery questions until ctx ends. info is asked at each question what to say and whether to answer at all; while it says not to, the mDNS port is not held. Errors are logged (at debug level: a host without discovery works as before) and retried; Serve returns when ctx ends.
Types ¶
type Host ¶
type Host struct {
// Name is the host's device name, cleaned of control characters
// (still print it with cli.Sanitize, like any text from another
// machine).
Name string `json:"name"`
// Addr is where the host listens: an address it gave on this
// machine's subnet, or else the one its answer came from.
Addr netip.AddrPort `json:"addr"`
// ID is its 9-digit ID, if it has one.
ID string `json:"id,omitempty"`
// Fingerprint is the fingerprint of its identity key, as
// auth.Fingerprint prints it.
Fingerprint string `json:"fingerprint"`
}
Host is a RemoHop host that answered on the local network. Everything in it is what that host said about itself, checked for form only: connecting to Addr still checks the host's key in the session handshake.
type Info ¶
type Info struct {
// Name is the device name.
Name string
// ID is the 9-digit ID, or "" when the host has none (not registered
// yet, or no rendezvous server).
ID string
// Fingerprint is auth.Fingerprint of the host's identity key.
Fingerprint string
// Port is the UDP port of the host's QUIC listener.
Port uint16
// Addr is the address the host's socket is bound to. The zero value or
// an unspecified address means every address of the machine.
Addr netip.Addr
}
Info is what a host tells the local network about itself.