Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quic: splitting into client and server #24513

Merged
merged 2 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
206 changes: 171 additions & 35 deletions bazel/external/quiche.BUILD

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion source/common/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ envoy_cc_library(
"//source/common/network:filter_lib",
"//source/common/runtime:runtime_features_lib",
] + envoy_select_enable_http3([
"//source/common/quic:codec_lib",
"//source/common/quic:client_codec_lib",
]),
)

Expand Down Expand Up @@ -340,6 +340,7 @@ envoy_cc_library(
"//source/common/http/match_delegate:config",
"//source/common/network:proxy_protocol_filter_state_lib",
"//source/common/network:utility_lib",
"//source/common/quic:quic_server_factory_stub_lib",
"//source/common/router:config_lib",
"//source/common/router:scoped_rds_lib",
"//source/common/stats:timespan_lib",
Expand Down
2 changes: 1 addition & 1 deletion source/common/http/codec_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "source/common/http/utility.h"

#ifdef ENVOY_ENABLE_QUIC
#include "source/common/quic/codec_impl.h"
#include "source/common/quic/client_codec_impl.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no source/common/http/codec_server.cc to correspond to this current file? I guess not. How come?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the client side of Envoy, creating upstream QUIC clients :-P
The server bits are in the HCM, and I turned that into factory code to avoid the direct dependency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, yeah I get that this particular file (codec_client.cc) is for making upstream connections. But I guess I kinda expected there to be some sort of server-side analog in this directory too. (Like how we have QuicSpdyServerStream vs QuicSpdyClientStream in QUICHE). But I guess, as you say, that's all in the HCM. Fascinating. Thanks!

#endif

namespace Envoy {
Expand Down
1 change: 1 addition & 0 deletions source/common/http/http3/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ envoy_cc_library(
"//source/common/http:codec_client_lib",
"//source/common/http:conn_pool_base_lib",
"//source/common/quic:client_connection_factory_lib",
"@com_github_google_quiche//:quic_core_deterministic_connection_id_generator_lib",
],
)

Expand Down
87 changes: 74 additions & 13 deletions source/common/quic/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,10 @@ envoy_cc_library(
hdrs = ["client_connection_factory_impl.h"],
tags = ["nofips"],
deps = [
":active_quic_listener_lib",
":envoy_quic_alarm_factory_lib",
":envoy_quic_client_session_lib",
":envoy_quic_connection_helper_lib",
":envoy_quic_proof_verifier_lib",
":envoy_quic_server_session_lib",
":envoy_quic_utils_lib",
"//envoy/http:codec_interface",
"//envoy/http:persistent_quic_info_interface",
Expand All @@ -191,14 +189,34 @@ envoy_cc_library(
)

envoy_cc_library(
name = "codec_lib",
srcs = ["codec_impl.cc"],
hdrs = ["codec_impl.h"],
name = "client_codec_lib",
srcs = ["client_codec_impl.cc"],
hdrs = [
"client_codec_impl.h",
"codec_impl.h",
],
tags = ["nofips"],
deps = [
":envoy_quic_client_session_lib",
":envoy_quic_utils_lib",
"//envoy/http:codec_interface",
"//envoy/registry",
"@com_github_google_quiche//:quic_core_http_spdy_session_lib",
],
)

envoy_cc_library(
name = "server_codec_lib",
srcs = ["server_codec_impl.cc"],
hdrs = [
"codec_impl.h",
"server_codec_impl.h",
],
tags = ["nofips"],
deps = [
":envoy_quic_server_session_lib",
":envoy_quic_utils_lib",
":quic_server_factory_stub_lib",
"//envoy/http:codec_interface",
"//envoy/registry",
"@com_github_google_quiche//:quic_core_http_spdy_session_lib",
Expand Down Expand Up @@ -251,17 +269,17 @@ envoy_cc_library(
],
tags = ["nofips"],
deps = [
":envoy_quic_crypto_stream_factory_lib",
":envoy_quic_proof_source_lib",
":envoy_quic_server_connection_lib",
":envoy_quic_server_crypto_stream_factory_lib",
":envoy_quic_stream_lib",
":envoy_quic_utils_lib",
":quic_filter_manager_connection_lib",
":quic_stat_names_lib",
"//source/common/buffer:buffer_lib",
"//source/common/common:assert_lib",
"//source/common/http:header_map_lib",
"@com_github_google_quiche//:quic_core_http_spdy_session_lib",
"@com_github_google_quiche//:quic_server_http_spdy_session_lib",
],
)

Expand All @@ -278,7 +296,7 @@ envoy_cc_library(
tags = ["nofips"],
deps = [
":envoy_quic_client_connection_lib",
":envoy_quic_crypto_stream_factory_lib",
":envoy_quic_client_crypto_stream_factory_lib",
":envoy_quic_proof_verifier_lib",
":envoy_quic_stream_lib",
":envoy_quic_utils_lib",
Expand Down Expand Up @@ -350,9 +368,9 @@ envoy_cc_library(
hdrs = ["envoy_quic_dispatcher.h"],
tags = ["nofips"],
deps = [
":envoy_quic_crypto_stream_factory_lib",
":envoy_quic_proof_source_lib",
":envoy_quic_server_connection_lib",
":envoy_quic_server_crypto_stream_factory_lib",
":envoy_quic_server_session_lib",
":quic_stat_names_lib",
"//envoy/network:listener_interface",
Expand Down Expand Up @@ -437,10 +455,41 @@ envoy_cc_library(
alwayslink = LEGACY_ALWAYSLINK,
)

# Create a single target that contains all the libraries that register client factories.
# All of these are needed for this extension to function.
envoy_cc_library(
name = "quic_client_factory_lib",
tags = ["nofips"],
# QUICHE can't build against FIPS BoringSSL until the FIPS build
# is on a new enough version to have QUIC support. Remove it from
# the build until then. Re-enable as part of #7433.
deps = select({
"//bazel:boringssl_fips": [],
"//bazel:boringssl_disabled": [],
"//conditions:default": [
":client_codec_lib",
":quic_transport_socket_factory_lib",
"//source/extensions/quic/proof_source:envoy_quic_proof_source_factory_impl_lib",
],
}),
)

# The factory for server connection creation.
envoy_cc_library(
name = "quic_server_factory_stub_lib",
hdrs = ["server_connection_factory.h"],
deps = [
"//envoy/http:codec_interface",
"//envoy/network:connection_interface",
"//source/common/http/http3:codec_stats_lib",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
],
)

# Create a single target that contains all the libraries that register factories.
# All of these are needed for this extension to function.
envoy_cc_library(
name = "quic_factory_lib",
name = "quic_server_factory_lib",
tags = ["nofips"],
# QUICHE can't build against FIPS BoringSSL until the FIPS build
# is on a new enough version to have QUIC support. Remove it from
Expand All @@ -449,7 +498,7 @@ envoy_cc_library(
"//bazel:boringssl_fips": [],
"//bazel:boringssl_disabled": [],
"//conditions:default": [
":codec_lib",
":server_codec_lib",
":quic_transport_socket_factory_lib",
"//source/extensions/quic/crypto_stream:envoy_quic_crypto_server_stream_lib",
"//source/extensions/quic/proof_source:envoy_quic_proof_source_factory_impl_lib",
Expand Down Expand Up @@ -499,12 +548,24 @@ envoy_cc_library(
)

envoy_cc_library(
name = "envoy_quic_crypto_stream_factory_lib",
hdrs = ["envoy_quic_crypto_stream_factory.h"],
name = "envoy_quic_client_crypto_stream_factory_lib",
hdrs = ["envoy_quic_client_crypto_stream_factory.h"],
tags = ["nofips"],
deps = [
"//envoy/config:typed_config_interface",
"@com_github_google_quiche//:quic_client_session_lib",
"@com_github_google_quiche//:quic_core_http_spdy_session_lib",
],
)

envoy_cc_library(
name = "envoy_quic_server_crypto_stream_factory_lib",
hdrs = ["envoy_quic_server_crypto_stream_factory.h"],
tags = ["nofips"],
deps = [
"//envoy/config:typed_config_interface",
"@com_github_google_quiche//:quic_core_http_spdy_session_lib",
"@com_github_google_quiche//:quic_server_session_lib",
],
)

Expand Down
61 changes: 61 additions & 0 deletions source/common/quic/client_codec_impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "source/common/quic/client_codec_impl.h"

#include "source/common/quic/envoy_quic_client_stream.h"

namespace Envoy {
namespace Quic {

// Converts a QuicStream instance to EnvoyQuicStream instance. The current stream implementation
// inherits from these two interfaces, with the former one providing Quic interface and the latter
// providing Envoy interface.
EnvoyQuicClientStream* quicStreamToEnvoyClientStream(quic::QuicStream* stream) {
return dynamic_cast<EnvoyQuicClientStream*>(stream);
}

QuicHttpClientConnectionImpl::QuicHttpClientConnectionImpl(
EnvoyQuicClientSession& session, Http::ConnectionCallbacks& callbacks,
Http::Http3::CodecStats& stats,
const envoy::config::core::v3::Http3ProtocolOptions& http3_options,
const uint32_t max_request_headers_kb, const uint32_t max_response_headers_count)
: QuicHttpConnectionImplBase(session, stats), quic_client_session_(session) {
session.setCodecStats(stats);
session.setHttp3Options(http3_options);
session.setHttpConnectionCallbacks(callbacks);
session.setMaxIncomingHeadersCount(max_response_headers_count);
session.set_max_inbound_header_list_size(max_request_headers_kb * 1024);
}

void QuicHttpClientConnectionImpl::goAway() {
quic_client_session_.SendHttp3GoAway(quic::QUIC_PEER_GOING_AWAY, "client goaway");
}

Http::RequestEncoder&
QuicHttpClientConnectionImpl::newStream(Http::ResponseDecoder& response_decoder) {
EnvoyQuicClientStream* stream =
quicStreamToEnvoyClientStream(quic_client_session_.CreateOutgoingBidirectionalStream());
ASSERT(stream != nullptr, "Fail to create QUIC stream.");
stream->setResponseDecoder(response_decoder);
if (quic_client_session_.aboveHighWatermark()) {
stream->runHighWatermarkCallbacks();
}
return *stream;
}

void QuicHttpClientConnectionImpl::onUnderlyingConnectionAboveWriteBufferHighWatermark() {
quic_client_session_.PerformActionOnActiveStreams([](quic::QuicStream* quic_stream) {
ENVOY_LOG(debug, "runHighWatermarkCallbacks on stream {}", quic_stream->id());
quicStreamToEnvoyClientStream(quic_stream)->runHighWatermarkCallbacks();
return true;
});
}

void QuicHttpClientConnectionImpl::onUnderlyingConnectionBelowWriteBufferLowWatermark() {
quic_client_session_.PerformActionOnActiveStreams([](quic::QuicStream* quic_stream) {
ENVOY_LOG(debug, "runLowWatermarkCallbacks on stream {}", quic_stream->id());
quicStreamToEnvoyClientStream(quic_stream)->runLowWatermarkCallbacks();
return true;
});
}

} // namespace Quic
} // namespace Envoy
37 changes: 37 additions & 0 deletions source/common/quic/client_codec_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include "envoy/http/codec.h"
#include "envoy/registry/registry.h"

#include "source/common/common/assert.h"
#include "source/common/common/logger.h"
#include "source/common/quic/codec_impl.h"
#include "source/common/quic/envoy_quic_client_session.h"

namespace Envoy {
namespace Quic {

class QuicHttpClientConnectionImpl : public QuicHttpConnectionImplBase,
public Http::ClientConnection {
public:
QuicHttpClientConnectionImpl(EnvoyQuicClientSession& session,
Http::ConnectionCallbacks& callbacks, Http::Http3::CodecStats& stats,
const envoy::config::core::v3::Http3ProtocolOptions& http3_options,
const uint32_t max_request_headers_kb,
const uint32_t max_response_headers_count);

// Http::ClientConnection
Http::RequestEncoder& newStream(Http::ResponseDecoder& response_decoder) override;

// Http::Connection
void goAway() override;
void shutdownNotice() override {}
void onUnderlyingConnectionAboveWriteBufferHighWatermark() override;
void onUnderlyingConnectionBelowWriteBufferLowWatermark() override;

private:
EnvoyQuicClientSession& quic_client_session_;
};

} // namespace Quic
} // namespace Envoy
50 changes: 2 additions & 48 deletions source/common/quic/codec_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

#include "source/common/common/assert.h"
#include "source/common/common/logger.h"
#include "source/common/quic/envoy_quic_client_session.h"
#include "source/common/quic/envoy_quic_server_session.h"
#include "source/common/quic/quic_filter_manager_connection_impl.h"

namespace Envoy {
namespace Quic {
Expand All @@ -29,57 +28,12 @@ class QuicHttpConnectionImplBase : public virtual Http::Connection,
Http::Protocol protocol() override { return Http::Protocol::Http3; }
// Returns true if the session has data to send but queued in connection or
// stream send buffer.
bool wantsToWrite() override;
bool wantsToWrite() override { return quic_session_.bytesToSend() > 0; }

protected:
QuicFilterManagerConnectionImpl& quic_session_;
Http::Http3::CodecStats& stats_;
};

class QuicHttpServerConnectionImpl : public QuicHttpConnectionImplBase,
public Http::ServerConnection {
public:
QuicHttpServerConnectionImpl(
EnvoyQuicServerSession& quic_session, Http::ServerConnectionCallbacks& callbacks,
Http::Http3::CodecStats& stats,
const envoy::config::core::v3::Http3ProtocolOptions& http3_options,
const uint32_t max_request_headers_kb, const uint32_t max_request_headers_count,
envoy::config::core::v3::HttpProtocolOptions::HeadersWithUnderscoresAction
headers_with_underscores_action);

// Http::Connection
void goAway() override;
void shutdownNotice() override;
void onUnderlyingConnectionAboveWriteBufferHighWatermark() override;
void onUnderlyingConnectionBelowWriteBufferLowWatermark() override;

EnvoyQuicServerSession& quicServerSession() { return quic_server_session_; }

private:
EnvoyQuicServerSession& quic_server_session_;
};

class QuicHttpClientConnectionImpl : public QuicHttpConnectionImplBase,
public Http::ClientConnection {
public:
QuicHttpClientConnectionImpl(EnvoyQuicClientSession& session,
Http::ConnectionCallbacks& callbacks, Http::Http3::CodecStats& stats,
const envoy::config::core::v3::Http3ProtocolOptions& http3_options,
const uint32_t max_request_headers_kb,
const uint32_t max_response_headers_count);

// Http::ClientConnection
Http::RequestEncoder& newStream(Http::ResponseDecoder& response_decoder) override;

// Http::Connection
void goAway() override;
void shutdownNotice() override {}
void onUnderlyingConnectionAboveWriteBufferHighWatermark() override;
void onUnderlyingConnectionBelowWriteBufferLowWatermark() override;

private:
EnvoyQuicClientSession& quic_client_session_;
};

} // namespace Quic
} // namespace Envoy