]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink.c
Also send the blacklist notification when we already have a connection.
[meshlink] / src / meshlink.c
index 4f9c5f407ba93b6680faa8aef5c8c3d6c0a10ede..c34b24c9643f4bde69e2904877502e78c01f2b86 100644 (file)
@@ -2060,6 +2060,20 @@ void meshlink_set_error_cb(struct meshlink_handle *mesh, meshlink_error_cb_t cb)
        pthread_mutex_unlock(&mesh->mutex);
 }
 
+void meshlink_set_blacklisted_cb(struct meshlink_handle *mesh, meshlink_blacklisted_cb_t cb) {
+       if(!mesh) {
+               meshlink_errno = MESHLINK_EINVAL;
+               return;
+       }
+
+       if(pthread_mutex_lock(&mesh->mutex) != 0) {
+               abort();
+       }
+
+       mesh->blacklisted_cb = cb;
+       pthread_mutex_unlock(&mesh->mutex);
+}
+
 static bool prepare_packet(meshlink_handle_t *mesh, meshlink_node_t *destination, const void *data, size_t len, vpn_packet_t *packet) {
        meshlink_packethdr_t *hdr;
 
@@ -3442,6 +3456,10 @@ static bool blacklist(meshlink_handle_t *mesh, node_t *n) {
         */
        for list_each(connection_t, c, mesh->connections) {
                if(c->node == n) {
+                       if(c->status.active) {
+                               send_error(mesh, c, BLACKLISTED, "blacklisted");
+                       }
+
                        shutdown(c->socket, SHUT_RDWR);
                }
        }