From d3d503d9977ed0b3b9a0240ea6c8d7790f4d5358 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 6 Dec 2021 14:58:29 -0800 Subject: [PATCH] ipn/ipnlocal: add HTTP/2 h2c server support to peerapi on non-mobile platforms To make ExitDNS cheaper. Might not finish client-side support in December before 1.20, but at least server support can start rolling out ahead of clients being ready for it. Tested with curl against peerapi. Updates #1713 Change-Id: I676fed5fb1aef67e78c542a3bc93bddd04dd11fe Signed-off-by: Brad Fitzpatrick --- cmd/tailscaled/depaware.txt | 4 +++- ipn/ipnlocal/peerapi.go | 7 +++++++ ipn/ipnlocal/peerapi_h2c.go | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 ipn/ipnlocal/peerapi_h2c.go diff --git a/cmd/tailscaled/depaware.txt b/cmd/tailscaled/depaware.txt index 7e3e88fd7..5b72d243a 100644 --- a/cmd/tailscaled/depaware.txt +++ b/cmd/tailscaled/depaware.txt @@ -275,7 +275,9 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de golang.org/x/net/dns/dnsmessage from net+ golang.org/x/net/http/httpguts from net/http+ golang.org/x/net/http/httpproxy from net/http - golang.org/x/net/http2/hpack from net/http + golang.org/x/net/http2 from golang.org/x/net/http2/h2c+ + golang.org/x/net/http2/h2c from tailscale.com/ipn/ipnlocal + golang.org/x/net/http2/hpack from net/http+ golang.org/x/net/idna from golang.org/x/net/http/httpguts+ golang.org/x/net/ipv4 from golang.zx2c4.com/wireguard/device golang.org/x/net/ipv6 from golang.zx2c4.com/wireguard/device+ diff --git a/ipn/ipnlocal/peerapi.go b/ipn/ipnlocal/peerapi.go index 1746a4d7e..1fa9e2122 100644 --- a/ipn/ipnlocal/peerapi.go +++ b/ipn/ipnlocal/peerapi.go @@ -46,6 +46,10 @@ import ( var initListenConfig func(*net.ListenConfig, netaddr.IP, *interfaces.State, string) error +// addH2C is non-nil on platforms where we want to add H2C +// ("cleartext" HTTP/2) support to the peerAPI. +var addH2C func(*http.Server) + type peerAPIServer struct { b *LocalBackend rootDir string // empty means file receiving unavailable @@ -492,6 +496,9 @@ func (pln *peerAPIListener) serve() { httpServer := &http.Server{ Handler: h, } + if addH2C != nil { + addH2C(httpServer) + } go httpServer.Serve(&oneConnListener{Listener: pln.ln, conn: c}) } } diff --git a/ipn/ipnlocal/peerapi_h2c.go b/ipn/ipnlocal/peerapi_h2c.go new file mode 100644 index 000000000..3888db8d9 --- /dev/null +++ b/ipn/ipnlocal/peerapi_h2c.go @@ -0,0 +1,22 @@ +// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build !ios && !android +// +build !ios,!android + +package ipnlocal + +import ( + "net/http" + + "golang.org/x/net/http2" + "golang.org/x/net/http2/h2c" +) + +func init() { + addH2C = func(s *http.Server) { + h2s := &http2.Server{} + s.Handler = h2c.NewHandler(s.Handler, h2s) + } +}