Add flap dampening to parent selection

Track parent switch frequency in a sliding window. When switches exceed
a configurable threshold (default 4 in 60s), impose an extended hold-down
period (default 120s) that prevents non-mandatory parent changes.

Mandatory switches (parent loss, root change, shouldn't-be-root) bypass
dampening. The flap counter resets when the window expires naturally.

Implements TASK-2026-0030 / IDEA-0013.
This commit is contained in:
Johnathan Corgan
2026-02-23 20:00:58 +00:00
parent 5d72e7cee1
commit 94c0e19951
5 changed files with 340 additions and 4 deletions
+10
View File
@@ -374,6 +374,11 @@ impl Node {
let mut tree_state = TreeState::new(node_addr);
tree_state.set_parent_hysteresis(config.node.tree.parent_hysteresis);
tree_state.set_hold_down(config.node.tree.hold_down_secs);
tree_state.set_flap_dampening(
config.node.tree.flap_threshold,
config.node.tree.flap_window_secs,
config.node.tree.flap_dampening_secs,
);
tree_state
.sign_declaration(&identity)
.expect("signing own declaration should never fail");
@@ -459,6 +464,11 @@ impl Node {
let mut tree_state = TreeState::new(node_addr);
tree_state.set_parent_hysteresis(config.node.tree.parent_hysteresis);
tree_state.set_hold_down(config.node.tree.hold_down_secs);
tree_state.set_flap_dampening(
config.node.tree.flap_threshold,
config.node.tree.flap_window_secs,
config.node.tree.flap_dampening_secs,
);
tree_state
.sign_declaration(&identity)
.expect("signing own declaration should never fail");