1
#pragma once
2

            
3
#include <memory>
4

            
5
#include "envoy/http/persistent_quic_info.h"
6
#include "envoy/upstream/upstream.h"
7

            
8
#include "source/common/quic/envoy_quic_alarm_factory.h"
9
#include "source/common/quic/envoy_quic_client_session.h"
10
#include "source/common/quic/envoy_quic_connection_helper.h"
11
#include "source/common/quic/envoy_quic_utils.h"
12
#include "source/common/tls/client_ssl_socket.h"
13
#include "source/extensions/quic/crypto_stream/envoy_quic_crypto_client_stream.h"
14

            
15
#include "quiche/quic/core/http/quic_connection_migration_manager.h"
16
#include "quiche/quic/core/quic_utils.h"
17

            
18
namespace Envoy {
19
namespace Quic {
20

            
21
// Information which can be shared across connections, though not across threads.
22
// TODO(danzh) considering exposing these QUICHE interfaces via base class virtual methods, so that
23
// down casting can be avoided while passing around this object.
24
struct PersistentQuicInfoImpl : public Http::PersistentQuicInfo {
25
  PersistentQuicInfoImpl(Event::Dispatcher& dispatcher, uint32_t buffer_limit,
26
                         quic::QuicByteCount max_packet_length = 0);
27

            
28
  EnvoyQuicConnectionHelper conn_helper_;
29
  EnvoyQuicAlarmFactory alarm_factory_;
30
  quic::QuicConfig quic_config_;
31
  // The connection send buffer limits from cluster config.
32
  const uint32_t buffer_limit_;
33
  // Hard code with the default crypto stream as there's no pluggable crypto for upstream Envoy.
34
  EnvoyQuicCryptoClientStreamFactoryImpl crypto_stream_factory_;
35
  // Override the maximum packet length of connections for tunneling. Use the default length in
36
  // QUICHE if this is set to 0.
37
  quic::QuicByteCount max_packet_length_;
38
  // TODO(danzh): Add a config knob to configure connection migration.
39
  quic::QuicConnectionMigrationConfig migration_config_;
40
  QuicClientPacketWriterFactoryPtr writer_factory_;
41
};
42

            
43
std::unique_ptr<PersistentQuicInfoImpl>
44
createPersistentQuicInfoForCluster(Event::Dispatcher& dispatcher,
45
                                   const Upstream::ClusterInfo& cluster,
46
                                   Server::Configuration::ServerFactoryContext& server_context);
47

            
48
std::unique_ptr<Network::ClientConnection> createQuicNetworkConnection(
49
    Http::PersistentQuicInfo& info, std::shared_ptr<quic::QuicCryptoClientConfig> crypto_config,
50
    const quic::QuicServerId& server_id, Event::Dispatcher& dispatcher,
51
    Network::Address::InstanceConstSharedPtr server_addr,
52
    Network::Address::InstanceConstSharedPtr local_addr, QuicStatNames& quic_stat_names,
53
    OptRef<Http::HttpServerPropertiesCache> rtt_cache, Stats::Scope& scope,
54
    const Network::ConnectionSocket::OptionsSharedPtr& options,
55
    const Network::TransportSocketOptionsConstSharedPtr& transport_socket_options,
56
    quic::ConnectionIdGeneratorInterface& generator,
57
    Network::UpstreamTransportSocketFactory& transport_socket_factory,
58
    EnvoyQuicNetworkObserverRegistry* network_observer_registry = nullptr);
59

            
60
} // namespace Quic
61
} // namespace Envoy