]> git.meshlink.io Git - meshlink/blobdiff - src/graph.c
Add meshlink_get_all_nodes_by_last_reachable().
[meshlink] / src / graph.c
index 9955ea41644721a208041de60860329158998e04..5afa7c32526509a31b610e8153d26c4c41a87829 100644 (file)
@@ -144,16 +144,35 @@ static void check_reachability(meshlink_handle_t *mesh) {
                        if(n->utcp) {
                                utcp_abort_all_connections(n->utcp);
                        }
+
+                       if(n->status.visited == n->status.reachable) {
+                               /* This session replaces the previous one without changing reachability status.
+                                * We still need to reset the UDP SPTPS state.
+                                */
+                               n->status.validkey = false;
+                               sptps_stop(&n->sptps);
+                               n->status.waitingforkey = false;
+                               n->last_req_key = 0;
+
+                               n->status.udp_confirmed = false;
+                               n->maxmtu = MTU;
+                               n->minmtu = 0;
+                               n->mtuprobes = 0;
+
+                               timeout_del(&mesh->loop, &n->mtutimeout);
+                       }
                }
 
                if(n->status.visited != n->status.reachable) {
                        n->status.reachable = !n->status.reachable;
-                       n->last_state_change = mesh->loop.now.tv_sec;
+                       n->status.dirty = true;
 
                        if(n->status.reachable) {
                                logger(mesh, MESHLINK_DEBUG, "Node %s became reachable", n->name);
+                               n->last_reachable = mesh->loop.now.tv_sec;
                        } else {
                                logger(mesh, MESHLINK_DEBUG, "Node %s became unreachable", n->name);
+                               n->last_unreachable = mesh->loop.now.tv_sec;
                        }
 
                        /* TODO: only clear status.validkey if node is unreachable? */