code wiki / shims / nx_mqtt_shim.nx

nx_mqtt_shim.nx

buildroot/runtime/shims/nx_mqtt_shim.nx

19846 B485 linesdepth 2pulls 2 transitivereach 1 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_mqtt_shim.nx -- MQTT 3.1.1 protocol shim. WHEELER-IMPLEMENTATION-OF-CANONICAL-SPEC. Wire-spec source (re-implemented clean-room from published spec; no external code imported per sovereignty audit): - OASIS MQTT Version 3.1.1 Plus Errata 01 (29 October 2015) - Optional V2+: OASIS MQTT Version 5.0 (07 March 2019) Third protocol shim per INTEROPERABILITY_CHARTER.md §5.5 (cloud). Opens the cloud-pub/sub family. MQTT is the IoT-standard pub/sub wire protocol; once this ships, the substrate's nx_telemetry bus can publish anomaly verdicts to an MQTT broker -> operator dashboards / mobile alerts / cloud aggregation, instead of just stdout NDJSON. Status: SEED v0.1.0. 2026-05-27. WINNER-TIER: BASELINE-C provisional INCUMBENTS: Mosquitto v2.x (broker; ISC), Eclipse Paho C v1.3.x (client; EPL), mqtt.js v5.x (JavaScript client; MIT), HiveMQ Cloud (commercial broker), AWS IoT Core (commercial cloud broker), Aedes (Node.js broker) NUMBERS: V1 ships framing + publish/subscribe + ping; paired throughput + connection-stability bench vs Paho C pending real broker fixture GAP: Paho has feature breadth (TLS, MQTT 5.0 properties, persistent session, will/retain); V1 covers the ~70% subset that publishes telemetry from substrate to broker. Nishi adds value via sealed verdict surface + telemetry-bus integration (Paho is string-keyed; loses type safety) PLAN: M-next: paired bench vs Paho on 10K-publish burst latency + broker reconnection storm; add MQTT 5.0 properties + TLS wrap when nx_tls_shim lands EXEMPTION REASON: n/a; provisional pending measurement V1 SCOPE: - CONNECT / CONNACK (client-side; clean-session only V1)

dependencies 1 imports · 1 importers

nx_syscalls.nx nx_mqtt_shim.nx nx_mqtt_sink_for_telemetry.nx

imports: nx_syscalls.nx

imported by: nx_mqtt_sink_for_telemetry.nx

structs

128struct NxMqttShim

consts

63const NX_SHIM_OK: i64 = 0
64const NX_SHIM_BAD_FRAME: i64 = 1
65const NX_SHIM_PROTOCOL_VIOLATION: i64 = 2
66const NX_SHIM_TIMEOUT: i64 = 3
67const NX_SHIM_BACKPRESSURE: i64 = 4
68const NX_SHIM_UNSUPPORTED_PID: i64 = 5 // here: unsupported control packet type
69const NX_SHIM_NO_WIRE: i64 = 6
72const NX_MQTT_VERDICT_BASE: i64 = 300
73const NX_MQTT_BAD_PROTO_NAME: i64 = 300 // CONNECT proto name != "MQTT"
74const NX_MQTT_BAD_PROTO_LEVEL: i64 = 301 // CONNECT proto level != 4 (v3.1.1)
75const NX_MQTT_BAD_VLI: i64 = 302 // var-len-int > 4 bytes (spec max)
76const NX_MQTT_BAD_QOS: i64 = 303 // QoS out of 0..2
77const NX_MQTT_BAD_TOPIC: i64 = 304 // topic name violates §4.7
78const NX_MQTT_UNSUPPORTED_QOS2: i64 = 305 // V1 doesn't implement QoS 2
79const NX_MQTT_CONNACK_REJECTED: i64 = 306 // broker rejected connection (CONNACK rc != 0)
80const NX_MQTT_TRUNCATED: i64 = 307
83const NX_MQTT_PKT_RESERVED_0: i64 = 0x00
84const NX_MQTT_PKT_CONNECT: i64 = 0x10 // client -> server
85const NX_MQTT_PKT_CONNACK: i64 = 0x20 // server -> client
86const NX_MQTT_PKT_PUBLISH: i64 = 0x30 // bidirectional
87const NX_MQTT_PKT_PUBACK: i64 = 0x40 // QoS 1 ack
88const NX_MQTT_PKT_PUBREC: i64 = 0x50 // QoS 2 step 1 (V2+)
89const NX_MQTT_PKT_PUBREL: i64 = 0x60 // QoS 2 step 2 (V2+)
90const NX_MQTT_PKT_PUBCOMP: i64 = 0x70 // QoS 2 step 3 (V2+)
91const NX_MQTT_PKT_SUBSCRIBE: i64 = 0x80
92const NX_MQTT_PKT_SUBACK: i64 = 0x90
93const NX_MQTT_PKT_UNSUBSCRIBE: i64 = 0xA0
94const NX_MQTT_PKT_UNSUBACK: i64 = 0xB0
95const NX_MQTT_PKT_PINGREQ: i64 = 0xC0
96const NX_MQTT_PKT_PINGRESP: i64 = 0xD0
97const NX_MQTT_PKT_DISCONNECT: i64 = 0xE0
100const NX_MQTT_CONNECT_FLAG_CLEAN_SESSION: i64 = 0x02
101const NX_MQTT_CONNECT_FLAG_WILL: i64 = 0x04
102const NX_MQTT_CONNECT_FLAG_WILL_QOS_1: i64 = 0x08
103const NX_MQTT_CONNECT_FLAG_WILL_QOS_2: i64 = 0x10
104const NX_MQTT_CONNECT_FLAG_WILL_RETAIN: i64 = 0x20
105const NX_MQTT_CONNECT_FLAG_PASSWORD: i64 = 0x40
106const NX_MQTT_CONNECT_FLAG_USERNAME: i64 = 0x80
109const NX_MQTT_CONNACK_OK: i64 = 0
110const NX_MQTT_CONNACK_UNSUPPORTED_PROTOCOL: i64 = 1
111const NX_MQTT_CONNACK_BAD_CLIENT_ID: i64 = 2
112const NX_MQTT_CONNACK_SERVER_UNAVAILABLE: i64 = 3
113const NX_MQTT_CONNACK_BAD_AUTH: i64 = 4
114const NX_MQTT_CONNACK_NOT_AUTHORIZED: i64 = 5
117const NX_MQTT_EVT_CONNECTED: i64 = 400 // v0=session_present; v1=connack_rc
118const NX_MQTT_EVT_MESSAGE_RX: i64 = 401 // v0=packet_id; v1=qos; v2=payload_len
120const NX_MQTT_EVT_PUBACK_RX: i64 = 402 // v0=packet_id (matches our prior PUBLISH)
121const NX_MQTT_EVT_SUBSCRIBED: i64 = 403 // v0=packet_id; v1=granted_qos
122const NX_MQTT_EVT_PING_RX: i64 = 404 // server-side PINGRESP received
123const NX_MQTT_EVT_DISCONNECTED: i64 = 405 // server initiated DISCONNECT
124const NX_MQTT_EVT_REJECTED: i64 = 406 // v0=connack_rc reason

functions

140func nx_mqtt_shim_init(s: *NxMqttShim) -> i64
159func nx_mqtt_vli_decode(buf: *u8, off: i64, out_value: *i64) -> i64
called by 1: nx_mqtt_rx_fn
176func nx_mqtt_vli_encode(value: i64, out: *u8, out_off: i64) -> i64
197func nx_mqtt_read_u16_be(buf: *u8, off: i64) -> i64
called by 1: nx_mqtt_rx_fn
203func nx_mqtt_write_u16_be(buf: *u8, off: i64, value: i64) -> i64
209func nx_mqtt_write_string(buf: *u8, off: i64, str: *u8, str_len: i64) -> i64
226func nx_mqtt_build_connect(s: *NxMqttShim, client_id: *u8, client_id_len: i64,
272func nx_mqtt_build_publish(s: *NxMqttShim, topic: *u8, topic_len: i64,
319func nx_mqtt_build_subscribe(s: *NxMqttShim, topic_filter: *u8, topic_filter_len: i64,
348func nx_mqtt_build_pingreq(s: *NxMqttShim, out: *u8, out_cap: i64) -> i64
356func nx_mqtt_build_disconnect(s: *NxMqttShim, out: *u8, out_cap: i64) -> i64
370func nx_mqtt_rx_fn(s: *NxMqttShim, frame: *u8, frame_len: i64,
478func nx_mqtt_diag_fn(s: *NxMqttShim, out_vec: *i64) -> i64