Skip to content

Commit ef43be4

Browse files
authored
boost 1.87.0 (#290)
Signed-off-by: turuslan <[email protected]>
1 parent c3e6cce commit ef43be4

File tree

17 files changed

+91
-78
lines changed

17 files changed

+91
-78
lines changed

cmake/Hunter/init.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ set(
3131
include(${CMAKE_CURRENT_LIST_DIR}/HunterGate.cmake)
3232

3333
HunterGate(
34-
URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.25.3-qdrvm23.zip
35-
SHA1 3fb58496e599fa3d35e94d1810324c6b379029f1
34+
URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.25.3-qdrvm28.tar.gz
35+
SHA1 a4f1b0f42464e07790b7f90b783a822d71be6c6d
3636
LOCAL
3737
)

example/01-echo/libp2p_echo_client.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ int main(int argc, char *argv[]) {
104104
auto context = injector.create<std::shared_ptr<boost::asio::io_context>>();
105105
auto sch = injector.create<std::shared_ptr<libp2p::basic::Scheduler>>();
106106

107-
context->post(
107+
post(
108+
*context,
108109
[log,
109110
host{std::move(host)},
110111
&echo,

example/01-echo/libp2p_echo_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ dPtse4GVRA2swbXcZX5iFVi/V8poIpdVrgn5iMadkQnYf9APWJuGcebK
173173
auto ma = libp2p::multi::Multiaddress::create(_ma).value();
174174

175175
// launch a Listener part of the Host
176-
io_context->post([&] {
176+
post(*io_context, [&] {
177177
auto listen_res = host->listen(ma);
178178
if (!listen_res) {
179179
log->error("host cannot listen the given multiaddress: {}",

example/02-kademlia/rendezvous_chat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Session : public std::enable_shared_from_this<Session> {
3737
public:
3838
explicit Session(std::shared_ptr<libp2p::connection::Stream> stream)
3939
: stream_(std::move(stream)),
40-
incoming_(std::make_shared<std::vector<uint8_t>>(1 << 12)){};
40+
incoming_(std::make_shared<std::vector<uint8_t>>(1 << 12)) {};
4141

4242
bool read() {
4343
if (stream_->isClosedForRead()) {
@@ -316,7 +316,7 @@ int main(int argc, char *argv[]) {
316316
kademlia_config.randomWalk.interval);
317317
};
318318

319-
io->post([&] {
319+
post(*io, [&] {
320320
auto listen = host->listen(ma);
321321
if (not listen) {
322322
fmt::println(std::cerr,

example/03-gossip/gossip_chat_example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ int main(int argc, char *argv[]) {
143143
}
144144

145145
// start the node as soon as async engine starts
146-
io->post([&] {
146+
post(*io, [&] {
147147
auto listen_res = host->listen(peer_info->addresses[0]);
148148
if (!listen_res) {
149149
fmt::println(std::cerr,

example/03-gossip/utility.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,14 @@ namespace libp2p::protocol::example::utility {
5151

5252
std::string getLocalIP(boost::asio::io_context &io) {
5353
boost::asio::ip::tcp::resolver resolver(io);
54-
boost::asio::ip::tcp::resolver::query query(boost::asio::ip::host_name(),
55-
"");
5654
boost::system::error_code ec;
57-
boost::asio::ip::tcp::resolver::iterator it = resolver.resolve(query, ec);
58-
boost::asio::ip::tcp::resolver::iterator end;
59-
std::string addr("127.0.0.1");
60-
while (it != end) {
61-
auto ep = it->endpoint();
62-
if (ep.address().is_v4()) {
63-
addr = ep.address().to_string();
64-
break;
55+
for (auto &entry : resolver.resolve(boost::asio::ip::host_name(), "", ec)) {
56+
auto address = entry.endpoint().address();
57+
if (address.is_v4()) {
58+
return address.to_string();
6559
}
66-
++it;
6760
}
68-
return addr;
61+
return "127.0.0.1";
6962
}
7063

7164
boost::optional<libp2p::peer::PeerInfo> str2peerInfo(const std::string &str) {

example/04-dnstxt/ares_resolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int main(int argc, char *argv[]) {
6262
auto context = injector.create<std::shared_ptr<boost::asio::io_context>>();
6363
// the guard to preserve context's running state when tasks queue is empty
6464
auto work_guard = boost::asio::make_work_guard(*context);
65-
context->post([&] {
65+
post(*context, [&] {
6666
ares.resolveTxt(
6767
"_dnsaddr.bootstrap.libp2p.io",
6868
context,

include/libp2p/boost/outcome.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright Quadrivium LLC
3+
* All Rights Reserved
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include <qtils/outcome.hpp>
10+
11+
/**
12+
* Boost 1.87.0 (1.86.0?) removed overloads with `error_code` and only kept
13+
* throwing overload.
14+
*/
15+
namespace boost_outcome {
16+
template <typename F>
17+
outcome::result<std::invoke_result_t<F>> tryCatch(const F &f) {
18+
try {
19+
return f();
20+
} catch (boost::system::system_error &e) {
21+
return e.code();
22+
}
23+
}
24+
25+
outcome::result<std::string> to_string(const auto &x) {
26+
return tryCatch([&] { return x.to_string(); });
27+
}
28+
} // namespace boost_outcome

include/libp2p/transport/tcp/tcp_util.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <boost/asio/ip/tcp.hpp>
1010
#include <boost/asio/ip/udp.hpp>
1111
#include <charconv>
12+
#include <libp2p/boost/outcome.hpp>
1213
#include <libp2p/multi/multiaddress.hpp>
1314
#include <variant>
1415

@@ -172,11 +173,7 @@ namespace libp2p::transport::detail {
172173
constexpr auto udp = std::is_same_v<T, boost::asio::ip::udp::endpoint>;
173174
static_assert(tcp or udp);
174175
auto ip = endpoint.address();
175-
boost::system::error_code ec;
176-
auto ip_str = ip.to_string(ec);
177-
if (ec) {
178-
return ec;
179-
}
176+
OUTCOME_TRY(ip_str, boost_outcome::to_string(ip));
180177
return fmt::format("/{}/{}/{}/{}",
181178
ip.is_v4() ? "ip4" : "ip6",
182179
ip_str,

src/basic/scheduler/asio_scheduler_backend.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include <libp2p/basic/scheduler/asio_scheduler_backend.hpp>
88

9+
#include <boost/asio/post.hpp>
10+
911
#include <libp2p/log/logger.hpp>
1012
#include <libp2p/outcome/outcome.hpp>
1113

@@ -15,7 +17,7 @@ namespace libp2p::basic {
1517
: io_context_(std::move(io_context)), timer_(*io_context_) {}
1618

1719
void AsioSchedulerBackend::post(std::function<void()> &&cb) {
18-
io_context_->post(std::move(cb));
20+
boost::asio::post(*io_context_, std::move(cb));
1921
}
2022

2123
std::chrono::milliseconds AsioSchedulerBackend::now() const {
@@ -25,16 +27,7 @@ namespace libp2p::basic {
2527
void AsioSchedulerBackend::setTimer(
2628
std::chrono::milliseconds abs_time,
2729
std::weak_ptr<SchedulerBackendFeedback> scheduler) {
28-
boost::system::error_code ec;
29-
timer_.expires_at(decltype(timer_)::clock_type::time_point(abs_time), ec);
30-
31-
if (ec) {
32-
// this should never happen
33-
auto log = log::createLogger("Scheduler", "scheduler");
34-
log->critical("cannot set timer: {}", ec);
35-
boost::asio::detail::throw_error(ec, "setTimer");
36-
}
37-
30+
timer_.expires_at(decltype(timer_)::clock_type::time_point(abs_time));
3831
timer_.async_wait([scheduler = std::move(scheduler)](
3932
const boost::system::error_code &error) {
4033
if (!error) {

0 commit comments

Comments
 (0)