refactor(mqtt): .Browser references .Driver — extract the client-options builder so the layering exception can go #512

Open
opened 2026-07-27 13:50:30 -04:00 by dohertj2 · 0 comments
Owner

ZB.MOM.WW.OtOpcUa.Driver.Mqtt.Browser.csproj carries a ProjectReference to
Driver.Mqtt (line 44) in addition to .Contracts. Every other driver's .Browser depends on
.Contracts only.

Why it was accepted. The browser needs to open its own broker connection, which means building MQTTnet
client options with the same TLS / CA-pinning / auth semantics the driver uses. Reusing
MqttConnection.BuildClientOptions was judged better than duplicating security-relevant TLS and CA-pin logic
in a second place, where the two copies would drift and one of them would drift open. The exception is
documented rather than silent.

Clean fix. Extract the pure options-building function to .Contracts (it is transport-free — it maps
MqttDriverOptions to client options; it does not connect), leaving MqttConnection as the only thing that
owns a live client. Then drop the .Driver reference from .Browser.

Guard against the wrong fix: do not resolve this by copy-pasting the TLS setup into the browser. The
duplication is the actual hazard the exception was taken to avoid.

Acceptance. .Browser references .Contracts only; one implementation of the TLS/CA-pin options builder
exists in the tree; the live browse suite still connects over TLS with CA pinning (both the pinned-good and
pinned-wrong cases).

`ZB.MOM.WW.OtOpcUa.Driver.Mqtt.Browser.csproj` carries a `ProjectReference` to **`Driver.Mqtt`** (line 44) in addition to `.Contracts`. Every other driver's `.Browser` depends on `.Contracts` only. **Why it was accepted.** The browser needs to open its own broker connection, which means building MQTTnet client options with the same TLS / CA-pinning / auth semantics the driver uses. Reusing `MqttConnection.BuildClientOptions` was judged better than duplicating security-relevant TLS and CA-pin logic in a second place, where the two copies would drift and one of them would drift *open*. The exception is documented rather than silent. **Clean fix.** Extract the pure options-building function to `.Contracts` (it is transport-free — it maps `MqttDriverOptions` to client options; it does not connect), leaving `MqttConnection` as the only thing that owns a live client. Then drop the `.Driver` reference from `.Browser`. **Guard against the wrong fix:** do not resolve this by copy-pasting the TLS setup into the browser. The duplication is the actual hazard the exception was taken to avoid. **Acceptance.** `.Browser` references `.Contracts` only; one implementation of the TLS/CA-pin options builder exists in the tree; the live browse suite still connects over TLS with CA pinning (both the pinned-good and pinned-wrong cases).
dohertj2 added the driver/mqtt label 2026-07-27 13:50:30 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dohertj2/lmxopcua#512