1
#pragma once
2

            
3
#include <chrono>
4
#include <memory>
5
#include <string>
6

            
7
#include "envoy/common/random_generator.h"
8
#include "envoy/config/core/v3/config_source.pb.h"
9
#include "envoy/config/subscription.h"
10
#include "envoy/event/dispatcher.h"
11
#include "envoy/local_info/local_info.h"
12
#include "envoy/stats/scope.h"
13
#include "envoy/upstream/cluster_manager.h"
14

            
15
#include "source/extensions/config_subscription/grpc/grpc_mux_context.h"
16
#include "source/extensions/config_subscription/grpc/grpc_mux_impl.h"
17
#include "source/extensions/config_subscription/grpc/grpc_subscription_impl.h"
18

            
19
namespace Envoy {
20
namespace Cilium {
21

            
22
// Cilium XDS API config source. Used for all Cilium XDS.
23
extern envoy::config::core::v3::ConfigSource cilium_xds_api_config;
24

            
25
// GrpcMux wrapper to get access to control plane identifier
26
class GrpcMuxImpl : public Config::GrpcMuxImpl {
27
public:
28
  GrpcMuxImpl(Config::GrpcMuxContext& grpc_mux_context, bool skip_subsequent_node)
29
      : Config::GrpcMuxImpl(grpc_mux_context, skip_subsequent_node) {}
30

            
31
  ~GrpcMuxImpl() override = default;
32

            
33
  void onStreamEstablished() override {
34
    new_stream_ = true;
35
    Config::GrpcMuxImpl::onStreamEstablished();
36
  }
37

            
38
  // isNewStream returns true for the first call after a new stream has been established
39
  bool isNewStream() {
40
    bool new_stream = new_stream_;
41
    new_stream_ = false;
42
    return new_stream;
43
  }
44

            
45
private:
46
  bool new_stream_ = true;
47
};
48

            
49
std::unique_ptr<Config::GrpcSubscriptionImpl>
50
subscribe(const std::string& type_url, const LocalInfo::LocalInfo& local_info,
51
          Upstream::ClusterManager& cm, Event::Dispatcher& dispatcher,
52
          Random::RandomGenerator& random, Stats::Scope& scope,
53
          Config::SubscriptionCallbacks& callbacks,
54
          Config::OpaqueResourceDecoderSharedPtr resource_decoder,
55
          std::chrono::milliseconds init_fetch_timeout = std::chrono::milliseconds(0));
56

            
57
} // namespace Cilium
58
} // namespace Envoy