[mle] simplify WillBecomeRouterSoon for clarity (#11768)

This commit renames `IsExpectedToBecomeRouterSoon()` to
`WillBecomeRouterSoon()` to better reflect its behavior.

The implementation is simplified by using the `VerifyOrExit` pattern
instead of a single complex boolean expression, which improves code
readability.
This commit is contained in:
Abtin Keshavarzian
2025-08-01 11:10:52 -07:00
committed by GitHub
parent 9cd5a2d93e
commit 0cf1ee09eb
4 changed files with 19 additions and 8 deletions
+2 -2
View File
@@ -320,7 +320,7 @@ void DuaManager::HandleNotifierEvents(Events aEvents)
// Wait for link establishment with neighboring routers.
UpdateRegistrationDelay(kNewRouterRegistrationDelay);
}
else if (mle.IsExpectedToBecomeRouterSoon())
else if (mle.WillBecomeRouterSoon())
{
// Will check again in case the device decides to stay REED when jitter timeout expires.
UpdateRegistrationDelay(mle.GetRouterRoleTransitionTimeout() + kNewRouterRegistrationDelay + 1);
@@ -434,7 +434,7 @@ void DuaManager::PerformNextRegistration(void)
// Only send DUA.req when necessary
#if OPENTHREAD_CONFIG_DUA_ENABLE
#if OPENTHREAD_FTD
if (!mle.IsRouterOrLeader() && mle.IsExpectedToBecomeRouterSoon())
if (!mle.IsRouterOrLeader() && mle.WillBecomeRouterSoon())
{
UpdateRegistrationDelay(mle.GetRouterRoleTransitionTimeout() + kNewRouterRegistrationDelay + 1);
ExitNow();
+1 -1
View File
@@ -990,7 +990,7 @@ public:
* @retval TRUE If the REED is going to become a Router soon.
* @retval FALSE If the REED is not going to become a Router soon.
*/
bool IsExpectedToBecomeRouterSoon(void) const;
bool WillBecomeRouterSoon(void) const;
/**
* Removes a link to a neighbor.
+15 -4
View File
@@ -3437,13 +3437,24 @@ exit:
return error;
}
bool Mle::IsExpectedToBecomeRouterSoon(void) const
bool Mle::WillBecomeRouterSoon(void) const
{
static constexpr uint8_t kMaxDelay = 10;
return IsRouterEligible() && IsChild() && !mAddressSolicitRejected &&
((mRouterRoleTransition.IsPending() && mRouterRoleTransition.GetTimeout() <= kMaxDelay) ||
mAddressSolicitPending);
bool willBecomeRouter = false;
VerifyOrExit(IsRouterEligible() && IsChild());
VerifyOrExit(!mAddressSolicitRejected);
if (!mAddressSolicitPending)
{
VerifyOrExit(mRouterRoleTransition.IsPending() && mRouterRoleTransition.GetTimeout() <= kMaxDelay);
}
willBecomeRouter = true;
exit:
return willBecomeRouter;
}
template <> void Mle::HandleTmf<kUriAddressSolicit>(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
+1 -1
View File
@@ -154,7 +154,7 @@ Error Notifier::UpdateInconsistentData(void)
// Don't send this Server Data Notification if the device is going
// to upgrade to Router.
if (Get<Mle::Mle>().IsExpectedToBecomeRouterSoon())
if (Get<Mle::Mle>().WillBecomeRouterSoon())
{
ExitNow(error = kErrorInvalidState);
}