26#ifndef ROUTING_CLASSIC_CONNECTION_BASE_INCLUDED
27#define ROUTING_CLASSIC_CONNECTION_BASE_INCLUDED
33#include <unordered_map>
66 std::optional<classic_protocol::message::server::Greeting>
104 std::optional<classic_protocol::message::client::Greeting> msg) {
114 std::optional<classic_protocol::message::server::Greeting> msg) {
221 public std::enable_shared_from_this<MysqlRoutingClassicConnectionBase> {
228 std::unique_ptr<ConnectionBase> client_connection,
229 std::unique_ptr<RoutingConnectionBase> client_routing_connection,
238 std::move(client_routing_connection),
250 template <
typename... Args>
251 [[nodiscard]]
static std::shared_ptr<MysqlRoutingClassicConnectionBase>
258 return std::shared_ptr<MysqlRoutingClassicConnectionBase>(
263 std::shared_ptr<MysqlRoutingClassicConnectionBase>
getptr() {
264 return shared_from_this();
268 std::vector<uint8_t> &error_frame,
const uint8_t seq_id,
270 const uint16_t error_code,
const std::string &msg,
271 const std::string &sql_state);
307 bool call_finish =
true);
356 return processors_.push_back(std::move(processor));
364 bool ignore_some_state_changed =
false);
368 std::string_view stage,
Function func);
524 std::optional<classic_protocol::session_track::TransactionState>
trx_state_;
525 std::optional<classic_protocol::session_track::TransactionCharacteristics>
protocol state of a classic protocol connection.
Definition: classic_connection_base.h:52
HandshakeState handshake_state_
Definition: classic_connection_base.h:216
classic_protocol::capabilities::value_type server_caps_
Definition: classic_connection_base.h:191
uint8_t seq_id() const
Definition: classic_connection_base.h:119
std::string schema()
Definition: classic_connection_base.h:158
ClassicProtocolState()=default
PreparedStatements & prepared_statements()
Definition: classic_connection_base.h:180
void sent_attributes(std::string attrs)
Definition: classic_connection_base.h:167
void seq_id(uint8_t id)
Definition: classic_connection_base.h:121
std::string auth_method_name() const
Definition: classic_connection_base.h:136
void handshake_state(HandshakeState state)
Definition: classic_connection_base.h:173
void status_flags(classic_protocol::status::value_type val)
Definition: classic_connection_base.h:186
uint8_t & seq_id()
Definition: classic_connection_base.h:118
std::unordered_map< uint32_t, PreparedStatement > PreparedStatements
Definition: classic_connection_base.h:175
std::optional< classic_protocol::message::server::Greeting > server_greeting() const
Definition: classic_connection_base.h:108
HandshakeState handshake_state() const
Definition: classic_connection_base.h:171
void server_capabilities(classic_protocol::capabilities::value_type caps)
Definition: classic_connection_base.h:78
std::string auth_method_data() const
Definition: classic_connection_base.h:144
HandshakeState
Definition: classic_connection_base.h:54
void password(std::optional< std::string > pw)
Definition: classic_connection_base.h:155
std::string sent_attributes()
Definition: classic_connection_base.h:166
std::string auth_method_name_
Definition: classic_connection_base.h:208
void client_greeting(std::optional< classic_protocol::message::client::Greeting > msg)
Definition: classic_connection_base.h:103
void server_greeting(std::optional< classic_protocol::message::server::Greeting > msg)
Definition: classic_connection_base.h:113
std::string sent_attributes_
Definition: classic_connection_base.h:206
std::optional< FrameInfo > & current_frame()
Definition: classic_connection_base.h:130
std::optional< uint8_t > msg_type_
Definition: classic_connection_base.h:198
std::optional< uint8_t > & current_msg_type()
Definition: classic_connection_base.h:131
classic_protocol::capabilities::value_type client_caps_
Definition: classic_connection_base.h:192
uint8_t seq_id_
Definition: classic_connection_base.h:200
void client_capabilities(classic_protocol::capabilities::value_type caps)
Definition: classic_connection_base.h:82
uint64_t columns_left
Definition: classic_connection_base.h:133
void schema(std::string s)
Definition: classic_connection_base.h:159
std::optional< classic_protocol::message::server::Greeting > server_greeting_
Definition: classic_connection_base.h:195
std::string username_
Definition: classic_connection_base.h:202
void auth_method_name(std::string name)
Definition: classic_connection_base.h:140
void attributes(std::string attrs)
Definition: classic_connection_base.h:163
classic_protocol::status::value_type status_flags() const
Definition: classic_connection_base.h:182
std::optional< FrameInfo > current_frame_
Definition: classic_connection_base.h:197
ClassicProtocolState(classic_protocol::capabilities::value_type server_caps, classic_protocol::capabilities::value_type client_caps, std::optional< classic_protocol::message::server::Greeting > server_greeting, std::string username, std::string schema, std::string attributes)
Definition: classic_connection_base.h:63
classic_protocol::capabilities::value_type client_capabilities() const
Definition: classic_connection_base.h:86
uint32_t params_left
Definition: classic_connection_base.h:134
classic_protocol::status::value_type status_flags_
Definition: classic_connection_base.h:214
void auth_method_data(std::string data)
Definition: classic_connection_base.h:148
std::optional< classic_protocol::message::client::Greeting > client_greeting() const
Definition: classic_connection_base.h:98
std::string auth_method_data_
Definition: classic_connection_base.h:209
PreparedStatements prepared_stmts_
Definition: classic_connection_base.h:211
std::optional< classic_protocol::message::client::Greeting > client_greeting_
Definition: classic_connection_base.h:194
std::string recv_attributes_
Definition: classic_connection_base.h:205
std::optional< std::string > password() const
Definition: classic_connection_base.h:156
classic_protocol::capabilities::value_type server_capabilities() const
Definition: classic_connection_base.h:90
void username(std::string user)
Definition: classic_connection_base.h:153
std::string username()
Definition: classic_connection_base.h:152
std::optional< std::string > password_
Definition: classic_connection_base.h:203
const PreparedStatements & prepared_statements() const
Definition: classic_connection_base.h:177
std::string attributes()
Definition: classic_connection_base.h:162
classic_protocol::capabilities::value_type shared_capabilities() const
Definition: classic_connection_base.h:94
std::string schema_
Definition: classic_connection_base.h:204
A forward iterable container of destinations.
Definition: destination.h:97
execution context for SQL.
Definition: sql_exec_context.h:43
Definition: connection.h:43
MySQLRoutingContext & context()
Definition: connection.h:52
MySQLRoutingContext holds data used by MySQLRouting (1 per plugin instances) and MySQLRoutingConnecti...
Definition: context.h:59
Definition: classic_connection_base.h:221
std::optional< classic_protocol::session_track::TransactionCharacteristics > trx_characteristics_
Definition: classic_connection_base.h:526
bool authenticated_
Definition: classic_connection_base.h:478
RouteDestination * destinations()
Definition: classic_connection_base.h:500
void destination_id(const std::string &id)
Definition: classic_connection_base.h:437
bool connection_sharing_possible() const
check if connection sharing is possible.
Definition: classic_connection_base.cc:834
bool authenticated() const
check if the connection is authenticated.
Definition: classic_connection_base.h:448
bool collation_connection_maybe_dirty_
Definition: classic_connection_base.h:529
void async_wait_client_closed()
void on_handshake_received()
Definition: classic_connection_base.cc:94
std::string destination_id_
Definition: classic_connection_base.h:517
void recv_server_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:133
Destinations destinations_
Definition: classic_connection_base.h:513
void pop_processor()
Definition: classic_connection_base.h:359
void async_recv_server(Function next)
Definition: classic_connection_base.cc:305
virtual void async_run()
Definition: classic_connection_base.h:294
ExecutionContext exec_ctx_
Definition: classic_connection_base.h:538
ClassicProtocolState * server_protocol()
Definition: classic_connection_base.h:419
net::steady_timer connect_timer_
Definition: classic_connection_base.h:573
static stdx::expected< size_t, std::error_code > encode_error_packet(std::vector< uint8_t > &error_frame, const uint8_t seq_id, const classic_protocol::capabilities::value_type caps, const uint16_t error_code, const std::string &msg, const std::string &sql_state)
Definition: classic_connection_base.cc:56
void server_socket_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:160
void call_next_function(Function next)
Definition: classic_connection_base.h:324
bool diagnostic_area_changed_
Definition: classic_connection_base.h:577
void collation_connection_maybe_dirty(bool val)
Definition: classic_connection_base.h:503
std::unique_ptr< ProtocolSplicerBase > socket_splicer_
Definition: classic_connection_base.h:515
void authenticated(bool v)
Definition: classic_connection_base.h:449
const ProtocolSplicerBase * socket_splicer() const
Definition: classic_connection_base.h:429
const ClassicProtocolState * client_protocol() const
Definition: classic_connection_base.h:414
net::steady_timer & connect_timer()
Definition: classic_connection_base.h:550
void send_client_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:142
bool connection_sharing_allowed() const
check if connection sharing is allowed.
Definition: classic_connection_base.cc:846
bool requires_tls() const
Definition: classic_connection_base.h:496
SslMode source_ssl_mode() const
Definition: classic_connection_base.h:276
void async_send_server(Function next)
Definition: classic_connection_base.cc:278
stdx::expected< void, std::error_code > track_session_changes(net::const_buffer session_trackers, classic_protocol::capabilities::value_type caps, bool ignore_some_state_changed=false)
Definition: classic_connection_base.cc:502
void trace_and_call_function(Tracer::Event::Direction dir, std::string_view stage, Function func)
Definition: classic_connection_base.cc:784
virtual void client_socket_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:184
void async_send_client_and_finish()
void connect_error_code(const std::error_code &ec)
Definition: classic_connection_base.h:552
std::optional< classic_protocol::session_track::TransactionState > trx_state_
Definition: classic_connection_base.h:524
void async_send_client(Function next)
Definition: classic_connection_base.cc:230
void on_handshake_aborted()
Definition: classic_connection_base.cc:107
std::shared_ptr< MysqlRoutingClassicConnectionBase > getptr()
Definition: classic_connection_base.h:263
void disconnect() override
Definition: classic_connection_base.cc:416
Destinations & current_destinations()
Definition: classic_connection_base.h:501
bool some_state_changed_
Definition: classic_connection_base.h:527
bool requires_tls_
Definition: classic_connection_base.h:531
int active_work_
Definition: classic_connection_base.h:476
static std::shared_ptr< MysqlRoutingClassicConnectionBase > create(Args &&... args)
Definition: classic_connection_base.h:252
void requires_tls(bool v)
Definition: classic_connection_base.h:494
SslMode dest_ssl_mode() const
Definition: classic_connection_base.h:280
void async_recv_client(Function next)
Definition: classic_connection_base.cc:257
void connection_sharing_allowed_reset()
reset the connection-sharing state.
Definition: classic_connection_base.cc:857
void send_server_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:124
void some_state_changed(bool v)
Definition: classic_connection_base.h:498
void server_side_client_greeting()
Definition: classic_connection_base.cc:438
void async_wait_send_server(Function next)
Definition: classic_connection_base.cc:397
ProtocolSplicerBase * socket_splicer()
Definition: classic_connection_base.h:433
FromEither
Definition: classic_connection_base.h:560
std::vector< std::unique_ptr< BasicProcessor > > processors_
Definition: classic_connection_base.h:352
RouteDestination * route_destination_
Definition: classic_connection_base.h:512
FromEither recv_from_either_
Definition: classic_connection_base.h:579
ClassicProtocolState * client_protocol()
Definition: classic_connection_base.h:409
void push_processor(std::unique_ptr< BasicProcessor > processor)
Definition: classic_connection_base.h:355
FromEither recv_from_either() const
Definition: classic_connection_base.h:569
bool in_handshake_
client side handshake isn't finished yet.
Definition: classic_connection_base.h:522
std::error_code connect_ec_
Definition: classic_connection_base.h:575
ExecutionContext & execution_context()
Definition: classic_connection_base.h:534
net::steady_timer & read_timer()
Definition: classic_connection_base.h:549
std::string get_client_address() const override
Returns address of client which connected to router.
Definition: classic_connection_base.h:284
void async_recv_both(Function next)
Definition: classic_connection_base.cc:323
void loop()
Definition: classic_connection_base.cc:794
void recv_from_either(FromEither v)
Definition: classic_connection_base.h:567
std::string get_destination_id() const override
Definition: classic_connection_base.h:435
virtual void done()
Definition: classic_connection_base.cc:499
void resume()
Definition: classic_connection_base.h:315
std::string get_server_address() const override
Returns address of server to which connection is established.
Definition: classic_connection_base.h:288
net::steady_timer read_timer_
Definition: classic_connection_base.h:572
Tracer tracer_
Definition: classic_connection_base.h:546
void recv_client_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:151
void finish()
Definition: classic_connection_base.cc:452
void diagnostic_area_changed(bool diagnostic_area_changed)
Definition: classic_connection_base.h:555
Function
Definition: classic_connection_base.h:318
const ExecutionContext & execution_context() const
Definition: classic_connection_base.h:535
bool greeting_from_router() const
if the router is sending the initial server-greeting.
Definition: classic_connection_base.h:488
const ClassicProtocolState * server_protocol() const
Definition: classic_connection_base.h:424
Tracer & tracer()
Definition: classic_connection_base.h:543
void trace(Tracer::Event e)
Definition: classic_connection_base.h:541
MysqlRoutingClassicConnectionBase(MySQLRoutingContext &context, RouteDestination *route_destination, std::unique_ptr< ConnectionBase > client_connection, std::unique_ptr< RoutingConnectionBase > client_routing_connection, std::function< void(MySQLRoutingConnectionBase *)> remove_callback)
Definition: classic_connection_base.h:226
bool diagnostic_area_changed() const
Definition: classic_connection_base.h:558
std::error_code connect_error_code() const
Definition: classic_connection_base.h:553
bool collation_connection_maybe_dirty() const
Definition: classic_connection_base.h:507
splices two connections together.
Definition: basic_protocol_splicer.h:484
TlsSwitchableConnection & client_conn()
Definition: basic_protocol_splicer.h:521
SslMode dest_ssl_mode() const
Definition: basic_protocol_splicer.h:537
SslMode source_ssl_mode() const
Definition: basic_protocol_splicer.h:533
TlsSwitchableConnection & server_conn()
Definition: basic_protocol_splicer.h:527
Definition: basic_protocol_splicer.h:291
Manage destinations for a Connection Routing.
Definition: destination.h:188
a Connection that can be switched to TLS.
Definition: basic_protocol_splicer.h:306
std::string endpoint() const
Definition: basic_protocol_splicer.h:427
ProtocolStateBase * protocol()
Definition: basic_protocol_splicer.h:449
Direction
Definition: tracer.h:73
traces the timestamps of events in a stderr log.
Definition: tracer.h:49
void trace(Event e)
Definition: tracer.h:128
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:222
char * user
Definition: mysqladmin.cc:60
std::bitset< 32 > value_type
Definition: classic_protocol_constants.h:73
std::bitset< 16 > value_type
Definition: classic_protocol_constants.h:168
std::string dir
Double write files location.
Definition: buf0dblwr.cc:77
Unique_ptr< T, std::nullptr_t > make_unique(size_t size)
In-place constructs a new unique pointer with no specific allocator and with array type T.
Definition: gcs_xcom_synode.h:64
SslMode
Definition: ssl_mode.h:29
case opt name
Definition: sslopt-case.h:33
Definition: classic_connection_base.h:123
size_t forwarded_frame_size_
size of the whole frame that's already forwarded.
Definition: classic_connection_base.h:126
size_t frame_size_
size of the whole frame.
Definition: classic_connection_base.h:125
uint8_t seq_id_
sequence id.
Definition: classic_connection_base.h:124
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:510