lan

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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
)
View Source
const DefaultWait = 2 * time.Second

DefaultWait is how long Browse listens for answers when not told.

View Source
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

func Allowed(values map[string]string) bool

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

func Serve(ctx context.Context, info func() (Info, bool), log *slog.Logger)

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.

func Browse

func Browse(ctx context.Context, wait time.Duration) ([]Host, error)

Browse asks the local network for RemoHop hosts and returns those that answered within wait (DefaultWait if 0), sorted by name. It returns early, with what it found, when ctx ends.

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.

func (Info) TXT

func (i Info) TXT() []string

TXT returns the host's TXT record strings: the format version, the name, the ID if there is one, and the key fingerprint.

Jump to

Keyboard shortcuts

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