]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink.c
fix for autoconnect (prevent ping pong)
[meshlink] / src / meshlink.c
index cbe88a3ed256e06f25a72663fc60991ff4189af3..994d8957ae696fe487035345a95f9e8e83cb18d1 100644 (file)
@@ -701,16 +701,15 @@ static bool ecdsa_keygen(meshlink_handle_t *mesh) {
 
 static struct timeval idle(event_loop_t *loop, void *data) {
        meshlink_handle_t *mesh = data;
-       int t, tmin = -1;
+       struct timeval t, tmin = {3600, 0};
        for splay_each(node_t, n, mesh->nodes) {
                if(!n->utcp)
                        continue;
                t = utcp_timeout(n->utcp);
-               if(t >= 0 && t < tmin)
+               if(timercmp(&t, &tmin, <))
                        tmin = t;
        }
-       struct timeval tv = {.tv_sec = t};
-       return tv;
+       return tmin;
 }
 
 static bool meshlink_setup(meshlink_handle_t *mesh) {
@@ -957,6 +956,9 @@ void meshlink_close(meshlink_handle_t *mesh) {
                return;
        }
 
+       // stop can be called even if mesh has not been started
+       meshlink_stop(mesh);
+
        // lock is not released after this
        pthread_mutex_lock(&(mesh->mesh_mutex));