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
926
EnvoyQuicStream* quicStreamToEnvoyStream(quic::QuicStream* stream) {
15
926
  return dynamic_cast<EnvoyQuicStream*>(stream);
16
926
}
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
2948
    : QuicHttpConnectionImplBase(quic_session, stats), quic_server_session_(quic_session) {
27
2948
  quic_session.setCodecStats(stats);
28
2948
  quic_session.setHttp3Options(http3_options);
29
2948
  quic_session.setHeadersWithUnderscoreAction(headers_with_underscores_action);
30
2948
  quic_session.setHttpConnectionCallbacks(callbacks);
31
2948
  quic_session.setMaxIncomingHeadersCount(max_request_headers_count);
32
2948
  quic_session.set_max_inbound_header_list_size(max_request_headers_kb * 1024u);
33
2948
  quic_session.setH3GoAwayLoadShedPoints(
34
2948
      overload_manager.getLoadShedPoint(
35
2948
          Server::LoadShedPointName::get().H3ServerGoAwayAndCloseOnDispatch),
36
2948
      overload_manager.getLoadShedPoint(Server::LoadShedPointName::get().H3ServerGoAwayOnDispatch));
37
2948
}
38

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

            
47
464
void QuicHttpServerConnectionImpl::onUnderlyingConnectionBelowWriteBufferLowWatermark() {
48
466
  quic_server_session_.PerformActionOnActiveStreams([](quic::QuicStream* quic_stream) {
49
461
    ENVOY_LOG(debug, "runLowWatermarkCallbacks on stream {}", quic_stream->id());
50
461
    quicStreamToEnvoyStream(quic_stream)->runLowWatermarkCallbacks();
51
461
    return true;
52
461
  });
53
464
}
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