]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink++.h
Add a callback that notifies the application when it is blacklisted.
[meshlink] / src / meshlink++.h
index c155086558ee4d77b25f95d2920b9133431a157a..551913d4ba2a94ceb4df51852dd8595ce563a28d 100644 (file)
@@ -274,6 +274,12 @@ public:
                (void)meshlink_errno;
        }
 
+       /// This functions is called whenever MeshLink is blacklisted by another node.
+       virtual void blacklisted(node *peer) {
+               /* do nothing */
+               (void)peer;
+       }
+
        /// This functions is called whenever MeshLink a meta-connection attempt is made.
        virtual void connection_try(node *peer) {
                /* do nothing */
@@ -374,6 +380,7 @@ public:
                meshlink_set_node_duplicate_cb(handle, &node_duplicate_trampoline);
                meshlink_set_log_cb(handle, MESHLINK_DEBUG, &log_trampoline);
                meshlink_set_error_cb(handle, &error_trampoline);
+               meshlink_set_blacklisted_cb(handle, &blacklisted_trampoline);
                meshlink_set_channel_listen_cb(handle, &channel_listen_trampoline);
                meshlink_set_channel_accept_cb(handle, &channel_accept_trampoline);
                meshlink_set_connection_try_cb(handle, &connection_try_trampoline);
@@ -479,6 +486,7 @@ public:
        /// Get a list of all nodes by blacklist status.
        /** This function returns a list with handles for all the nodes who were either blacklisted or whitelisted.
         *
+        *  @param blacklisted  If true, a list of blacklisted nodes will be returned, otherwise whitelisted nodes.
         *  @param nodes        A pointer to an array of pointers to meshlink::node, which should be allocated by the application.
         *  @param nmemb        The maximum number of pointers that can be stored in the nodes array.
         *
@@ -544,7 +552,6 @@ public:
        /// Clear the canonical Address for a node.
        /** This function clears the canonical Address for a node.
         *
-        *  @param mesh         A handle which represents an instance of MeshLink.
         *  @param node         A pointer to a struct meshlink_node describing the node.
         *
         *  @return             This function returns true if the address was removed, false otherwise.
@@ -1208,6 +1215,15 @@ private:
                that->error(meshlink_errno);
        }
 
+       static void blacklisted_trampoline(meshlink_handle_t *handle, meshlink_node_t *peer) {
+               if(!(handle->priv)) {
+                       return;
+               }
+
+               meshlink::mesh *that = static_cast<mesh *>(handle->priv);
+               that->blacklisted(static_cast<node *>(peer));
+       }
+
        static void connection_try_trampoline(meshlink_handle_t *handle, meshlink_node_t *peer) {
                if(!(handle->priv)) {
                        return;