1
#include "source/common/quic/server_codec_impl.h"
2

            
3
#include "envoy/server/overload/load_shed_point.h"
4
#include "envoy/server/overload/overload_manager.h"
5

            
6
#include "source/common/quic/envoy_quic_server_stream.h"
7

            
8
namespace Envoy {
9
namespace Quic {
10

            
11
// Converts a QuicStream instance to EnvoyQuicStream instance. The current stream implementation
12
// inherits from these two interfaces, with the former one providing Quic interface and the latter
13
// providing Envoy interface.
14
767
EnvoyQuicStream* quicStreamToEnvoyStream(quic::QuicStream* stream) {
15
767
  return dynamic_cast<EnvoyQuicStream*>(stream);
16
767
}
17

            
18
QuicHttpServerConnectionImpl::QuicHttpServerConnectionImpl(
19
    EnvoyQuicServerSession& quic_session, Http::ServerConnectionCallbacks& callbacks,
20
    Http::Http3::CodecStats& stats,
21
    const envoy::config::core::v3::Http3ProtocolOptions& http3_options,
22
    const uint32_t max_request_headers_kb, const uint32_t max_request_headers_count,
23
    envoy::config::core::v3::HttpProtocolOptions::HeadersWithUnderscoresAction
24
        headers_with_underscores_action,
25
    Server::OverloadManager& overload_manager)
26
2950
    : QuicHttpConnectionImplBase(quic_session, stats), quic_server_session_(quic_session) {
27
2950
  quic_session.setCodecStats(stats);
28
2950
  quic_session.setHttp3Options(http3_options);
29
2950
  quic_session.setHeadersWithUnderscoreAction(headers_with_underscores_action);
30
2950
  quic_session.setHttpConnectionCallbacks(callbacks);
31
2950
  quic_session.setMaxIncomingHeadersCount(max_request_headers_count);
32
2950
  quic_session.set_max_inbound_header_list_size(max_request_headers_kb * 1024u);
33
2950
  quic_session.setH3GoAwayLoadShedPoints(
34
2950
      overload_manager.getLoadShedPoint(
35
2950
          Server::LoadShedPointName::get().H3ServerGoAwayAndCloseOnDispatch),
36
2950
      overload_manager.getLoadShedPoint(Server::LoadShedPointName::get().H3ServerGoAwayOnDispatch));
37
2950
}
38

            
39
385
void QuicHttpServerConnectionImpl::onUnderlyingConnectionAboveWriteBufferHighWatermark() {
40
386
  quic_server_session_.PerformActionOnActiveStreams([](quic::QuicStream* quic_stream) {
41
386
    ENVOY_LOG(debug, "runHighWatermarkCallbacks on stream {}", quic_stream->id());
42
386
    quicStreamToEnvoyStream(quic_stream)->runHighWatermarkCallbacks();
43
386
    return true;
44
386
  });
45
385
}
46

            
47
385
void QuicHttpServerConnectionImpl::onUnderlyingConnectionBelowWriteBufferLowWatermark() {
48
387
  quic_server_session_.PerformActionOnActiveStreams([](quic::QuicStream* quic_stream) {
49
381
    ENVOY_LOG(debug, "runLowWatermarkCallbacks on stream {}", quic_stream->id());
50
381
    quicStreamToEnvoyStream(quic_stream)->runLowWatermarkCallbacks();
51
381
    return true;
52
381
  });
53
385
}
54

            
55
48
void QuicHttpServerConnectionImpl::shutdownNotice() {
56
48
  quic_server_session_.SendHttp3GoAway(quic::QUIC_PEER_GOING_AWAY, "Server shutdown");
57
48
}
58

            
59
44
void QuicHttpServerConnectionImpl::goAway() {
60
44
  quic_server_session_.SendHttp3GoAway(quic::QUIC_PEER_GOING_AWAY, "server shutdown imminent");
61
44
}
62

            
63
REGISTER_FACTORY(QuicHttpServerConnectionFactoryImpl, QuicHttpServerConnectionFactory);
64

            
65
} // namespace Quic
66
} // namespace Envoy