/*-------------------------------------------------------------------------*/ static void leader_deliver(char * value, size_t size, iid_t iid, ballot_t ballot, int proposer) { UNUSED_ARG(ballot); UNUSED_ARG(proposer); LOG(DBG, ("Instance %lu delivered to Leader\n", iid)); //Verify that the value is the one found or associated p_inst_info * ii = GET_PRO_INSTANCE(iid); //Instance not even initialized, skip if(ii->iid != iid) { return; } if(ii->status == p1_pending) { p1_info.pending_count -= 1; } if(p2_info.next_unused_iid == iid) { p2_info.next_unused_iid += 1; } int opened_by_me = (ii->status == p1_pending && ii->p2_value != NULL) || (ii->status == p1_ready && ii->p2_value != NULL) || (ii->status == p2_pending); if(opened_by_me) { p2_info.open_count -= 1; } int my_val = (ii->p2_value != NULL) && (ii->p2_value->value_size == size) && (memcmp(value, ii->p2_value->value, size) == 0); if(my_val) { //Our value accepted, notify client that submitted it vh_notify_client(0, ii->p2_value); } else if(ii->p2_value != NULL) { //Different value accepted, push back our value vh_push_back_value(ii->p2_value); ii->p2_value = NULL; } else { //We assigned no value to this instance, //it comes from somebody else?? } //Clear current instance pro_clear_instance_info(ii); //If enough instances are ready to // be opened, start phase2 for them leader_open_instances_p2_new(); }
void vh_shutdown() { //Delete event event_del(&leader_msg_event); //Close socket and free receiver udp_receiver_destroy(for_leader); //All values in pending could not be delivered yet. // Notify the respective clients vh_value_wrapper * vw; while ((vw = vh_get_next_pending()) != NULL) { vh_notify_client(-1, vw); PAX_FREE(vw); } }