Ejemplo n.º 1
0
static void 
vh_handle_newmsg(int sock, short event, void *arg) {
    //Make the compiler happy!
    UNUSED_ARG(sock);
    UNUSED_ARG(event);
    UNUSED_ARG(arg);
    
    assert(sock == for_leader->sock);
    
    //Read the next message
    int valid = udp_read_next_message(for_leader);
    if (valid < 0) {
        printf("Dropping invalid client-to-leader message\n");
        return;
    }

    //The message is valid, take the appropriate action
    // based on the type
    paxos_msg * msg = (paxos_msg*) &for_leader->recv_buffer;
    switch(msg->type) {
        case submit: {
            vh_enqueue_value(msg->data, msg->data_size);
        }
        break;

        default: {
            printf("Unknow msg type %d received by proposer\n", msg->type);
        }
    }
}
Ejemplo n.º 2
0
//This function is invoked when a new message is ready to be read
// from the proposer UDP socket
static void 
pro_handle_newmsg(int sock, short event, void *arg) {
    //Make the compiler happy!
    UNUSED_ARG(sock);
    UNUSED_ARG(event);
    UNUSED_ARG(arg);
    
    assert(sock == for_proposer->sock);
    
    //Read the next message
    int valid = udp_read_next_message(for_proposer);
    if (valid < 0) {
        printf("Dropping invalid proposer message\n");
        return;
    }

    //The message is valid, take the appropriate action
    // based on the type
    paxos_msg * msg = (paxos_msg*) &for_proposer->recv_buffer;
    switch(msg->type) {
        case prepare_acks: {
            handle_prepare_ack_batch((prepare_ack_batch*) msg->data);
        }
        break;

        default: {
            printf("Unknow msg type %d received from acceptors\n", msg->type);
        }
    }
}
Ejemplo n.º 3
0
void * get_proposer_pings(void * arg) {
    arg = arg;
    struct timeval current_time;
    //Read the next message
    while(1) {
        int valid = udp_read_next_message(for_oracle);
        if (valid < 0) {
            printf("Dropping invalid proposer message\n");
            continue;
        }

        //The message is valid, take the appropriate action
        // based on the type
        paxos_msg * msg = (paxos_msg*) &for_oracle->recv_buffer;

        switch(msg->type) {
        case alive_ping: {
            alive_ping_msg * ap = (alive_ping_msg *) msg->data;
            gettimeofday(&current_time, NULL);
            update_oracle_state(ap->proposer_id, ap->sequence_number, &current_time);
        }
        break;

        default: {
            printf("Unknow msg type %d received by oracle\n", msg->type);
        }
        }
    }
    return NULL;
}
Ejemplo n.º 4
0
//This function is invoked when a new message is ready to be read
// from the leader election oracle UDP socket
static void 
pro_handle_oracle_msg(int sock, short event, void *arg) {
    //Make the compiler happy!
    UNUSED_ARG(sock);
    UNUSED_ARG(event);
    UNUSED_ARG(arg);
    
    assert(sock == from_oracle->sock);
    
    //Read the next message
    int valid = udp_read_next_message(from_oracle);
    if (valid < 0) {
        printf("Dropping invalid oracle message\n");
        return;
    }

    //The message is valid, take the appropriate action
    // based on the type
    paxos_msg * msg = (paxos_msg*) &from_oracle->recv_buffer;
    switch(msg->type) {
        case leader_announce: {
            leader_announce_msg * la = (leader_announce_msg *)msg->data;
            if(LEADER_IS_ME && la->current_leader != this_proposer_id) {
            //Some other proposer was nominated leader instead of this one, 
            // step down from leadership
                leader_shutdown();
            } else if (!LEADER_IS_ME 
                && la->current_leader == this_proposer_id) {
            //This proposer has just been promoted to leader
                leader_init();
            }
            current_leader_id = la->current_leader;
        }
        break;

        default: {
            printf("Unknow msg type %d received from oracle\n", msg->type);
        }
    }
}