MySQL 9.0.0
Source Code Documentation
xcom_network_provider.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2024, 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
82 const Network_configuration_parameters &params) override {
83#ifndef XCOM_WITHOUT_OPENSSL
84 bool const successful =
91 params.ssl_params.crl_path, params.ssl_params.cipher,
93 params.tls_params.tls_ciphersuites) == 1);
94 return successful;
95#else
96 return true;
97#endif
98 }
99
101
103
104 std::unique_ptr<Network_connection> open_connection(
105 const std::string &address, const unsigned short port,
106 const Network_security_credentials &security_credentials,
107 int connection_timeout = Network_provider::default_connection_timeout(),
110
111 int close_connection(const Network_connection &connection) override;
112
113 /**
114 * @brief Waits for the provider to become ready. This call is blocking.
115 *
116 * @return true in case of error or timeout
117 * @return false in case of success
118 */
120
121 /**
122 * @brief Notify that the provider is ready. It unblocks
123 * wait_for_provider_ready()
124 *
125 * @param init_error sets the error state of this notifier
126 */
127 void notify_provider_ready(bool init_error = false);
128
129 xcom_port get_port() const { return m_port; }
131
133 std::lock_guard<std::mutex> lck(m_init_lock);
134 return m_initialized;
135 }
136
138 void set_shutdown_tcp_server(bool shutdown_tcp_server) {
139 m_shutdown_tcp_server = shutdown_tcp_server;
140 }
141
143 void set_open_server_socket(result open_socket) {
144 m_open_server_socket = open_socket;
145 }
146
147 private:
150
153 mutable std::mutex m_init_lock;
154 mutable std::condition_variable m_init_cond_var;
155
157
159};
160
161#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:477
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:158
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:152
bool m_initialized
Definition: xcom_network_provider.h:151
result get_open_server_socket() const
Definition: xcom_network_provider.h:142
xcom_port get_port() const
Definition: xcom_network_provider.h:129
bool m_shutdown_tcp_server
Definition: xcom_network_provider.h:156
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:154
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:132
Xcom_network_provider(Xcom_network_provider &param)=delete
void set_shutdown_tcp_server(bool shutdown_tcp_server)
Definition: xcom_network_provider.h:138
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:137
std::thread m_network_provider_tcp_server
Definition: xcom_network_provider.h:149
std::mutex m_init_lock
Definition: xcom_network_provider.h:153
void cleanup_secure_connections_context() override
Definition: xcom_network_provider.cc:156
void set_port(xcom_port port)
Definition: xcom_network_provider.h:130
void set_open_server_socket(result open_socket)
Definition: xcom_network_provider.h:143
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:148
static loglevel log_level(const Sql_condition *condition)
Definition: histogram.cc:1644
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
struct ssl_parameters ssl_params
Definition: network_provider.h:194
struct tls_parameters tls_params
Definition: network_provider.h:195
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
const char * server_key_file
Definition: network_provider.h:173
const char * client_key_file
Definition: network_provider.h:175
const char * ca_path
Definition: network_provider.h:178
const char * cipher
Definition: network_provider.h:181
const char * crl_file
Definition: network_provider.h:179
const char * client_cert_file
Definition: network_provider.h:176
const char * crl_path
Definition: network_provider.h:180
const char * server_cert_file
Definition: network_provider.h:174
const char * ca_file
Definition: network_provider.h:177
const char * tls_ciphersuites
Definition: network_provider.h:185
const char * tls_version
Definition: network_provider.h:184
unsigned short xcom_port
Definition: xcom_common.h:46