MySQL 8.4.2
Source Code Documentation
basic_protocol_splicer.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2020, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTING_BASIC_PROTOCOL_SPLICER_INCLUDED
27#define ROUTING_BASIC_PROTOCOL_SPLICER_INCLUDED
28
29#include <cstdint> // size_t
30#include <cstdio>
31#include <functional> // function
32#include <optional>
33#include <sstream>
34#include <string>
35
36#include "blocked_endpoints.h"
37#include "harness_assert.h"
41#include "mysql/harness/net_ts/internet.h" // net::ip::tcp
43#include "mysql/harness/net_ts/local.h" // local::stream_protocol
46#include "mysqlrouter/channel.h"
48
50 public:
51 virtual ~RoutingConnectionBase() = default;
52
53 [[nodiscard]] virtual std::vector<std::pair<std::string, std::string>>
55
56 virtual uint64_t reset_error_count(BlockedEndpoints &blocked_endpoints) = 0;
57 virtual uint64_t increment_error_count(
58 BlockedEndpoints &blocked_endpoints) = 0;
59};
60
61template <class Protocol>
63 public:
65 using endpoint_type = typename protocol_type::endpoint;
66
68
69 [[nodiscard]] std::vector<std::pair<std::string, std::string>>
72 }
73
74 uint64_t reset_error_count(BlockedEndpoints &blocked_endpoints) override {
75 return blocked_endpoints.reset_error_count(ep_);
76 }
77
78 uint64_t increment_error_count(BlockedEndpoints &blocked_endpoints) override {
79 return blocked_endpoints.increment_error_count(ep_);
80 }
81
82 private:
84};
85
86template <class T>
89
90 public:
92
94 std::unique_ptr<ConnectionBase> conn,
95 std::unique_ptr<RoutingConnectionBase> routing_conn, SslMode ssl_mode,
97 : base_class_(std::move(conn), ssl_mode, std::move(state)),
98 routing_conn_(std::move(routing_conn)) {}
99
101 std::unique_ptr<ConnectionBase> conn,
102 std::unique_ptr<RoutingConnectionBase> routing_conn, SslMode ssl_mode,
104 : base_class_(std::move(conn), ssl_mode, std::move(channel),
105 std::move(state)),
106 routing_conn_(std::move(routing_conn)) {}
107
108 [[nodiscard]] std::vector<std::pair<std::string, std::string>>
110 return routing_conn_->initial_connection_attributes();
111 }
112
113 [[nodiscard]] uint64_t reset_error_count(
114 BlockedEndpoints &blocked_endpoints) {
115 return routing_conn_->reset_error_count(blocked_endpoints);
116 }
117
118 [[nodiscard]] uint64_t increment_error_count(
119 BlockedEndpoints &blocked_endpoints) {
120 return routing_conn_->increment_error_count(blocked_endpoints);
121 }
122
123 private:
124 std::unique_ptr<RoutingConnectionBase> routing_conn_;
125};
126
127#endif
Definition: blocked_endpoints.h:34
uint64_t increment_error_count(const net::ip::tcp::endpoint &endpoint)
increments the error count of an endpoint.
Definition: blocked_endpoints.cc:45
uint64_t reset_error_count(const net::ip::tcp::endpoint &endpoint)
resets error counter for an endpoint.
Definition: blocked_endpoints.cc:58
SSL aware socket buffers.
Definition: channel.h:65
Definition: protocol.h:33
Definition: basic_protocol_splicer.h:49
virtual std::vector< std::pair< std::string, std::string > > initial_connection_attributes() const =0
virtual ~RoutingConnectionBase()=default
virtual uint64_t increment_error_count(BlockedEndpoints &blocked_endpoints)=0
virtual uint64_t reset_error_count(BlockedEndpoints &blocked_endpoints)=0
Definition: basic_protocol_splicer.h:62
typename protocol_type::endpoint endpoint_type
Definition: basic_protocol_splicer.h:65
std::vector< std::pair< std::string, std::string > > initial_connection_attributes() const override
Definition: basic_protocol_splicer.h:70
uint64_t increment_error_count(BlockedEndpoints &blocked_endpoints) override
Definition: basic_protocol_splicer.h:78
RoutingConnection(endpoint_type ep)
Definition: basic_protocol_splicer.h:67
endpoint_type ep_
Definition: basic_protocol_splicer.h:83
uint64_t reset_error_count(BlockedEndpoints &blocked_endpoints) override
Definition: basic_protocol_splicer.h:74
Definition: basic_protocol_splicer.h:87
TlsSwitchableClientConnection(std::unique_ptr< ConnectionBase > conn, std::unique_ptr< RoutingConnectionBase > routing_conn, SslMode ssl_mode, Channel channel, protocol_state_type state)
Definition: basic_protocol_splicer.h:100
std::vector< std::pair< std::string, std::string > > initial_connection_attributes() const
Definition: basic_protocol_splicer.h:109
TlsSwitchableClientConnection(std::unique_ptr< ConnectionBase > conn, std::unique_ptr< RoutingConnectionBase > routing_conn, SslMode ssl_mode, protocol_state_type state)
Definition: basic_protocol_splicer.h:93
uint64_t increment_error_count(BlockedEndpoints &blocked_endpoints)
Definition: basic_protocol_splicer.h:118
uint64_t reset_error_count(BlockedEndpoints &blocked_endpoints)
Definition: basic_protocol_splicer.h:113
std::unique_ptr< RoutingConnectionBase > routing_conn_
Definition: basic_protocol_splicer.h:124
a Connection that can be switched to TLS.
Definition: connection_base.h:264
T protocol_state_type
Definition: connection_base.h:272
SslMode ssl_mode() const
Definition: connection_base.h:363
std::vector< std::pair< std::string, std::string > > initial_connection_attributes(const net::ip::tcp::endpoint &ep)
TCP/IP socket related connection attributes.
Definition: initial_connection_attributes.h:43
Definition: gcs_xcom_synode.h:64
SslMode
Definition: ssl_mode.h:29
Definition: task.h:427