From 0bf742895a8a1f055a480017dbb4221b82dda800 Mon Sep 17 00:00:00 2001 From: giskard Date: Mon, 7 Oct 2024 00:35:11 +0800 Subject: [PATCH] udp2p: server echo with hex/b64 --- src/udp2p/meson.build | 1 + src/udp2p/server.cc | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/udp2p/meson.build b/src/udp2p/meson.build index 3404847..b151344 100644 --- a/src/udp2p/meson.build +++ b/src/udp2p/meson.build @@ -2,4 +2,5 @@ udp2p_deps = [ dependency('asio'), dependency('zpp_bits'), dependency('magic_enum'), + dependency('botan-3'), ] diff --git a/src/udp2p/server.cc b/src/udp2p/server.cc index 44c25e9..2677158 100644 --- a/src/udp2p/server.cc +++ b/src/udp2p/server.cc @@ -1,3 +1,4 @@ +#include #include #include @@ -8,8 +9,10 @@ #include #include +#include +#include + #include "server.h" -#include "utils/misc.h" namespace mtrx { namespace udp2p { @@ -23,13 +26,14 @@ void Server::serv(const std::string & addr, uint port) { asio::co_spawn( ctx_, [&socket, this]() -> asio::awaitable { - char buffer[1024]; + uint8_t buffer[1024]; asio::ip::udp::endpoint remote_endpoint; while (true) { size_t n = co_await socket.async_receive_from( asio::buffer(buffer), remote_endpoint, asio::use_awaitable); - logger_->debug("get: {}", utils::hexFromBytes(buffer, n)); + logger_->debug("get hex: {}", Botan::hex_encode(buffer, n, false)); + logger_->debug("get b64: {}", Botan::base64_encode(buffer, n)); co_await socket.async_send_to(asio::buffer(buffer, n), remote_endpoint, asio::use_awaitable);