Line data Source code
1 : #pragma once 2 : 3 : #include "envoy/network/connection.h" 4 : 5 : #include "source/extensions/common/tap/tap.h" 6 : 7 : namespace Envoy { 8 : namespace Extensions { 9 : namespace TransportSockets { 10 : namespace Tap { 11 : 12 : /** 13 : * Per-socket tap implementation. Abstractly handles all socket lifecycle events in order to tap 14 : * if the configuration matches. 15 : */ 16 : class PerSocketTapper { 17 : public: 18 0 : virtual ~PerSocketTapper() = default; 19 : 20 : /** 21 : * Called when the socket is closed. 22 : * @param event supplies the close type. 23 : */ 24 : virtual void closeSocket(Network::ConnectionEvent event) PURE; 25 : 26 : /** 27 : * Called when data is read from the underlying transport. 28 : * @param data supplies the read data. 29 : * @param bytes_read supplies the number of bytes read (data might already have bytes in it). 30 : */ 31 : virtual void onRead(const Buffer::Instance& data, uint32_t bytes_read) PURE; 32 : 33 : /** 34 : * Called when data is written to the underlying transport. 35 : * @param data supplies the written data. 36 : * @param bytes_written supplies the number of bytes written (data might not have been fully 37 : * written). 38 : * @param end_stream supplies whether this is the end of socket writes. 39 : */ 40 : virtual void onWrite(const Buffer::Instance& data, uint32_t bytes_written, bool end_stream) PURE; 41 : }; 42 : 43 : using PerSocketTapperPtr = std::unique_ptr<PerSocketTapper>; 44 : 45 : /** 46 : * Abstract socket tap configuration. 47 : */ 48 : class SocketTapConfig : public virtual Extensions::Common::Tap::TapConfig { 49 : public: 50 : /** 51 : * @return a new per-socket tapper which is used to handle tapping of a discrete socket. 52 : * @param connection supplies the underlying network connection. 53 : */ 54 : virtual PerSocketTapperPtr createPerSocketTapper(const Network::Connection& connection) PURE; 55 : 56 : /** 57 : * @return time source to use for stamping events. 58 : */ 59 : virtual TimeSource& timeSource() const PURE; 60 : }; 61 : 62 : using SocketTapConfigSharedPtr = std::shared_ptr<SocketTapConfig>; 63 : 64 : } // namespace Tap 65 : } // namespace TransportSockets 66 : } // namespace Extensions 67 : } // namespace Envoy