MySQL 8.4.0
Source Code Documentation
ServerGreetor Class Reference

classic protocol handshake between client<->router and router<->server. More...

#include <classic_greeting_forwarder.h>

Inheritance diagram for ServerGreetor:
[legend]

Public Types

enum class  Stage {
  ServerGreeting , ServerGreetingError , ServerGreetingGreeting , ClientGreeting ,
  ClientGreetingStartTls , ClientGreetingFull , TlsConnectInit , TlsConnect ,
  ClientGreetingAfterTls , InitialResponse , FinalResponse , AuthOk ,
  AuthError , ServerGreetingSent , Error , Ok
}
 stages of the handshake flow. More...
 
- Public Types inherited from BasicProcessor
enum class  Result {
  Again , RecvFromClient , SendToClient , RecvFromServer ,
  RecvFromBoth , SendToServer , SendableToServer , Suspend ,
  Done , Void
}
 

Public Member Functions

 ServerGreetor (MysqlRoutingClassicConnectionBase *conn, bool in_handshake, std::function< void(const classic_protocol::message::server::Error &)> on_error, TraceEvent *parent_event)
 construct a server::greeting processor. More...
 
stdx::expected< Result, std::error_code > process () override
 
void stage (Stage stage)
 
Stage stage () const
 
void failed (const std::optional< classic_protocol::message::server::Error > &err)
 
std::optional< classic_protocol::message::server::Errorfailed () const
 
- Public Member Functions inherited from Processor
 BasicProcessor (MysqlRoutingClassicConnectionBase *conn)
 
- Public Member Functions inherited from BasicProcessor
 BasicProcessor (MysqlRoutingClassicConnectionBase *conn)
 
virtual ~BasicProcessor ()=default
 
const MysqlRoutingClassicConnectionBaseconnection () const
 
MysqlRoutingClassicConnectionBaseconnection ()
 

Private Member Functions

stdx::expected< Result, std::error_code > server_greeting ()
 
stdx::expected< Result, std::error_code > server_greeting_greeting ()
 received a server::greeting from the server. More...
 
stdx::expected< Result, std::error_code > server_greeting_error ()
 received an server::error from the server. More...
 
stdx::expected< Result, std::error_code > client_greeting ()
 
stdx::expected< Result, std::error_code > client_greeting_start_tls ()
 
stdx::expected< Result, std::error_code > client_greeting_full ()
 send a non-TLS client greeting to the server. More...
 
stdx::expected< Result, std::error_code > tls_connect_init ()
 
stdx::expected< Result, std::error_code > tls_connect ()
 
stdx::expected< Result, std::error_code > client_greeting_after_tls ()
 a TLS client greeting. More...
 
stdx::expected< Result, std::error_code > initial_response ()
 
stdx::expected< Result, std::error_code > final_response ()
 
stdx::expected< Result, std::error_code > auth_error ()
 router<-server: auth error. More...
 
stdx::expected< Result, std::error_code > auth_ok ()
 server-side: auth is ok. More...
 
stdx::expected< Result, std::error_code > error ()
 
void client_greeting_server_adjust_caps (ClassicProtocolState &src_protocol, ClassicProtocolState &dst_protocol)
 

Private Attributes

bool in_handshake_
 
Stage stage_ {Stage::ServerGreeting}
 
std::optional< classic_protocol::message::server::Errorfailed_
 
std::function< void(const classic_protocol::message::server::Error &err)> on_error_
 
TraceEventparent_event_ {nullptr}
 
TraceEventtrace_event_greeting_ {nullptr}
 
TraceEventtrace_event_server_greeting_ {nullptr}
 
TraceEventtrace_event_client_greeting_ {nullptr}
 
TraceEventtrace_event_tls_connect_ {nullptr}
 

Additional Inherited Members

- Static Public Attributes inherited from ForwardingProcessor
static constexpr const std::chrono::milliseconds kConnectRetryInterval
 interval between connect-retries. More...
 
- Protected Member Functions inherited from ForwardingProcessor
stdx::expected< Result, std::error_code > forward_server_to_client (bool noflush=false)
 forward the current packet from the server-side to the client-side. More...
 
stdx::expected< Result, std::error_code > forward_client_to_server (bool noflush=false)
 forward the current packet from the client-side to the server-side. More...
 
stdx::expected< Processor::Result, std::error_code > skip_or_inject_end_of_columns (bool no_flush=false)
 adjust the end-of-columns packet. More...
 
stdx::expected< bool, std::error_code > pool_server_connection ()
 move the server connection to the pool. More...
 
stdx::expected< Processor::Result, std::error_code > socket_reconnect_start (TraceEvent *parent_event)
 reconnect a socket. More...
 
stdx::expected< Processor::Result, std::error_code > mysql_reconnect_start (TraceEvent *parent_event)
 reconnect a mysql classic connection. More...
 
stdx::expected< Result, std::error_code > recv_server_failed_and_check_client_socket (std::error_code ec)
 handle error-code of a failed receive() from the server-socket and check the status of the client socket. More...
 
stdx::expected< Processor::Result, std::error_code > reconnect_send_error_msg (Channel &src_channel, ClassicProtocolState &src_protocol)
 send a Error msg based on the reconnect_error(). More...
 
template<class Proto >
stdx::expected< Processor::Result, std::error_code > reconnect_send_error_msg (TlsSwitchableConnection< Proto > &conn)
 
void reconnect_error (classic_protocol::message::server::Error err)
 set the reconnect error. More...
 
classic_protocol::message::server::Error reconnect_error () const
 get the reconnect error. More...
 
- Protected Member Functions inherited from Processor
stdx::expected< Result, std::error_code > send_server_failed (std::error_code ec)
 
stdx::expected< Result, std::error_code > recv_server_failed (std::error_code ec)
 
stdx::expected< Result, std::error_code > send_client_failed (std::error_code ec)
 
stdx::expected< Result, std::error_code > recv_client_failed (std::error_code ec)
 
stdx::expected< Result, std::error_code > server_socket_failed (std::error_code ec)
 
stdx::expected< Result, std::error_code > client_socket_failed (std::error_code ec)
 
stdx::expected< void, std::error_code > discard_current_msg (Channel &src_channel, ClassicProtocolState &src_protocol)
 discard to current message. More...
 
template<class Proto >
stdx::expected< void, std::error_code > discard_current_msg (TlsSwitchableConnection< Proto > &conn)
 
void trace (Tracer::Event e)
 
Tracertracer ()
 
TraceEventtrace_span (TraceEvent *parent_span, const std::string_view &prefix)
 start a span. More...
 
void trace_span_end (TraceEvent *event, TraceEvent::StatusCode status_code=TraceEvent::StatusCode::kUnset)
 end a span and set a status-code. More...
 
TraceEventtrace_command (const std::string_view &prefix)
 start a command span. More...
 
TraceEventtrace_connect_and_forward_command (TraceEvent *parent_span)
 start a connect-and-forward span. More...
 
TraceEventtrace_connect (TraceEvent *parent_span)
 start a connect span. More...
 
void trace_set_connection_attributes (TraceEvent *ev)
 start a connect span. More...
 
TraceEventtrace_forward_command (TraceEvent *parent_span)
 start a forward span. More...
 
void trace_command_end (TraceEvent *event, TraceEvent::StatusCode status_code=TraceEvent::StatusCode::kUnset)
 end a command span and set a status-code. More...
 
- Static Protected Member Functions inherited from ForwardingProcessor
template<class T >
static bool message_can_be_forwarded_as_is (ClassicProtocolState &src_protocol, ClassicProtocolState &dst_protocol, const T &msg)
 check of the capabilities of the source and the destination are the same for this message. More...
 
static bool connect_error_is_transient (const classic_protocol::message::server::Error &err)
 check if the error is a transient error. More...
 
- Static Protected Member Functions inherited from Processor
static void log_fatal_error_code (const char *msg, std::error_code ec)
 log a message with error-code as error. More...
 

Detailed Description

classic protocol handshake between client<->router and router<->server.

Member Enumeration Documentation

◆ Stage

enum class ServerGreetor::Stage
strong

stages of the handshake flow.

  • Client stages are on the client<->router side.
  • Server stages are on the router<->server side.
Enumerator
ServerGreeting 
ServerGreetingError 
ServerGreetingGreeting 
ClientGreeting 
ClientGreetingStartTls 
ClientGreetingFull 
TlsConnectInit 
TlsConnect 
ClientGreetingAfterTls 
InitialResponse 
FinalResponse 
AuthOk 
AuthError 
ServerGreetingSent 
Error 
Ok 

Constructor & Destructor Documentation

◆ ServerGreetor()

ServerGreetor::ServerGreetor ( MysqlRoutingClassicConnectionBase conn,
bool  in_handshake,
std::function< void(const classic_protocol::message::server::Error &)>  on_error,
TraceEvent parent_event 
)
inline

construct a server::greeting processor.

c->r   : ...
   r->s: connect()
   r<-s: server::greeting

a server greeting may be sent as part of the initial connection setup between client<->router<->server (in_handshake=true) or when router starts a connection on its own.

If in_handshake is true, the ServerGreetor expects it can send:

  • server::AuthMethodSwitch and
  • server::Ok

to the client connection.

Parameters
connthe connection the greeting will be transferred on.
in_handshaketrue if the greeting is part of the initial handshake.
on_errorcallback called on failure.
parent_eventparent span for the TraceEvents

Member Function Documentation

◆ auth_error()

stdx::expected< Processor::Result, std::error_code > ServerGreetor::auth_error ( )
private

router<-server: auth error.

◆ auth_ok()

stdx::expected< Processor::Result, std::error_code > ServerGreetor::auth_ok ( )
private

server-side: auth is ok.

◆ client_greeting()

stdx::expected< Processor::Result, std::error_code > ServerGreetor::client_greeting ( )
private

◆ client_greeting_after_tls()

stdx::expected< Processor::Result, std::error_code > ServerGreetor::client_greeting_after_tls ( )
private

a TLS client greeting.

◆ client_greeting_full()

stdx::expected< Processor::Result, std::error_code > ServerGreetor::client_greeting_full ( )
private

send a non-TLS client greeting to the server.

◆ client_greeting_server_adjust_caps()

void ServerGreetor::client_greeting_server_adjust_caps ( ClassicProtocolState src_protocol,
ClassicProtocolState dst_protocol 
)
private

◆ client_greeting_start_tls()

stdx::expected< Processor::Result, std::error_code > ServerGreetor::client_greeting_start_tls ( )
private

◆ error()

stdx::expected< Processor::Result, std::error_code > ServerGreetor::error ( )
private

◆ failed() [1/2]

std::optional< classic_protocol::message::server::Error > ServerGreetor::failed ( ) const
inline

◆ failed() [2/2]

void ServerGreetor::failed ( const std::optional< classic_protocol::message::server::Error > &  err)
inline

◆ final_response()

stdx::expected< Processor::Result, std::error_code > ServerGreetor::final_response ( )
private

◆ initial_response()

stdx::expected< Processor::Result, std::error_code > ServerGreetor::initial_response ( )
private

◆ process()

stdx::expected< Processor::Result, std::error_code > ServerGreetor::process ( )
overridevirtual

Implements BasicProcessor.

◆ server_greeting()

stdx::expected< Processor::Result, std::error_code > ServerGreetor::server_greeting ( )
private

◆ server_greeting_error()

stdx::expected< Processor::Result, std::error_code > ServerGreetor::server_greeting_error ( )
private

received an server::error from the server.

forward it to the client and close the connection.

◆ server_greeting_greeting()

stdx::expected< Processor::Result, std::error_code > ServerGreetor::server_greeting_greeting ( )
private

received a server::greeting from the server.

decode it.

◆ stage() [1/2]

Stage ServerGreetor::stage ( ) const
inline

◆ stage() [2/2]

void ServerGreetor::stage ( Stage  stage)
inline

◆ tls_connect()

stdx::expected< Processor::Result, std::error_code > ServerGreetor::tls_connect ( )
private

◆ tls_connect_init()

stdx::expected< Processor::Result, std::error_code > ServerGreetor::tls_connect_init ( )
private

Member Data Documentation

◆ failed_

std::optional<classic_protocol::message::server::Error> ServerGreetor::failed_
private

◆ in_handshake_

bool ServerGreetor::in_handshake_
private

◆ on_error_

std::function<void(const classic_protocol::message::server::Error &err)> ServerGreetor::on_error_
private

◆ parent_event_

TraceEvent* ServerGreetor::parent_event_ {nullptr}
private

◆ stage_

Stage ServerGreetor::stage_ {Stage::ServerGreeting}
private

◆ trace_event_client_greeting_

TraceEvent* ServerGreetor::trace_event_client_greeting_ {nullptr}
private

◆ trace_event_greeting_

TraceEvent* ServerGreetor::trace_event_greeting_ {nullptr}
private

◆ trace_event_server_greeting_

TraceEvent* ServerGreetor::trace_event_server_greeting_ {nullptr}
private

◆ trace_event_tls_connect_

TraceEvent* ServerGreetor::trace_event_tls_connect_ {nullptr}
private

The documentation for this class was generated from the following files: