MySQL 9.4.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
xcom_network_provider.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2025, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef XCOM_NETWORK_PROVIDER_H
25#define XCOM_NETWORK_PROVIDER_H
26
27// #include
28//"plugin/group_replication/libmysqlgcs/include/mysql/gcs/xplatform/my_xp_thread.h"
29
30#include <condition_variable>
31#include <mutex>
32#include <thread>
33
35
37#include "xcom/result.h"
38#include "xcom/xcom_common.h"
39
41 public:
44 : Network_provider(std::move(param)) {}
45
46 /**
47 * @brief Construct a new Xcom_network_provider object
48 */
50 : m_port(0),
51 m_initialized(false),
52 m_init_error(false),
55
56 virtual ~Xcom_network_provider() override {}
57
58 /**
59 * Inherited methods from Gcs_network_provider
60 */
61 std::pair<bool, int> start() override;
62 std::pair<bool, int> stop() override;
64 return XCOM_PROTOCOL;
65 }
66
67 /**
68 * @brief Configures this network provider. It is mandatory to be called in
69 * This provider, else we won't know which listen port to use.
70 *
71 * @param params Network_configuration_parameters with the listen port
72 * configured
73 * @return true if configure went well. False otherwise.
74 */
75 bool configure(const Network_configuration_parameters &params) override {
76 m_port = params.port;
77
78 return true;
79 }
80
83 [[maybe_unused]]) override {
84#ifndef XCOM_WITHOUT_OPENSSL
85 bool const successful =
87 params.ssl_params.server_key_file,
88 params.ssl_params.server_cert_file,
89 params.ssl_params.client_key_file,
90 params.ssl_params.client_cert_file, params.ssl_params.ca_file,
91 params.ssl_params.ca_path, params.ssl_params.crl_file,
92 params.ssl_params.crl_path, params.ssl_params.cipher,
93 params.tls_params.tls_version,
94 params.tls_params.tls_ciphersuites) == 1);
95 return successful;
96#else
97 return true;
98#endif
99 }
100
102
104
105 std::unique_ptr<Network_connection> open_connection(
106 const std::string &address, const unsigned short port,
107 const Network_security_credentials &security_credentials,
108 int connection_timeout = Network_provider::default_connection_timeout(),
111
112 int close_connection(const Network_connection &connection) override;
113
114 /**
115 * @brief Waits for the provider to become ready. This call is blocking.
116 *
117 * @return true in case of error or timeout
118 * @return false in case of success
119 */
121
122 /**
123 * @brief Notify that the provider is ready. It unblocks
124 * wait_for_provider_ready()
125 *
126 * @param init_error sets the error state of this notifier
127 */
128 void notify_provider_ready(bool init_error = false);
129
130 xcom_port get_port() const { return m_port; }
132
134 std::lock_guard<std::mutex> lck(m_init_lock);
135 return m_initialized;
136 }
137
139 void set_shutdown_tcp_server(bool shutdown_tcp_server) {
140 m_shutdown_tcp_server = shutdown_tcp_server;
141 }
142
144 void set_open_server_socket(result open_socket) {
145 m_open_server_socket = open_socket;
146 }
147
148 private:
151
154 mutable std::mutex m_init_lock;
155 mutable std::condition_variable m_init_cond_var;
156
158
160};
161
162#endif // XCOM_NETWORK_PROVIDER_H
Base class for External Network Providers.
Definition: network_provider.h:295
static constexpr int default_connection_timeout()
Definition: network_provider.h:457
static int xcom_init_ssl(const char *server_key_file, const char *server_cert_file, const char *client_key_file, const char *client_cert_file, const char *ca_file, const char *ca_path, const char *crl_file, const char *crl_path, const char *cipher, const char *tls_version, const char *tls_ciphersuites)
Definition: xcom_network_provider_ssl_native_lib.cc:479
Definition: xcom_network_provider.h:40
Xcom_network_provider()
Construct a new Xcom_network_provider object.
Definition: xcom_network_provider.h:49
std::unique_ptr< Network_connection > open_connection(const std::string &address, const unsigned short port, const Network_security_credentials &security_credentials, int connection_timeout=Network_provider::default_connection_timeout(), network_provider_dynamic_log_level log_level=network_provider_dynamic_log_level::PROVIDED) override
Opens a new connection to another XCom endpoint served by the same Network provider.
Definition: xcom_network_provider.cc:189
bool configure(const Network_configuration_parameters &params) override
Configures this network provider.
Definition: xcom_network_provider.h:75
virtual ~Xcom_network_provider() override
Definition: xcom_network_provider.h:56
bool finalize_secure_connections_context() override
Definition: xcom_network_provider.cc:162
result m_open_server_socket
Definition: xcom_network_provider.h:159
enum_transport_protocol get_communication_stack() const override
Get the communication stack implemented by this provider.
Definition: xcom_network_provider.h:63
bool configure_secure_connections(const Network_configuration_parameters &params) override
Configures the active provider with all things needed to establish SSL connections.
Definition: xcom_network_provider.h:81
bool m_init_error
Definition: xcom_network_provider.h:153
bool m_initialized
Definition: xcom_network_provider.h:152
result get_open_server_socket() const
Definition: xcom_network_provider.h:143
xcom_port get_port() const
Definition: xcom_network_provider.h:130
bool m_shutdown_tcp_server
Definition: xcom_network_provider.h:157
Xcom_network_provider(Xcom_network_provider &&param)
Definition: xcom_network_provider.h:43
std::condition_variable m_init_cond_var
Definition: xcom_network_provider.h:155
void notify_provider_ready(bool init_error=false)
Notify that the provider is ready.
Definition: xcom_network_provider.cc:377
bool is_provider_initialized() const
Definition: xcom_network_provider.h:133
Xcom_network_provider(Xcom_network_provider &param)=delete
void set_shutdown_tcp_server(bool shutdown_tcp_server)
Definition: xcom_network_provider.h:139
int close_connection(const Network_connection &connection) override
Closes an open connection to another XCom endpoint served by the same Network provider.
Definition: xcom_network_provider.cc:170
bool wait_for_provider_ready()
Waits for the provider to become ready.
Definition: xcom_network_provider.cc:363
bool should_shutdown_tcp_server() const
Definition: xcom_network_provider.h:138
std::thread m_network_provider_tcp_server
Definition: xcom_network_provider.h:150
std::mutex m_init_lock
Definition: xcom_network_provider.h:154
void cleanup_secure_connections_context() override
Definition: xcom_network_provider.cc:156
void set_port(xcom_port port)
Definition: xcom_network_provider.h:131
void set_open_server_socket(result open_socket)
Definition: xcom_network_provider.h:144
std::pair< bool, int > start() override
Inherited methods from Gcs_network_provider.
Definition: xcom_network_provider.cc:384
std::pair< bool, int > stop() override
Stops the network provider.
Definition: xcom_network_provider.cc:412
xcom_port m_port
Definition: xcom_network_provider.h:149
static loglevel log_level(const Sql_condition *condition)
Definition: histogram.cc:1650
Definition: gcs_xcom_synode.h:64
enum_transport_protocol
Enum that describes the available XCom Communication Stacks.
Definition: network_provider.h:45
@ XCOM_PROTOCOL
Definition: network_provider.h:47
network_provider_dynamic_log_level
Dynamic log level enum values.
Definition: network_provider.h:103
int init_error(const PFS_global_param *param)
Definition: pfs_error.cc:66
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33
Possible configuration parameters.
Definition: network_provider.h:191
unsigned short port
Definition: network_provider.h:192
Represents an open connection.
Definition: network_provider.h:201
Security credentials to establish a connection.
Definition: network_provider.h:134
Definition: result.h:30
unsigned short xcom_port
Definition: xcom_common.h:46