26#ifndef MYSQL_ROUTER_CHANNEL_INCLUDED
27#define MYSQL_ROUTER_CHANNEL_INCLUDED
30#include <system_error>
41#include <openssl/ssl.h>
69 std::vector<uint8_t, default_init_allocator<uint8_t>>;
79 ssl_.reset(SSL_new(ssl_ctx));
81 SSL_set_bio(
ssl_.get(), BIO_new(BIO_s_mem()), BIO_new(BIO_s_mem()));
111 template <
class DynamicBuffer>
112 typename std::enable_if<net::is_dynamic_buffer<DynamicBuffer>::value,
115 auto orig_size = dyn_buf.size();
116 size_t transferred{};
118 auto write_res =
write_plain(dyn_buf.data(0, orig_size));
120 return write_res.get_unexpected();
123 transferred += write_res.value();
124 dyn_buf.consume(write_res.value());
145 template <
class DynamicBuffer>
148 auto orig_size = dyn_buf.size();
150 size_t transferred{};
152 dyn_buf.grow(grow_size);
154 const auto res_res =
read_plain(dyn_buf.data(orig_size, grow_size));
156 dyn_buf.shrink(grow_size);
157 return res_res.get_unexpected();
160 transferred += res_res.value();
161 dyn_buf.shrink(grow_size - res_res.value());
SSL aware socket buffers.
Definition: channel.h:64
stdx::expected< size_t, std::error_code > flush_from_recv_buf()
flush data from receive buffer to recv_plain_buffer().
Definition: channel.cc:114
stdx::expected< size_t, std::error_code > flush_to_send_buf()
flush data to the send buffer.
Definition: channel.cc:152
stdx::expected< bool, std::error_code > tls_shutdown()
Definition: channel.cc:63
stdx::expected< void, std::error_code > tls_accept()
accept a TLS session.
Definition: channel.cc:37
void view_discard_raw()
Definition: channel.cc:304
stdx::expected< size_t, std::error_code > write(const net::const_buffer &b)
write unencrypted net::const_buffer to the channel.
Definition: channel.h:135
recv_buffer_type send_buffer_
Definition: channel.h:326
recv_buffer_type send_plain_buffer_
Definition: channel.h:325
void view_discard_plain()
Definition: channel.cc:309
const recv_buffer_type & recv_buffer() const
buffer of data that was received from the socket.
Definition: channel.h:242
void consume_plain(size_t count)
Definition: channel.cc:293
size_t want_recv() const
bytes wanted.
Definition: channel.h:219
stdx::expected< size_t, std::error_code > read(DynamicBuffer &dyn_buf, size_t sz)
read unencrypted data from channel to a net::dynamic_buffer.
Definition: channel.h:146
const recv_buffer_type & send_buffer() const
buffer of data to be sent to the socket.
Definition: channel.h:252
void init_ssl(SSL_CTX *ssl_ctx)
initialize the SSL session.
Definition: channel.h:78
void is_tls(bool v)
mark channel as containing TLS data in the recv_buffer().
Definition: channel.h:291
void want_recv(size_t wanted)
bytes wanted.
Definition: channel.h:212
recv_buffer_type & payload_buffer()
Definition: channel.h:259
stdx::expected< size_t, std::error_code > read_plain(const net::mutable_buffer &b)
read plaintext data from recv_plain_buffer() into b.
Definition: channel.cc:90
Ssl ssl_
Definition: channel.h:330
SSL * ssl() const
get access to the raw SSL handle.
Definition: channel.h:308
std::enable_if< net::is_dynamic_buffer< DynamicBuffer >::value, stdx::expected< size_t, std::error_code > >::type write(DynamicBuffer &dyn_buf)
write unencrypted net::dynamic_buffer to the channel.
Definition: channel.h:114
Ssl release_ssl()
release the internal Ssl structure.
Definition: channel.cc:271
const recv_buffer_type & payload_buffer() const
payload buffer for
Definition: channel.h:257
Channel(Ssl ssl)
Definition: channel.h:73
size_t want_recv_
Definition: channel.h:316
recv_buffer_type & send_plain_buffer()
unencrypted data to be sent to the socket.
Definition: channel.cc:277
recv_view_type recv_view_
Definition: channel.h:319
recv_buffer_type recv_buffer_
Definition: channel.h:318
recv_view_type recv_plain_view_
Definition: channel.h:321
mysql_harness::Ssl Ssl
Definition: channel.h:71
void view_sync_plain()
Definition: channel.cc:320
void view_sync_raw()
Definition: channel.cc:318
recv_buffer_type & send_buffer()
buffer of data to be sent to the socket.
Definition: channel.h:231
stdx::expected< size_t, std::error_code > read_to_plain(size_t sz)
Definition: channel.cc:219
stdx::expected< void, std::error_code > tls_connect()
connect a TLS session.
Definition: channel.cc:48
const recv_view_type & recv_plain_view() const
decrypted data after a recv().
Definition: channel.cc:283
stdx::expected< size_t, std::error_code > write_plain(const net::const_buffer &b)
write unencrypted data from a net::const_buffer to the channel.
Definition: channel.cc:79
std::vector< uint8_t, default_init_allocator< uint8_t > > recv_buffer_type
Definition: channel.h:69
bool tls_init_is_finished()
Definition: channel.cc:59
stdx::span< typename recv_buffer_type::value_type > recv_view_type
Definition: channel.h:70
bool is_tls_
Definition: channel.h:328
bool is_tls() const
check if connection switched to TLS.
Definition: channel.h:296
recv_buffer_type & recv_buffer()
buffer of data that was received from the socket.
Definition: channel.h:224
recv_buffer_type payload_buffer_
Definition: channel.h:323
const recv_view_type & recv_view() const
network data after a recv().
Definition: channel.cc:281
void consume_raw(size_t count)
Definition: channel.cc:287
recv_buffer_type recv_plain_buffer_
Definition: channel.h:320
Definition: expected.h:944
static int count
Definition: myisam_ftdump.cc:43
std::unique_ptr< SSL, mysql_harness::impl::Deleter_SSL > Ssl
Definition: tls_types.h:48
Definition: gcs_xcom_synode.h:64
required string type
Definition: replication_group_member_actions.proto:34