From 75c5d220dece649e712f3aa4e1daae3d9e3e389e Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 7 Nov 2025 14:22:27 -0800 Subject: [PATCH] [border-agent] inline `ForwardContext::ToHeader()` (#12118) Remove the `CoapDtlsSession::ForwardContext::ToHeader()` helper method and move its logic directly into the `HandleCoapResponse()` method. This simplifies the implementation by removing an unnecessary function call for a single-use case. Additionally, convert `ForwardContext` from a `class` to a `struct`. This change makes the constructor public, removing the need for a `friend` declaration for `Heap::Allocatable`, and better reflects its role as a simple data structure. --- src/core/meshcop/border_agent.cpp | 11 +++-------- src/core/meshcop/border_agent.hpp | 14 ++++---------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/core/meshcop/border_agent.cpp b/src/core/meshcop/border_agent.cpp index b2a1c4509..7fabc27ec 100644 --- a/src/core/meshcop/border_agent.cpp +++ b/src/core/meshcop/border_agent.cpp @@ -1106,7 +1106,9 @@ void Manager::CoapDtlsSession::HandleLeaderResponseToFwdTmf(const ForwardContext } } - SuccessOrExit(error = aForwardContext.ToHeader(*forwardMessage, aResponse->GetCode())); + forwardMessage->Init(Coap::kTypeNonConfirmable, static_cast(aResponse->GetCode())); + + SuccessOrExit(error = forwardMessage->SetToken(aForwardContext.mToken, aForwardContext.mTokenLength)); if (aResponse->GetLength() > aResponse->GetOffset()) { @@ -1357,13 +1359,6 @@ Manager::CoapDtlsSession::ForwardContext::ForwardContext(CoapDtlsSession &aS memcpy(mToken, aMessage.GetToken(), mTokenLength); } -Error Manager::CoapDtlsSession::ForwardContext::ToHeader(Coap::Message &aMessage, uint8_t aCode) const -{ - aMessage.Init(Coap::kTypeNonConfirmable, static_cast(aCode)); - - return aMessage.SetToken(mToken, mTokenLength); -} - } // namespace BorderAgent } // namespace MeshCoP } // namespace ot diff --git a/src/core/meshcop/border_agent.hpp b/src/core/meshcop/border_agent.hpp index 4f03e4bf5..3593be66b 100644 --- a/src/core/meshcop/border_agent.hpp +++ b/src/core/meshcop/border_agent.hpp @@ -262,23 +262,17 @@ private: uint64_t GetAllocationTime(void) const { return mAllocationTime; } private: - class ForwardContext : public ot::LinkedListEntry, - public Heap::Allocatable, - private ot::NonCopyable + struct ForwardContext : public ot::LinkedListEntry, + public Heap::Allocatable, + private ot::NonCopyable { - friend class Heap::Allocatable; - - public: - Error ToHeader(Coap::Message &aMessage, uint8_t aCode) const; + ForwardContext(CoapDtlsSession &aSession, const Coap::Message &aMessage, Uri aUri); CoapDtlsSession &mSession; ForwardContext *mNext; Uri mUri; uint8_t mTokenLength; uint8_t mToken[Coap::Message::kMaxTokenLength]; - - private: - ForwardContext(CoapDtlsSession &aSession, const Coap::Message &aMessage, Uri aUri); }; CoapDtlsSession(Instance &aInstance, Dtls::Transport &aDtlsTransport);