25 Commits
Author SHA1 Message Date
lotherk dd05d43cab libDtChat: link libiconv
libDtChat's text.c converts the session charset with iconv, and AM_ICONV
finds GNU libiconv, but libDtChat_la_LIBADD did not carry LTLIBICONV: the
library kept libiconv_open/-close/- undefined, and dtchat, dtchat-headless
and dtchat-irc failed to link ("undefined reference to libiconv_open",
measured 2026-11-22 on the MacBook).  The library carries the dependency now,
so every program that links it gets it too.

Measured: after the change lib/libDtChat/libDtChat.la lists
/usr/pkg/lib/libiconv.la in dependency_libs; make -C programs/dtchat rc=0,
0 errors (dtchat-build3.log).
2026-11-22 13:51:31 +01:00
lotherk 8169c04b38 mcde: a cross build makes no test programs; check-buildtools stopped on 28
build/logs/userland-2026-11-17f.log:22437: the 25 test programs of
libDtChat, dtchat-demo and McdeSys's test_audio/test_netwatch were
noinst_PROGRAMS, so the package build compiled them for NetBSD and
tools/check-buildtools.sh took them for build tools.  configure.ac has
MCDE_CROSS now; in a cross build they are check_PROGRAMS (dtchat-demo
EXTRA_PROGRAMS), in a native one noinst as before, so tools/mcde-tests.sh
still finds them in build/mcde-host.  autoreconf -fi of the tree: exit 0,
the Makefile.in lines are @MCDE_CROSS_TRUE@check_PROGRAMS /
@MCDE_CROSS_FALSE@noinst_PROGRAMS.
2026-11-17 16:55:45 +00:00
lotherk 91dfe20658 dtchat: camera capture, VP8 on the call and a real video picture (T7.1)
media_capture.c: V4L2 (YUYV, 4 mmap buffers, poll, QBUF again after use) and a
test pattern; a camera with another size is scaled to the call's 640x360, and a
build without HAVE_V4L2 gets the pattern. On this T14 the integrated camera is
/dev/video0 and gives frames (test_capture: v4l2:/dev/video0, non-uniform
frame, 320x180 through the scaler; pattern frames differ and have Y and
chroma). configure defines HAVE_V4L2 for linux/videodev2.h.

media_video.c gains dc_vpx_enc_keyframe (VPX_EFLAG_FORCE_KF on the next
frame), media_packet a DC_MEDIA_KFREQ control, media_call
dc_call_request_keyframe/take and DC_MEDIA_KFREQ in the sealed type range.
dc_call_video_out now decodes the reassembled VP8 frame into I420 (it returned
the compressed frame, which the UI drew as a green picture);
dc_call_video_packet keeps the compressed frame for tests and recordings.
Video timestamps are wall clock, not frame counts, so a pump slower than 15 fps
does not drift behind the audio clock.

localui starts camera+encoder on entering the call, sends 15 fps, requests a
keyframe after a loss, forces one when asked, decodes incoming frames into the
call window, drains up to four 20 ms capture frames per 40 ms pump (one per
pump halved the audio clock), and logs video in/out under
DTCHAT_CALL_DEBUG; DTCHAT_TEST_VIDEO switches to the pattern.

Two UIs under Xvfb: A pattern, B camera, 90 frames each way in about 6 s,
audio 300 frames (real time), the window shows the peer's picture
(build/mcde-shots/dtchat-t71-video-call.png). test_video_packet uses the
packet interface; its 50 KB/42-fragment loopback check still passes. New
harness entry DtChat/test_capture (43). In-tree build pending: a foreign
make release holds the lock.
2026-11-17 09:19:48 +00:00
lotherk 76ccabd127 dtchat: synchronise video to the audio clock (T7.5)
media_sync.c: audio is the clock (20 ms per decoded frame); a video frame whose timestamp is more than DC_SYNC_LATE_MS (80 ms) behind it is dropped, anything else is rendered and its video-audio offset recorded. media_call.c advances the clock on every decoded audio frame, timestamps video at 1000/15 ms per frame, drops late frames in dc_call_video_out (-1) and counts them; the reassembler now carries the media packet's timestamp with the frame. test_media_sync: on-time, 20 ms late, exactly 80 ms (rendered), 81 ms (dropped), early, a one-minute call and NULL arguments. test_video_packet gains a call-level sequence: 200 ms of decoded audio, then four video frames at 0/66/132/198 ms; the first two are dropped, the third renders with offset -68 ms and the dropped counter is 2. Standalone and ASan/UBSan clean. In-tree build pending: the next make mcde-host carries it and the harness reaches 41 entries.
2026-11-17 08:27:58 +00:00
lotherk 09656fef62 dtchat: scale and convert I420 for the call window (T7.2)
media_render.c: dc_i420_scale resizes Y/U/V bilinearly (chroma at half size), so a 640x360 call fits a tile or a full-screen window; dc_i420_to_xrgb converts to 0x00RRGGBB for an XImage with the BT.601 limited-range matrix (Y 16..235, Cb/Cr 16..240) and an optional pixel stride. test_video_render: white/black/red solids, 1:1 identity, 2x up then down with PSNR > 28 dB, corners of the upscale, odd sizes with rounded chroma and stride padding untouched; standalone and ASan/UBSan clean. In-tree build pending: the next make mcde-host carries it.
2026-11-17 08:21:37 +00:00
lotherk 4be64d1abc dtchat: fragment and reassemble VP8 frames over media packets (T7.4)
media_video_packet.c: a frame travels in 1200-byte DC_MEDIA_VIDEO packets with an 8-byte header (start/end/keyframe flags, reserved, frame id, fragment index and count, big-endian) and 1192 data bytes. The reassembler keeps one frame, accepts fragments out of order, ignores duplicates, bounds the frame at 256 KiB and refuses a fragment count that cannot fit, drops an incomplete frame when the next frame id starts and then asks for a keyframe. media_call.c gains dc_call_send_video (fragments + seals while in a call), dc_call_video_out and dc_call_wants_keyframe; drained VIDEO packets feed the reassembler. test_video_packet: 50 KB in 42 fragments in order and reversed with a duplicate, missing fragment -> no frame then wants_keyframe on the next id, bad/oversize fragments refused, and a loopback call where an 11-frame sequence (50 KB each) crosses sealed UDP and reassembles byte-identical in 0.6 ms per frame; standalone and ASan/UBSan clean. In-tree build still pending: make mcde-host was running when this landed.
2026-11-17 08:14:02 +00:00
lotherk a2f65b4528 dtchat: add the VP8 video wrapper (T7.1)
media_video.c wraps libvpx: VP8, I420, realtime deadline, CBR, error resilience, one keyframe per second, 320x240 at 15 fps and 300 kbit/s by default; dc_vpx_enc_frame returns the packet (0: none, -1: error, too small a buffer refused), dc_vpx_dec_frame copies Y/U/V into the caller's I420 buffer and drops damaged packets (0) or refuses a size that does not match (-1). configure checks vpx/vpx_encoder.h and libvpx as an optional build dependency (HAVE_VPX, VPXLIB); without it the functions answer 'no libvpx' and the test skips. test_video_vp8: 30 frames of a moving square on a gradient, encode/decode round trip, decoded PSNR > 20 dB on the last frame, corrupted packet and plain garbage without a crash, small output buffer and odd dimensions refused; standalone and ASan/UBSan clean with libvpx 1.17.0, and 'no libvpx, skipped' in the stub build. In-tree build pending: make mcde-host was already running when this landed, so the next build carries it.
2026-11-17 08:11:01 +00:00
lotherk 67a6a1bb71 dtchat: add the UDP call, jitter buffer and push-to-talk (T6.4)
media_call.c: one UDP socket per call (bound, non-blocking, pollable through dc_call_fd), the two direction keys of T6.3, Opus 48 kHz mono and a jitter buffer. dc_call_drain authenticates every datagram and only then puts it into the buffer; dc_call_audio_out decodes one frame (a lost one becomes PLC), dc_call_audio_in encodes and sends one 20 ms frame, dc_call_send_ptt tells the peer about the key (DC_MEDIA_PTT). The jitter buffer starts after DEPTH frames (3 = 60 ms), reorders, drops duplicates and late frames, turns a proved gap into one frame of length 0 and is bounded by 32 slots. test_media_call: jitter below depth/reorder, loss -> concealment, duplicates/late/oversize, depth clamping, and a real loopback UDP run between two calls (PTT on/off seen, ten frames decoded in order with RMS > 1000, a damaged datagram dropped); standalone and ASan/UBSan clean. In-tree build pending: a foreign release chain holds the lock (pid 141722).
2026-11-17 07:28:48 +00:00
lotherk efca77d22d dtchat: add the media packet, key agreement and replay window (T6.3)
media_packet.c: X25519 key pairs, HKDF-SHA256 over the shared secret with the sorted public keys as salt gives two 32-byte direction keys (the responder mirrors send/recv); ChaCha20-Poly1305 seals the payload with a 12-byte header (version, type, flags, reserved, 32-bit sequence, 32-bit timestamp) as additional data, the nonce is the 64-bit sequence after four zero bytes (fresh keys per session), 16-byte tag, payload at most 1200 bytes. dc_media_replay_ok is the 64-packet RFC 3711 window and is only advanced after the tag verified, so a forged packet cannot move it. test_media_packet: key agreement mirrors, roundtrip with payload and empty payload, changed header/payload/tag/truncation/wrong key refused, out-of-order delivery inside the window accepted once, replays and packets 64 behind refused, window slide, size/type limits and 1000 random payloads round-tripping; standalone and ASan/UBSan clean. In-tree build pending: a foreign release chain holds the lock (pid 141722).
2026-11-17 07:25:33 +00:00
lotherk e3e4e95d07 dtchat: add the Opus encoder and decoder (T6.2)
media_audio.c wraps libopus for 48 kHz mono, 20 ms frames (960 samples), 24 kbit/s, in-band FEC and a 10 percent loss hint; dc_opus_dec_frame with len 0 conceals a lost frame. configure requires libopus (OPUSLIB). test_audio_opus encodes/decodes 2 s of a 440 Hz sine, checks the frame size, a decoded RMS above half the input, a 3-12 KB budget for 24 kbit/s and a non-silent PLC frame after a loss; standalone and ASan/UBSan clean. libopus 1.6.1 was installed on the build host together with libstrophe, avahi-client and libvpx, so T4/T5.2/T6/T7 are no longer missing libraries. In-tree build pending: a foreign release chain holds the lock (pid 141722).
2026-11-17 07:14:51 +00:00
lotherk f46a914c73 dtchat: add the message catalog and the German UI (T10.4)
i18n.c opens catopen("dtchat", NL_CAT_LOCALE) and dc_text(id, fallback) reads set 1; the program calls dc_i18n_init after setlocale. The visible labels of the main window, the account editor, the request/peer/file/pair dialogs and the local status texts use ui_text.h ids; dtchat.msg (English) has 75 entries and programs/localized/de_DE.UTF-8/msg/dtchat.msg the German copy (ASCII transliteration, core font). test_i18n builds both catalogs with gencat and checks File/Datei, Send/Senden and the fallback; the German run under Xvfb shows Datei/Bearbeiten/Ansicht/Konversation/Hilfe, In der Naehe and Senden (screenshot build/mcde-shots/dtchat-t104-de.png) and the smoke stays green. Dynamic formatted statuses are partly still English. The in-tree build is pending: a foreign release chain holds the lock (pid 141722).
2026-11-17 07:06:55 +00:00
lotherk 79caf69db9 dtchat: fuzz the JSON and IRC parsers (T10.1)
fuzz.c is a deterministic harness: 1,000,000 iterations of random bytes, mutations of valid seeds, generated JSON (valid and broken) and IRC lines (long trailing, NULs, extra params). A parsed document is written and parsed again; an IRC result must have a command and at most 15 parameters; the splitter must finish. The input of iteration I depends only on the seed and I, so a crash reproduces with 'test_fuzz 1 SEED I'. Standalone: 1,000,000 iterations in 6.3 s; ASan/UBSan 1,000,000 clean (the only finding was the harness's own overlapping memcpy, fixed). Built test_fuzz 1M ok; make mcde-host exit=0; tools/mcde-tests.sh 31 ok/0 bad.
2026-11-17 06:42:04 +00:00
lotherk e9d8d9df4c dtchat: add the pairing SAS and the TOFU pin store (T5.4a)
pair.c derives the 6-digit SAS from both certificate pins (sorted, SHA-256, mod 1000000) so both sides compute the same code; peers.json keeps id -> pin and the blocked flag (0600, atomic store). dc_pins_check answers 1 for a known pin, 0 for an unknown id and -1 for a changed pin; only dc_pins_confirm stores a new pin after the person compared the SAS; a changed pin stays blocked until then. test_pair: known SAS answers (448183 for A+B, 500498 for A+A), order independence, malformed pins, empty store, confirm/check, changed pin, block persistence, save/reload. Standalone and ASan/UBSan clean. make mcde-host still blocked by pid 2126511.
2026-11-16 20:46:19 +00:00
lotherk 7c8642298c dtchat: add local file transfer (T5.6)
filexfer.c offers name/size/sha256, sends 64 KiB chunks as base64 file-data lines and a file-end; the receiver writes NAME.part, enforces the 512 MiB limit, checks size and SHA-256 and renames to a sanitized name without overwriting. Cancel removes the part. Names take the basename, drop dot-dot and control characters. The local connection buffers grow to 128 KiB for one chunk per line; dc_local_conn_busy() lets the sender pace itself. test_filexfer: safe names, 1 MiB+12345 transfer with 64 KiB chunks and matching hash, oversized offer refused, cancel leaves no part file; standalone and ASan/UBSan clean; test_local still green. make mcde-host still blocked by the foreign release/sourcesets/usb chain (pid 2126511).
2026-11-16 20:39:37 +00:00
lotherk 3aab4e35c8 dtchat: add the local TLS listener and TOFU hello (T5.4)
local.c binds a nonblocking TLS listener (identity certificate, 127.0.0.1 or all interfaces, port 0 = ephemeral) and drives the handshake from DcLoop. A peer sends one JSON line {type:hello,id,pin}; the listener checks id and pin against what it expects, answers {type:hello-ack,ok:true|false,pin:...} and closes on a wrong pin, a lying or malformed hello. The accepted hello goes to the callback once; connections stay open for the protocol of T5.5. identity.c now also exposes the private key as PEM for libtls. test_local starts a listener per case and connects with a blocking libtls client: matching pin accepted (callback sees id/pin), wrong pin rejected (no callback, ok:false), any-pin accepted. Standalone test all ok; make mcde-host could not run because another agent's release+sourcesets+usb chain holds build/.build.lock (pid 2126511); the next build verifies the wiring.
2026-11-16 20:23:14 +00:00
lotherk 38304c4378 dtchat: add the local peer model (T5.3)
peers.c keeps one peer per identity id: the TXT record (v/id/name/pin/port, ';'-joined) merges by id and marks the peer online; a service that disappears is marked offline, a manual peer stays; blocking is a property that survives announcements. Strings are owned by the peer. test_peers covers announce/merge, port preference, offline per peer, block survival, manual peers and malformed records; built test all ok, make mcde-host exit=0, tools/mcde-tests.sh 26 ok/0 bad.
2026-11-16 19:50:16 +00:00
lotherk 027d797bf0 dtchat: add the Ed25519 identity and certificate (T5.1)
identity.c generates an Ed25519 key, a self-signed X.509 certificate (CN dtchat, ten years) and its SHA-256 pin; identity.json holds version/algo/public/private/cert/pin and is written atomically through the store (dir 0700, file 0600). Load verifies that the pin, the raw public key and the certificate match; a corrupt file is moved to .bad and load_or_create fails instead of replacing the identity. configure requires libcrypto and passes CRYPTOLIB. test_identity covers creation, modes, restart persistence, a second identity, and the corrupt-file path; the built test passes and tools/mcde-tests.sh is 25 ok/0 bad after make mcde-host exit=0.
2026-11-16 19:45:15 +00:00
lotherk 954bfc70bb dtchat: add the IRC line parser with tests (T3.2)
lib/libDtChat/irc.c parses IRCv3 tags, the prefix, the command, up to 15 parameters and the trailing text into a DcIrcMessage; NUL in the line, a missing command, more than 15 parameters and lines over 1 MiB are clean errors. test_irc covers PRIVMSG, tags+prefix, 001/005/353, PING, MODE, CAP, an empty trailing, repeated spaces, the error cases and 1 MiB of rubbish; all ok and ASan/UBSan clean. The IRC adapter now routes PING/001/ERROR/433 through the parser; the fake-server harness still passes 13/13. Added test_irc to tools/mcde-tests.sh. make mcde-host still held by another agent's sourcesets/usb build (pid 1207058).
2026-11-16 19:11:11 +00:00
lotherk 581735f013 dtchat: add the single-instance lock and control socket (T1.6)
instance.c: DIR/run 0700, dtchat.lock 0600 with flock(LOCK_EX|LOCK_NB), primary Unix listener at dtchat.sock 0600, one open request per client with a 2 s timeout, non-primary instance plus dc_instance_notify with connect retries, and socket/lock cleanup on close. test_instance covers primary/secondary, modes, open callback, malformed client, notify after close and re-acquisition. make mcde-host exit=0; all eight dtchat tests 'all ok'; ASan/UBSan clean. SIGPIPE is ignored so a dead local client cannot kill the core.
2026-11-16 17:45:58 +00:00
lotherk e162ba645d dtchat: add the adapter process manager (T1.5)
adapter.c spawns a helper, waits for hello (ipc 1), sends configure/connect, routes events, drains stderr, buffers stdin, reaps zombies and restarts with 2..60 s backoff unless the child said bye. fake_adapter.c and test_adapter.c cover normal handshake, send/message echo, join/answer, stop/bye, crash restart and invalid JSON. make mcde-host exit=0; test_adapter 'all ok'; ASan/UBSan clean. test_adapter_DEPENDENCIES now includes libDtChat/libDtChatIpc to avoid the parallel relink race.
2026-11-16 17:35:28 +00:00
lotherk 83741ce6eb dtchat: add the conversation model and text helpers (T1.4)
conv.c: accounts, conversations, topics, idempotent add, a 2000-message ring buffer and unread counts that ignore our own/system messages. text.c: UTF-8 validation, C0 cleaning, mIRC formatting strip and iconv display with ASCII//TRANSLIT and '?' fallbacks. test_conv and test_text cover duplicate adds, ordering, the ring boundary, flags/unread, IRC codes, CR/CRLF and ISO-8859-1/ASCII output. make mcde-host exit=0; all six dtchat tests report 'all ok'; ASan/UBSan clean.
2026-11-16 17:18:12 +00:00
lotherk 82ab2cb4b5 dtchat: add the atomic state store (T1.3)
store.c keeps accounts.json, secrets.json and identity.json in a 0700 directory with 0600 files, writes through a temporary file with fsync/rename/dir-fsync, repairs a wrong file mode on load, moves invalid JSON to NAME.bad and rejects path names. test_store covers accounts/secrets/identity, overwrite, corrupt/missing files, stale tmp, read-only directory, default HOME path and permissions. make mcde-host exit=0; test_json, test_frame, test_loop and test_store all ok; ASan/UBSan clean.
2026-11-16 17:09:27 +00:00
lotherk 4e97d5930d dtchat: add the poll and timer event loop (T1.2)
loop.c: one poll(2) per run, monotonic one-shot timers (sorted, FIFO on equal deadlines), non-blocking wakeup pipe and safe fd dispatch when a callback removes another fd. test_loop covers timer order/cancel, timeout, wakeup, pipe, delete-in-callback, timer-added-timer, monotonicity and invalid arguments. make mcde-host exit=0; test_json, test_frame and test_loop all ok.
2026-11-16 17:00:50 +00:00
lotherk 7dbaad5afa dtchat: build the IPC tests with mcde-host (T1.1)
test_json and test_frame are noinst_PROGRAMS so the native build produces them for tools/mcde-tests.sh; TESTS still runs them under make check.
2026-11-16 16:45:22 +00:00
lotherk e645e8160d dtchat: add the core API, JSON reader and line framing (T1.1)
include/DtChat/DtChat.h and Ipc.h define the UI-facing core API and the adapter contract. lib/libDtChat builds libDtChatIpc (strict JSON parser/writer, 1 MiB line framing) and the libDtChat core stub; test_json and test_frame cover escapes, UTF-8, depth 32, duplicate keys, overlong lines, CRLF, NUL and the write path. Wired into configure.ac, lib/Makefile.am and the installed headers. Standalone tests pass, ASan/UBSan clean.
2026-11-16 16:35:48 +00:00