/*
* handle_packet
* DESCRIPTION: Called when this system has received a data packet. This
* function parses the packet and calls the requested function.
* INPUTS: TBD
* OUTPUTS: 0 on success, -1 on failure
*/
int handle_packet() {
int packet_function;
int result;
addr_t sender_addr;
packet_t* rcvd_packet; // pointer to malloc'd packet
switch(packet_function) {
case DATABLOCK_REQUEST:
result = handle_datablock_request();
break;
case ADDR_REQUEST:
result = handle_addr_request(sender_addr);
case NODE_ADDED:
result = handle_node_join(rcvd_packet);
break;
case NODE_REMOVED:
result = handle_node_leave(0, rcvd_packet);
break;
}
if(result == -1) { // fatal error
return -1;
}
if(result == -2) { // non-fatal error
return 0;
}
return 0;
}