mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +00:00
221a9cbbb0
This commit introduces a new member variable `mRouterRoleAllowed` in the `Mle` class to cache the evaluation of whether the device is currently permitted to operate as a router. Previously, the `IsRouterEligible()` method evaluated several conditions (e.g., `IsFullThreadDevice()`, `mRouterEligible` config, and various fields in `SecurityPolicy`) every time it was called. Since this method is invoked frequently across different `Mle` operations, re-evaluating these conditions repeatedly was inefficient. The new `mRouterRoleAllowed` variable caches the final computed result. It is updated via the `UpdateRouterRoleAllowed()` method whenever any underlying input changes, such as: - `Mle` starting. - Configuration parameter updates (e.g., `SetRouterEligible()`). - Security policy changes from the `KeyManager`. This change centralizes the logic for handling role permission updates into a single location (`UpdateRouterRoleAllowed()`). By consolidating the actions taken when the allowed state changes, the codebase is cleaner and easier to maintain and update. It also provides a clearer conceptual distinction between the user's router configuration (`mRouterEligible`) and the effective state used by the device.