Files
voice-cat/server/src/server.h
Talon 694494a5be feat(M2): UDP voice/media plane -- SFU relay, Opus, AEAD, jitter buffer
Adds the full voice pipeline: 14-byte binary frame header, ChaCha20-Poly1305
AEAD keyed from the TLS exporter, libopus encode/decode with FEC/PLC/DTX,
an adaptive per-ssrc jitter buffer, a miniaudio capture/playback engine, an
APM passthrough stub, and the UdpBinding/StreamAnnounce signaling chain
wired through ConnSession/SessionRegistry into a new server-side SFU
(MediaRelay) that decrypts and re-encrypts frames per channel member.

Exit criterion verified: test_m2_voice — two headless clients relay 50
encrypted Opus frames through the server; ctest --preset m1-dev is 9/9
green. Also corrects protocol.md's UdpBinding diagram, which described the
UDP-side binding packet as AEAD-sealed when it is in fact a plaintext
bootstrap frame (separate from the TCP/TLS UdpBinding ack).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-16 01:31:14 +02:00

48 lines
1.4 KiB
C++

/*
* server/server.h — VoiceCat server entry point.
*
* Design: docs/architecture.md §5. Headless process: TLS control listener,
* session registry, text relay, SQLite persistence. Zero-config first-run.
*/
#ifndef VOICECAT_SERVER_SERVER_H
#define VOICECAT_SERVER_SERVER_H
#include <cstdint>
#include <functional>
#include <mutex>
#include <string>
namespace voicecat::server {
struct Config {
std::string server_name = "VoiceCat Server";
std::string data_dir = "voicecat-data";
uint16_t bind_port = 8384; // 0 = let OS pick (useful for tests)
uint16_t media_port = 0; // M2 UDP media port; 0 = OS-assigned
bool allow_guests = true;
// Called with the actual bound TCP port once the acceptor is ready.
std::function<void(uint16_t)> on_ready;
// Called with the actual bound UDP media port once the relay is ready.
std::function<void(uint16_t)> on_media_ready;
};
class Server {
public:
explicit Server(Config cfg) : cfg_(std::move(cfg)) {}
// Block until the server shuts down. Returns process exit code.
int run();
// Thread-safe stop: unblocks run() from any thread. No-op if not running.
void stop();
private:
Config cfg_;
std::mutex stop_mutex_;
std::function<void()> stop_fn_;
};
} // namespace voicecat::server
#endif // VOICECAT_SERVER_SERVER_H