1
#pragma once
2

            
3
#include "envoy/extensions/common/dynamic_forward_proxy/v3/dns_cache.pb.h"
4
#include "envoy/server/factory_context.h"
5

            
6
#include "source/extensions/common/dynamic_forward_proxy/dns_cache.h"
7
#include "source/server/generic_factory_context.h"
8

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

            
11
namespace Envoy {
12
namespace Extensions {
13
namespace Common {
14
namespace DynamicForwardProxy {
15

            
16
class DnsCacheManagerImpl : public DnsCacheManager, public Singleton::Instance {
17
public:
18
175
  DnsCacheManagerImpl(Server::Configuration::GenericFactoryContext& context) : context_(context) {}
19

            
20
  // DnsCacheManager
21
  absl::StatusOr<DnsCacheSharedPtr> getCache(
22
      const envoy::extensions::common::dynamic_forward_proxy::v3::DnsCacheConfig& config) override;
23
  DnsCacheSharedPtr lookUpCacheByName(absl::string_view cache_name) override;
24

            
25
private:
26
  struct ActiveCache {
27
    ActiveCache(const envoy::extensions::common::dynamic_forward_proxy::v3::DnsCacheConfig& config,
28
                DnsCacheSharedPtr cache)
29
112
        : config_(config), cache_(cache) {}
30

            
31
    const envoy::extensions::common::dynamic_forward_proxy::v3::DnsCacheConfig config_;
32
    DnsCacheSharedPtr cache_;
33
  };
34

            
35
  Server::GenericFactoryContextImpl context_;
36
  absl::flat_hash_map<std::string, ActiveCache> caches_;
37
};
38

            
39
class DnsCacheManagerFactoryImpl : public DnsCacheManagerFactory {
40
public:
41
  DnsCacheManagerFactoryImpl(Server::Configuration::ServerFactoryContext& server_context,
42
                             ProtobufMessage::ValidationVisitor& validation_visitor)
43
111
      : context_(server_context, validation_visitor) {}
44
  DnsCacheManagerFactoryImpl(Server::Configuration::GenericFactoryContext& context)
45
97
      : context_(context) {}
46

            
47
  DnsCacheManagerSharedPtr get() override;
48

            
49
private:
50
  Server::GenericFactoryContextImpl context_;
51
};
52

            
53
} // namespace DynamicForwardProxy
54
} // namespace Common
55
} // namespace Extensions
56
} // namespace Envoy