| 562 | } |
| 563 | |
| 564 | void handle_sync_packet(bin_packet_t *packet, int packet_type, |
| 565 | cluster_info_t *cluster, int source_id) |
| 566 | { |
| 567 | str cap_name; |
| 568 | struct local_cap *cap; |
| 569 | int data_version; |
| 570 | int no_sync_chunks; |
| 571 | int was_in_progress = 0; |
| 572 | |
| 573 | if (get_bin_pkg_version(packet) != BIN_SYNC_VERSION) { |
| 574 | LM_INFO("discarding sync packet version %d, need version %d\n", |
| 575 | get_bin_pkg_version(packet), BIN_SYNC_VERSION); |
| 576 | return; |
| 577 | } |
| 578 | |
| 579 | bin_pop_str(packet, &cap_name); |
| 580 | for (cap = cluster->capabilities; cap; cap = cap->next) |
| 581 | if (!str_strcmp(&cap_name, &cap->reg.name)) |
| 582 | break; |
| 583 | if (!cap) { |
| 584 | LM_ERR("Capability: %.*s from sync packet, not found\n", |
| 585 | cap_name.len, cap_name.s); |
| 586 | return; |
| 587 | } |
| 588 | |
| 589 | if (get_capability_status(cluster, &cap_name) != 1) { |
| 590 | LM_DBG("capability disabled, drop sync packet\n"); |
| 591 | return; |
| 592 | } |
| 593 | |
| 594 | if (packet_type == CLUSTERER_SYNC) { |
| 595 | bin_pop_int(packet, &data_version); |
| 596 | |
| 597 | lock_get(cluster->lock); |
| 598 | |
| 599 | /* if the cap's state is already OK (e.g. donor aborted sync mid-way, |
| 600 | * then sync_check_timer() timed out the sync back to CAP_STATE_OK), |
| 601 | * avoid forcing a state where repl packets queue indefinitely! */ |
| 602 | if (!(cap->flags & CAP_STATE_OK)) { |
| 603 | if (cap->flags & CAP_SYNC_IN_PROGRESS) |
| 604 | was_in_progress = 1; |
| 605 | |
| 606 | /* buffer other types of packets during sync */ |
| 607 | cap->flags |= CAP_SYNC_IN_PROGRESS; |
| 608 | } |
| 609 | |
| 610 | cap->last_sync_pkt = get_ticks(); |
| 611 | lock_release(cluster->lock); |
| 612 | |
| 613 | if (!was_in_progress) { |
| 614 | sr_set_status(cl_srg, STR2CI(cap->reg.sr_id), CAP_SR_SYNCING, |
| 615 | STR2CI(CAP_SR_STATUS_STR(CAP_SR_SYNCING)), 0); |
| 616 | sr_add_report_fmt(cl_srg, STR2CI(cap->reg.sr_id), 0, |
| 617 | "Sync started from node [%d]", source_id); |
| 618 | } |
| 619 | |
| 620 | /* overwrite packet type with one identifiable by modules */ |
| 621 | packet->type = SYNC_PACKET_TYPE; |
no test coverage detected