MySQL 9.1.0
Source Code Documentation
gcs_xcom_utils.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 GCS_XCOM_UTILS_INCLUDED
25#define GCS_XCOM_UTILS_INCLUDED
26
27#include <vector>
31#include "plugin/group_replication/libmysqlgcs/xdr_gen/xcom_vp.h"
32
33#define XCOM_PREFIX "[XCOM] "
34
35/**
36 @class gcs_xcom_utils
37
38 Class where the common binding utilities reside as static methods.
39*/
41 public:
42 /**
43 Create a xcom group identifier from a Group Identifier.
44
45 @param[in] group_id A group identifier
46
47 @return an hash of the group identifier string that will serve as input
48 for the group id in XCom
49 */
51
52 /**
53 Processes a list of comma separated peer nodes.
54
55 @param peer_nodes input string of comma separated peer nodes
56 @param[out] processed_peers the list of configured peers
57 */
58 static void process_peer_nodes(const std::string *peer_nodes,
59 std::vector<std::string> &processed_peers);
60
61 /**
62 Validates peer nodes according with IP/Address rules enforced by
63 is_valid_hostname function
64
65 @param [in,out] peers input list of peer nodes. It will be cleansed of
66 invalid peers
67 @param [in,out] invalid_peers This list will contain all invalid peers.
68 */
69 static void validate_peer_nodes(std::vector<std::string> &peers,
70 std::vector<std::string> &invalid_peers);
71
72 /**
73 Simple multiplicative hash.
74
75 @param buf the data to create an hash from
76 @param length data length
77
78 @return calculated hash
79 */
80 static uint32_t mhash(const unsigned char *buf, size_t length);
81
82 static int init_net();
83 static int deinit_net();
84
85 virtual ~Gcs_xcom_utils();
86};
87
88/**
89 * Converts the given GCS protocol version into the MySQL version that
90 * introduced it.
91 *
92 * @param protocol the GCS protocol
93 * @return the MySQL version that introduced it, in format major.minor.patch
94 */
96
97/*****************************************************
98 *****************************************************
99
100 Auxiliary checking functions.
101
102 *****************************************************
103 *****************************************************
104 */
105
106/**
107 Checks whether the given string is a number or not
108 @param s the string to check.
109 @return true if it is a number, false otherwise.
110 */
111inline bool is_number(const std::string &s) {
112 return s.find_first_not_of("0123456789") == std::string::npos;
113}
114
115/**
116 * @brief Parses the string "host:port" and checks if it is correct.
117 *
118 * @param server_and_port the server hostname and port in the form
119 * hostname:port.
120 *
121 * @return true if it is a valid URL, false otherwise.
122 */
123bool is_valid_hostname(const std::string &server_and_port);
124
125/**
126 Checks whether the given string is a valid GCS protocol known by this node.
127
128 @returns true If it is, false otherwise.
129 */
130bool is_valid_protocol(std::string const &protocol);
131
132/**
133 Does some transformations on the parameters. For instance, replaces
134 aliases with the correct ones
135 */
137
138/**
139 Checks that parameters are syntactically valid.
140
141 @param params The parameters to validate syntactically.
142 @param netns_manager A reference to a Network Namespace Manager.
143 This is needed because of the allowlist configuration and
144 local address validation.
145
146 @returns false if there is a syntax error, true otherwise.
147 */
149 Network_namespace_manager *netns_manager);
150#endif /* GCS_XCOM_UTILS_INCLUDED */
This represents the unique identification of a group.
Definition: gcs_group_identifier.h:35
This class is to be used to provide parameters to bindings in a transparent and generic way.
Definition: gcs_types.h:59
Definition: gcs_xcom_utils.h:40
static uint32_t mhash(const unsigned char *buf, size_t length)
Simple multiplicative hash.
Definition: gcs_xcom_utils.cc:116
static void validate_peer_nodes(std::vector< std::string > &peers, std::vector< std::string > &invalid_peers)
Validates peer nodes according with IP/Address rules enforced by is_valid_hostname function.
Definition: gcs_xcom_utils.cc:102
static void process_peer_nodes(const std::string *peer_nodes, std::vector< std::string > &processed_peers)
Processes a list of comma separated peer nodes.
Definition: gcs_xcom_utils.cc:75
virtual ~Gcs_xcom_utils()
static u_long build_xcom_group_id(Gcs_group_identifier &group_id)
Create a xcom group identifier from a Group Identifier.
Definition: gcs_xcom_utils.cc:68
static int deinit_net()
Definition: gcs_xcom_utils.cc:128
static int init_net()
Definition: gcs_xcom_utils.cc:126
Class that provides Network Namespace services.
Definition: network_provider.h:242
Gcs_protocol_version
The GCS protocol versions.
Definition: gcs_types.h:128
bool is_number(const std::string &s)
Checks whether the given string is a number or not.
Definition: gcs_xcom_utils.h:111
bool is_valid_hostname(const std::string &server_and_port)
Parses the string "host:port" and checks if it is correct.
Definition: gcs_xcom_utils.cc:130
bool is_parameters_syntax_correct(const Gcs_interface_parameters &params, Network_namespace_manager *netns_manager)
Checks that parameters are syntactically valid.
Definition: gcs_xcom_utils.cc:320
bool is_valid_protocol(std::string const &protocol)
Checks whether the given string is a valid GCS protocol known by this node.
Definition: gcs_xcom_utils.cc:284
std::string gcs_protocol_to_mysql_version(Gcs_protocol_version protocol)
Converts the given GCS protocol version into the MySQL version that introduced it.
Definition: gcs_xcom_utils.cc:663
void fix_parameters_syntax(Gcs_interface_parameters &params)
Does some transformations on the parameters.
Definition: gcs_xcom_utils.cc:150
Definition: buf0block_hint.cc:30
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
__u_long u_long
Definition: types.h:74