mirror of
https://github.com/espressif/openthread.git
synced 2026-10-11 18:27:43 +00:00
[nexus] simplify node lookup using LinkedList matching methods (#12849)
This commit updates the address-based node lookup methods in `Core` to use the `FindMatching()` and `ContainsMatching()` methods provided by the `LinkedList` class. This replaces manual `for` loops with cleaner, built-in list operations. To facilitate this, a new `AddressNetif` enum and a `Matches()` method are added to the `Node` class. The `Matches()` method accepts an `Ip6::Address` and an `AddressNetif` indicator, allowing it to check if the node has the specified address on its Thread interface, its Infrastructure interface, or any. Additionally, a `const` overload for the `Get()` template method is added to the `Node` class to ensure proper const-correctness.
This commit is contained in:
@@ -229,5 +229,27 @@ const Ip6::Address &Node::FindGlobalAddress(void)
|
||||
return *matchedAddress;
|
||||
}
|
||||
|
||||
bool Node::Matches(const Ip6::Address &aAddress, AddressNetif aNetif) const
|
||||
{
|
||||
bool matches = false;
|
||||
|
||||
switch (aNetif)
|
||||
{
|
||||
case kThreadNetifAddress:
|
||||
matches = Get<ThreadNetif>().HasUnicastAddress(aAddress);
|
||||
break;
|
||||
|
||||
case kInfraNetifAddress:
|
||||
matches = mInfraIf.HasAddress(aAddress);
|
||||
break;
|
||||
|
||||
case kAnyNetifAddress:
|
||||
matches = Get<ThreadNetif>().HasUnicastAddress(aAddress) || mInfraIf.HasAddress(aAddress);
|
||||
break;
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
} // namespace Nexus
|
||||
} // namespace ot
|
||||
|
||||
Reference in New Issue
Block a user