1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
https://bugs.gentoo.org/946389
https://github.com/randombit/botan/pull/4484
From 2a406beab449a2cb310fa543451a7087ca7b4b1a Mon Sep 17 00:00:00 2001
From: q66 <q66@chimera-linux.org>
Date: Sun, 15 Dec 2024 02:42:02 +0100
Subject: [PATCH 1/2] Remove usage of deprecated asio API
These were all finally dropped with boost 1.87, so this fixes
build with boost 1.87.
--- a/src/cli/tls_proxy.cpp
+++ b/src/cli/tls_proxy.cpp
@@ -106,11 +106,11 @@ class tls_proxy_session final : public std::enable_shared_from_this<tls_proxy_se
typedef std::shared_ptr<tls_proxy_session> pointer;
- static pointer create(boost::asio::io_service& io,
+ static pointer create(boost::asio::io_context& io,
const std::shared_ptr<Botan::TLS::Session_Manager>& session_manager,
const std::shared_ptr<Botan::Credentials_Manager>& credentials,
const std::shared_ptr<Botan::TLS::Policy>& policy,
- const tcp::resolver::iterator& endpoints) {
+ const tcp::resolver::results_type& endpoints) {
auto session = std::make_shared<tls_proxy_session>(io, endpoints);
// Defer the setup of the TLS server to make use of
@@ -144,7 +144,7 @@ class tls_proxy_session final : public std::enable_shared_from_this<tls_proxy_se
}
}
- tls_proxy_session(boost::asio::io_service& io, tcp::resolver::iterator endpoints) :
+ tls_proxy_session(boost::asio::io_context& io, tcp::resolver::results_type endpoints) :
m_strand(io),
m_server_endpoints(std::move(endpoints)),
m_client_socket(io),
@@ -287,7 +287,7 @@ class tls_proxy_session final : public std::enable_shared_from_this<tls_proxy_se
void tls_session_activated() override {
auto onConnect = [self = weak_from_this()](boost::system::error_code ec,
- const tcp::resolver::iterator& /*endpoint*/) {
+ tcp::resolver::results_type::iterator /*endpoint*/) {
if(ec) {
log_error("Server connection", ec);
return;
@@ -301,7 +301,7 @@ class tls_proxy_session final : public std::enable_shared_from_this<tls_proxy_se
return;
}
};
- async_connect(m_server_socket, m_server_endpoints, onConnect);
+ async_connect(m_server_socket, m_server_endpoints.begin(), m_server_endpoints.end(), onConnect);
}
void tls_session_established(const Botan::TLS::Session_Summary& session) override {
@@ -315,9 +315,9 @@ class tls_proxy_session final : public std::enable_shared_from_this<tls_proxy_se
}
}
- boost::asio::io_service::strand m_strand;
+ boost::asio::io_context::strand m_strand;
- tcp::resolver::iterator m_server_endpoints;
+ tcp::resolver::results_type m_server_endpoints;
tcp::socket m_client_socket;
tcp::socket m_server_socket;
@@ -341,9 +341,9 @@ class tls_proxy_server final {
public:
typedef tls_proxy_session session;
- tls_proxy_server(boost::asio::io_service& io,
+ tls_proxy_server(boost::asio::io_context& io,
unsigned short port,
- tcp::resolver::iterator endpoints,
+ tcp::resolver::results_type endpoints,
std::shared_ptr<Botan::Credentials_Manager> creds,
std::shared_ptr<Botan::TLS::Policy> policy,
std::shared_ptr<Botan::TLS::Session_Manager> session_mgr,
@@ -383,7 +383,7 @@ class tls_proxy_server final {
}
tcp::acceptor m_acceptor;
- tcp::resolver::iterator m_server_endpoints;
+ tcp::resolver::results_type m_server_endpoints;
std::shared_ptr<Botan::Credentials_Manager> m_creds;
std::shared_ptr<Botan::TLS::Policy> m_policy;
@@ -429,10 +429,10 @@ class TLS_Proxy final : public Command {
auto policy = load_tls_policy(get_arg("policy"));
- boost::asio::io_service io;
+ boost::asio::io_context io;
tcp::resolver resolver(io);
- auto server_endpoint_iterator = resolver.resolve({target, target_port});
+ auto server_endpoint_iterator = resolver.resolve(target, target_port);
std::shared_ptr<Botan::TLS::Session_Manager> session_mgr;
--- a/src/lib/utils/socket/socket.cpp
+++ b/src/lib/utils/socket/socket.cpp
@@ -46,20 +46,19 @@ class Asio_Socket final : public OS::Socket {
public:
Asio_Socket(std::string_view hostname, std::string_view service, std::chrono::milliseconds timeout) :
m_timeout(timeout), m_timer(m_io), m_tcp(m_io) {
- m_timer.expires_from_now(m_timeout);
+ m_timer.expires_after(m_timeout);
check_timeout();
boost::asio::ip::tcp::resolver resolver(m_io);
- boost::asio::ip::tcp::resolver::query query(std::string{hostname}, std::string{service});
- boost::asio::ip::tcp::resolver::iterator dns_iter = resolver.resolve(query);
+ boost::asio::ip::tcp::resolver::results_type dns_iter = resolver.resolve(std::string{hostname}, std::string{service});
boost::system::error_code ec = boost::asio::error::would_block;
- auto connect_cb = [&ec](const boost::system::error_code& e, const boost::asio::ip::tcp::resolver::iterator&) {
+ auto connect_cb = [&ec](const boost::system::error_code& e, boost::asio::ip::tcp::resolver::results_type::iterator) {
ec = e;
};
- boost::asio::async_connect(m_tcp, dns_iter, connect_cb);
+ boost::asio::async_connect(m_tcp, dns_iter.begin(), dns_iter.end(), connect_cb);
while(ec == boost::asio::error::would_block) {
m_io.run_one();
@@ -74,7 +73,7 @@ class Asio_Socket final : public OS::Socket {
}
void write(const uint8_t buf[], size_t len) override {
- m_timer.expires_from_now(m_timeout);
+ m_timer.expires_after(m_timeout);
boost::system::error_code ec = boost::asio::error::would_block;
@@ -90,7 +89,7 @@ class Asio_Socket final : public OS::Socket {
}
size_t read(uint8_t buf[], size_t len) override {
- m_timer.expires_from_now(m_timeout);
+ m_timer.expires_after(m_timeout);
boost::system::error_code ec = boost::asio::error::would_block;
size_t got = 0;
@@ -116,7 +115,7 @@ class Asio_Socket final : public OS::Socket {
private:
void check_timeout() {
- if(m_tcp.is_open() && m_timer.expires_at() < std::chrono::system_clock::now()) {
+ if(m_tcp.is_open() && m_timer.expiry() < std::chrono::system_clock::now()) {
boost::system::error_code err;
// NOLINTNEXTLINE(bugprone-unused-return-value,cert-err33-c)
@@ -127,7 +126,7 @@ class Asio_Socket final : public OS::Socket {
}
const std::chrono::milliseconds m_timeout;
- boost::asio::io_service m_io;
+ boost::asio::io_context m_io;
boost::asio::system_timer m_timer;
boost::asio::ip::tcp::socket m_tcp;
};
--- a/src/lib/utils/socket/socket_udp.cpp
+++ b/src/lib/utils/socket/socket_udp.cpp
@@ -46,20 +46,19 @@ class Asio_SocketUDP final : public OS::SocketUDP {
public:
Asio_SocketUDP(std::string_view hostname, std::string_view service, std::chrono::microseconds timeout) :
m_timeout(timeout), m_timer(m_io), m_udp(m_io) {
- m_timer.expires_from_now(m_timeout);
+ m_timer.expires_after(m_timeout);
check_timeout();
boost::asio::ip::udp::resolver resolver(m_io);
- boost::asio::ip::udp::resolver::query query(std::string{hostname}, std::string{service});
- boost::asio::ip::udp::resolver::iterator dns_iter = resolver.resolve(query);
+ boost::asio::ip::udp::resolver::results_type dns_iter = resolver.resolve(std::string{hostname}, std::string{service});
boost::system::error_code ec = boost::asio::error::would_block;
- auto connect_cb = [&ec](const boost::system::error_code& e, const boost::asio::ip::udp::resolver::iterator&) {
+ auto connect_cb = [&ec](const boost::system::error_code& e, boost::asio::ip::udp::resolver::results_type::iterator) {
ec = e;
};
- boost::asio::async_connect(m_udp, dns_iter, connect_cb);
+ boost::asio::async_connect(m_udp, dns_iter.begin(), dns_iter.end(), connect_cb);
while(ec == boost::asio::error::would_block) {
m_io.run_one();
@@ -74,7 +73,7 @@ class Asio_SocketUDP final : public OS::SocketUDP {
}
void write(const uint8_t buf[], size_t len) override {
- m_timer.expires_from_now(m_timeout);
+ m_timer.expires_after(m_timeout);
boost::system::error_code ec = boost::asio::error::would_block;
@@ -90,7 +89,7 @@ class Asio_SocketUDP final : public OS::SocketUDP {
}
size_t read(uint8_t buf[], size_t len) override {
- m_timer.expires_from_now(m_timeout);
+ m_timer.expires_after(m_timeout);
boost::system::error_code ec = boost::asio::error::would_block;
size_t got = 0;
@@ -116,7 +115,7 @@ class Asio_SocketUDP final : public OS::SocketUDP {
private:
void check_timeout() {
- if(m_udp.is_open() && m_timer.expires_at() < std::chrono::system_clock::now()) {
+ if(m_udp.is_open() && m_timer.expiry() < std::chrono::system_clock::now()) {
boost::system::error_code err;
// NOLINTNEXTLINE(bugprone-unused-return-value,cert-err33-c)
@@ -127,7 +126,7 @@ class Asio_SocketUDP final : public OS::SocketUDP {
}
const std::chrono::microseconds m_timeout;
- boost::asio::io_service m_io;
+ boost::asio::io_context m_io;
boost::asio::system_timer m_timer;
boost::asio::ip::udp::socket m_udp;
};
From 3820f357017eacef1fcb5119582bc9789b88f6c2 Mon Sep 17 00:00:00 2001
From: Jack Lloyd <jack@randombit.net>
Date: Wed, 18 Dec 2024 17:10:34 -0500
Subject: [PATCH 2/2] Address review comments
--- a/src/cli/tls_proxy.cpp
+++ b/src/cli/tls_proxy.cpp
@@ -287,7 +287,7 @@ class tls_proxy_session final : public std::enable_shared_from_this<tls_proxy_se
void tls_session_activated() override {
auto onConnect = [self = weak_from_this()](boost::system::error_code ec,
- tcp::resolver::results_type::iterator /*endpoint*/) {
+ const tcp::resolver::results_type::iterator& /*endpoint*/) {
if(ec) {
log_error("Server connection", ec);
return;
--- a/src/examples/tls_stream_client.cpp
+++ b/src/examples/tls_stream_client.cpp
@@ -35,7 +35,7 @@ class Credentials_Manager : public Botan::Credentials_Manager {
class client {
public:
client(boost::asio::io_context& io_context,
- boost::asio::ip::tcp::resolver::iterator endpoint_iterator,
+ const boost::asio::ip::tcp::resolver::results_type& endpoints,
std::string_view host,
const http::request<http::string_body>& req) :
m_request(req),
@@ -46,7 +46,8 @@ class client {
host)),
m_stream(io_context, m_ctx) {
boost::asio::async_connect(m_stream.lowest_layer(),
- std::move(endpoint_iterator),
+ endpoints.begin(),
+ endpoints.end(),
boost::bind(&client::handle_connect, this, ap::error));
}
@@ -111,8 +112,7 @@ int main(int argc, char* argv[]) {
boost::asio::io_context io_context;
boost::asio::ip::tcp::resolver resolver(io_context);
- boost::asio::ip::tcp::resolver::query query(host, port);
- boost::asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query);
+ boost::asio::ip::tcp::resolver::results_type endpoints = resolver.resolve(host, port);
http::request<http::string_body> req;
req.version(11);
@@ -121,7 +121,7 @@ int main(int argc, char* argv[]) {
req.set(http::field::host, host);
req.set(http::field::user_agent, Botan::version_string());
- client c(io_context, iterator, host, req);
+ client c(io_context, endpoints, host, req);
io_context.run();
} catch(std::exception& e) {
--- a/src/lib/utils/socket/socket.cpp
+++ b/src/lib/utils/socket/socket.cpp
@@ -50,13 +50,12 @@ class Asio_Socket final : public OS::Socket {
check_timeout();
boost::asio::ip::tcp::resolver resolver(m_io);
- boost::asio::ip::tcp::resolver::results_type dns_iter = resolver.resolve(std::string{hostname}, std::string{service});
+ boost::asio::ip::tcp::resolver::results_type dns_iter =
+ resolver.resolve(std::string{hostname}, std::string{service});
boost::system::error_code ec = boost::asio::error::would_block;
- auto connect_cb = [&ec](const boost::system::error_code& e, boost::asio::ip::tcp::resolver::results_type::iterator) {
- ec = e;
- };
+ auto connect_cb = [&ec](const boost::system::error_code& e, const auto&) { ec = e; };
boost::asio::async_connect(m_tcp, dns_iter.begin(), dns_iter.end(), connect_cb);
--- a/src/lib/utils/socket/socket_udp.cpp
+++ b/src/lib/utils/socket/socket_udp.cpp
@@ -50,13 +50,13 @@ class Asio_SocketUDP final : public OS::SocketUDP {
check_timeout();
boost::asio::ip::udp::resolver resolver(m_io);
- boost::asio::ip::udp::resolver::results_type dns_iter = resolver.resolve(std::string{hostname}, std::string{service});
+ boost::asio::ip::udp::resolver::results_type dns_iter =
+ resolver.resolve(std::string{hostname}, std::string{service});
boost::system::error_code ec = boost::asio::error::would_block;
- auto connect_cb = [&ec](const boost::system::error_code& e, boost::asio::ip::udp::resolver::results_type::iterator) {
- ec = e;
- };
+ auto connect_cb = [&ec](const boost::system::error_code& e,
+ const boost::asio::ip::udp::resolver::results_type::iterator&) { ec = e; };
boost::asio::async_connect(m_udp, dns_iter.begin(), dns_iter.end(), connect_cb);
|