[border-agent] simplify forwarding logic to leader - #12114
Conversation
This commit simplifies the CoAP message forwarding logic within the `CoapDtlsSession` by removing the `mPetition` and `mSeparate` boolean flags from the `ForwardContext`. The `Uri` of the request is now stored directly in `ForwardContext` and used to determine the logic flow, making the code more explicit and easier to understand. The `ForwardToLeader()` is only used with `kUriLeaderPetition` and `kUriLeaderKeepAlive`, both of which requires a separate non-confirmable response in addition to an immediate CoAP Ack (i.e., as if `mSeperate` is `true`). This change removes the need for intermediate flags and simplifies the implementation of `ForwardToLeader()`, `SendErrorMessage()`, and the `ForwardContext` constructor and `ToHeader()` method. The CoAP message initialization is now more direct, always using `kTypeNonConfirmable` for forwarded responses and error messages.
Library files
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request simplifies the CoAP message forwarding logic by removing intermediate flags (mPetition, mSeparate) and using the request URI directly. This is a great refactoring that makes the code more explicit and easier to follow. The changes are consistent and the logic is sound. I have a couple of minor suggestions to further improve conciseness and debuggability.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #12114 +/- ##
==========================================
- Coverage 77.77% 69.44% -8.34%
==========================================
Files 668 667 -1
Lines 91356 102812 +11456
==========================================
+ Hits 71056 71399 +343
- Misses 20300 31413 +11113
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This pull request refactors the ForwardToLeader functionality in the Border Agent code to simplify the handling of different URI types. The changes remove separate boolean flags (petition and separate) in favor of storing the URI directly, and consolidate response message handling.
Key changes:
- Replace boolean flags with direct URI storage in
ForwardContext - Simplify
SendErrorMessageto always send non-confirmable error responses - Remove conditional ACK logic since all forwarded messages now send ACKs
- Update response handling to check URI directly instead of using boolean flags
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/core/meshcop/border_agent.hpp | Updates ForwardContext structure and SendErrorMessage signature to use URI directly |
| src/core/meshcop/border_agent.cpp | Implements simplified forwarding logic, removes conditional ACK handling, and updates error message generation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This commit simplifies the CoAP message forwarding logic within the `CoapDtlsSession` by removing the `mPetition` and `mSeparate` boolean flags from the `ForwardContext`. The `Uri` of the request is now stored directly in `ForwardContext` and used to determine the logic flow, making the code more explicit and easier to understand. The `ForwardToLeader()` is only used with `kUriLeaderPetition` and `kUriLeaderKeepAlive`, both of which requires a separate non-confirmable response in addition to an immediate CoAP Ack (i.e., as if `mSeperate` is `true`). This change removes the need for intermediate flags and simplifies the implementation of `ForwardToLeader()`, `SendErrorMessage()`, and the `ForwardContext` constructor and `ToHeader()` method. The CoAP message initialization is now more direct, always using `kTypeNonConfirmable` for forwarded responses and error messages.
This commit simplifies the CoAP message forwarding logic within the
CoapDtlsSessionby removing themPetitionandmSeparateboolean flags from theForwardContext.The
Uriof the request is now stored directly inForwardContextand used to determine the logic flow, making the code more explicit and easier to understand.The
ForwardToLeader()is only used withkUriLeaderPetitionandkUriLeaderKeepAlive, both of which require a separate non-confirmable response in addition to an immediate CoAP Ack (i.e., as ifmSeparateistrue).This change removes the need for intermediate flags and simplifies the implementation of
ForwardToLeader(),SendErrorMessage(), and theForwardContextconstructor andToHeader()method. The CoAP message initialization is now more direct, always usingkTypeNonConfirmablefor forwarded responses and error messages.