Client connects to a [Server] over a WireGuard tunnel relayed through DERP. Populate Server (the only required field, or use the [NewClient] shorthand), then just dial: [Client.Dial], [Client.DialTCPPort], and [Client.DialTCP] lazily establish the tunnel on first use, picking defaults for any unset
| 1397 | // and is useful to test connectivity first or to measure the relay |
| 1398 | // round-trip time. |
| 1399 | type Client struct { |
| 1400 | // Server is the token identifying the server to connect to. |
| 1401 | // It is required and must be set before the client's first use. |
| 1402 | Server ConnBlob |
| 1403 | |
| 1404 | // Key is the client's node identity, which servers can allowlist. |
| 1405 | // If zero, a new ephemeral key is generated at first use. |
| 1406 | // If set, it must be set before the client's first use. |
| 1407 | Key key.NodePrivate |
| 1408 | |
| 1409 | // Logf is the logger used for debug messages. If nil, log.Printf |
| 1410 | // is used. If set, it must be set before the client's first use. |
| 1411 | Logf logger.Logf |
| 1412 | |
| 1413 | // DERPMapURL, if non-empty, is an alternate URL to fetch the DERP |
| 1414 | // map from when the token doesn't embed the relay details. |
| 1415 | // If empty, [DefaultDERPMapURL] is used. If set, it must be set |
| 1416 | // before the client's first use. |
| 1417 | DERPMapURL string |
| 1418 | |
| 1419 | // DERPMapCache, if non-nil, caches fetched DERP maps. If nil, a |
| 1420 | // process-wide in-memory cache is used. If set, it must be set |
| 1421 | // before the client's first use. |
| 1422 | DERPMapCache DERPMapCache |
| 1423 | |
| 1424 | lb *locoBackend |
| 1425 | ci ConnInfo // of server |
| 1426 | meowWait chan struct{} // closed on first meowed message from server |
| 1427 | |
| 1428 | serverAddr netip.Addr |
| 1429 | |
| 1430 | startMu sync.Mutex // guards key, started, and the one-time startup work |
| 1431 | key key.NodePrivate // the effective node identity; Key or generated |
| 1432 | started bool |
| 1433 | |
| 1434 | upDone atomic.Bool // whether the server has meowed us at least once |
| 1435 | } |
| 1436 | |
| 1437 | // nodeKeyLocked returns the client's effective node private key, |
| 1438 | // resolving it from the Key field (or generating a fresh one) on |
nothing calls this directly
no outgoing calls
no test coverage detected