1
#pragma once
2

            
3
#include <memory>
4

            
5
#include "envoy/event/dispatcher.h"
6
#include "envoy/event/timer.h"
7
#include "envoy/http/http_server_properties_cache.h"
8

            
9
namespace Envoy {
10
namespace Http {
11

            
12
// Tracks the status of HTTP/3 being broken for a period of time
13
// subject to exponential backoff.
14
class Http3StatusTrackerImpl : public HttpServerPropertiesCache::Http3StatusTracker {
15
public:
16
  explicit Http3StatusTrackerImpl(Event::Dispatcher& dispatcher);
17

            
18
  // Returns true if HTTP/3 status is pending.
19
  bool isHttp3Pending() const override;
20
  // Returns true if HTTP/3 is broken.
21
  bool isHttp3Broken() const override;
22
  // Returns true if HTTP/3 is confirmed to be working.
23
  bool isHttp3Confirmed() const override;
24
  // Returns true if HTTP/3 has failed recently.
25
  bool hasHttp3FailedRecently() const override;
26
  // Marks HTTP/3 status as pending.
27
  void markHttp3Pending() override;
28
  // Marks HTTP/3 broken for a period of time, subject to backoff.
29
  void markHttp3Broken() override;
30
  // Marks HTTP/3 as confirmed to be working and resets the backoff timeout.
31
  void markHttp3Confirmed() override;
32
  // Marks HTTP/3 as failed recently.
33
  void markHttp3FailedRecently() override;
34

            
35
private:
36
  enum class State {
37
    Pending,
38
    FailedRecently,
39
    Broken,
40
    Confirmed,
41
  };
42

            
43
  // Called when the expiration timer fires.
44
  void onExpirationTimeout();
45

            
46
  State state_{State::Pending};
47
  // The number of consecutive times HTTP/3 has been marked broken.
48
  int consecutive_broken_count_{};
49
  // The timer which tracks when HTTP/3 broken status should expire
50
  Event::TimerPtr expiration_timer_;
51
};
52

            
53
} // namespace Http
54
} // namespace Envoy