mirror of
https://github.com/jhuebert/MeshCore.git
synced 2026-12-03 10:54:13 +00:00
feat(filter): deferred script execution hook (MyMesh loop)
A file-static trampoline runs each queued script line through handleCommand(0, ...) — the same dispatch and privilege as the serial console — and logs 'cli[<key>] <line>' 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.
This commit is contained in:
1 parent
828e6325f5
commit
2e0fdd7419
1 file changed
+17
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user