Line data Source code
1 : #pragma once 2 : 3 : #include "envoy/extensions/transport_sockets/quic/v3/quic_transport.pb.h" 4 : #include "envoy/network/transport_socket.h" 5 : #include "envoy/server/transport_socket_config.h" 6 : #include "envoy/ssl/context_config.h" 7 : 8 : #include "source/common/common/assert.h" 9 : #include "source/common/network/transport_socket_options_impl.h" 10 : #include "source/extensions/transport_sockets/tls/ssl_socket.h" 11 : 12 : #include "quiche/quic/core/crypto/quic_crypto_client_config.h" 13 : 14 : namespace Envoy { 15 : namespace Quic { 16 : 17 : #define QUIC_TRANSPORT_SOCKET_FACTORY_STATS(COUNTER) \ 18 0 : COUNTER(context_config_update_by_sds) \ 19 0 : COUNTER(upstream_context_secrets_not_ready) \ 20 0 : COUNTER(downstream_context_secrets_not_ready) 21 : 22 : struct QuicTransportSocketFactoryStats { 23 : QUIC_TRANSPORT_SOCKET_FACTORY_STATS(GENERATE_COUNTER_STRUCT) 24 : }; 25 : 26 : namespace { 27 : 28 0 : QuicTransportSocketFactoryStats generateStats(Stats::Scope& store, const std::string& perspective) { 29 0 : return {QUIC_TRANSPORT_SOCKET_FACTORY_STATS( 30 0 : POOL_COUNTER_PREFIX(store, fmt::format("quic_{}_transport_socket_factory.", perspective)))}; 31 0 : } 32 : 33 : } // namespace 34 : 35 : // Base class for QUIC transport socket factory. 36 : // Because QUIC stack handles all L4 data, there is no need of a real transport 37 : // socket for QUIC in current implementation. This factory doesn't provides a 38 : // transport socket, instead, its derived class provides TLS context config for 39 : // server and client. 40 : class QuicTransportSocketFactoryBase : protected Logger::Loggable<Logger::Id::quic> { 41 : public: 42 : QuicTransportSocketFactoryBase(Stats::Scope& store, const std::string& perspective) 43 0 : : stats_(generateStats(store, perspective)) {} 44 : 45 0 : virtual ~QuicTransportSocketFactoryBase() = default; 46 : 47 : // To be called right after construction. 48 : virtual void initialize() PURE; 49 : 50 : // Returns the ALPN list to negotiate during the handshake. 51 0 : const std::vector<absl::string_view>& supportedAlpnProtocols() const { return supported_alpns_; } 52 : 53 : protected: 54 : virtual void onSecretUpdated() PURE; 55 : QuicTransportSocketFactoryStats stats_; 56 : // Populated during initialization. 57 : std::vector<absl::string_view> supported_alpns_; 58 : }; 59 : 60 : // Base class to create above QuicTransportSocketFactory for server and client 61 : // side. 62 : class QuicTransportSocketConfigFactory 63 : : public virtual Server::Configuration::TransportSocketConfigFactory { 64 : public: 65 : // Server::Configuration::TransportSocketConfigFactory 66 338 : std::string name() const override { return "envoy.transport_sockets.quic"; } 67 : }; 68 : 69 : } // namespace Quic 70 : } // namespace Envoy