Skip to content

fix(protocol): harden UDP parsing, matching, and Block1 transfers - #32

Merged
maikebing merged 11 commits into
masterfrom
codex/coap-protocol-20261113
Nov 12, 2026
Merged

maikebing merged 11 commits into
masterfrom
codex/coap-protocol-20261113

Conversation

@maikebing

@maikebing maikebing commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Malformed UDP datagrams could be dispatched, a response could match the wrong peer, and invalid or interleaved Block1/Block2 responses could advance a partial upload or strand its caller. The final change rejects malformed packets, locks failed decoders, binds matching to endpoint/MID/full token with mapped-address normalization, and serializes Block1 continuation with final Block2 response retrieval.

Blockwise handling preserves RFC 7959's legal per-block success mode, manually managed Block1 and initial 4.13 size hints. Invalid current acknowledgements explicitly cancel the original request and notify asynchronous callers through appended FailReason.Cancelled=2; existing Rejected=0 and TimedOut=1 remain unchanged. Critical-option bit classification is corrected. The narrow smeshlink PR64/PR80 shutdown-log/test-counter fixes are also included.

The audit covers all 65 upstream issues and 17 PRs, 75 visible forks (73 readable repositories, 301 refs, 47 unique heads), plus a bounded 100-candidate CoAP-topic survey across 21 named languages. It distinguishes codecs, protocol stacks, platforms, LwM2M and testing tools, records current RFC/IANA and license evidence, and leaves optional capabilities as individual open contracts.

Validation on final head 9f53d25:

  • Windows Release: 258/258 tests passed, zero failed/skipped.
  • Linux PR CI: 258/258 tests passed; library/sample builds have zero warnings/errors and tested packages pack successfully.
  • Owned-source format verification and final staged whitespace check passed.
  • Four automatic-review findings were reproduced, fixed, independently reviewed, replied to, and resolved; 13 endpoint-level combination cases cover the resulting state transitions.
  • Baseline failures, exact source hashes and commands are in docs/audits/coap-20261113/validation-review.json.
  • Real-peer interoperability, NativeAOT execution, public package publication/consumption, and device/soak acceptance are NOT_RUN.

The option19 legacy/default API compatibility decision remains pending in #23. Known-option semantic policy (#28), remaining lifecycle work (#29), common extensions and transports/security stay open. This PR does not publish a tag or NuGet package.

Closes #20
Closes #21
Closes #22

Refs #23, #24, #25, #26, #27, #28, #29, #30, #31.

Copilot AI balanced review requested due to automatic review settings November 12, 2026 18:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Blockwise response handling can prematurely report success for incomplete uploads or leave competing same-token requests outstanding.

4 open issues
What changed in this PR

This PR hardens CoAP.NET’s UDP parsing, response matching, and Block1 uploads while preserving the Resource/MVC hosting API. It also records the standards audit and separates completed validation from pending interoperability and deployment checks.

Changes:

  • Reject malformed datagrams, lock failed decoders, and strengthen endpoint, message-ID, and token matching.
  • Validate Block1 continuation state, report async cancellation, and correct critical-option classification.
  • Add protocol regressions, small logging/test-isolation fixes, and standards audit documentation.
File Description
ROADMAP.md Links protocol priorities and clarifies validation boundaries.
README.md Links the standards and interoperability roadmap.
HANDOFF.md Records integration results and remaining work.
docs/​coap-standards-roadmap.md Defines standards gaps, audit scope, and implementation priorities.
docs/​audits/​coap-20261113/​validation-first-wave.json Records initial validation and baseline failures.
docs/​audits/​coap-20261113/​validation-final.json Records final validation results and source hashes.
docs/​audits/​coap-20261113/​upstream-prs.json Catalogs upstream pull requests.
docs/​audits/​coap-20261113/​issue-decisions.json Records upstream issue triage.
docs/​audits/​coap-20261113/​fork-review.json Documents fork comparisons and adoption decisions.
CoAP.Test/​MatcherProtocolTest.cs Tests endpoint, message-ID, and full-token matching.
CoAP.Test/​MalformedDatagramTest.cs Tests malformed packet rejection and reset behavior.
CoAP.Test/​DecoderFailureStateTest.cs Tests decoder lockout after parsing failures.
CoAP.Test/​CriticalOptionClassificationTest.cs Tests critical and elective option classification.
CoAP.Test/​CoapClientTest.cs Resets notification counts before each test.
CoAP.Test/​CoapClientProtocolFailureTest.cs Tests cancellation reporting and upload response matching.
CoAP.Test/​BlockwiseProtocolRegressionTest.cs Tests Block1 errors, sequencing, and size changes.
CoAP.NET/​Stack/​BlockwiseLayer.cs Validates upload acknowledgements and continuation offsets.
CoAP.NET/​Spec.cs Validates UDP headers and message-type/code combinations.
CoAP.NET/​Server/​CoapServer.cs Corrects the shutdown log message.
CoAP.NET/​Option.cs Fixes critical-option bit classification.
CoAP.NET/​Net/​Matcher.cs Binds matching to endpoints and complete tokens.
CoAP.NET/​Net/​CoAPEndPoint.cs Contains decoding failures and controls malformed-packet resets.
CoAP.NET/​Codec/​MessageDecoder.cs Prevents reuse after parsing errors.
CoAP.NET/​Codec/​DatagramReader.cs Rejects reads beyond available input.
CoAP.NET/​CoapClient.cs Adds cancellation failure notifications.
CHANGELOG.md Summarizes protocol fixes and audit documentation.

Review effort: Balanced

Comment thread CoAP.NET/Stack/BlockwiseLayer.cs Resolved
Comment thread CoAP.NET/Net/Matcher.cs Resolved
Comment thread CoAP.NET/Stack/BlockwiseLayer.cs Resolved
Comment thread CoAP.NET/Stack/BlockwiseLayer.cs Resolved
@maikebing
maikebing merged commit 557b31a into master Nov 12, 2026
4 checks passed
@maikebing
maikebing deleted the codex/coap-protocol-20261113 branch November 13, 2026 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants