Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve Boost deprecations #4484

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/cli/tls_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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*/) {
const tcp::resolver::results_type::iterator& /*endpoint*/) {
if(ec) {
log_error("Server connection", ec);
return;
Expand All @@ -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 {
Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions src/examples/tls_stream_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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));
}

Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
20 changes: 9 additions & 11 deletions src/lib/utils/socket/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,18 @@ 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});
reneme marked this conversation as resolved.
Show resolved Hide resolved

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&) {
ec = e;
};
auto connect_cb = [&ec](const boost::system::error_code& e, const auto&) { 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();
Expand All @@ -74,7 +72,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;

Expand All @@ -90,7 +88,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;
Expand All @@ -116,7 +114,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)
Expand All @@ -127,7 +125,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;
};
Expand Down
21 changes: 10 additions & 11 deletions src/lib/utils/socket/socket_udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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&) {
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, 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();
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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;
};
Expand Down
Loading