Skip to content

Commit c7b90d0

Browse files
DavidCozensclaude
andcommitted
feat: hold a real mutual-TLS session to the broker from bring-up
The other half. The device now opens a session to the broker at bring-up, over lwIP's raw TCP and mbedTLS, with the credentials DeviceCertStore already holds — and never closes it. Held rather than opened-and-closed on purpose: two sessions that do not overlap measure max(), not sum(), and it is the sum that says what a second session costs. flash_text 361,736 -> 362,968 (+1,232) static_bss 133,152 -> 157,280 (+24,128) mbedtls_peak 22,208 -> 37,224 (+15,016) heap_used 4,440 -> 4,440 The last line is the point of the exercise. mbedTLS's buffer used to peak at 22,208 bytes with SolidSyslog's session in it and nothing else; with the device's own session open alongside it, 37,224. So a second concurrent session costs about 15,000 bytes, not 22,208 — the difference is the parsed certificates, the DRBG and the rest of the first session's one-off state, which a device speaking mTLS has paid for already. Once the baseline is regenerated it will hold that first session, and what SolidSyslog is charged for TLS memory becomes the marginal figure, measured rather than argued. "About", because mbedtls_peak is not byte-reproducible. Five runs of this image gave 37,152 / 37,224 / 37,236 / 37,244 / 37,248 — a spread wider than the run's 64-byte drift tolerance, for the same reason heap_used moves: gen-certs.sh builds a fresh PKI every run and DER lengths shift with the key material. The figures above are the two committed run reports, so the arithmetic is checkable; the marginal cost it yields is good to about a hundred bytes, not to the byte. That has to be settled before the baseline is frozen with this key in it. flash_text and static_bss are exact. The static RAM growth is almost entirely the buffer: 32 KiB to 55 KiB, which is the peak times 1.5 rounded up to the next KiB. The margin is not padding — buffer_alloc hands out contiguous space, and 24 KiB against a 22.2 KiB peak failed on fragmentation where 32 KiB worked. The remaining 576 bytes are the ssl context, its config, and the TCP state. The keep-alive list loses the mbedTLS client surface and most of the TCP entries, because the session calls them for real now and naming a function there that the device runs would say something untrue. Flash did not move for it: those call closures were in the image either way, which is what the list was for. What stays is what is still unexercised — UDP, the file API, and the teardown path a session held for the life of the device never reaches. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent be1f78e commit c7b90d0

8 files changed

Lines changed: 456 additions & 72 deletions

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ endforeach()
141141
add_executable(baseline
142142
${APP_DIR}/main.c
143143
${APP_DIR}/sim/SimulatedExistingApp.c
144+
${APP_DIR}/sim/SimulatedBrokerSession.c
144145
${APP_DIR}/tasks/LogTask.c
145146
${APP_DIR}/tasks/ServiceTask.c
146147
${APP_DIR}/measure/Measure.c
@@ -187,8 +188,8 @@ target_include_directories(baseline PRIVATE
187188
${FATFS_STAGE_DIR}
188189
)
189190

190-
# sim/SimulatedExistingApp.c includes <mbedtls/ssl.h> — it MUST see the same user
191-
# config as the library, or context struct sizes diverge between consumer and library.
191+
# app/sim includes <mbedtls/ssl.h> — it MUST see the same user config as the
192+
# library, or context struct sizes diverge between consumer and library.
192193
target_compile_definitions(baseline PRIVATE MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_HEADER})
193194

194195
# SolidSyslog is the Core library (a real .a); the SolidSyslog::* packs are

app/AppConfig.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@
4242
* the report prints absolutes for us to commit as the baseline. */
4343
#define BASELINE_FILE_PATH "measurements/Baseline.csv"
4444

45-
/* The static buffer mbedTLS sub-allocates from. Sized from the high-water mark the
46-
* device reports, so a step that asks more of mbedTLS grows this and is charged for
47-
* it — the baseline holds no spare capacity on a later step's behalf. */
48-
#define SIMULATED_APP_MBEDTLS_HEAP_BYTES (32 * 1024)
45+
/* The static buffer mbedTLS sub-allocates from. Sized at the high-water mark the
46+
* device reports times 1.5, rounded up to the next KiB — buffer_alloc hands out
47+
* contiguous space, so a buffer only a little over the peak fails on
48+
* fragmentation rather than on capacity. One rule, applied again at every step
49+
* that asks more of mbedTLS, so the baseline holds no spare capacity on a later
50+
* step's behalf and each step is charged what it actually added. */
51+
#define SIMULATED_APP_MBEDTLS_HEAP_BYTES (55 * 1024)
4952

5053
#endif /* APP_CONFIG_H */

app/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* with ZERO SolidSyslog.
33
*
44
* This is the "simulated existing application": a device that already networks,
5-
* already uses storage, and has TLS on board — the frozen platform SolidSyslog's
6-
* footprint deltas are measured against. main() is deliberately thin: it starts
5+
* already uses storage, and already holds a TLS session — the frozen platform
6+
* SolidSyslog's footprint deltas are measured against. main() is deliberately thin: it starts
77
* the console, creates the two idle application seams (a log source and a service
88
* worker), and hands off to a harness task that brings up the simulated existing
99
* application, measures the cost above the frozen baseline, and exits.
@@ -68,7 +68,7 @@ static void HarnessTask(void* parameters)
6868
(void) printf("[device] starting simulated existing application...\n");
6969
bool simReady = SimulatedExistingApp_Start();
7070
(void) printf(
71-
"[device] sim app (lwIP up, FatFs mounted, mTLS credentials loaded, mbedTLS linked): %s\n",
71+
"[device] sim app (lwIP up, FatFs mounted, broker session held over mTLS): %s\n",
7272
simReady ? "ready" : "FAILED"
7373
);
7474

0 commit comments

Comments
 (0)