#!/usr/bin/env raku
use Crypt::Argon2;
use Log::Async <info color>;
unit sub MAIN(
Str :a(:$address) = 'localhost', #= Address to bind
UInt :p(:$port) = 9988 #= Port to bind
);
given IO::Socket::Async.bind-udp($address, $port) -> $udp-server {
$udp-server.Supply(:datagram).tap: {
info "Got {.data.gist} from {.hostname}:{.port}";
my $argon2hash = argon2-hash(.data.gist, :t_cost(11), :m_cost(64 * 1024), :parallelism(4), :hashlen(32));
info "Argon2Hash: $argon2hash";
$udp-server.print-to: .hostname, .port, "$argon2hash\n";
}
}
info "Listening on udp://$address:$port";
react {
whenever signal(SIGINT) { print "\r"; warning "(Ctrl-C) Bye !"; exit }
}