#include (b2 << 16) + (b3 << 8)

#include #include #include //unsigned int node_str_to_node_id(const char *node_str){    unsigned int b1, b2, b3, b4;    unsigned int result;    sscanf(node_str, “%u.%u.%u.%u”, &b1, &b2, &b3, &b4);    result = (b1 << 24) + (b2 << 16) + (b3 << 8) + b4; return result;}//char *node_id_to_node_str(int node_id){    unsigned char b4; b0 = node_id & 0xff; b1 = (node_id >> 8) & 0xff; b2 = (node_id >> 16) & 0xff;    b3 = (node_id >> 24) & 0xff; char *result = malloc(sizeof(char) * ((3 * 4) + 4 + 1));    sprintf(result, “%u.%u.%u.%u”, b3, b2, b1, b0); return result;}//(id1, id2)int id1_ex_id2(unsigned int id1, unsigned int id2, unsigned int id){    if (id1 < id2){        return ((id > id1) && (id < id2));    } return ((id > id1) || (id < id2));}//id1, id2int id1_in_id2(unsigned int id1, unsigned int id2, unsigned int id){ if ((id == id1) || (id == id2)){        return 1;    }else if (id1 < id2){        return ((id >= id1) && (id <= id2));    } return ((id >= id1) || (id <= id2));}//id1, id2)int id1_in_ex_id2(unsigned int id1, unsigned int id2, unsigned int id){ if (id == id1){        return 1;    } else if (id1 < id2){        return ((id >= id1) && (id < id2));    } return ((id >= id1) || (id < id2));}//(id1, id2int id1_ex_in_id2(unsigned int id1, unsigned int id2, unsigned int id){ if (id == id2){        return 1;    } else if (id1 < id2){        return ((id > id1) && (id <= id2));    } return ((id > id1) || (id <= id2));}//unsigned int immediate_before_finger(node_t *node, unsigned int node_id){    int i;    for (i = (FT_LENGTH - 1); i >= 0; i–){ unsigned int next_check = node->finger_tablei.after; if (id1_ex_id2(node->id, node_id, next_check)){            return next_check;        } } return node->id;}//unsigned int get_before(node_t *node, unsigned int node_id){ if (id1_in_ex_id2(node->id, node->after, node_id)){        return node->id;    } unsigned int i = node->id; while (!id1_ex_in_id2(i, ((i == node->id) ? node->after : rpc_find_after(i, node->node_port, node->root_port)), node_id)){// rpc_find_after w args if (i == node->id){            i = immediate_before_finger(node, node_id);        } else {            i = rpc_find_immediate_before_finger(i, node_id);        } } return i;}//unsigned int get_after(node_t *node, unsigned int node_id){ if (id1_ex_in_id2(node->before, node->id, node_id)){        return node->id;    } unsigned int before = get_before(node, node_id); return ((before == node->id) ? node->after : rpc_find_after(before, node->node_port, node->root_port));} //void initialize_finger_table(node_t *node, unsigned int ring_node){    int i;    for (i = 0; i < FT_LENGTH; i++) { node->finger_tablei.start = (node->id + (1 << i)); node->finger_tablei.end = (node->id + (1 << (i + 1)));    } unsigned int after = rpc_get_after(ring_node, node->finger_table0.start); node->finger_table0.after = after; node->after = after; node->before = rpc_find_before(after, node->node_port, node->root_port); // rpc_find_before w args rpc_put_before(node->after, node->id); rpc_put_after(node->before, node->id); for (i = 0; i < (FT_LENGTH - 1); i++){ if (id1_in_ex_id2(node->id, node->finger_tablei.after, node->finger_tablei + 1.start)){            node->finger_tablei + 1.after = node->finger_tablei.after;        } else {            node->finger_tablei + 1.after = rpc_get_after(ring_node, node->finger_tablei + 1.start);        } }}//void drop_finger_table(node_t *node){ unsigned int store = node->after; rpc_put_before(node->after, node->before); rpc_put_after(node->before, store);}//void record_join_finger_table(node_t *node, int i, unsigned int node_id){ if (id1_ex_id2(node->id, node->finger_tablei.after, node_id)){        node->finger_tablei.after = node_id; if (i == 0){            node->after = node_id;        }        unsigned int before = node->before; if (before == node->id){        record_join_finger_table(node, i, node_id);        } else {            rpc_record_join_finger_table(before, i, node_id);        } }}//void record_leave_finger_table(node_t *node, int i, unsigned int node_id){ if (node->finger_tablei.after == node_id){        node->finger_tablei.after = ((node_id == node->id) ? node->after : rpc_find_after(node_id, node->node_port, node->root_port)); // rpc_find_after w args    }    unsigned int before = node->before; if (before != node->id){        rpc_record_leave_finger_table(before, i, node_id);    }}//void record_join_all_nodes(node_t *node){    int i;    for (i = 0; i < FT_LENGTH; i++){ unsigned int store = node->id – (1 << i); unsigned int before = get_before(node, (node->id – (1 << i)));printf("finger %d (checking status of %10u / %15s) ", i, store, node_id_to_node_str(store)), fflush(stdout);        status_t st = ((store == node->id) ? node->status : rpc_find_status(store,node->node_port,node->root_port)); if (st == CONNECTED){            before = store;        } rpc_record_join_finger_table(before, i, node->id); }}//void record_leave_all_nodes(node_t *node){    int i;    for (i = 0; i < FT_LENGTH; i++){ unsigned int store = node->id – (1 << i); unsigned int before = get_before(node, (node->id – (1 << i)));printf("finger %d (checking status of %10u / %15s) ", i, store, node_id_to_node_str(store)), fflush(stdout); status_t st = ((store == node->id) ? node->status : rpc_find_status(store,node->node_port,node->root_port));        if (st == CONNECTED){            before = store;        }        rpc_record_leave_finger_table(before, i, node->id); }}//void print_a_node(node_t *node){ printf(“id: %u (%s)
“, node->id, node_id_to_node_str(node->id)); printf(“before: %u (%s)
“, node->before, node_id_to_node_str(node->before)); printf(“after: %u (%s)
“, node->after, node_id_to_node_str(node->after));  int i;  for (i = 0; i < FT_LENGTH; i++) {        printf("finger %2d range: %10u / %15s, %10u / %15s ) after: %10u / %15s ", i,            node->finger_tablei.start, node_id_to_node_str(node->finger_tablei.start), node->finger_tablei.end,            node_id_to_node_str(node->finger_tablei.end), node->finger_tablei.after, node_id_to_node_str(node->finger_tablei.after)); }}//unsigned int rpc_find_status(unsigned int node_id, unsigned short host_port, unsigned short root_port){ unsigned int result; char *ip_address = node_id_to_node_str(node_id);  connect_host_t peer, ring_node;    printf(“con open
“); printf(“%d
“,connection_open(&peer, IN_PROT_UDP, IN_ADDR_ANY, host_port));    printf(“con setup
“);  connection_setup(&ring_node, IN_PROT_UDP, ip_address, root_port);//RPC_PORT msg_t message; message.type = MESSAGE_FIND_STATUS;  printf(“con message con send
“);  printf(“%d
“,connection_send(&peer, &ring_node, &message, sizeof(msg_t)));printf(“sent (MESSAGE_FIND_STATUS:%s)
“, ip_address), fflush(stdout); msg_t acknowlegdement;  printf(“con message con receive
“);  printf(“%d
“,connection_receive(&ring_node, &peer, &acknowlegdement, sizeof(msg_t), 1)); if (acknowlegdement.type == MESSAGE_FIND_STATUS_ACK){ printf(“received (MESSAGE_FIND_STATUS_ACK)
“), fflush(stdout); printf(“STATUS = %d
“, acknowlegdement.data0), fflush(stdout); result = acknowlegdement.data0;    } connection_close(&peer);    free(ip_address);    return result;}//int rpc_put_status(unsigned int node_id, status_t st, unsigned short host_port, unsigned short root_port){ unsigned int result = 0; char *ip_address = node_id_to_node_str(node_id);    connect_host_t peer, ring_node; connection_open(&peer, IN_PROT_UDP, IN_ADDR_ANY, host_port);    connection_setup(&ring_node, IN_PROT_UDP, ip_address, root_port); msg_t message; message.type = MESSAGE_PUT_STATUS; message.data0 = st; connection_send(&peer, &ring_node, &message, sizeof(msg_t));printf(“sent (MESSAGE_PUT_STATUS:%s)
“, ip_address), fflush(stdout); msg_t acknowledgement;    connection_receive(&ring_node, &peer, &acknowledgement, sizeof(msg_t), -1); if (acknowledgement.type == MESSAGE_PUT_STATUS_ACK) { printf(“received (MESSAGE_PUT_STATUS_ACK)
“), fflush(stdout); result = 1;    } connection_close(&peer); free(ip_address); return result;}//unsigned int rpc_find_after(unsigned int node_id, unsigned short host_port, unsigned short root_port){ unsigned int result; char *ip_address = node_id_to_node_str(node_id);    connect_host_t peer, ring_node; connection_open(&peer, IN_PROT_UDP, IN_ADDR_ANY, host_port);    connection_setup(&ring_node, IN_PROT_UDP, ip_address, root_port); msg_t message; message.type = MESSAGE_FIND_AFTER; connection_send(&peer, &ring_node, &message, sizeof(msg_t));printf(“sent (MESSAGE_FIND_AFTER:%s)
“, ip_address), fflush(stdout); msg_t acknowledgement;    connection_receive(&ring_node, &peer, &acknowledgement, sizeof(msg_t), -1); if (acknowledgement.type == MESSAGE_FIND_AFTER_ACK) { printf(“received (MESSAGE_FIND_AFTER_ACK)
“), fflush(stdout); printf(“AFTER = %u
“, acknowledgement.data0), fflush(stdout); result = acknowledgement.data0;    } connection_close(&peer); free(ip_address); return result;}//int rpc_put_after(unsigned int node_id, unsigned int after){ unsigned int result = 0; char *ip_address = node_id_to_node_str(node_id);    connect_host_t peer, ring_node; connection_open(&peer, IN_PROT_UDP, IN_ADDR_ANY, COM_PORT); connection_setup(&ring_node, IN_PROT_UDP, ip_address, RPC_PORT);    msg_t message; message.type = MESSAGE_PUT_AFTER; message.data0 = after; connection_send(&peer, &ring_node, &message, sizeof(msg_t));printf(“sent (MESSAGE_PUT_AFTER:%s)
“, ip_address), fflush(stdout); msg_t acknowledgement;    connection_receive(&ring_node, &peer, &acknowledgement, sizeof(msg_t), -1); if (acknowledgement.type == MESSAGE_PUT_AFTER_ACK) { printf(“received (MESSAGE_PUT_AFTER_ACK)
“), fflush(stdout); result = 1;    } connection_close(&peer); free(ip_address); return result;}//unsigned int rpc_find_before(unsigned int node_id, unsigned short host_port, unsigned short root_port){ unsigned int result; char *ip_address = node_id_to_node_str(node_id);    connect_host_t peer, ring_node; connection_open(&peer, IN_PROT_UDP, IN_ADDR_ANY, host_port); connection_setup(&ring_node, IN_PROT_UDP, ip_address, root_port);    msg_t message; message.type = MESSAGE_FIND_BEFORE;    connection_send(&peer, &ring_node, &message, sizeof(msg_t));    printf(“sent (MESSAGE_FIND_BEFORE:%s)
“, ip_address), fflush(stdout); msg_t acknowledgement;    connection_receive(&ring_node, &peer, &acknowledgement, sizeof(msg_t), -1); if (acknowledgement.type == MESSAGE_FIND_BEFORE_ACK) { printf(“received (MESSAGE_FIND_BEFORE_ACK)
“), fflush(stdout); printf(“BEFORE = %u
“, acknowledgement.data0), fflush(stdout); result = acknowledgement.data0;    } connection_close(&peer); free(ip_address); return result;}//int rpc_put_before(unsigned int node_id, unsigned int before){ unsigned int result = 0; char *ip_address = node_id_to_node_str(node_id);    connect_host_t peer, ring_node; connection_open(&peer, IN_PROT_UDP, IN_ADDR_ANY, COM_PORT); connection_setup(&ring_node, IN_PROT_UDP, ip_address, RPC_PORT);    msg_t message; message.type = MESSAGE_PUT_BEFORE; message.data0 = before; connection_send(&peer, &ring_node, &message, sizeof(msg_t));printf(“sent (MESSAGE_PUT_BEFORE:%s)
“, ip_address), fflush(stdout);    msg_t acknowledgement;    connection_receive(&ring_node, &peer, &acknowledgement, sizeof(msg_t), -1); if (acknowledgement.type == MESSAGE_PUT_BEFORE_ACK){ printf(“received (MESSAGE_PUT_BEFORE_ACK)
“), fflush(stdout); result = 1;    } connection_close(&peer); free(ip_address); return result;}//unsigned int rpc_find_immediate_before_finger(unsigned int node, unsigned int node_id){ unsigned int result; char *ip_address = node_id_to_node_str(node);    connect_host_t peer, ring_node; connection_open(&peer, IN_PROT_UDP, IN_ADDR_ANY, COM_PORT); connection_setup(&ring_node, IN_PROT_UDP, ip_address, RPC_PORT);    msg_t message; message.type = MESSAGE_FIND_IMMEDIATE_BEFORE_FINGER; message.data0 = node_id; connection_send(&peer, &ring_node, &message, sizeof(msg_t));printf(“sent (MESSAGE_FIND_IMMEDIATE_BEFORE_FINGER:%s)
“, ip_address), fflush(stdout);    msg_t acknowledgement; connection_receive(&ring_node, &peer, &acknowledgement, sizeof(msg_t), -1); if (acknowledgement.type == MESSAGE_FIND_IMMEDIATE_BEFORE_FINGER_ACK){ printf(“received (MESSAGE_FIND_IMMEDIATE_BEFORE_FINGER_ACK)
“), fflush(stdout); printf(“CLOSEST_PRECEDING_FINGER = %u
“, acknowledgement.data0), fflush(stdout); result = acknowledgement.data0;    } connection_close(&peer); free(ip_address); return result;}//unsigned int rpc_get_before(unsigned int node, unsigned int node_id){ unsigned int result; char *ip_address = node_id_to_node_str(node);    connect_host_t peer, ring_node; connection_open(&peer, IN_PROT_UDP, IN_ADDR_ANY, COM_PORT); connection_setup(&ring_node, IN_PROT_UDP, ip_address, RPC_PORT);    msg_t message; message.type = MESSAGE_GET_BEFORE; message.data0 = node_id; connection_send(&peer, &ring_node, &message, sizeof(msg_t));printf(“sent (MESSAGE_GET_BEFORE:%s)
“, ip_address), fflush(stdout);    msg_t acknowledgement; connection_receive(&ring_node, &peer, &acknowledgement, sizeof(msg_t), -1);    if (acknowledgement.type == MESSAGE_GET_BEFORE_ACK){ printf(“received (MESSAGE_GET_BEFORE_ACK)
“), fflush(stdout); printf(“PREDECESSOR(%u) = %u
“, node_id, acknowledgement.data0), fflush(stdout); result = acknowledgement.data0;    } connection_close(&peer); free(ip_address); return result;}//unsigned int rpc_get_after(unsigned int node, unsigned int node_id){    unsigned int result; char *ip_address = node_id_to_node_str(node);    connect_host_t peer, ring_node; connection_open(&peer, IN_PROT_UDP, IN_ADDR_ANY, COM_PORT); connection_setup(&ring_node, IN_PROT_UDP, ip_address, RPC_PORT);    msg_t message; message.type = MESSAGE_GET_AFTER; message.data0 = node_id; connection_send(&peer, &ring_node, &message, sizeof(msg_t));printf(“sent (MESSAGE_GET_AFTER:%s)
“, ip_address), fflush(stdout);    msg_t acknowledgement; connection_receive(&ring_node, &peer, &acknowledgement, sizeof(msg_t), -1);    if (acknowledgement.type == MESSAGE_GET_AFTER_ACK){ printf(“received (MESSAGE_GET_AFTER_ACK)
“), fflush(stdout); printf(“AFTER(%u) = %u
“, node_id, acknowledgement.data0), fflush(stdout); result = acknowledgement.data0;    } connection_close(&peer); free(ip_address); return result;}//int rpc_record_join_finger_table(unsigned int p, unsigned int f, unsigned int node_id){ unsigned int result = 0; char *ip_address = node_id_to_node_str(p);    connect_host_t peer, ring_node; connection_open(&peer, IN_PROT_UDP, IN_ADDR_ANY, COM_PORT); connection_setup(&ring_node, IN_PROT_UDP, ip_address, RPC_PORT);    msg_t message; message.type = MESSAGE_RECORD_JOIN_FINGER_TABLE; message.data0 = f; message.data1 = node_id; connection_send(&peer, &ring_node, &message, sizeof(msg_t));printf(“sent (MESSAGE_RECORD_JOIN_FINGER_TABLE:%s)
“, ip_address), fflush(stdout);    msg_t acknowledgement; connection_receive(&ring_node, &peer, &acknowledgement, sizeof(msg_t), -1);    if (acknowledgement.type == MESSAGE_RECORD_JOIN_FINGER_TABLE_ACK) { printf(“received (MESSAGE_RECORD_JOIN_FINGER_TABLE_ACK)
“), fflush(stdout); result = 1;    } connection_close(&peer); free(ip_address); return result;}//int rpc_record_leave_finger_table(unsigned int p, unsigned int f, unsigned int node_id){ unsigned int result = 0; char *ip_address = node_id_to_node_str(p);    connect_host_t peer, ring_node; connection_open(&peer, IN_PROT_UDP, IN_ADDR_ANY, COM_PORT); connection_setup(&ring_node, IN_PROT_UDP, ip_address, RPC_PORT);    msg_t message; message.type = MESSAGE_RECORD_LEAVE_FINGER_TABLE; message.data0 = f; message.data1 = node_id; connection_send(&peer, &ring_node, &message, sizeof(msg_t));printf(“sent (MESSAGE_RECORD_LEAVE_FINGER_TABLE:%s)
“, ip_address), fflush(stdout);    msg_t acknowledgement; connection_receive(&ring_node, &peer, &acknowledgement, sizeof(msg_t), -1);    if (acknowledgement.type == MESSAGE_RECORD_LEAVE_FINGER_TABLE_ACK) { printf(“received (MESSAGE_RECORD_LEAVE_FINGER_TABLE_ACK)
“), fflush(stdout); result = 1; }    connection_close(&peer); free(ip_address); return result;}void *rpc_helper(void *data){ node_t *node = (node_t *)data;    connect_host_t peer, ring_node; while (1) { connection_open(&peer, IN_PROT_UDP, IN_ADDR_ANY, RPC_PORT); printf(“waiting for node to connect in rpc_helper…
“), fflush(stdout); msg_t message; if (connection_receive(&ring_node, &peer, &message, sizeof(msg_t), -1) == sizeof(msg_t)) { printf(“received message (%d)
“, message.type), fflush(stdout);            msg_t acknowledgement; switch (message.type) { case MESSAGE_QUIT: printf(“received (MESSAGE_QUIT)
“), fflush(stdout); { acknowledgement.type = MESSAGE_QUIT_ACK; printf(“quitting…
“), fflush(stdout); connection_send(&peer, &ring_node, &acknowledgement, sizeof(msg_t)); connection_close(&peer); pthread_exit(0); } case MESSAGE_FIND_STATUS: printf(“received (MESSAGE_FIND_STATUS)
“), fflush(stdout); { acknowledgement.type = MESSAGE_FIND_STATUS_ACK; acknowledgement.data0 = node->status; connection_send(&peer, &ring_node, &acknowledgement, sizeof(msg_t)); break; } case MESSAGE_PUT_STATUS: printf(“received (MESSAGE_PUT_STATUS)
“), fflush(stdout); { node->status = message.data0; acknowledgement.type = MESSAGE_PUT_STATUS_ACK; connection_send(&peer, &ring_node, &acknowledgement, sizeof(msg_t)); break; } case MESSAGE_FIND_AFTER: printf(“received (MESSAGE_FIND_AFTER)
“), fflush(stdout); { acknowledgement.type = MESSAGE_FIND_AFTER_ACK; acknowledgement.data0 = node->after; connection_send(&peer, &ring_node, &acknowledgement, sizeof(msg_t)); break; } case MESSAGE_PUT_AFTER: printf(“received (MESSAGE_PUT_AFTER)
“), fflush(stdout); { node->after = message.data0; acknowledgement.type = MESSAGE_PUT_AFTER_ACK; connection_send(&peer, &ring_node, &acknowledgement, sizeof(msg_t)); break; } case MESSAGE_FIND_BEFORE: printf(“received (MESSAGE_FIND_BEFORE)
“), fflush(stdout); { acknowledgement.type = MESSAGE_FIND_BEFORE_ACK; acknowledgement.data0 = node->before; connection_send(&peer, &ring_node, &acknowledgement, sizeof(msg_t)); break; } case MESSAGE_PUT_BEFORE: printf(“received (MESSAGE_PUT_BEFORE)
“), fflush(stdout); { node->before = message.data0; acknowledgement.type = MESSAGE_PUT_BEFORE_ACK; connection_send(&peer, &ring_node, &acknowledgement, sizeof(msg_t)); break; } case MESSAGE_FIND_IMMEDIATE_BEFORE_FINGER: printf(“received (MESSAGE_FIND_IMMEDIATE_BEFORE_FINGER)
“), fflush(stdout); { acknowledgement.type = MESSAGE_FIND_IMMEDIATE_BEFORE_FINGER_ACK; acknowledgement.data0 = immediate_before_finger(node, message.data0); connection_send(&peer, &ring_node, &acknowledgement, sizeof(msg_t)); break; } case MESSAGE_GET_AFTER: printf(“received (MESSAGE_GET_AFTER)
“), fflush(stdout); { acknowledgement.type = MESSAGE_GET_AFTER_ACK; acknowledgement.data0 = get_after(node, message.data0); connection_send(&peer, &ring_node, &acknowledgement, sizeof(msg_t)); break; } case MESSAGE_GET_BEFORE: printf(“received (MESSAGE_GET_BEFORE)
“), fflush(stdout); { acknowledgement.type = MESSAGE_GET_BEFORE_ACK; acknowledgement.data0 = get_before(node, message.data0); connection_send(&peer, &ring_node, &acknowledgement, sizeof(msg_t)); break; } case MESSAGE_RECORD_JOIN_FINGER_TABLE: printf(“received (MESSAGE_RECORD_JOIN_FINGER_TABLE)
“), fflush(stdout); { record_join_finger_table(node, message.data0, message.data1); acknowledgement.type = MESSAGE_RECORD_JOIN_FINGER_TABLE_ACK; connection_send(&peer, &ring_node, &acknowledgement, sizeof(msg_t)); break; } case MESSAGE_RECORD_LEAVE_FINGER_TABLE: printf(“received (MESSAGE_RECORD_LEAVE_FINGER_TABLE)
“), fflush(stdout); { record_leave_finger_table(node, message.data0, message.data1); acknowledgement.type = MESSAGE_RECORD_LEAVE_FINGER_TABLE_ACK; connection_send(&peer, &ring_node, &acknowledgement, sizeof(msg_t)); break; } } } connection_close(&peer); }}//node_t *ring_initialize(const char *ip_address, unsigned short host_port, unsigned short root_port){ node_t *node = malloc(sizeof(node_t)); node->id = node_str_to_node_id(ip_address); node->after = node->id; node->after_port = host_port; node->before = node->id; node->before_port = host_port; node->node_port = host_port; node->root_port = root_port;  int i; for (i = 0; i < FT_LENGTH; i++){ node->finger_tablei.start = (node->id + (1 << i)); node->finger_tablei.end = (node->id + (1 << (i + 1))); node->finger_tablei.after = node->id;    } node->status = DISCONNECTED;  pthread_create(&(node->rpc_thread), NULL, rpc_helper, node); return node;}//int ring_drop(node_t *node){ connect_host_t peer, ring_node; connection_open(&peer, IN_PROT_UDP, IN_ADDR_ANY, COM_PORT);    char *ip_address = node_id_to_node_str(node->id); connection_setup(&ring_node, IN_PROT_UDP, ip_address, RPC_PORT);    msg_t message; message.type = MESSAGE_QUIT; connection_send(&peer, &ring_node, &message, sizeof(msg_t));    msg_t acknowledgement; connection_receive(&ring_node, &peer, &acknowledgement, sizeof(msg_t), -1);    if (acknowledgement.type == MESSAGE_QUIT_ACK){        printf(“received (MESSAGE_QUIT_ACK)
“), fflush(stdout);    } connection_close(&peer); printf(“waiting for child thread…
“), fflush(stdout); pthread_join(node->rpc_thread, NULL); return 1;}//int ring_join(node_t *node, const char *ip_address){ unsigned int id = node_str_to_node_id(ip_address);printf(“attempting to join ring at %s and node id %d…
“, ip_address, id);    if (rpc_find_status(id,node->node_port,node->root_port) == CONNECTED){ initialize_finger_table(node, id); record_join_all_nodes(node); rpc_put_status(node->id, CONNECTED,node->node_port,node->root_port); printf(“joined an existing ring!
“); } else { int i; for (i = 0; i < FT_LENGTH; i++) { node->finger_tablei.start = (node->id + (1 << i)); node->finger_tablei.end = (node->id + (1 << (i + 1))); node->finger_tablei.after = node->id;        } node->before = node->id; node->after = node->id; rpc_put_status(node->id, CONNECTED,node->node_port,node->root_port); printf(“started a new ring!
“); }}//int ring_leave(node_t *node){ drop_finger_table(node);    record_leave_all_nodes(node); int i; for (i = 0; i < FT_LENGTH; i++) { node->finger_tablei.start = (node->id + (1 << i)); node->finger_tablei.end = (node->id + (1 << (i + 1))); node->finger_tablei.after = node->id; node->after = node->id; node->before = node->id;    } rpc_put_status(node->id, DISCONNECTED,node->node_port,node->root_port);}char *ring_lookup(node_t *node, unsigned int node_id){ unsigned int nd = get_after(node, node_id); return node_id_to_node_str(nd);}

x

Hi!
I'm Isaac!

Would you like to get a custom essay? How about receiving a customized one?

Check it out