1
#pragma once
2

            
3
#include "envoy/config/typed_config.h"
4
#include "envoy/network/address.h"
5
#include "envoy/network/listen_socket.h"
6
#include "envoy/server/factory_context.h"
7

            
8
#include "source/common/quic/envoy_quic_packet_writer.h"
9

            
10
#include "quiche/quic/core/quic_path_validator.h"
11

            
12
namespace Envoy {
13
namespace Quic {
14

            
15
// An extension interface to creating customized UDP sockets and creating
16
// QUIC packet writers for upstream connections based on such sockets.
17
class QuicClientPacketWriterFactory {
18
public:
19
2129
  virtual ~QuicClientPacketWriterFactory() = default;
20

            
21
  struct CreationResult {
22
    // Not null.
23
    std::unique_ptr<EnvoyQuicPacketWriter> writer_;
24
    // Not null but can be a bad socket if creation goes wrong.
25
    Network::ConnectionSocketPtr socket_;
26
  };
27

            
28
  /**
29
   * Creates a socket and a QUIC packet writer associated with it.
30
   * @param server_addr The server address to connect to.
31
   * @param network The network to bind the socket to.
32
   * @param local_addr The local address to bind if not nullptr and if the network is invalid. Will
33
   * be set to the actual local address of the created socket.
34
   * @param options The socket options to apply.
35
   * @return A struct containing the created socket and writer objects.
36
   */
37
  virtual CreationResult
38
  createSocketAndQuicPacketWriter(Network::Address::InstanceConstSharedPtr server_addr,
39
                                  quic::QuicNetworkHandle network,
40
                                  Network::Address::InstanceConstSharedPtr& local_addr,
41
                                  const Network::ConnectionSocket::OptionsSharedPtr& options) PURE;
42
};
43

            
44
using QuicClientPacketWriterFactoryPtr = std::shared_ptr<QuicClientPacketWriterFactory>;
45

            
46
class QuicClientPacketWriterConfigFactory : public Config::TypedFactory {
47
public:
48
1046
  std::string category() const override { return "envoy.quic.client_packet_writer"; }
49

            
50
  /**
51
   * Returns a packet writer factory based on the given config.
52
   */
53
  virtual QuicClientPacketWriterFactoryPtr
54
  createQuicClientPacketWriterFactory(const Protobuf::Message& config,
55
                                      Event::Dispatcher& dispatcher,
56
                                      ProtobufMessage::ValidationVisitor& validation_visitor) PURE;
57
};
58

            
59
} // namespace Quic
60
} // namespace Envoy