diff --git a/core/src/net/transport.cpp b/core/src/net/transport.cpp index a952c47..a8dad8f 100644 --- a/core/src/net/transport.cpp +++ b/core/src/net/transport.cpp @@ -6,7 +6,6 @@ namespace voicecat::net { -// ── TcpControlChannel ──────────────────────────────────────────────────────── TcpControlChannel::TcpControlChannel(TcpChannelCallbacks cbs) : work_guard_(asio::make_work_guard(io_)), @@ -129,7 +128,7 @@ void TcpControlChannel::close() { if (net_thread_.joinable()) net_thread_.join(); } -// ── TcpServerConn ──────────────────────────────────────────────────────────── + TcpServerConn::TcpServerConn(asio::ip::tcp::socket socket, TcpChannelCallbacks cbs) : socket_(std::move(socket)), @@ -323,7 +322,7 @@ void TcpServerConn::close() { void TcpServerConn::wait_closed() { if (tls_thread_.joinable()) { if (std::this_thread::get_id() == tls_thread_.get_id()) { - // Being called from our own TLS thread — detach to avoid self-join deadlock. + // Being called from our own TLS thread, detach to avoid self-join deadlock. tls_thread_.detach(); } else { tls_thread_.join(); @@ -331,7 +330,7 @@ void TcpServerConn::wait_closed() { } } -// ── TcpAcceptor ───────────────────────────────────────────────────────────── + namespace { // Try IPv6 dual-stack first (one socket handles both ::1 and 127.0.0.1 — fixes the common @@ -392,7 +391,7 @@ void TcpAcceptor::shutdown() { for (auto& conn : to_join) { conn->wait_closed(); } - // to_join drops here — if a thread captured shared_from_this, the TcpServerConn stays + // to_join drops here if a thread captured shared_from_this, the TcpServerConn stays // alive until that thread releases it; the destructor's close() is a no-op (already // closed) and tls_thread_ is already joined, so no reactor access occurs. } @@ -419,7 +418,7 @@ void TcpAcceptor::do_accept() { }); } -// ── UdpMediaChannel ────────────────────────────────────────────────────────── + bool UdpMediaChannel::bind(asio::io_context& io, uint16_t port) { if (bound_.load()) return false; diff --git a/core/src/net/transport.h b/core/src/net/transport.h index a0da996..a057310 100644 --- a/core/src/net/transport.h +++ b/core/src/net/transport.h @@ -1,8 +1,6 @@ /* - * net/transport.h — TCP control channel + UDP media channel. + * net/transport.h: TCP control channel + UDP media channel. * - * Design: docs/architecture.md (Net thread), docs/protocol.md §1 (framing). - * Implementation uses standalone Asio for sockets and timers. */ #ifndef VOICECAT_NET_TRANSPORT_H #define VOICECAT_NET_TRANSPORT_H @@ -40,7 +38,7 @@ struct TcpChannelCallbacks { std::function on_tls_ready; }; -// ── Client-side: owns an io_context + dedicated net thread ────────────────── +// Client-side: owns an io_context + dedicated net thread class TcpControlChannel { public: explicit TcpControlChannel(TcpChannelCallbacks cbs); @@ -84,7 +82,7 @@ class TcpControlChannel { std::atomic closing_{false}; }; -// ── Server-side: one per accepted socket, shares the server's io_context ──── +// Server-side: one per accepted socket, shares the server's io_context class TcpServerConn : public std::enable_shared_from_this { public: // Plain TCP constructor (no TLS — for tests or future plaintext paths). @@ -113,13 +111,13 @@ class TcpServerConn : public std::enable_shared_from_this { bool connected() const { return connected_.load(std::memory_order_acquire); } private: - // ── Asio path (no TLS) ─────────────────────────────────────────────────── + // Asio path (no TLS) void start_read(); void handle_length(std::error_code ec, std::size_t n); void handle_body(uint32_t length, std::error_code ec, std::size_t n); void do_send(); - // ── TLS path ───────────────────────────────────────────────────────────── + // TLS path void tls_read_loop(); void tls_drain_sends(); @@ -142,7 +140,7 @@ class TcpServerConn : public std::enable_shared_from_this { std::deque> tls_send_queue_; }; -// ── Server-side acceptor ───────────────────────────────────────────────────── +// Server-side acceptor // Spawns a TcpServerConn (via factory) for each accepted TCP connection. class TcpAcceptor { public: @@ -177,7 +175,7 @@ class TcpAcceptor { std::vector> conns_; }; -// ── UDP media channel ──────────────────────────────────────────────────────── +// UDP media channel // Thin async UDP socket. send_to() is thread-safe. Recv callbacks fire on the // io_context's thread (same thread that runs the io_context::run() loop). class UdpMediaChannel { diff --git a/core/src/net/voice_frame.h b/core/src/net/voice_frame.h index 5d20543..0fc2476 100644 --- a/core/src/net/voice_frame.h +++ b/core/src/net/voice_frame.h @@ -1,7 +1,7 @@ /* - * net/voice_frame.h — UDP media frame wire format (header-only). + * net/voice_frame.h: UDP media frame wire format (header-only). * - * Design: docs/voice.md §2. The 14-byte fixed header is also used as AEAD associated data. + * The 14-byte fixed header is also used as AEAD associated data. * Multi-byte fields are big-endian. The payload (Opus packet) is AEAD-encrypted. */ #ifndef VOICECAT_NET_VOICE_FRAME_H @@ -44,9 +44,7 @@ inline constexpr size_t kVoiceHeaderSize = 20; * The 20-byte header is the AEAD AAD (authenticated, not encrypted). * The payload region is the AEAD ciphertext + 16-byte Poly1305 MAC. * - * Protocol v2 widened `seq` from u16 to u64: the receiver reconstructs the AEAD - * nonce counter directly from this field, so the full 64-bit counter must be on the - * wire (a 16-bit field wrapped after 65,536 frames and desynced the nonce). + */ struct VoiceFrame { uint8_t type = kFrameVoice;