1
#pragma once
2

            
3
#include "source/common/grpc/typed_async_client.h"
4

            
5
namespace Envoy {
6
namespace Config {
7

            
8
// Oversees communication for gRPC xDS implementations (parent to both SotW xDS and delta
9
// xDS variants). Reestablishes the gRPC channel when necessary, and provides rate limiting of
10
// requests.
11
template <class RequestProto, class ResponseProto>
12
class GrpcStreamInterface : public Grpc::AsyncStreamCallbacks<ResponseProto> {
13
public:
14
2274
  ~GrpcStreamInterface() override = default;
15

            
16
  // Attempt to establish a new gRPC stream to the xDS server.
17
  virtual void establishNewStream() PURE;
18

            
19
  // Returns true if the gRPC stream is available and messages can be sent over it.
20
  virtual bool grpcStreamAvailable() const PURE;
21

            
22
  // Sends a request to the xDS server over the stream.
23
  virtual void sendMessage(const RequestProto& request) PURE;
24

            
25
  // Updates the control_plane_stats `pending_requests` value. Note that the
26
  // update will not be taken into effect if the size is 0, and the
27
  // `pending_request` value was not set previously to non-zero value.
28
  // This is done to avoid updating the queue's length until the first
29
  // meaningful value is given.
30
  virtual void maybeUpdateQueueSizeStat(uint64_t size) PURE;
31

            
32
  // Returns true if a message can be sent from the rate-limiting perspective.
33
  // The rate-limiting counters may be updated by this method.
34
  virtual bool checkRateLimitAllowsDrain() PURE;
35

            
36
  // Intentionally close the gRPC stream and reset to the pre-establishNewStream() state.
37
  // Prevents the retry timer from reconnecting.
38
  virtual void closeStream() PURE;
39
};
40

            
41
template <class RequestProto, class ResponseProto>
42
using GrpcStreamInterfacePtr = std::unique_ptr<GrpcStreamInterface<RequestProto, ResponseProto>>;
43
} // namespace Config
44
} // namespace Envoy