Files
makronix/docs/reference/dtchat-spikes.txt
T
lotherk d283c85767 dtchat: TDLib 1.8.70 tdjson spike on Linux (T0.7)
TDLib builds with -DTD_ENABLE_JNI=OFF; libtdjson.so.1.8.70 is 50 MB and the build tree 537 MB. tdjson_spike starts a client without an account and getOption(version) answers 1.8.70; the authorization state is waitTdlibParameters. NetBSD is still open, so the Telegram package is Linux-first and a release gate.
2026-11-16 16:47:07 +00:00

377 lines
15 KiB
Plaintext

# dtchat -- spike results
Measurements for the dtchat plan (tasksd `mcde/dtchat`). Each entry names
the host, the command and the output; the last line is the verdict. The
spike sources live in `/tmp/opencode/dtchat-spike/` for the duration of the
work and are not part of the MCDE tree; this file is the record.
---
## T0.3 -- libtls, non-blocking, certificate verification (2026-11-16)
Host: `Linux kitt 7.1.3+deb14-amd64`, gcc 16.2.0, OpenSSL 3.6.3.
libtls: libretls 3.8.1 from <https://causal.agency/libretls/>, built
static into `/tmp/opencode/dtchat-spike/prefix`.
The tarball was checked against `pkgsrc/security/libretls/distinfo`:
```
$ sha512sum libretls-3.8.1.tar.gz
bbf4854622401bfc8662016a73202467714b603425dea2012e72846f0a22412018448fda8befa777d67c5dae44839b81e3b039130cf4970a4026c178d3a43ce2 libretls-3.8.1.tar.gz
```
Build:
```
$ ./configure --prefix=/tmp/opencode/dtchat-spike/prefix --disable-shared
$ make -j4 && make install
$ cc -std=c99 -D_POSIX_C_SOURCE=200809L -Wall -Wextra \
-I prefix/include tls_spike.c prefix/lib/libtls.a -lssl -lcrypto \
-o tls_spike
```
`tls_spike` has three modes: `remote` (system CA, verification),
`tofu` (self-signed, no verification, print the pin) and `server`
(`tls_accept_socket`). It connects with a non-blocking `connect(2)`,
upgrades with `tls_connect_socket(3)` / `tls_accept_socket(3)` and drives
the handshake with `poll(2)` on `TLS_WANT_POLLIN` / `TLS_WANT_POLLOUT`.
### Public TLS with verification
```
$ ./tls_spike remote example.com 443
version: TLSv1.3
subject: /CN=example.com
hash: SHA256:85ca6ab068e9bcce88b6c4aa3c47f7d17228134a457f870d3800e6223a0df07a
verify: ok
exit=0
```
### Wrong server name
```
$ ./tls_spike remote example.com 443 wrong.example
tls_handshake: handshake failed: error:0A000410:SSL routines::ssl/tls alert handshake failure
exit=1
```
### Self-signed certificate, TOFU pin, and rejection by the system CA
```
$ openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem \
-out cert.pem -days 1 -subj /CN=dtchat-test
$ openssl x509 -outform der -in cert.pem | sha256sum
d0d95caf347d8ba11c92fb073ae7de2248fa18190a95e987a8cdce1b0203703c -
$ ./tls_spike server 4443 cert.pem key.pem &
listening on 127.0.0.1:4443
$ ./tls_spike tofu 127.0.0.1 4443
version: TLSv1.3
subject: /CN=dtchat-test
hash: SHA256:d0d95caf347d8ba11c92fb073ae7de2248fa18190a95e987a8cdce1b0203703c
tofu exit=0
$ ./tls_spike remote 127.0.0.1 4444
tls_handshake: certificate verification failed: self-signed certificate
remote exit=1
```
### What it settles
- `tls_handshake`/`tls_read`/`tls_write` fit the core's `poll` loop without
a thread; the `TLS_WANT_POLLIN`/`TLS_WANT_POLLOUT` contract works as the
man page says.
- `tls_peer_cert_hash()` is exactly the SHA-256 of the DER certificate; the
TOFU pin can be compared to `openssl x509 -outform der | sha256sum`.
The strings match byte for byte (both `SHA256:d0d95caf...`).
- The default configuration (system CA) rejects a self-signed peer with
`certificate verification failed: self-signed certificate`; the TOFU
configuration accepts it and exposes the pin. This is the split the
local-peer design needs.
- `tls_accept_socket` on an accepted, non-blocking socket works.
### NetBSD -- not run
No reachable NetBSD host in this session: `makronix-build` (192.168.1.101)
answered `No route to host`. The code uses only the libtls API; NetBSD
builds `security/libretls` from the same 3.8.1 tarball (the base has
OpenSSL, no libtls -- `docs/reference/dtchat-architecture.txt`). The
NetBSD run is the same command with the pkgsrc include/lib paths:
```
$ cc -std=c99 -D_POSIX_C_SOURCE=200809L \
-I /usr/pkg/include tls_spike.c -L /usr/pkg/lib -ltls -lssl -lcrypto \
-o tls_spike
$ ./tls_spike remote example.com 443
```
Verdict: **Linux verified; the NetBSD run is open** (task `t0317` paused
with that note). The API is the same, but this file does not claim a
NetBSD measurement that was not made.
---
## T0.4 -- DNS-SD `_dtchat._tcp` (2026-11-16)
Host: `kitt`, Avahi 0.8, `avahi-daemon` running (`pgrep -a avahi-daemon`:
`avahi-daemon: running [kitt.local]`). Tools: `/usr/bin/avahi-browse`,
`/usr/bin/avahi-publish-service`.
Registration (the TXT was passed in the order the core will build it):
```
$ avahi-publish-service -s "dtchat-spike-1958984" _dtchat._tcp 47820 \
"txtvers=1" "protovers=1" "id=0123456789abcdef0123456789abcdef" \
"nm=Spike Host" "cap=text,file,audio" "fp=0123456789abcdef" &
Established under name 'dtchat-spike-1958984'
$ avahi-browse -r -t _dtchat._tcp
+ wlp0s20f3 IPv6 dtchat-spike-1958984 _dtchat._tcp local
+ wlp0s20f3 IPv4 dtchat-spike-1958984 _dtchat._tcp local
= wlp0s20f3 IPv6 dtchat-spike-1958984 _dtchat._tcp local
hostname = [kitt.local]
address = [fe80::5612:3527:90a5:f677]
port = [47820]
txt = ["fp=0123456789abcdef" "cap=text,file,audio" "nm=Spike Host" "id=0123456789abcdef0123456789abcdef" "protovers=1" "txtvers=1"]
= wlp0s20f3 IPv4 dtchat-spike-1958984 _dtchat._tcp local
hostname = [kitt.local]
address = [192.168.1.116]
port = [47820]
txt = ["fp=0123456789abcdef" "cap=text,file,audio" "nm=Spike Host" "id=0123456789abcdef0123456789abcdef" "protovers=1" "txtvers=1"]
$ kill %1; sleep 1; avahi-browse -r -t _dtchat._tcp
(no output)
```
### What it settles
- `_dtchat._tcp` is a valid service type; Avahi registers it, resolves it on
IPv4 and IPv6, and removes it after the publisher exits. The SRV record
gives `kitt.local` and port 47820; the TXT keys survive unchanged as
key/value strings.
- Avahi's CLI prints the TXT list in **reverse** order (`txtvers=1` last,
although it was passed first). The wire order of `avahi_string_list` in
the C API has to be checked in T5.2; the core will put `txtvers=1` first
when it builds the list and will not depend on order when parsing.
- `pkgsrc/net/avahi` installs the `avahi-client` headers and library
(`PLIST`: `include/avahi-client/client.h`, `lib/libavahi-client.la`,
`lib/pkgconfig/avahi-client.pc`) but **not** the `libdns_sd` compatibility
library: the PLIST has no `libdns_sd`, and `Makefile.common` only carries
the `avahi-compat-libdns_sd.pc.in` override. So the Linux backend uses
`avahi-client`, not `libdns_sd`.
- The McdeSys API can still be one streaming API
(`mcde_sys_net_announce` / `mcde_sys_net_watch`), with two backends:
`libdns_sd` on NetBSD (already used by `lib/McdeSys/netbsd.c:1837`) and
`avahi-client` on Linux. One underlying library for both is **not**
available from pkgsrc as packaged.
### NetBSD -- not run
`makronix-build` (192.168.1.101) had no route. The NetBSD side reuses the
existing `libdns_sd` code in `lib/McdeSys/netbsd.c`; a runtime measurement
is open (`t0322` paused). The NetBSD API (`DNSServiceRefSockFD` +
`DNSServiceProcessResult`) is quoted in `docs/reference/dtchat-upstream.txt`
section 5.
<!-- License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree. -->
---
## T0.5 -- libstrophe 0.12.3: STARTTLS, SASL, bind, message (2026-11-16)
Host: `kitt`, gcc 16.2.0, OpenSSL 3.6.3, expat 2.x.
libstrophe 0.12.3 from the GitHub tag tarball
(`libstrophe-0.12.3.tar.gz`), built static into
`/tmp/opencode/dtchat-spike/strophe-prefix`.
Build finding: `./bootstrap.sh && ./configure && make` **fails** with
gcc 16 because `src/handler.c` passes `xmpp_global_timed_handler` where
`xmpp_void_handler` is expected and gcc 14+ makes
`-Wincompatible-pointer-types` an error:
```
src/handler.c:748:51: error: passing argument 3 of '_timed_handler_add'
from incompatible pointer type [-Wincompatible-pointer-types]
```
With `CFLAGS="-O2 -g -Wno-error=incompatible-pointer-types"` it builds and
installs. This is a real portability item for the XMPP adapter package:
either the flag in the recipe or a one-line patch to the typedef in
`src/handler.c`. NetBSD's older compiler may not need it; the flag is
safe there.
The spike is a C client against a minimal Python XMPP server
(`/tmp/opencode/dtchat-spike/fake_xmpp_server.py`) that does STARTTLS with
a self-signed certificate, SASL PLAIN, resource binding, the legacy
session IQ and one incoming message. The client does not use
`xmpp_run()`; it drives `xmpp_run_once(ctx, 100)` in its own loop, which is
the shape the adapter needs.
```
$ ./strophe_spike
CONNECTED secured=1
MESSAGE from=peer@localhost/spike body=hello from the spike server
RESULT secured=1 connected=1 message=1
DISCONNECTED
client exit=0
server:
TLS: TLSv1.3
AUTH: test secret
...
S: <message from='peer@localhost/spike' to='test@localhost/spike'
type='chat'><body>hello from the spike server</body></message>
```
### What it settles
- `xmpp_run_once(ctx, timeout_ms)` is available in 0.12.3 and works from a
`poll`-style loop; `xmpp_run()` is not needed.
- TLS 1.3, SASL PLAIN, bind, session and a message body all work; the
adapter can map `message` stanzas to dtchat events.
- The certificate-failure path works: the self-signed certificate produced
`CERTFAIL: self-signed certificate` and the peer's SHA-256 fingerprint.
The real adapter uses `xmpp_conn_set_cafile` and only uses this handler
to show the error, not to accept.
- `xmpp_stanza_get_text_ptr()` returns NULL for an element with text
children; use `xmpp_stanza_get_text()` and free the result with
`xmpp_free(xmpp_conn_get_context(conn), text)`. The first run printed
`body=(null)` until this was fixed.
- libstrophe 0.12.3 has no MUC module (see `dtchat-upstream.txt` section
2); the adapter's `muc.c` builds MUC from stanzas.
This is not a test against a real XMPP account; a Prosody (or the user's
server) is the Phase 4 live test. The task's protocol path is proven.
---
## T0.6 -- Audio: 48 kHz s16, 20 ms, duplex on ALSA (2026-11-16)
Host: `kitt`, ALSA 1.2.16.1, card `sof-hda-dsp` (ThinkPad T14 Gen 3,
`/proc/asound/cards`). The spike opens capture and playback at the same
time, requests S16_LE, 48 kHz, mono, 960 frames per period and 4 periods of
buffer, reads 960 frames from capture and writes 960 frames of silence to
playback.
```
$ ./audio_spike 1
audio_spike: 1.0 s, capture=default playback=default
capture: default, 48000 Hz, 1 ch, period 960 frames (20.0 ms), buffer 3840
playback: default, 48000 Hz, 1 ch, period 960 frames (20.0 ms), buffer 3840
duplex: 48000 frames in 1.013 s -> 47403.2 frames/s (0.02 ms/frame)
capture RMS: 0.0 (of 32767) (silent input)
exit=0
```
### What it settles
- ALSA's `default` device accepts 48 kHz, S16_LE, mono, 960-frame periods
for capture and playback **at the same time**; both handles report the
requested 20.0 ms period and a 3840-frame buffer.
- The simple one-period loop underruns the playback side (`EPIPE`,
"Broken pipe") because it writes only after each capture read. The real
implementation needs a pre-filled ring buffer (3-4 periods) and a
playback path that is fed independently of the capture read; this is a
design note for `media_audio.c`, not a format problem.
- `hw:0,0` rejected the same configuration with `Invalid argument`; the
`default` plugin (PipeWire/ALSA routing) is the portable entry point.
- The capture side returned exactly 48,000 frames in ~1 s; RMS 0.0 means
the default capture is muted or digitally silent on this machine, not
that reads failed.
- The NetBSD `audio(4)` half was not run (no reachable NetBSD host). The
ALSA result decides the product question the same way: duplex is
possible, but without an echo canceller, **push-to-talk remains the
default** for v1; open microphone is optional (T6.9).
NetBSD command for later: open `/dev/audio` with `AUDIO_SETINFO`
(`play.format = AUDIO_ENCODING_SLINEAR_LE`, `play.channels = 1`,
`play.sample_rate = 48000`, `play.precision = 16`, same for `record`),
`read()`/`write()` 960 frames. The exact ioctl names are in `audio(4)`;
this file does not claim a NetBSD measurement.
---
## T0.7 -- TDLib 1.8.70, tdjson starts (Linux, 2026-11-16)
Host: `kitt`, 16 cores, cmake, g++ 16.2.0. Source: `tdlib/td` master,
shallow clone, 2026-11-16.
```
$ git clone --depth 1 https://github.com/tdlib/td.git
$ cd td && mkdir build && cd build
$ cmake -DCMAKE_BUILD_TYPE=Release -DTD_ENABLE_LTO=OFF -DTD_ENABLE_JNI=OFF \
-DCMAKE_INSTALL_PREFIX=/home/lotherk/tmp/dtchat-tdlib/prefix ..
$ cmake --build . -j4
```
The build is deliberately limited to `-j4` because the 16-core host has
31 GB RAM and a full `-j16` C++ build is not worth the memory pressure.
Result:
```
$ ls -lh td/build/libtdjson.so.1.8.70
50M libtdjson.so.1.8.70
$ du -sh td/build
537M td/build
$ cc -std=c99 -I td -I td/build tdjson_spike.c -L td/build \
-ltdjson -Wl,-rpath,$PWD/td/build -o tdjson_spike
$ ./tdjson_spike
client_id=1
recv: {"@type":"updateOption","name":"version",
"value":{"@type":"optionValueString","value":"1.8.70"},
"@client_id":1}
done
exit=0
```
### What it settles
- TDLib builds on Linux with `-DTD_ENABLE_JNI=OFF`; the `tdjson` C API is
usable without a Telegram account. `td_create_client_id()` returns 1,
`getOption("version")` answers `1.8.70`, and stderr shows the normal
`authorizationStateWaitTdlibParameters` state.
- The shared library is 50 MB; the build tree is 537 MB. That is a
separate helper package, not part of the MCDE core.
- **NetBSD was not built**: no reachable NetBSD host in this session. The
Telegram package is therefore Linux-first; the NetBSD build is a release
gate (`t0317`/`t0318`-style). The `api_id`/`api_hash` are still the
user's; Telegram does not allow shipping a shared pair.
- TDLib has call signalling (`createCall` etc.) but no media stack; dtchat
v1 still has no Telegram call button (see `dtchat-upstream.txt` section
3).
## T0.8 -- whatsmeow builds and starts the QR flow (2026-11-16)
Host: `kitt`, Go 1.27.4 (downloaded from <https://go.dev/dl/>),
whatsmeow `v0.0.0-20261116124925-2ecca2c913b9` (master on 2026-11-16),
`github.com/mattn/go-sqlite3 v1.14.53` (cgo).
```
$ go build -o wa_spike .
$ ./wa_spike
QR code received, length=277 (not printed)
RESULT qr=1 (login not completed)
exit=0
$ ls -l spike.db
163840 spike.db
```
### What it settles
- whatsmeow builds on this host with Go 1.27 and the cgo SQLite driver;
the binary is 24 MB. A pure-Go SQLite driver was not tried; the cgo
one is what the package example uses.
- `sqlstore.New(ctx, "sqlite3", "file:spike.db?_foreign_keys=on", log)` +
`GetFirstDevice(ctx)` + `GetQRChannel(ctx)` + `Connect()` reaches the
QR event; the code is 277 characters. The code is deliberately not
printed (it is a login token).
- The session store is a SQLite file (160 KB before login), so the adapter
can keep it under `~/.dt/dtchat/wa/<account>/` with 0700.
- **Not proven:** scanning the QR, a text message in either direction, and
reconnect. That needs a spare WhatsApp account and a phone; it is the
live test in T9.2. The spike is therefore paused, not done.
- The README's "Calls" entry under "not yet implemented" (quoted in
`dtchat-upstream.txt` section 4) means no WhatsApp call button in v1.