MySQL 8.1.0
Source Code Documentation
xcom_network_provider.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2023, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef XCOM_NETWORK_PROVIDER_H
24#define XCOM_NETWORK_PROVIDER_H
25
26//#include
27//"plugin/group_replication/libmysqlgcs/include/mysql/gcs/xplatform/my_xp_thread.h"
28
29#include <condition_variable>
30#include <mutex>
31#include <thread>
32
34
36#include "xcom/result.h"
37#include "xcom/xcom_common.h"
38
40 public:
43 : Network_provider(std::move(param)) {}
44
45 /**
46 * @brief Construct a new Xcom_network_provider object
47 */
49 : m_port(0),
50 m_initialized(false),
51 m_init_error(false),
54
55 virtual ~Xcom_network_provider() override {}
56
57 /**
58 * Inherited methods from Gcs_network_provider
59 */
60 std::pair<bool, int> start() override;
61 std::pair<bool, int> stop() override;
63 return XCOM_PROTOCOL;
64 }
65
66 /**
67 * @brief Configures this network provider. It is mandatory to be called in
68 * This provider, else we won't know which listen port to use.
69 *
70 * @param params Network_configuration_parameters with the listen port
71 * configured
72 * @return true if configure went well. False otherwise.
73 */
74 bool configure(const Network_configuration_parameters &params) override {
75 m_port = params.port;
76
77 return true;
78 }
79
81 const Network_configuration_parameters &params) override {
82 bool const successful =
89 params.ssl_params.crl_path, params.ssl_params.cipher,
91 params.tls_params.tls_ciphersuites) == 1);
92 return successful;
93 }
94
96
98
99 std::unique_ptr<Network_connection> open_connection(
100 const std::string &address, const unsigned short port,
101 const Network_security_credentials &security_credentials,
102 int connection_timeout =
104
105 int close_connection(const Network_connection &connection) override;
106
107 /**
108 * @brief Waits for the provider to become ready. This call is blocking.
109 *
110 * @return true in case of error or timeout
111 * @return false in case of success
112 */
114
115 /**
116 * @brief Notify that the provider is ready. It unblocks
117 * wait_for_provider_ready()
118 *
119 * @param init_error sets the error state of this notifier
120 */
121 void notify_provider_ready(bool init_error = false);
122
123 xcom_port get_port() const { return m_port; }
125
127 std::lock_guard<std::mutex> lck(m_init_lock);
128 return m_initialized;
129 }
130
132 void set_shutdown_tcp_server(bool shutdown_tcp_server) {
133 m_shutdown_tcp_server = shutdown_tcp_server;
134 }
135
137 void set_open_server_socket(result open_socket) {
138 m_open_server_socket = open_socket;
139 }
140
141 private:
144
147 mutable std::mutex m_init_lock;
148 mutable std::condition_variable m_init_cond_var;
149
151
153};
154
155#endif // XCOM_NETWORK_PROVIDER_H
Base class for External Network Providers.
Definition: network_provider.h:268
static constexpr int default_connection_timeout()
Definition: network_provider.h:424
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:466
Definition: xcom_network_provider.h:39
Xcom_network_provider()
Construct a new Xcom_network_provider object.
Definition: xcom_network_provider.h:48
bool configure(const Network_configuration_parameters &params) override
Configures this network provider.
Definition: xcom_network_provider.h:74
virtual ~Xcom_network_provider() override
Definition: xcom_network_provider.h:55
bool finalize_secure_connections_context() override
Definition: xcom_network_provider.cc:154
result m_open_server_socket
Definition: xcom_network_provider.h:152
enum_transport_protocol get_communication_stack() const override
Get the communication stack implemented by this provider.
Definition: xcom_network_provider.h:62
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:80
bool m_init_error
Definition: xcom_network_provider.h:146
bool m_initialized
Definition: xcom_network_provider.h:145
result get_open_server_socket() const
Definition: xcom_network_provider.h:136
xcom_port get_port() const
Definition: xcom_network_provider.h:123
bool m_shutdown_tcp_server
Definition: xcom_network_provider.h:150
Xcom_network_provider(Xcom_network_provider &&param)
Definition: xcom_network_provider.h:42
std::condition_variable m_init_cond_var
Definition: xcom_network_provider.h:148
void notify_provider_ready(bool init_error=false)
Notify that the provider is ready.
Definition: xcom_network_provider.cc:394
bool is_provider_initialized() const
Definition: xcom_network_provider.h:126
Xcom_network_provider(Xcom_network_provider &param)=delete
void set_shutdown_tcp_server(bool shutdown_tcp_server)
Definition: xcom_network_provider.h:132
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:160
bool wait_for_provider_ready()
Waits for the provider to become ready.
Definition: xcom_network_provider.cc:380
bool should_shutdown_tcp_server() const
Definition: xcom_network_provider.h:131
std::thread m_network_provider_tcp_server
Definition: xcom_network_provider.h:143
std::mutex m_init_lock
Definition: xcom_network_provider.h:147
void cleanup_secure_connections_context() override
Definition: xcom_network_provider.cc:148
void set_port(xcom_port port)
Definition: xcom_network_provider.h:124
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()) override
Opens a new connection to another XCom endpoint served by the same Network provider.
Definition: xcom_network_provider.cc:179
void set_open_server_socket(result open_socket)
Definition: xcom_network_provider.h:137
std::pair< bool, int > start() override
Inherited methods from Gcs_network_provider.
Definition: xcom_network_provider.cc:401
std::pair< bool, int > stop() override
Stops the network provider.
Definition: xcom_network_provider.cc:429
xcom_port m_port
Definition: xcom_network_provider.h:142
Definition: varlen_sort.h:183
enum_transport_protocol
Enum that describes the available XCom Communication Stacks.
Definition: network_provider.h:44
@ XCOM_PROTOCOL
Definition: network_provider.h:46
int init_error(const PFS_global_param *param)
Definition: pfs_error.cc:65
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:32
Possible configuration parameters.
Definition: network_provider.h:153
struct ssl_parameters ssl_params
Definition: network_provider.h:156
struct tls_parameters tls_params
Definition: network_provider.h:157
unsigned short port
Definition: network_provider.h:154
Represents an open connection.
Definition: network_provider.h:163
Security credentials to establish a connection.
Definition: network_provider.h:96
Definition: result.h:29
const char * server_key_file
Definition: network_provider.h:135
const char * client_key_file
Definition: network_provider.h:137
const char * ca_path
Definition: network_provider.h:140
const char * cipher
Definition: network_provider.h:143
const char * crl_file
Definition: network_provider.h:141
const char * client_cert_file
Definition: network_provider.h:138
const char * crl_path
Definition: network_provider.h:142
const char * server_cert_file
Definition: network_provider.h:136
const char * ca_file
Definition: network_provider.h:139
const char * tls_ciphersuites
Definition: network_provider.h:147
const char * tls_version
Definition: network_provider.h:146
unsigned short xcom_port
Definition: xcom_common.h:45