From: Guus Sliepen Date: Mon, 23 Sep 2019 19:15:31 +0000 (+0200) Subject: Add missing parts of meshlink_set_node_pmtu_cb(). X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=23af52a05391e8083e7211358021bac94e5e0103;p=meshlink Add missing parts of meshlink_set_node_pmtu_cb(). --- diff --git a/src/meshlink++.h b/src/meshlink++.h index 5550a9e3..6b9c6855 100644 --- a/src/meshlink++.h +++ b/src/meshlink++.h @@ -57,6 +57,14 @@ typedef void (*connection_try_cb_t)(mesh *mesh, node *node); */ typedef void (*node_status_cb_t)(mesh *mesh, node *node, bool reachable); +/// A callback reporting node path MTU changes. +/** @param mesh A handle which represents an instance of MeshLink. + * @param node A pointer to a meshlink_node_t describing the node whose status changed. + * This pointer is valid until meshlink_close() is called. + * @param pmtu The current path MTU to the node, or 0 if UDP communication is not (yet) possible. + */ +typedef void (*node_pmtu_cb_t)(mesh *mesh, node *node, uint16_t pmtu); + /// A callback reporting duplicate node detection. /** @param mesh A handle which represents an instance of MeshLink. * @param node A pointer to a meshlink_node_t describing the node which is duplicate. @@ -231,6 +239,13 @@ public: (void)reachable; } + /// This functions is called whenever another node's path MTU changes. + virtual void node_pmtu(node *peer, uint16_t pmtu) { + /* do nothing */ + (void)peer; + (void)pmtu; + } + /// This functions is called whenever a duplicate node is detected. virtual void node_duplicate(node *peer) { /* do nothing */ @@ -321,6 +336,7 @@ public: bool start() { meshlink_set_receive_cb(handle, &receive_trampoline); meshlink_set_node_status_cb(handle, &node_status_trampoline); + meshlink_set_node_pmtu_cb(handle, &node_pmtu_trampoline); meshlink_set_node_duplicate_cb(handle, &node_duplicate_trampoline); meshlink_set_log_cb(handle, MESHLINK_DEBUG, &log_trampoline); meshlink_set_channel_accept_cb(handle, &channel_accept_trampoline); @@ -905,6 +921,15 @@ private: that->node_status(static_cast(peer), reachable); } + static void node_pmtu_trampoline(meshlink_handle_t *handle, meshlink_node_t *peer, uint16_t pmtu) { + if(!(handle->priv)) { + return; + } + + meshlink::mesh *that = static_cast(handle->priv); + that->node_pmtu(static_cast(peer), pmtu); + } + static void node_duplicate_trampoline(meshlink_handle_t *handle, meshlink_node_t *peer) { if(!(handle->priv)) { return; diff --git a/src/meshlink.c b/src/meshlink.c index d619f544..bb77ccf8 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1672,6 +1672,17 @@ void meshlink_set_node_status_cb(meshlink_handle_t *mesh, meshlink_node_status_c pthread_mutex_unlock(&(mesh->mesh_mutex)); } +void meshlink_set_node_pmtu_cb(meshlink_handle_t *mesh, meshlink_node_pmtu_cb_t cb) { + if(!mesh) { + meshlink_errno = MESHLINK_EINVAL; + return; + } + + pthread_mutex_lock(&(mesh->mesh_mutex)); + mesh->node_pmtu_cb = cb; + pthread_mutex_unlock(&(mesh->mesh_mutex)); +} + void meshlink_set_node_duplicate_cb(meshlink_handle_t *mesh, meshlink_node_duplicate_cb_t cb) { if(!mesh) { meshlink_errno = MESHLINK_EINVAL; diff --git a/src/meshlink.sym b/src/meshlink.sym index 784ff5c4..207da7c4 100644 --- a/src/meshlink.sym +++ b/src/meshlink.sym @@ -66,6 +66,7 @@ meshlink_set_dev_class_timeouts meshlink_set_invitation_timeout meshlink_set_log_cb meshlink_set_node_duplicate_cb +meshlink_set_node_pmtu_cb meshlink_set_node_status_cb meshlink_set_port meshlink_set_receive_cb