]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink.c
Add meshlink_hint_network_change().
[meshlink] / src / meshlink.c
index 1b65e40c3efc6c59d6e1bb2e6347096c6e7b1741..f6b12bd89d0e26e87e796290b3e9305263db573c 100644 (file)
@@ -1,6 +1,6 @@
 /*
     meshlink.c -- Implementation of the MeshLink API.
-    Copyright (C) 2014-2018 Guus Sliepen <guus@meshlink.io>
+    Copyright (C) 2014-2021 Guus Sliepen <guus@meshlink.io>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -4570,6 +4570,28 @@ end:
        pthread_mutex_unlock(&mesh->mutex);
 }
 
+void meshlink_hint_network_change(struct meshlink_handle *mesh) {
+       if(!mesh) {
+               meshlink_errno = MESHLINK_EINVAL;
+               return;
+       }
+
+       if(pthread_mutex_lock(&mesh->mutex) != 0) {
+               abort();
+       }
+
+       if(mesh->discovery.enabled) {
+               scan_ifaddrs(mesh);
+       }
+
+       if(mesh->loop.now.tv_sec > mesh->discovery.last_update + 5) {
+               mesh->discovery.last_update = mesh->loop.now.tv_sec;
+               handle_network_change(mesh, 1);
+       }
+
+       pthread_mutex_unlock(&mesh->mutex);
+}
+
 void meshlink_set_dev_class_timeouts(meshlink_handle_t *mesh, dev_class_t devclass, int pinginterval, int pingtimeout) {
        if(!mesh || devclass < 0 || devclass >= DEV_CLASS_COUNT) {
                meshlink_errno = EINVAL;