1212#include < boost/beast.hpp>
1313
1414#include < libp2p/basic/write_return_size.hpp>
15- #include < libp2p/common/hexutil .hpp>
15+ #include < libp2p/common/literals .hpp>
1616#include < libp2p/injector/kademlia_injector.hpp>
1717#include < libp2p/log/configurator.hpp>
1818#include < libp2p/log/sublogger.hpp>
1919#include < libp2p/multi/content_identifier_codec.hpp>
2020
21+ using libp2p::common::operator " " _unhex;
22+
2123class Session ;
2224
2325struct Cmp {
@@ -46,7 +48,7 @@ class Session : public std::enable_shared_from_this<Session> {
4648 stream_->readSome (
4749 *incoming_,
4850 incoming_->size (),
49- [self = shared_from_this ()](libp2p:: outcome::result<size_t > result) {
51+ [self = shared_from_this ()](outcome::result<size_t > result) {
5052 if (not result) {
5153 self->close ();
5254 std::cout << self->stream_ ->remotePeerId ().value ().toBase58 ()
@@ -71,8 +73,7 @@ class Session : public std::enable_shared_from_this<Session> {
7173 libp2p::writeReturnSize (
7274 stream_,
7375 *buffer,
74- [self = shared_from_this (),
75- buffer](libp2p::outcome::result<size_t > result) {
76+ [self = shared_from_this (), buffer](outcome::result<size_t > result) {
7677 if (not result) {
7778 self->close ();
7879 std::cout << self->stream_ ->remotePeerId ().value ().toBase58 ()
@@ -129,8 +130,8 @@ void handleIncomingStream(libp2p::StreamAndProtocol stream_and_protocol) {
129130
130131void handleOutgoingStream (libp2p::StreamAndProtocolOrError stream_res) {
131132 if (not stream_res) {
132- std::cerr << " ! outgoing connection failed: "
133- << stream_res.error (). message () << std::endl ;
133+ fmt::println (
134+ std::cerr, " ! outgoing connection failed: {} " , stream_res.error ()) ;
134135 return ;
135136 }
136137 auto &stream = stream_res.value ().stream ;
@@ -198,11 +199,11 @@ int main(int argc, char *argv[]) {
198199 // clang-format off
199200 .publicKey = {{
200201 .type = libp2p::crypto::Key::Type::Ed25519,
201- .data = libp2p::common::unhex ( " 48453469c62f4885373099421a7365520b5ffb0d93726c124166be4b81d852e6" ). value ()
202+ .data = " 48453469c62f4885373099421a7365520b5ffb0d93726c124166be4b81d852e6" _unhex,
202203 }},
203204 .privateKey = {{
204205 .type = libp2p::crypto::Key::Type::Ed25519,
205- .data = libp2p::common::unhex ( " 4a9361c525840f7086b893d584ebbe475b4ec7069951d2e897e8bceb0a3f35ce" ). value ()
206+ .data = " 4a9361c525840f7086b893d584ebbe475b4ec7069951d2e897e8bceb0a3f35ce" _unhex,
206207 }},
207208 // clang-format on
208209 };
@@ -291,14 +292,12 @@ int main(int argc, char *argv[]) {
291292 [[maybe_unused]] auto res1 = kademlia->findProviders (
292293 content_id,
293294 0 ,
294- [&](libp2p::outcome::result<std::vector<libp2p::peer::PeerInfo>>
295- res) {
295+ [&](outcome::result<std::vector<libp2p::peer::PeerInfo>> res) {
296296 scheduler.schedule (std::function{find_providers},
297297 kademlia_config.randomWalk .interval );
298298
299299 if (not res) {
300- std::cerr << " Cannot find providers: " << res.error ().message ()
301- << std::endl;
300+ fmt::println (std::cerr, " Cannot find providers: {}" , res.error ());
302301 return ;
303302 }
304303
@@ -320,8 +319,10 @@ int main(int argc, char *argv[]) {
320319 io->post ([&] {
321320 auto listen = host->listen (ma);
322321 if (not listen) {
323- std::cerr << " Cannot listen address " << ma.getStringAddress ().data ()
324- << " . Error: " << listen.error ().message () << std::endl;
322+ fmt::println (std::cerr,
323+ " Cannot listen address {}. Error: {}" ,
324+ ma.getStringAddress (),
325+ listen.error ());
325326 std::exit (EXIT_FAILURE);
326327 }
327328
0 commit comments