]> git.meshlink.io Git - meshlink/commitdiff
Add devtool_set_meta_status_cb().
authorGuus Sliepen <guus@meshlink.io>
Wed, 22 Jul 2020 18:29:22 +0000 (20:29 +0200)
committerGuus Sliepen <guus@meshlink.io>
Wed, 22 Jul 2020 18:29:22 +0000 (20:29 +0200)
This function is similar to meshlink_set_node_status_cb(), except that
this callback will only be called when a meta-connection to a node is
activated or terminated. This is mainly useful for the test suite.

src/devtools.c
src/devtools.h
src/meshlink.sym
src/meshlink_internal.h
src/net.c
src/protocol_auth.c

index 22a0818b559b3e6f291a3e27e36531e4a305071e..2a98e595054850a78fecd489058acba6914db846 100644 (file)
@@ -367,3 +367,17 @@ void devtool_force_sptps_renewal(meshlink_handle_t *mesh, meshlink_node_t *node)
                c->last_key_renewal = -3600;
        }
 }
                c->last_key_renewal = -3600;
        }
 }
+
+void devtool_set_meta_status_cb(meshlink_handle_t *mesh, meshlink_node_status_cb_t cb) {
+       if(!mesh) {
+               meshlink_errno = MESHLINK_EINVAL;
+               return;
+       }
+
+       if(pthread_mutex_lock(&mesh->mutex) != 0) {
+               abort();
+       }
+
+       mesh->meta_status_cb = cb;
+       pthread_mutex_unlock(&mesh->mutex);
+}
index 44965c37078e38c11ff5604ba7c4b48b2b6887f5..786e290012e6f28c13f8e60940247413d263cf0b 100644 (file)
@@ -195,4 +195,18 @@ void devtool_force_sptps_renewal(meshlink_handle_t *mesh, meshlink_node_t *node)
  */
 extern void (*devtool_set_inviter_commits_first)(bool inviter_commited_first);
 
  */
 extern void (*devtool_set_inviter_commits_first)(bool inviter_commited_first);
 
+/// Set the meta-connection status callback.
+/** This functions sets the callback that is called whenever a meta-connection is made or closed.
+ *  The callback is run in MeshLink's own thread.
+ *  It is therefore important that the callback uses apprioriate methods (queues, pipes, locking, etc.)
+ *  to hand the data over to the application's thread.
+ *  The callback should also not block itself and return as quickly as possible.
+ *
+ *  \memberof meshlink_handle
+ *  @param mesh      A handle which represents an instance of MeshLink.
+ *  @param cb        A pointer to the function which will be called when a node's meta-connection status changes.
+ *                   If a NULL pointer is given, the callback will be disabled.
+ */
+void devtool_set_meta_status_cb(struct meshlink_handle *mesh, meshlink_node_status_cb_t cb);
+
 #endif
 #endif
index 6be514aec561467b23adbb7e2e923b3d02c4a15d..00f8fa381ec4c3728cc4ec7b86805a15821faec2 100644 (file)
@@ -5,6 +5,7 @@ devtool_get_all_submeshes
 devtool_get_node_status
 devtool_keyrotate_probe
 devtool_open_in_netns
 devtool_get_node_status
 devtool_keyrotate_probe
 devtool_open_in_netns
+devtool_set_meta_status_cb
 devtool_set_inviter_commits_first
 devtool_trybind_probe
 meshlink_add_address
 devtool_set_inviter_commits_first
 devtool_trybind_probe
 meshlink_add_address
index c75e6957bb0bf7181ab8ee46ac4da2f612d3074c..588c630ab423be68c2d3acf739f27a9d700b93f6 100644 (file)
@@ -135,6 +135,7 @@ struct meshlink_handle {
 
        // Infrequently used callbacks
        meshlink_node_status_cb_t node_status_cb;
 
        // Infrequently used callbacks
        meshlink_node_status_cb_t node_status_cb;
+       meshlink_node_status_cb_t meta_status_cb;
        meshlink_node_pmtu_cb_t node_pmtu_cb;
        meshlink_channel_accept_cb_t channel_accept_cb;
        meshlink_node_duplicate_cb_t node_duplicate_cb;
        meshlink_node_pmtu_cb_t node_pmtu_cb;
        meshlink_channel_accept_cb_t channel_accept_cb;
        meshlink_node_duplicate_cb_t node_duplicate_cb;
index 6fd90e194442e9e96298825fa28083bf6cb444be..9dc9598afc663ff8a08352e151bd816e2f8ad90c 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -54,12 +54,16 @@ static const int default_interval = 60;
 void terminate_connection(meshlink_handle_t *mesh, connection_t *c, bool report) {
        logger(mesh, MESHLINK_INFO, "Closing connection with %s", c->name);
 
 void terminate_connection(meshlink_handle_t *mesh, connection_t *c, bool report) {
        logger(mesh, MESHLINK_INFO, "Closing connection with %s", c->name);
 
-       c->status.active = false;
-
        if(c->node && c->node->connection == c) {
        if(c->node && c->node->connection == c) {
+               if(c->status.active && mesh->meta_status_cb) {
+                       mesh->meta_status_cb(mesh, (meshlink_node_t *)c->node, false);
+               }
+
                c->node->connection = NULL;
        }
 
                c->node->connection = NULL;
        }
 
+       c->status.active = false;
+
        if(c->edge) {
                if(report) {
                        send_del_edge(mesh, mesh->everyone, c->edge, 0);
        if(c->edge) {
                if(report) {
                        send_del_edge(mesh, mesh->everyone, c->edge, 0);
index 201cac9fe000eef05b17561fd4223ec31805e60b..2154faae09cce7cf9a305464561eaf2e9adb507f 100644 (file)
@@ -370,6 +370,10 @@ bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
 
        logger(mesh, MESHLINK_INFO, "Connection with %s activated", c->name);
 
 
        logger(mesh, MESHLINK_INFO, "Connection with %s activated", c->name);
 
+       if(mesh->meta_status_cb) {
+               mesh->meta_status_cb(mesh, (meshlink_node_t *)n, true);
+       }
+
        /* Send him everything we know */
 
        send_everything(mesh, c);
        /* Send him everything we know */
 
        send_everything(mesh, c);