Browse code

dmq: skip removing local node via rpc command

Daniel-Constantin Mierla authored on 22/04/2021 06:36:11
Showing 1 changed files
... ...
@@ -328,9 +328,12 @@ void pkg_free_node(dmq_node_t *node)
328 328
 }
329 329
 
330 330
 /**
331
- * @brief delete dmq node
331
+ * @brief delete dmq node with filter rules
332
+ * - list - the list of nodes
333
+ * - node - the structure with characteristics of the node to be deleted
334
+ * - filter - if 0: delete node always; if 1: delete node if not local
332 335
  */
333
-int del_dmq_node(dmq_node_list_t *list, dmq_node_t *node)
336
+int dmq_node_del_filter(dmq_node_list_t *list, dmq_node_t *node, int filter)
334 337
 {
335 338
 	dmq_node_t *cur, **prev;
336 339
 	lock_get(&list->lock);
... ...
@@ -338,8 +341,10 @@ int del_dmq_node(dmq_node_list_t *list, dmq_node_t *node)
338 341
 	prev = &list->nodes;
339 342
 	while(cur) {
340 343
 		if(cmp_dmq_node(cur, node)) {
341
-			*prev = cur->next;
342
-			destroy_dmq_node(cur, 1);
344
+			if(filter==0 || cur->local==0) {
345
+				*prev = cur->next;
346
+				destroy_dmq_node(cur, 1);
347
+			}
343 348
 			lock_release(&list->lock);
344 349
 			return 1;
345 350
 		}
... ...
@@ -350,6 +355,14 @@ int del_dmq_node(dmq_node_list_t *list, dmq_node_t *node)
350 355
 	return 0;
351 356
 }
352 357
 
358
+/**
359
+ * @brief delete dmq node
360
+ */
361
+int del_dmq_node(dmq_node_list_t *list, dmq_node_t *node)
362
+{
363
+	return  dmq_node_del_filter(list, node, 0);
364
+}
365
+
353 366
 /**
354 367
  * @brief delete dmq node by uri
355 368
  */
... ...
@@ -363,7 +376,7 @@ int dmq_node_del_by_uri(dmq_node_list_t *list, str *suri)
363 376
 		return -1;
364 377
 	}
365 378
 
366
-	return del_dmq_node(list, &dnode);
379
+	return dmq_node_del_filter(list, &dnode, 1);
367 380
 }
368 381
 
369 382
 /**