Documentation
¶
Overview ¶
Package discovery finds Planck hosts on the LAN and the tailnet and picks the best path to one.
Hosts answer probes and broadcast beacons on one UDP port (DefaultPort). Every datagram is a small JSON object tagged with the protocol version.
Index ¶
- Constants
- func Announce(ctx context.Context, conn PacketWriter, b Beacon, dst []netip.AddrPort, ...) error
- func AnnounceFunc(ctx context.Context, conn PacketWriter, beacon func() Beacon, ...) error
- func BroadcastAddrs(port uint16) []netip.AddrPort
- func Listen(ctx context.Context, conn net.PacketConn, found func(Announcement)) error
- func ProbeAll(ctx context.Context, dst []netip.AddrPort, found func(Announcement)) error
- func Serve(ctx context.Context, conn net.PacketConn, b Beacon) error
- func ServeFunc(ctx context.Context, conn net.PacketConn, beacon func() Beacon) error
- type Announcement
- type Beacon
- type Candidate
- type PacketWriter
- type PathKind
- type Port
- type Racer
- type Result
- type StatusSource
Constants ¶
const ( DefaultPort = 47700 // SafeShardPayload is the media payload that fits a Tailscale 1280-byte // MTU after IPv6, UDP, and Planck's AEAD and media headers. LAN paths use // it too: spike 3 measured no gain from larger shards on wired LAN. SafeShardPayload = 1152 )
const DefaultHeadStart = 50 * time.Millisecond
DefaultHeadStart is how long each path kind probes alone before the next, worse kind starts.
const LANMaxBitrateKbps = 150_000
LANMaxBitrateKbps is the highest rate spike 3 sustained on wired LAN with 100% delivery (150 Mbps at 120 and 240 fps).
Variables ¶
This section is empty.
Functions ¶
func Announce ¶
func Announce(ctx context.Context, conn PacketWriter, b Beacon, dst []netip.AddrPort, interval time.Duration) error
Announce sends the beacon to every address in dst now and then once per interval until ctx ends. Send errors on one address do not stop the others; interfaces come and go.
func AnnounceFunc ¶
func AnnounceFunc(ctx context.Context, conn PacketWriter, beacon func() Beacon, dst []netip.AddrPort, interval time.Duration) error
AnnounceFunc is Announce with the beacon read before each round.
func BroadcastAddrs ¶
BroadcastAddrs returns the directed broadcast address of every up IPv4 interface that supports broadcast. The limited broadcast 255.255.255.255 leaves through only one interface on macOS, which misses clients on the other NIC of a multi-homed host.
func Listen ¶
func Listen(ctx context.Context, conn net.PacketConn, found func(Announcement)) error
Listen reports LAN beacons received on conn until ctx ends. Bind conn to DefaultPort on all interfaces to hear broadcasts.
func ProbeAll ¶
ProbeAll probes every address in dst at once, such as the LAN's BroadcastAddrs, and reports each reply until ctx ends: every host that answers, from the address it answered from. Each probe goes out three times, as broadcasts are easily lost on Wi-Fi.
Types ¶
type Announcement ¶
Announcement is a host found by a beacon or a probe. Addr is the host's discovery address; the control address is Addr's IP with Beacon.ControlPort.
func ProbeTailscale ¶
func ProbeTailscale(ctx context.Context, ts StatusSource, port uint16) ([]Announcement, error)
ProbeTailscale probes every online tailnet peer on port and returns the Planck hosts that answered before ctx ended, fastest first. Peers that do not answer are not errors; most tailnet devices are not Planck hosts, so ctx must carry a deadline.
func (Announcement) Candidate ¶
func (a Announcement) Candidate() Candidate
type Beacon ¶
type Beacon struct {
HostID string `json:"hostID"`
Name string `json:"name"`
ControlPort uint16 `json:"controlPort"`
CertFingerprint string `json:"certFingerprint"`
OS string `json:"os"`
GPUs []string `json:"gpus,omitempty"`
TailscaleIP string `json:"tailscaleIP,omitempty"`
}
Beacon is what a host says about itself.
func Probe ¶
Probe asks the host at addr for its beacon and measures the round trip. It resends every 100 ms until a reply arrives or ctx ends. Replies are matched by nonce, not source address: a multi-homed host may answer from another interface. RTT uses transport.Mono because Go's monotonic clock on Windows steps in about 0.5 ms, which reads a LAN round trip as zero.
type Candidate ¶
Candidate is one way to reach a host. HostID, when set, must match the beacon in the probe reply, so a stale address that now belongs to another host cannot win.
type PacketWriter ¶
PacketWriter is the sending half of a net.PacketConn, which a Port is too.
type PathKind ¶
type PathKind uint8
func (PathKind) RecommendedMaxBitrateKbps ¶
RecommendedMaxBitrateKbps is the bitrate ceiling for a path kind.
type Port ¶
type Port struct {
// contains filtered or unexported fields
}
Port is a discovery socket shared by the hosts and the browsers of one process: OpenPort gives every caller of an address the same socket, so that an app hosting and browsing at once does not bind its port twice. One reader answers probes with each host's beacon (Serve) and hands beacons to each browser (Listen).
The socket lets other processes bind the port as well. macOS and Windows deliver a broadcast to every socket on the port but a unicast datagram to the oldest one alone, so a port with no host on it that hears a probe binds its socket anew, at most once per yieldEvery, leaving unicast probes to a host in another process.
func OpenPort ¶
OpenPort binds addr, such as ":47700", or joins the socket this process already has on it. Each OpenPort needs its own Close. An address on port 0 binds a socket of its own each time.
func (*Port) Close ¶
Close lets go of the port; the last Close closes the socket and waits for its reader to end.
func (*Port) Listen ¶
func (p *Port) Listen(ctx context.Context, found func(Announcement)) error
Listen reports the beacons the port hears until ctx ends.
type Racer ¶
type Racer struct {
// HeadStart defaults to DefaultHeadStart.
HeadStart time.Duration
// Probe defaults to the package Probe function.
Probe func(ctx context.Context, addr netip.AddrPort) (Beacon, time.Duration, error)
}