node: determine roamability when selecting neighbors
authorDavid Bauer <mail@david-bauer.net>
Wed, 29 Sep 2021 17:17:11 +0000 (19:17 +0200)
committerDavid Bauer <mail@david-bauer.net>
Thu, 25 Nov 2021 21:28:57 +0000 (22:28 +0100)
Currently, the neighbor report list is sorted based on the total amount
of roam actions to and from the specific foreign nodes.

This does not take into account that nodes might not be created at the
same time. When a popular neighbor node reboots, it's roam actions are
reset and it's ranking might not recover for a long amount of time
depending on how long the local node is already running.

Change this shotcoming to take into account the timestamp at which a
node was created. This way, the ranking depends on the amount of roam
actions relative to the nodes uptime / seen-time.

Signed-off-by: David Bauer <mail@david-bauer.net>
node.c

diff --git a/node.c b/node.c
index 00ffb99fc78931a731540b8b780748a20514d55c..8e0b30d436100bb6eefda0e43ee092ad55a12b48 100644 (file)
--- a/node.c
+++ b/node.c
@@ -56,13 +56,14 @@ usteer_node_higher_bssid(struct usteer_node *node1, struct usteer_node *node2)
 }
 
 static struct usteer_node *
-usteer_node_more_roam_interactions(struct usteer_node *node, struct usteer_node *ref)
+usteer_node_higher_roamability(struct usteer_node *node, struct usteer_node *ref)
 {
-       int roam_actions_node, roam_actions_ref;
+       uint64_t roamability_node, roamability_ref;
 
-       roam_actions_node = node->roam_source + node->roam_destination;
-       roam_actions_ref = ref->roam_source + ref->roam_destination;
-       if (roam_actions_node < roam_actions_ref)
+       roamability_node = ((uint64_t)(node->roam_source + node->roam_destination)) * current_time / ((current_time - node->created) + 1);
+       roamability_ref = ((uint64_t)(ref->roam_source + ref->roam_destination)) * current_time / ((current_time - ref->created) + 1);
+
+       if (roamability_node < roamability_ref)
                return ref;
 
        return node;
@@ -86,8 +87,8 @@ usteer_node_better_neighbor(struct usteer_node *node, struct usteer_node *ref)
        if (!node)
                return ref;
 
-       n1 = usteer_node_more_roam_interactions(node, ref);
-       n2 = usteer_node_more_roam_interactions(ref, node);
+       n1 = usteer_node_higher_roamability(node, ref);
+       n2 = usteer_node_higher_roamability(ref, node);
        if (n1 == n2)
                return n1;