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/common/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
4369
  COUNTER(context_config_update_by_sds)                                                            \
19
4369
  COUNTER(upstream_context_secrets_not_ready)                                                      \
20
4369
  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
4369
QuicTransportSocketFactoryStats generateStats(Stats::Scope& store, const std::string& perspective) {
29
4369
  return {QUIC_TRANSPORT_SOCKET_FACTORY_STATS(
30
4369
      POOL_COUNTER_PREFIX(store, fmt::format("quic_{}_transport_socket_factory.", perspective)))};
31
4369
}
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
4369
      : stats_(generateStats(store, perspective)) {}
44

            
45
4369
  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
9632
  const std::vector<absl::string_view>& supportedAlpnProtocols() const { return supported_alpns_; }
52

            
53
protected:
54
  virtual absl::Status 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
23172
  std::string name() const override { return "envoy.transport_sockets.quic"; }
67
};
68

            
69
} // namespace Quic
70
} // namespace Envoy