Skip to content

Commit

Permalink
udp2p: server echo with hex/b64
Browse files Browse the repository at this point in the history
  • Loading branch information
rtgiskard committed Oct 7, 2024
1 parent 79d443a commit 0bf7428
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/udp2p/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ udp2p_deps = [
dependency('asio'),
dependency('zpp_bits'),
dependency('magic_enum'),
dependency('botan-3'),
]
10 changes: 7 additions & 3 deletions src/udp2p/server.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <cstdint>
#include <string>

#include <asio/detached.hpp>
Expand All @@ -8,8 +9,10 @@
#include <asio/ip/address.hpp>
#include <asio/ip/udp.hpp>

#include <botan/hex.h>
#include <botan/base64.h>

#include "server.h"
#include "utils/misc.h"

namespace mtrx {
namespace udp2p {
Expand All @@ -23,13 +26,14 @@ void Server::serv(const std::string & addr, uint port) {
asio::co_spawn(
ctx_,
[&socket, this]() -> asio::awaitable<void> {
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);
Expand Down

0 comments on commit 0bf7428

Please sign in to comment.