[tmf] introduce specialized SendMessageTo() methods in Tmf::Agent (#12548)

This commit introduces new helper methods in the `Tmf::Agent` class
(`SendMessageTo()`, `SendMessageToRloc()`, `SendMessageToLeaderAloc()`,
and `SendMessageAllowMulticastLoop()`) to simplify the transmission of
TMF messages.

Previously, callers of `Tmf::Agent::SendMessage()` were required to
manually configure a `Tmf::MessageInfo` object with the appropriate
socket and peer address information before sending a message. This led
to repetitive code across the various modules utilizing TMF.

By incorporating these address resolution and message info preparation
steps directly into `Tmf::Agent`, this change significantly reduces
boilerplate code. All existing calls to `SendMessage()` have been
updated to use the new flavors.
This commit is contained in:
Abtin Keshavarzian
2026-02-26 15:26:45 -06:00
committed by GitHub
parent 3ea2dbe146
commit f03cecdff6
36 changed files with 336 additions and 437 deletions
+12 -12
View File
@@ -3258,9 +3258,9 @@ void Mle::SetRouterId(uint8_t aRouterId)
Error Mle::SendAddressSolicit(RouterUpgradeReason aReason)
{
Error error = kErrorNone;
Tmf::MessageInfo messageInfo(GetInstance());
Coap::Message *message = nullptr;
Error error = kErrorNone;
Coap::Message *message = nullptr;
Ip6::Address leaderRloc;
VerifyOrExit(!mAddressSolicitPending);
@@ -3280,12 +3280,12 @@ Error Mle::SendAddressSolicit(RouterUpgradeReason aReason)
SuccessOrExit(error = Tlv::Append<XtalAccuracyTlv>(*message, otPlatTimeGetXtalAccuracy()));
#endif
messageInfo.SetSockAddrToRlocPeerAddrToLeaderRloc();
GetLeaderRloc(leaderRloc);
SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, messageInfo, HandleAddressSolicitResponse, this));
SuccessOrExit(error = Get<Tmf::Agent>().SendMessageTo(*message, leaderRloc, HandleAddressSolicitResponse, this));
mAddressSolicitPending = true;
Log(kMessageSend, kTypeAddressSolicit, messageInfo.GetPeerAddr());
Log(kMessageSend, kTypeAddressSolicit, leaderRloc);
exit:
FreeMessageOnError(message, error);
@@ -3294,9 +3294,9 @@ exit:
void Mle::SendAddressRelease(void)
{
Error error = kErrorNone;
Tmf::MessageInfo messageInfo(GetInstance());
Coap::Message *message;
Error error = kErrorNone;
Coap::Message *message;
Ip6::Address leaderRloc;
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(kUriAddressRelease);
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
@@ -3304,11 +3304,11 @@ void Mle::SendAddressRelease(void)
SuccessOrExit(error = Tlv::Append<ThreadRloc16Tlv>(*message, Rloc16FromRouterId(mRouterId)));
SuccessOrExit(error = Tlv::Append<ThreadExtMacAddressTlv>(*message, Get<Mac::Mac>().GetExtAddress()));
messageInfo.SetSockAddrToRlocPeerAddrToLeaderRloc();
GetLeaderRloc(leaderRloc);
SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, messageInfo));
SuccessOrExit(error = Get<Tmf::Agent>().SendMessageTo(*message, leaderRloc));
Log(kMessageSend, kTypeAddressRelease, messageInfo.GetPeerAddr());
Log(kMessageSend, kTypeAddressRelease, leaderRloc);
exit:
FreeMessageOnError(message, error);