Skip to content

MQTT 3.1.1 broker (mqtt package) - #34

Merged
y001j merged 1 commit into
masterfrom
feat/mqtt
Nov 22, 2026
Merged

y001j merged 1 commit into
masterfrom
feat/mqtt

Conversation

@y001j

@y001j y001j commented Nov 22, 2026

Copy link
Copy Markdown
Owner

An MQTT broker for IoT gateways, on the public uringnet API. Devices connect and publish; the application in the same process receives every message (OnPublish) and publishes to devices (Publish).

Protocol: all 14 packet types, strict parsing; QoS 0/1/2 from publishers (QoS 2 delivered once); subscriptions granted at most QoS 1; wildcards +/# ($-topics excluded), retained messages, wills, persistent sessions (QoS 1 queued offline, resent with DUP after reconnect), session takeover, CONNECT + 1.5× keepalive timeouts; authentication / publish / subscribe hooks; Stats. MQTT 5 clients get a v5 CONNACK 0x84 (mosquitto_pub -V mqttv5 prints "Unsupported Protocol Version").

Flow control: QoS 1 bounded by inflight window + queue; QoS 0 dropped above MaxClientBuffer for slow subscribers (test: 20MB flood to a non-reading subscriber stays bounded, others unaffected).

uringnet API: adds Conn.SameLoop and Conn.Post (run code on a connection's loop). Delivery writes directly within a ring and posts otherwise; QoS 0 packets encoded once and shared.

Tests: 13 broker tests + codec/topic tests (the latter platform-independent, run on macOS too); both backends, -race, 5×. Interop with mosquitto_pub/mosquitto_sub: QoS 0–2 + wildcard, retained, will, persistent session.

vs Mosquitto 2.0.22 (both 1 core, QoS 1 publishers waiting for PUBACK, 64B):

uringnet Mosquitto ratio
100 pubs → 1 sub 213k/s 119k/s 1.79
10 pubs → 100 subs 1.35M deliveries/s 507k/s 2.67
1000 pubs 314k/s 179k/s 1.75

Docs: README (EN/中文), architecture, changelog (Unreleased), example/mqttbroker.

🤖 Generated with Claude Code

An MQTT broker for IoT gateways on the public uringnet API: devices
connect and publish; the application in the same process receives
every message (OnPublish) and publishes to devices (Publish).

- All 14 packet types with strict parsing (variable byte integer of at
  most 4 bytes, packet size limit, flag checks, UTF-8 without U+0000).
- QoS 0, 1 and 2 from publishers (QoS 2 delivered once, deduplicated
  until PUBREL); subscriptions granted at most QoS 1.
- Wildcards + and # in a trie ($-topics excluded from leading
  wildcards), retained messages, wills, persistent sessions with QoS 1
  queued while offline and resent with DUP after a reconnect, session
  takeover, CONNECT and 1.5x keepalive timeouts.
- Authentication and publish/subscribe authorization hooks, OnConnect/
  OnDisconnect, Stats. MQTT 5 clients get a v5 CONNACK 0x84.
- Delivery writes directly within a ring (Conn.SameLoop) and posts to
  the subscriber's ring otherwise (Conn.Post, new), where QoS 0 is
  dropped above MaxClientBuffer so slow subscribers cannot make the
  broker buffer without limit; QoS 0 packets are encoded once.
- Codec and topic matching are platform-independent and tested on any
  OS; broker tests run on both backends; interop verified with
  mosquitto_pub/mosquitto_sub; example/mqttbroker.

Against Mosquitto 2.0.22 on one core: 1.79x (100 publishers to one
subscriber), 2.67x (fan-out to 100 subscribers), 1.75x (1000
publishers).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.21922% with 58 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.92%. Comparing base (d34e73f) to head (f9bc2d0).

Files with missing lines Patch % Lines
mqtt/broker.go 89.41% 36 Missing ⚠️
mqtt/packet.go 88.75% 18 Missing ⚠️
conn.go 0.00% 2 Missing ⚠️
mqtt/topic.go 97.80% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #34      +/-   ##
==========================================
+ Coverage   71.36%   74.92%   +3.55%     
==========================================
  Files          28       31       +3     
  Lines        2553     3146     +593     
==========================================
+ Hits         1822     2357     +535     
- Misses        731      789      +58     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@y001j
y001j merged commit f92576a into master Nov 22, 2026
6 checks passed
@y001j
y001j deleted the feat/mqtt branch November 22, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant