Repository navigation
Description
I run a private DERP relay that can't answer STUN. It's a Cloudflare Worker, so it has no UDP: https://github.com/cnupy/derp-worker. To give clients STUN I want a region with the relay as a relay-only node plus a couple of STUN-only nodes.
tailcfg already expresses that with STUNOnly. The tailcat address format drops it, though. wireNode has no field for the flag (wire.go:57 in v0.8.0) and wireRegionOf skips STUN-only nodes (wire.go:88), so a client that gets the address never sees the STUN servers. main is the same.
My workaround is to list the STUN servers as plain nodes after the relay. derphttp tries the nodes in order and the relay comes first, so it works today. But those entries now look like DERP servers, and if the relay is down a client tries to dial the STUN hosts as DERP.
Could the wire format carry STUNOnly instead of dropping those nodes? It's one omitempty field in wireNode and removing the skip, so addresses without STUN-only nodes keep the same bytes. derphttp already skips STUN-only nodes when it dials (derp/derphttp/derphttp_client.go:717) and netcheck probes every node in the region, so nothing else needs to change.
Another option would be a STUN server list on Client and Server, kept out of the address. That keeps addresses short, but each side has to be configured.
The change in wire.go:
@@ type wireNode struct {
InsecureForTests bool `cbor:"x,omitempty" json:"InsecureForTests,omitempty"`
+
+ // STUNOnly marks a node that only answers STUN, such as a public
+ // STUN server listed next to a relay that can't do UDP. derphttp
+ // never dials it for DERP; netcheck still probes it. Clients that
+ // predate this field ignore it and see a node whose DERP dial fails.
+ STUNOnly bool `cbor:"o,omitempty" json:"STUNOnly,omitempty"`
}
@@ func wireRegionOf(r *tailcfg.DERPRegion) *wireRegion {
for _, n := range r.Nodes {
- if n.STUNOnly {
- continue
- }
w.Nodes = append(w.Nodes, &wireNode{
@@
InsecureForTests: n.InsecureForTests,
+ STUNOnly: n.STUNOnly,
})
@@ func (w *wireRegion) derpRegion() *tailcfg.DERPRegion {
InsecureForTests: n.InsecureForTests,
+ STUNOnly: n.STUNOnly,
})The tests check that an address made by current main still parses, that a region without STUN-only nodes encodes to the same bytes as before, and that a STUN-only node survives the round trip.
I have a patch with tests for this approach and can open a PR if it looks right.
Activity
brofranks commentedon Nov 23, 2026
Sidenote: your Cloudflare Worker DERP server is cool! I was looking into getting something similar running with AWS WebSockets, but its lack of support for binary frames and two-hour connection time limit seemed like they might be issues. Didn't realize Cloudflare Workers didn't have these limitations.