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