node: save created time for node
[project/usteer.git] / remote.c
index d0d9e174d5264635a89ab23289edab2d6f27aace..282e39b3f290b3ea56abfda3ac81acaea53da24d 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -155,9 +155,11 @@ static void
 interface_add_station(struct usteer_remote_node *node, struct blob_attr *data)
 {
        struct sta *sta;
-       struct sta_info *si;
+       struct sta_info *si, *local_si;
        struct apmsg_sta msg;
+       struct usteer_node *local_node;
        bool create;
+       bool connect_change;
 
        if (!parse_apmsg_sta(&msg, data)) {
                MSG(DEBUG, "Cannot parse station in message\n");
@@ -177,10 +179,26 @@ interface_add_station(struct usteer_remote_node *node, struct blob_attr *data)
        if (!si)
                return;
 
+       connect_change = si->connected != msg.connected;
        si->connected = msg.connected;
        si->signal = msg.signal;
        si->seen = current_time - msg.seen;
        si->last_connected = current_time - msg.last_connected;
+
+       /* Check if client roamed to this foreign node */
+       if ((connect_change || create) && si->connected == STA_CONNECTED) {
+               for_each_local_node(local_node) {
+                       local_si = usteer_sta_info_get(sta, local_node, NULL);
+                       if (!local_si)
+                               continue;
+
+                       if (current_time - local_si->last_connected < config.roam_process_timeout) {
+                               node->node.roam_destination++;
+                               break;
+                       }
+               }
+       }
+
        usteer_sta_info_update_timeout(si, msg.timeout);
 }
 
@@ -239,6 +257,7 @@ interface_get_node(struct usteer_remote_host *host, const char *name)
 
        node = calloc_a(sizeof(*node), &buf, addr_len + 1 + strlen(name) + 1);
        node->node.type = NODE_TYPE_REMOTE;
+       node->node.created = current_time;
 
        sprintf(buf, "%s#%s", host->addr, name);
        node->node.avl.key = buf;