|
25 | 25 | #include "source/common/quic/envoy_quic_proof_source.h" |
26 | 26 | #include "source/common/quic/envoy_quic_utils.h" |
27 | 27 | #include "source/common/quic/quic_network_connection.h" |
| 28 | +#include "source/common/quic/quic_packet_writer_interface.h" |
28 | 29 | #include "source/common/runtime/runtime_features.h" |
29 | 30 |
|
30 | 31 | namespace Envoy { |
@@ -104,22 +105,39 @@ ActiveQuicListener::ActiveQuicListener( |
104 | 105 |
|
105 | 106 | absl::AnyInvocable<void() &&> on_can_write_cb = [&]() { quic_dispatcher_->OnCanWrite(); }; |
106 | 107 |
|
107 | | - // Create udp_packet_writer |
108 | | - Network::UdpPacketWriterPtr udp_packet_writer = |
109 | | - listener_config.udpListenerConfig()->packetWriterFactory().createUdpPacketWriter( |
110 | | - listen_socket_.ioHandle(), listener_config.listenerScope(), dispatcher, |
111 | | - std::move(on_can_write_cb)); |
112 | | - udp_packet_writer_ = udp_packet_writer.get(); |
113 | | - |
114 | | - // Some packet writers (like `UdpGsoBatchWriter`) already directly implement |
115 | | - // `quic::QuicPacketWriter` and can be used directly here. Other types need |
116 | | - // `EnvoyQuicPacketWriter` as an adapter. |
117 | | - auto* quic_packet_writer = dynamic_cast<quic::QuicPacketWriter*>(udp_packet_writer.get()); |
118 | | - if (quic_packet_writer != nullptr) { |
119 | | - quic_dispatcher_->InitializeWithWriter(quic_packet_writer); |
120 | | - udp_packet_writer.release(); |
| 108 | + // Create quic_packet_writer |
| 109 | + QuicPacketWriterFactory* quic_packet_writer_factory = |
| 110 | + listener_config.udpListenerConfig()->quicPacketWriterFactory(); |
| 111 | + |
| 112 | + if (quic_packet_writer_factory != nullptr) { |
| 113 | + QuicPacketWriterPtr quic_writer = quic_packet_writer_factory->createQuicPacketWriter( |
| 114 | + listen_socket_.ioHandle(), listener_config.listenerScope(), dispatcher, |
| 115 | + std::move(on_can_write_cb)); |
| 116 | + quic_packet_writer_ = quic_writer.get(); |
| 117 | + quic_dispatcher_->InitializeWithWriter(quic_writer.release()); |
121 | 118 | } else { |
122 | | - quic_dispatcher_->InitializeWithWriter(new EnvoyQuicPacketWriter(std::move(udp_packet_writer))); |
| 119 | + // TODO(panting): This fallback is a temporary migration bridge. We must keep this |
| 120 | + // logic because there is currently no QUIC GSO batch factory implemented to create |
| 121 | + // GSO writers natively. Once a native QuicGsoBatchWriterFactory is implemented |
| 122 | + // and default configurations are migrated, this fallback can be removed. |
| 123 | + // Create udp_packet_writer |
| 124 | + Network::UdpPacketWriterPtr udp_packet_writer = |
| 125 | + listener_config.udpListenerConfig()->packetWriterFactory().createUdpPacketWriter( |
| 126 | + listen_socket_.ioHandle(), listener_config.listenerScope(), dispatcher, |
| 127 | + std::move(on_can_write_cb)); |
| 128 | + udp_packet_writer_ = udp_packet_writer.get(); |
| 129 | + |
| 130 | + // Some packet writers (like `UdpGsoBatchWriter`) already directly implement |
| 131 | + // `quic::QuicPacketWriter` and can be used directly here. Other types need |
| 132 | + // `EnvoyQuicPacketWriter` as an adapter. |
| 133 | + auto* quic_packet_writer = dynamic_cast<quic::QuicPacketWriter*>(udp_packet_writer.get()); |
| 134 | + if (quic_packet_writer != nullptr) { |
| 135 | + quic_dispatcher_->InitializeWithWriter(quic_packet_writer); |
| 136 | + udp_packet_writer.release(); |
| 137 | + } else { |
| 138 | + quic_dispatcher_->InitializeWithWriter( |
| 139 | + new EnvoyQuicPacketWriter(std::move(udp_packet_writer))); |
| 140 | + } |
123 | 141 | } |
124 | 142 |
|
125 | 143 | if (listener_config.udpListenerConfig()) { |
|
0 commit comments