return (node *)meshlink_get_node(handle, name);
}
+ /// Get a node's reachability status.
+ /** This function returns the current reachability of a given node, and the times of the last state changes.
+ * If a given state change never happened, the time returned will be 0.
+ *
+ * @param node A pointer to a meshlink::node describing the node.
+ * @param last_reachable A pointer to a time_t variable that will be filled in with the last time the node became reachable.
+ * @param last_unreachable A pointer to a time_t variable that will be filled in with the last time the node became unreachable.
+ *
+ * @return This function returns true if the node is currently reachable, false otherwise.
+ */
+ bool get_node_reachability(node *node, time_t *last_reachable = NULL, time_t *last_unreachable = NULL) {
+ return meshlink_get_node_reachability(handle, node, last_reachable, last_unreachable);
+ }
+
/// Get a handle for a specific submesh.
/** This function returns a handle for the submesh with the given name.
*
return s;
}
+bool meshlink_get_node_reachability(struct meshlink_handle *mesh, struct meshlink_node *node, time_t *last_reachable, time_t *last_unreachable) {
+ if(!mesh || !node) {
+ meshlink_errno = MESHLINK_EINVAL;
+ return NULL;
+ }
+
+ node_t *n = (node_t *)node;
+ bool reachable;
+
+ pthread_mutex_lock(&mesh->mutex);
+ reachable = n->status.reachable;
+
+ if(last_reachable) {
+ *last_reachable = n->last_reachable;
+ }
+
+ if(last_unreachable) {
+ *last_unreachable = n->last_unreachable;
+ }
+
+ pthread_mutex_unlock(&mesh->mutex);
+
+ return reachable;
+}
+
bool meshlink_sign(meshlink_handle_t *mesh, const void *data, size_t len, void *signature, size_t *siglen) {
if(!mesh || !data || !len || !signature || !siglen) {
meshlink_errno = MESHLINK_EINVAL;
*/
extern struct meshlink_submesh *meshlink_get_node_submesh(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__));
+/// Get a node's reachability status.
+/** This function returns the current reachability of a given node, and the times of the last state changes.
+ * If a given state change never happened, the time returned will be 0.
+ *
+ * \memberof meshlink_node
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param node A pointer to a struct meshlink_node describing the node.
+ * @param last_reachable A pointer to a time_t variable that will be filled in with the last time the node became reachable.
+ * Pass NULL to not have anything written.
+ * @param last_unreachable A pointer to a time_t variable that will be filled in with the last time the node became unreachable.
+ * Pass NULL to not have anything written.
+ *
+ * @return This function returns true if the node is currently reachable, false otherwise.
+ */
+extern bool meshlink_get_node_reachability(struct meshlink_handle *mesh, struct meshlink_node *node, time_t *last_reachable, time_t *last_unreachable);
+
/// Verify the signature generated by another node of a piece of data.
/** This function verifies the signature that another node generated for a piece of data.
*
meshlink_get_local_address_for_family
meshlink_get_node
meshlink_get_node_dev_class
+meshlink_get_node_reachability
meshlink_get_node_submesh
meshlink_get_pmtu
meshlink_get_port
assert(self);
assert(!strcmp(self->name, "foo"));
+ // Check that we are reachable.
+
+ assert(meshlink_get_node_reachability(mesh, self, NULL, NULL));
+
// Start and stop the mesh.
assert(meshlink_start(mesh));
meshlink_stop(mesh);
+ // Check that we are still reachable.
+
+ assert(meshlink_get_node_reachability(mesh, self, NULL, NULL));
+
// Make sure we can start and stop the mesh again.
assert(meshlink_start(mesh));
assert(meshlink_import(mesh1, data));
free(data);
+ // Check that foo knows bar, but that it is not reachable.
+
+ time_t last_reachable;
+ time_t last_unreachable;
+ meshlink_node_t *bar = meshlink_get_node(mesh1, "bar");
+ assert(bar);
+ assert(!meshlink_get_node_reachability(mesh1, bar, &last_reachable, &last_unreachable));
+ assert(!last_reachable);
+ assert(!last_unreachable);
+
// Start both instances
meshlink_set_node_status_cb(mesh1, status_cb);
assert(pmtu);
+ // Check that we now have reachability information
+
+ assert(meshlink_get_node_reachability(mesh1, bar, &last_reachable, &last_unreachable));
+ assert(last_reachable);
+ assert(!last_unreachable);
+
+ // Stop the meshes.
+
+ meshlink_stop(mesh1);
+ meshlink_stop(mesh2);
+
+ // Check that bar is no longer reachable
+
+ assert(!meshlink_get_node_reachability(mesh1, bar, &last_reachable, &last_unreachable));
+ assert(last_reachable);
+ assert(last_unreachable);
+ assert(last_reachable <= last_unreachable);
+
// Clean up.
meshlink_close(mesh2);