1
#pragma once
2

            
3
#include "envoy/config/core/v3/protocol.pb.h"
4
#include "envoy/http/http_server_properties_cache.h"
5
#include "envoy/server/factory_context.h"
6
#include "envoy/singleton/instance.h"
7
#include "envoy/singleton/manager.h"
8
#include "envoy/thread_local/thread_local.h"
9

            
10
#include "absl/container/flat_hash_map.h"
11

            
12
namespace Envoy {
13
namespace Http {
14

            
15
struct AlternateProtocolsData {
16
  AlternateProtocolsData(Server::Configuration::ServerFactoryContext& context,
17
                         ProtobufMessage::ValidationVisitor& validation_visitor)
18
10723
      : dispatcher_(context.mainThreadDispatcher()), validation_visitor_(validation_visitor),
19
10723
        file_system_(context.api().fileSystem()), concurrency_(context.options().concurrency()) {}
20

            
21
  Event::Dispatcher& dispatcher_;
22
  ProtobufMessage::ValidationVisitor& validation_visitor_;
23
  Filesystem::Instance& file_system_;
24
  uint32_t concurrency_;
25
};
26

            
27
class HttpServerPropertiesCacheManagerImpl : public HttpServerPropertiesCacheManager,
28
                                             public Singleton::Instance {
29
public:
30
  HttpServerPropertiesCacheManagerImpl(Server::Configuration::ServerFactoryContext& context,
31
                                       ProtobufMessage::ValidationVisitor& validation_visitor,
32
                                       ThreadLocal::SlotAllocator& tls);
33

            
34
  // HttpServerPropertiesCacheManager
35
  HttpServerPropertiesCacheSharedPtr
36
  getCache(const envoy::config::core::v3::AlternateProtocolsCacheOptions& options,
37
           Event::Dispatcher& dispatcher) override;
38

            
39
  void forEachThreadLocalCache(CacheFn cache_fn) override;
40

            
41
private:
42
  // Contains a cache and the options associated with it.
43
  struct CacheWithOptions {
44
    CacheWithOptions(const envoy::config::core::v3::AlternateProtocolsCacheOptions& options,
45
                     HttpServerPropertiesCacheSharedPtr cache)
46
5267
        : options_(options), cache_(cache) {}
47

            
48
    const envoy::config::core::v3::AlternateProtocolsCacheOptions options_;
49
    HttpServerPropertiesCacheSharedPtr cache_;
50
  };
51

            
52
  // Per-thread state.
53
  struct State : public ThreadLocal::ThreadLocalObject {
54
    // Map from config name to cache for that config.
55
    absl::flat_hash_map<std::string, CacheWithOptions> caches_;
56
  };
57

            
58
  AlternateProtocolsData data_;
59

            
60
  // Thread local state for the cache.
61
  ThreadLocal::TypedSlot<State> slot_;
62
};
63

            
64
} // namespace Http
65
} // namespace Envoy