From 2e0fdd7419a96ea084e07f852e6aa1d660fe3368 Mon Sep 17 00:00:00 2001 From: Jason Huebert Date: Wed, 7 Oct 2026 08:45:01 -0500 Subject: [PATCH] feat(filter): deferred script execution hook (MyMesh loop) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A file-static trampoline runs each queued script line through handleCommand(0, ...) — the same dispatch and privilege as the serial console — and logs 'cli[] ' plus its reply, so an operator at the console sees exactly what ran. MyMesh::loop() drains one script per call right after filter.loop(), outside the receive bracket that queued it: no rule-list mutation while checkContent() is scanning, no verdict stash cleared mid-receive, no flash I/O in the receive path. MyMesh.h is unchanged (trampoline is file-static; handleCommand is already public) and hasPendingWork() is unchanged: the queue drains in the same loop() call that received the message, before the sleep check. --- examples/simple_repeater/MyMesh.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index d12b17e7..d6eb55fd 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -1326,6 +1326,17 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply } } +// Executor for remote CLI scripts queued by action=cli filter rules (see +// CliScript.h): each line runs through handleCommand(0, ...) — serial-privilege +// dispatch, sender_timestamp = 0 — and both the line and its reply are logged +// in the serial CLI's style, so an operator at the console sees exactly what +// ran. `key` is the job's !id key string from the queued script itself. +static void execCliLine(void* ctx, const char* key, char* line, char* reply) { + ((MyMesh*)ctx)->handleCommand(0, line, reply); + Serial.printf("cli[%s] %s\n", key, line); + if (reply[0]) Serial.printf(" -> %s\n", reply); +} + void MyMesh::loop() { #ifdef WITH_BRIDGE bridge.loop(); @@ -1373,6 +1384,12 @@ void MyMesh::loop() { // lazy dirty-flag save for the packet filter config filter.loop(_fs); + // Remote CLI scripts (action=cli rules): drain one queued script per loop, + // after mesh::Mesh::loop() and outside the receive bracket that produced it — + // never while the filter is evaluating a packet. handleCommand(0, ...) gives + // a script line the same dispatch and privilege as the serial console. + filter.runCliScripts(execCliLine, this); + // update uptime uint32_t now = millis(); uptime_millis += now - last_millis;