MySQL 8.0.37
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 bool const successful =
90 params.ssl_params.crl_path, params.ssl_params.cipher,
92 params.tls_params.tls_ciphersuites) == 1);
93 return successful;
94 }
95
97
99
100 std::unique_ptr<Network_connection> open_connection(
101 const std::string &address, const unsigned short port,
102 const Network_security_credentials &security_credentials,
103 int connection_timeout = Network_provider::default_connection_timeout(),
106
107 int close_connection(const Network_connection &connection) override;
108
109 /**
110 * @brief Waits for the provider to become ready. This call is blocking.
111 *
112 * @return true in case of error or timeout
113 * @return false in case of success
114 */
116
117 /**
118 * @brief Notify that the provider is ready. It unblocks
119 * wait_for_provider_ready()
120 *
121 * @param init_error sets the error state of this notifier
122 */
123 void notify_provider_ready(bool init_error = false);
124
125 xcom_port get_port() const { return m_port; }
127
129 std::lock_guard<std::mutex> lck(m_init_lock);
130 return m_initialized;
131 }
132
134 void set_shutdown_tcp_server(bool shutdown_tcp_server) {
135 m_shutdown_tcp_server = shutdown_tcp_server;
136 }
137
139 void set_open_server_socket(result open_socket) {
140 m_open_server_socket = open_socket;
141 }
142
143 private:
146
149 mutable std::mutex m_init_lock;
150 mutable std::condition_variable m_init_cond_var;
151
153
155};
156
157#endif // XCOM_NETWORK_PROVIDER_H
Base class for External Network Providers.
Definition: network_provider.h:306
static constexpr int default_connection_timeout()
Definition: network_provider.h:466
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:467
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:180
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:155
result m_open_server_socket
Definition: xcom_network_provider.h:154
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:148
bool m_initialized
Definition: xcom_network_provider.h:147
result get_open_server_socket() const
Definition: xcom_network_provider.h:138
xcom_port get_port() const
Definition: xcom_network_provider.h:125
bool m_shutdown_tcp_server
Definition: xcom_network_provider.h:152
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:150
void notify_provider_ready(bool init_error=false)
Notify that the provider is ready.
Definition: xcom_network_provider.cc:396
bool is_provider_initialized() const
Definition: xcom_network_provider.h:128
Xcom_network_provider(Xcom_network_provider &param)=delete
void set_shutdown_tcp_server(bool shutdown_tcp_server)
Definition: xcom_network_provider.h:134
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:161
bool wait_for_provider_ready()
Waits for the provider to become ready.
Definition: xcom_network_provider.cc:382
bool should_shutdown_tcp_server() const
Definition: xcom_network_provider.h:133
std::thread m_network_provider_tcp_server
Definition: xcom_network_provider.h:145
std::mutex m_init_lock
Definition: xcom_network_provider.h:149
void cleanup_secure_connections_context() override
Definition: xcom_network_provider.cc:149
void set_port(xcom_port port)
Definition: xcom_network_provider.h:126
void set_open_server_socket(result open_socket)
Definition: xcom_network_provider.h:139
std::pair< bool, int > start() override
Inherited methods from Gcs_network_provider.
Definition: xcom_network_provider.cc:403
std::pair< bool, int > stop() override
Stops the network provider.
Definition: xcom_network_provider.cc:431
xcom_port m_port
Definition: xcom_network_provider.h:144
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