Skip to content

Commit 391fa0a

Browse files
Merge pull request #519 from daschwanden:feature/http2
PiperOrigin-RevId: 650525181
2 parents 1779566 + 5b111d5 commit 391fa0a

File tree

12 files changed

+59
-18
lines changed

12 files changed

+59
-18
lines changed

fleetspeak/src/client/https/https.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import (
3636
"github.com/google/fleetspeak/fleetspeak/src/client/comms"
3737
"github.com/google/fleetspeak/fleetspeak/src/client/stats"
3838
"github.com/google/fleetspeak/fleetspeak/src/common"
39+
40+
"golang.org/x/net/http2"
3941
)
4042

4143
const (
@@ -92,7 +94,17 @@ func makeTransport(cctx comms.Context, dc func(ctx context.Context, network, add
9294
proxy = http.ProxyURL(si.Proxy)
9395
}
9496

95-
return ci.ID, &http.Transport{
97+
// We'll make the Transport configurable so we can be both backwards compatible but also forward looking
98+
nextProtos := []string{"http/1.1"}
99+
preferHttp2 := false
100+
if cctx.CommunicatorConfig() != nil {
101+
preferHttp2 = cctx.CommunicatorConfig().PreferHttp2
102+
}
103+
if preferHttp2 {
104+
nextProtos = []string{"h2", "http/1.1"}
105+
}
106+
107+
tr := &http.Transport{
96108
Proxy: proxy,
97109
TLSClientConfig: &tls.Config{
98110
RootCAs: si.TrustedCerts,
@@ -110,12 +122,18 @@ func makeTransport(cctx comms.Context, dc func(ctx context.Context, network, add
110122
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
111123
VerifyPeerCertificate: cv,
112124
ServerName: si.ServerName,
125+
NextProtos: nextProtos,
113126
},
114127
MaxIdleConns: 10,
115128
DialContext: dc,
116129
TLSHandshakeTimeout: 10 * time.Second,
117130
ExpectContinueTimeout: 1 * time.Second,
118-
}, certBytes, nil
131+
}
132+
133+
if preferHttp2 {
134+
err = http2.ConfigureTransport(tr)
135+
}
136+
return ci.ID, tr, certBytes, err
119137
}
120138

121139
// jitter adds up to 50% random jitter, and converts to time.Duration.

fleetspeak/src/client/https/streaming.go

+1
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ func (c *StreamingCommunicator) connect(ctx context.Context, host string, maxLif
345345
c.cctx.Stats().OutboundContactData(host, len(buf), err)
346346
return fail(err)
347347
}
348+
log.V(2).Infof("POST to %v succeeded with status: %v and protocol: %v", host, resp.StatusCode, resp.Proto)
348349
c.cctx.Stats().OutboundContactData(host, len(buf), nil)
349350
body := bufio.NewReader(resp.Body)
350351
cd, err := ret.readContact(body)

fleetspeak/src/client/proto/fleetspeak_client/client.pb.go

+27-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fleetspeak/src/client/proto/fleetspeak_client/client.proto

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ message CommunicatorConfig {
3737
//
3838
// No compression is applied if unset.
3939
fleetspeak.CompressionAlgorithm compression = 6;
40+
41+
// If set, the client will prefer comms with HTTP2 Transport
42+
bool prefer_http2 = 7;
4043
}
4144

4245
// ClientState contains the state of the client which should be persisted across
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
prefer_http2: true

sandboxes/cleartext-header-mode/envoy-https-http.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ static_resources:
8080
common_tls_context:
8181
validation_context:
8282
trust_chain_verification: ACCEPT_UNTRUSTED
83+
alpn_protocols: ["h2,http/1.1"]
8384
tls_certificates:
8485
# The following self-signed certificate pair is generated using:
8586
# $ openssl req -x509 -newkey rsa:2048 -keyout a/front-proxy-key.pem -out a/front-proxy-crt.pem -days 3650 -nodes -subj '/CN=front-envoy'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
prefer_http2: true

sandboxes/cleartext-xfcc-mode/envoy-https-http.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static_resources:
4747
common_tls_context:
4848
validation_context:
4949
trust_chain_verification: ACCEPT_UNTRUSTED
50+
alpn_protocols: ["h2,http/1.1"]
5051
tls_certificates:
5152
# The following self-signed certificate pair is generated using:
5253
# $ openssl req -x509 -newkey rsa:2048 -keyout a/front-proxy-key.pem -out a/front-proxy-crt.pem -days 3650 -nodes -subj '/CN=front-envoy'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
prefer_http2: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
prefer_http2: true

sandboxes/https-header-mode/envoy-https-https.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ static_resources:
8080
common_tls_context:
8181
validation_context:
8282
trust_chain_verification: ACCEPT_UNTRUSTED
83+
alpn_protocols: ["h2,http/1.1"]
8384
tls_certificates:
8485
# The following self-signed certificate pair is generated using:
8586
# $ openssl req -x509 -newkey rsa:2048 -keyout a/front-proxy-key.pem -out a/front-proxy-crt.pem -days 3650 -nodes -subj '/CN=front-envoy'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
prefer_http2: true

0 commit comments

Comments
 (0)