/proc/self/cwd/source/extensions/filters/network/thrift_proxy/transport.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include <memory> |
4 | | #include <string> |
5 | | |
6 | | #include "envoy/buffer/buffer.h" |
7 | | #include "envoy/config/typed_config.h" |
8 | | #include "envoy/registry/registry.h" |
9 | | |
10 | | #include "source/common/common/assert.h" |
11 | | #include "source/common/config/utility.h" |
12 | | #include "source/common/singleton/const_singleton.h" |
13 | | #include "source/extensions/filters/network/thrift_proxy/metadata.h" |
14 | | |
15 | | namespace Envoy { |
16 | | namespace Extensions { |
17 | | namespace NetworkFilters { |
18 | | namespace ThriftProxy { |
19 | | |
20 | | /** |
21 | | * Transport represents a Thrift transport. The Thrift transport is nominally a generic, |
22 | | * bi-directional byte stream. In Envoy we assume it always represents a network byte stream and |
23 | | * the Transport is just a mechanism for framing messages and passing message metadata. |
24 | | */ |
25 | | class Transport { |
26 | | public: |
27 | 0 | virtual ~Transport() = default; |
28 | | |
29 | | /* |
30 | | * Returns this transport's name. |
31 | | * |
32 | | * @return std::string containing the transport name. |
33 | | */ |
34 | | virtual const std::string& name() const PURE; |
35 | | |
36 | | /** |
37 | | * @return TransportType the transport type |
38 | | */ |
39 | | virtual TransportType type() const PURE; |
40 | | |
41 | | /* |
42 | | * Decodes the start of a transport message. If successful, the start of the frame is removed |
43 | | * from the buffer. Transports should not modify the buffer, headers, protocol type, or size if |
44 | | * more data is required to decode the frame's start. If the full frame start can be decoded, the |
45 | | * Transport must drain the frame start data from the buffer. The request metadata should be |
46 | | * modified with any data available to the transport. |
47 | | * |
48 | | * @param buffer the currently buffered thrift data. |
49 | | * @param metadata MessageMetadata to be modified if transport supports additional information |
50 | | * @return bool true if a complete frame header was successfully consumed, false if more data |
51 | | * is required. |
52 | | * @throws EnvoyException if the data is not valid for this transport. |
53 | | */ |
54 | | virtual bool decodeFrameStart(Buffer::Instance& buffer, MessageMetadata& metadata) PURE; |
55 | | |
56 | | /* |
57 | | * Decodes the end of a transport message. If successful, the end of the frame is removed from |
58 | | * the buffer. |
59 | | * |
60 | | * @param buffer the currently buffered thrift data. |
61 | | * @return bool true if a complete frame trailer was successfully consumed, false if more data |
62 | | * is required. |
63 | | * @throws EnvoyException if the data is not valid for this transport. |
64 | | */ |
65 | | virtual bool decodeFrameEnd(Buffer::Instance& buffer) PURE; |
66 | | |
67 | | /** |
68 | | * Wraps the given message buffer with the transport's header and trailer (if any). After |
69 | | * encoding, message will be empty. |
70 | | * @param buffer is the output buffer |
71 | | * @param metadata MessageMetadata for the message |
72 | | * @param message a protocol-encoded message |
73 | | * @throws EnvoyException if the message is too large for the transport |
74 | | */ |
75 | | virtual void encodeFrame(Buffer::Instance& buffer, const MessageMetadata& metadata, |
76 | | Buffer::Instance& message) PURE; |
77 | | }; |
78 | | |
79 | | using TransportPtr = std::unique_ptr<Transport>; |
80 | | |
81 | | /** |
82 | | * Implemented by each Thrift transport and registered via Registry::registerFactory or the |
83 | | * convenience class RegisterFactory. |
84 | | */ |
85 | | class NamedTransportConfigFactory : public Envoy::Config::UntypedFactory { |
86 | | public: |
87 | | ~NamedTransportConfigFactory() override = default; |
88 | | |
89 | | /** |
90 | | * Create a particular Thrift transport. |
91 | | * @return TransportPtr the transport |
92 | | */ |
93 | | virtual TransportPtr createTransport() PURE; |
94 | | |
95 | 20 | std::string category() const override { return "envoy.thrift_proxy.transports"; } |
96 | | |
97 | | /** |
98 | | * Convenience method to lookup a factory by type. |
99 | | * @param TransportType the transport type |
100 | | * @return NamedTransportConfigFactory& for the TransportType |
101 | | */ |
102 | 0 | static NamedTransportConfigFactory& getFactory(TransportType type) { |
103 | 0 | const std::string& name = TransportNames::get().fromType(type); |
104 | 0 | return Envoy::Config::Utility::getAndCheckFactoryByName<NamedTransportConfigFactory>(name); |
105 | 0 | } |
106 | | }; |
107 | | |
108 | | /** |
109 | | * TransportFactoryBase provides a template for a trivial NamedTransportConfigFactory. |
110 | | */ |
111 | | template <class TransportImpl> class TransportFactoryBase : public NamedTransportConfigFactory { |
112 | | public: |
113 | 0 | TransportPtr createTransport() override { return std::move(std::make_unique<TransportImpl>()); } Unexecuted instantiation: Envoy::Extensions::NetworkFilters::ThriftProxy::TransportFactoryBase<Envoy::Extensions::NetworkFilters::ThriftProxy::AutoTransportImpl>::createTransport() Unexecuted instantiation: Envoy::Extensions::NetworkFilters::ThriftProxy::TransportFactoryBase<Envoy::Extensions::NetworkFilters::ThriftProxy::FramedTransportImpl>::createTransport() Unexecuted instantiation: Envoy::Extensions::NetworkFilters::ThriftProxy::TransportFactoryBase<Envoy::Extensions::NetworkFilters::ThriftProxy::HeaderTransportImpl>::createTransport() Unexecuted instantiation: Envoy::Extensions::NetworkFilters::ThriftProxy::TransportFactoryBase<Envoy::Extensions::NetworkFilters::ThriftProxy::UnframedTransportImpl>::createTransport() |
114 | | |
115 | 32 | std::string name() const override { return name_; } Envoy::Extensions::NetworkFilters::ThriftProxy::TransportFactoryBase<Envoy::Extensions::NetworkFilters::ThriftProxy::AutoTransportImpl>::name() const Line | Count | Source | 115 | 8 | std::string name() const override { return name_; } |
Envoy::Extensions::NetworkFilters::ThriftProxy::TransportFactoryBase<Envoy::Extensions::NetworkFilters::ThriftProxy::FramedTransportImpl>::name() const Line | Count | Source | 115 | 8 | std::string name() const override { return name_; } |
Envoy::Extensions::NetworkFilters::ThriftProxy::TransportFactoryBase<Envoy::Extensions::NetworkFilters::ThriftProxy::HeaderTransportImpl>::name() const Line | Count | Source | 115 | 8 | std::string name() const override { return name_; } |
Envoy::Extensions::NetworkFilters::ThriftProxy::TransportFactoryBase<Envoy::Extensions::NetworkFilters::ThriftProxy::UnframedTransportImpl>::name() const Line | Count | Source | 115 | 8 | std::string name() const override { return name_; } |
|
116 | | |
117 | | protected: |
118 | 16 | TransportFactoryBase(const std::string& name) : name_(name) {} Envoy::Extensions::NetworkFilters::ThriftProxy::TransportFactoryBase<Envoy::Extensions::NetworkFilters::ThriftProxy::AutoTransportImpl>::TransportFactoryBase(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 118 | 4 | TransportFactoryBase(const std::string& name) : name_(name) {} |
Envoy::Extensions::NetworkFilters::ThriftProxy::TransportFactoryBase<Envoy::Extensions::NetworkFilters::ThriftProxy::FramedTransportImpl>::TransportFactoryBase(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 118 | 4 | TransportFactoryBase(const std::string& name) : name_(name) {} |
Envoy::Extensions::NetworkFilters::ThriftProxy::TransportFactoryBase<Envoy::Extensions::NetworkFilters::ThriftProxy::HeaderTransportImpl>::TransportFactoryBase(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 118 | 4 | TransportFactoryBase(const std::string& name) : name_(name) {} |
Envoy::Extensions::NetworkFilters::ThriftProxy::TransportFactoryBase<Envoy::Extensions::NetworkFilters::ThriftProxy::UnframedTransportImpl>::TransportFactoryBase(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 118 | 4 | TransportFactoryBase(const std::string& name) : name_(name) {} |
|
119 | | |
120 | | private: |
121 | | const std::string name_; |
122 | | }; |
123 | | |
124 | | } // namespace ThriftProxy |
125 | | } // namespace NetworkFilters |
126 | | } // namespace Extensions |
127 | | } // namespace Envoy |