#udp #hub #lru-cache #udp-socket #command-line-tool #sockets #min-sized-rust

app udpexchange

Small CLI tool for creating simple UDP hubs; small executable size experiment

2 releases

0.1.1 Oct 18, 2023
0.1.0 Oct 3, 2023

#20 in #hub

MIT/Apache

8KB
124 lines

udpexchange

This program follows the following algorithm:

  1. Listen UDP socket at specified address
  2. For each incoming UDP datagram, remember source address in LRU cache
  3. Return empty datagrams back to sender (pings/keepalives)
  4. Forward non-empty datagrams to each known unexpired address (except of sender).

Optionally, it can remember some recent messages and send them to newly seen clients.

Security

This service may allow DDoS amplification, so should not be run publicly.

Small executable size

This project is partly an experiment to create small executables using Rust while having (partial?) access to libstd and using reasonable command-line arguments parser.

cargo build --release -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort --target=x86_64-unknown-linux-musl --features=mini

should produce a working 51-kilobyte executable.

Note that hacks activated by --features=mini may be unsound and less portable. Even smaller size is attainable by also using eyra.

Installation

Download a pre-built executable from Github releases or install from source code with cargo install --path . or cargo install udpexchange.

CLI options

udpexchange --help output
Usage: udpexchange <listen_addr> [-t <timeout>] [-r]

Simple UDP service which replies to all other known clients

Positional Arguments:
  listen_addr       socket address to bind UDP to

Options:
  -t, --timeout     timeout, in seconds, to expire clients.
  -r, --replay      send recent accumulated messages to newly seen clients
  --help            display usage information

Dependencies

~0.7–1.3MB
~27K SLoC