• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pomerium / envoy-custom / 18108646320

29 Sep 2025 07:41PM UTC coverage: 99.401% (-0.6%) from 100.0%
18108646320

Pull #115

github

web-flow
Merge 1312a9cee into 89e57158c
Pull Request #115: mark envoy/, absl/, and api/ as system include prefixes

5145 of 5176 relevant lines covered (99.4%)

22178.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.91
/source/extensions/filters/network/ssh/stream_tracker.h
1
#pragma once
2

3
#include "source/extensions/filters/network/ssh/channel.h"
4

5
#include "envoy/event/dispatcher.h"
6
#include "envoy/server/factory_context.h"
7
#include "api/extensions/filters/network/ssh/ssh.pb.h"
8
#include "api/extensions/filters/network/ssh/ssh.pb.validate.h"
9

10
#include "source/extensions/filters/network/ssh/common.h"
11

12
namespace Envoy::Extensions::NetworkFilters::GenericProxy::Codec {
13

14
using Envoy::Event::Dispatcher;
15
using Envoy::Event::FileReadyType;
16
using Envoy::Event::PlatformDefaultTriggerType;
17

18
class StreamCallbacks {
19
public:
20
  virtual ~StreamCallbacks() = default;
226✔
21
  virtual absl::StatusOr<uint32_t> startChannel(std::unique_ptr<Channel> channel, std::optional<uint32_t> channel_id = std::nullopt) PURE;
22
};
23

24
class StreamContext {
25
public:
26
  StreamContext(stream_id_t stream_id, Network::Connection& connection, StreamCallbacks& stream_callbacks, ChannelEventCallbacks& event_callbacks)
27
      : stream_id_(stream_id),
477✔
28
        connection_(connection),
477✔
29
        stream_callbacks_(stream_callbacks),
477✔
30
        event_callbacks_(event_callbacks) {}
477✔
31
  StreamContext(StreamContext&&) noexcept = default;
32
  StreamContext& operator=(StreamContext&&) noexcept = delete;
33
  StreamContext(const StreamContext&) = delete;
34
  StreamContext& operator=(const StreamContext&) = delete;
35

36
  stream_id_t streamId() { return stream_id_; }
6✔
37
  Network::Connection& connection() { return connection_; }
1✔
38
  StreamCallbacks& streamCallbacks() { return stream_callbacks_; }
1✔
39
  ChannelEventCallbacks& eventCallbacks() { return event_callbacks_; }
1✔
40

41
private:
42
  stream_id_t stream_id_;
43
  Network::Connection& connection_;
44
  StreamCallbacks& stream_callbacks_;
45
  ChannelEventCallbacks& event_callbacks_;
46
};
47

48
#define ALL_STREAM_TRACKER_STATS(COUNTER, GAUGE, HISTOGRAM, TEXT_READOUT, STATNAME) \
49
  COUNTER(total_streams)                                                            \
50
  GAUGE(active_streams, Accumulate)                                                 \
51
  STATNAME(ssh)
52

53
MAKE_STAT_NAMES_STRUCT(StreamTrackerStatNames, ALL_STREAM_TRACKER_STATS);
×
54
MAKE_STATS_STRUCT(StreamTrackerStats, StreamTrackerStatNames, ALL_STREAM_TRACKER_STATS);
×
55

×
56
class StreamHandle;
×
57
using StreamHandlePtr = std::unique_ptr<StreamHandle>;
×
58

×
59
class StreamTracker : public Singleton::Instance,
×
60
                      public std::enable_shared_from_this<StreamTracker>,
×
61
                      public Logger::Loggable<Logger::Id::filter> {
×
62
  friend class StreamHandle;
×
63

×
64
public:
×
65
  explicit StreamTracker(Server::Configuration::ServerFactoryContext& context);
×
66
  static std::shared_ptr<StreamTracker> fromContext(Server::Configuration::ServerFactoryContext& context);
×
67

×
68
  // If a stream with the given key is active, invokes the given callback in the stream's thread
×
69
  // with a valid StreamContext. Otherwise, invokes the callback with an empty context.
×
70
  // Does not block.
×
71
  void tryLock(stream_id_t key, absl::AnyInvocable<void(Envoy::OptRef<StreamContext>)> cb);
×
72

×
73
  // Adds the stream to the stream tracker, and returns a handle which removes the stream from
×
74
  // the stream tracker when deleted. The caller must arrange for the handle to live no longer than
×
75
  // the connection or the callback references passed to this function.
×
76
  // This function must be called from the same thread as the given connection, and the stream
×
77
  // handle must also be deleted in the same thread.
×
78
  [[nodiscard]] StreamHandlePtr onStreamBegin(stream_id_t stream_id,
×
79
                                              Network::Connection& connection,
×
80
                                              StreamCallbacks& stream_callbacks,
×
81
                                              ChannelEventCallbacks& event_callbacks,
×
82
                                              const std::function<void()>& on_sync_complete = nullptr);
×
83

×
84
  StreamTrackerStats& stats() { return stats_; }
8✔
85

86
private:
87
  class ThreadLocalStreamTable : public ThreadLocal::ThreadLocalObject {
88
  public:
89
    using StreamTable = absl::flat_hash_map<stream_id_t, std::variant<StreamContext, ::Envoy::Event::Dispatcher*>>;
90
    inline StreamTable& get() { return data_; }
2,061✔
91

92
  private:
93
    StreamTable data_;
94
  };
95

96
  void onStreamEnd(stream_id_t stream_id);
97

98
  ThreadLocal::TypedSlot<ThreadLocalStreamTable> thread_local_stream_table_;
99
  Dispatcher& main_thread_dispatcher_;
100

101
  Stats::Scope& scope_;
102
  StreamTrackerStatNames stat_names_;
103
  StreamTrackerStats stats_;
104
};
105
using StreamTrackerPtr = std::unique_ptr<StreamTracker>;
106
using StreamTrackerSharedPtr = std::shared_ptr<StreamTracker>;
107

108
class StreamHandle {
109
  friend class StreamTracker;
110

111
public:
112
  ~StreamHandle();
113

114
  StreamHandle(StreamHandle&&) noexcept = default;
115
  StreamHandle& operator=(StreamHandle&&) noexcept = default;
116
  StreamHandle(const StreamHandle&) = delete;
117
  StreamHandle& operator=(const StreamHandle&) = delete;
118

119
  stream_id_t streamId() const { return id_; }
6✔
120

121
private:
122
  StreamHandle(stream_id_t id, std::weak_ptr<StreamTracker> parent);
123

124
  stream_id_t id_;
125
  std::weak_ptr<StreamTracker> parent_;
126
};
127

128
} // namespace Envoy::Extensions::NetworkFilters::GenericProxy::Codec
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc