balancer-lite-lua.dlog 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # balancer-lite-lua.dlog — Deployment Log
  2. ## 2026-09-04 Initial Prototype
  3. ### What
  4. Created new workspace project `balancer-lite-lua/` for OpenWrt 22.03 Lua 5.1 port of
  5. balancer-lite's hysteresis watchdog, flap detection, signed webhook outbox, and retention store.
  6. Thin-layer only (~800–1000 LOC) — composes with mwan3/netifd rather than replacing them.
  7. ### Commit
  8. Not yet committed (pending lint).
  9. ### Files
  10. - `src/balancerlite/state.lua` — 8-state hysteresis machine (INIT, WAN_A_PRIMARY, WAN_B_PRIMARY, SWITCHING_TO_A, SWITCHING_TO_B, DEGRADED, BOTH_DOWN)
  11. - `src/balancerlite/probes.lua` — ICMP/TCP/DNS health checks via ping/nc/nslookup subprocesses
  12. - `src/balancerlite/store.lua` — JSONL append-only event log + compaction
  13. - `src/balancerlite/outbox.lua` — Signed webhook retry queue with exponential backoff + circuit breaker
  14. - `src/balancerlite/sha256.lua` — SHA-256/HMAC-SHA256 via `openssl dgst` CLI
  15. - `src/balancerlite/config.lua` — UCI config file parser
  16. - `src/balancerlite/main.lua` — procd-compatible poll loop daemon
  17. - `src/balancerlite/json.lua` — Pure-Lua JSON encoder (JSON.stringify only)
  18. - `etc/init.d/balancerlite` — procd init script
  19. - `etc/config/balancerlite` — UCI config example
  20. - `Makefile` — lint + test targets
  21. - `tests/state.lua` — 8 state machine tests (all passing)
  22. - `tests/sha256.lua` — SHA-256 + HMAC-SHA256 test vectors (all passing)
  23. - `MEMORY.md`, `README.md`
  24. ### Test Results
  25. ```
  26. lua5.1 tests/state.lua → PASS: state (8/8 tests)
  27. lua5.1 tests/sha256.lua → PASS: sha256 (3/3 vectors)
  28. ```
  29. ### Verification Commands
  30. ```sh
  31. cd /root/.openclaw/workspace/balancer-lite-lua
  32. make test
  33. make lint
  34. ```
  35. ### Notes
  36. - HMAC-SHA256 uses `openssl dgst -hmac` CLI (openssl-util package on OpenWrt 22.03)
  37. - No lua-crypto dependency; no raw sockets; all probes via subprocess
  38. - State machine behavior verified against Go source: 8 states, same transition logic
  39. - SWITCHING_TO_* are intermediate (one-drive-cycle) states; BOTH_DOWN transitions directly to stable primary (no intermediate)
  40. - BOTH_DOWN clears switch_times (flap detection not counted during all-down)
  41. - DEGRADED entry: flap check counts #record_switch calls; needs `flap_threshold` of them before DEGRADED triggers
  42. ### Next Steps
  43. 1. Run lua51-openwrt-lint on all modules
  44. 2. Run openwrt-testbed for runtime validation
  45. 3. Write remaining modules: routing.lua (policy routing), wg.lua (WG endpoint re-point)
  46. 4. Write balancerlite-ctl CLI tool
  47. 5. Commit and push to git3