From 5d085a6f4196c4213a37be4a9f405d2478bec3f7 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 26 Feb 2022 09:19:18 -0800 Subject: [PATCH] controlhttp: add some docs, change Dial's path from /switch to /ts2021 When I deployed server-side changes, I put the upgrade handler at /ts2021 instead of /switch. We could move the server to /switch, but ts2021 seems more specific and better, but I don't feel strongly. Updates #3488 Change-Id: Ifbf8ea60a815fd2fa1bfbe1b7af1ac2a27218354 Signed-off-by: Brad Fitzpatrick --- control/controlhttp/client.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/control/controlhttp/client.go b/control/controlhttp/client.go index bf07a1a29..c9db75025 100644 --- a/control/controlhttp/client.go +++ b/control/controlhttp/client.go @@ -40,11 +40,19 @@ import ( "tailscale.com/types/key" ) -// upgradeHeader is the value of the Upgrade HTTP header used to -// indicate the Tailscale control protocol. const ( - upgradeHeaderValue = "tailscale-control-protocol" + // upgradeHeader is the value of the Upgrade HTTP header used to + // indicate the Tailscale control protocol. + upgradeHeaderValue = "tailscale-control-protocol" + + // handshakeHeaderName is the HTTP request header that can + // optionally contain base64-encoded initial handshake + // payload, to save an RTT. handshakeHeaderName = "X-Tailscale-Handshake" + + // serverUpgradePath is where the server-side HTTP handler to + // to do the protocol switch is located. + serverUpgradePath = "/ts2021" ) // Dial connects to the HTTP server at addr, requests to switch to the @@ -53,6 +61,9 @@ const ( // // If Dial fails to connect using addr, it also tries to tunnel over // TLS to :443 as a compatibility fallback. +// +// The provided ctx is only used for the initial connection, until +// Dial returns. It does not affect the connection once established. func Dial(ctx context.Context, addr string, machineKey key.MachinePrivate, controlKey key.MachinePublic) (*controlbase.Conn, error) { host, port, err := net.SplitHostPort(addr) if err != nil { @@ -92,7 +103,7 @@ func (a *dialParams) dial() (*controlbase.Conn, error) { u := &url.URL{ Scheme: "http", Host: net.JoinHostPort(a.host, a.httpPort), - Path: "/switch", + Path: serverUpgradePath, } conn, httpErr := a.tryURL(u, init) if httpErr == nil {