| 359 | } |
| 360 | |
| 361 | enum clusterer_send_ret clusterer_send_msg(bin_packet_t *packet, |
| 362 | int cluster_id, int dst_node_id, int check_cap, int locked) |
| 363 | { |
| 364 | node_info_t *node; |
| 365 | int rc; |
| 366 | cluster_info_t *cl; |
| 367 | int ev_actions_required = 0; |
| 368 | str capability; |
| 369 | |
| 370 | if (!cl_list_lock) { |
| 371 | LM_ERR("cluster shutdown - cannot send new messages!\n"); |
| 372 | return CLUSTERER_CURR_DISABLED; |
| 373 | } |
| 374 | if (!locked) |
| 375 | lock_start_read(cl_list_lock); |
| 376 | |
| 377 | cl = get_cluster_by_id(cluster_id); |
| 378 | if (!cl) { |
| 379 | LM_ERR("Unknown cluster id [%d]\n", cluster_id); |
| 380 | if (!locked) |
| 381 | lock_stop_read(cl_list_lock); |
| 382 | return CLUSTERER_SEND_ERR; |
| 383 | } |
| 384 | |
| 385 | lock_get(cl->current_node->lock); |
| 386 | if (!(cl->current_node->flags & NODE_STATE_ENABLED)) { |
| 387 | lock_release(cl->current_node->lock); |
| 388 | if (!locked) |
| 389 | lock_stop_read(cl_list_lock); |
| 390 | return CLUSTERER_CURR_DISABLED; |
| 391 | } |
| 392 | lock_release(cl->current_node->lock); |
| 393 | |
| 394 | if (dst_node_id == cl->current_node->node_id) { |
| 395 | node = cl->current_node; |
| 396 | } else { |
| 397 | node = get_node_by_id(cl, dst_node_id); |
| 398 | if (!node) { |
| 399 | LM_ERR("Node id [%d] not found in cluster\n", dst_node_id); |
| 400 | if (!locked) |
| 401 | lock_stop_read(cl_list_lock); |
| 402 | return CLUSTERER_SEND_ERR; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | lock_get(node->lock); |
| 407 | if (!(node->flags & NODE_STATE_ENABLED)) { |
| 408 | lock_release(node->lock); |
| 409 | lock_stop_read(cl_list_lock); |
| 410 | LM_DBG("node disabled, skip message sending\n"); |
| 411 | return CLUSTERER_SEND_SUCCESS; |
| 412 | } |
| 413 | lock_release(node->lock); |
| 414 | |
| 415 | if (check_cap) { |
| 416 | bin_get_capability(packet, &capability); |
| 417 | rc = get_capability_status(cl, &capability); |
| 418 | if (rc == -1) { |
no test coverage detected