[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.
This commit is contained in:
Abtin Keshavarzian
2025-11-07 14:22:27 -08:00
committed by GitHub
parent 74ba475914
commit 75c5d220de
2 changed files with 7 additions and 18 deletions
+3 -8
View File
@@ -1106,7 +1106,9 @@ void Manager::CoapDtlsSession::HandleLeaderResponseToFwdTmf(const ForwardContext
}
}
SuccessOrExit(error = aForwardContext.ToHeader(*forwardMessage, aResponse->GetCode()));
forwardMessage->Init(Coap::kTypeNonConfirmable, static_cast<Coap::Code>(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<Coap::Code>(aCode));
return aMessage.SetToken(mToken, mTokenLength);
}
} // namespace BorderAgent
} // namespace MeshCoP
} // namespace ot
+4 -10
View File
@@ -262,23 +262,17 @@ private:
uint64_t GetAllocationTime(void) const { return mAllocationTime; }
private:
class ForwardContext : public ot::LinkedListEntry<ForwardContext>,
public Heap::Allocatable<ForwardContext>,
private ot::NonCopyable
struct ForwardContext : public ot::LinkedListEntry<ForwardContext>,
public Heap::Allocatable<ForwardContext>,
private ot::NonCopyable
{
friend class Heap::Allocatable<ForwardContext>;
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);