#include "../include/repository.h"
#include "../include/command.h"
#include "../include/DFR_CL.h"
#include "../include/cond_comp.h"
#include <arpa/inet.h>
Go to the source code of this file.
Functions | |
void | serve_start_file_transfer (int req_sock, string file_name, string CL_address, list< string > *obtained_files, bool *error) |
support function for command start_file_transfer | |
void | serve_end_file_transfer (int req_sock, string file_name, string CL_address, list< string > *obtained_files, bool *error) |
support function for command end_file_transfer | |
void | serve_reg_notification (int req_sock, string file_name, string CL_address, list< string > *obtained_files, bool *error) |
support function for command reg_notification | |
void * | CL_req_s_body (void *sock) |
body of the threads which serve requests coming from a singular CL | |
void * | CL_s_body (void *sock) |
body of the CL_s thread | |
Variables | |
repository_class | repository |
the DFR repository of file |
void* CL_req_s_body | ( | void * | sock | ) |
body of the threads which serve requests coming from a singular CL
when a connection from a CL to the DFR is accepted, a new thread with this function as a body is created, the CL requests server. This thread will serve ALL the commands arriving from that particular CL, sequentially. The socket used for the two-way communication should be open all the time, if the CL closes the socket, the DFR assumes that the CL has gone down or finished using the Distributed Repository, this means that when this happens, the CL SHOULD NOT be transferring files from a FS. when the CL is sensed to be going down, this thread will automatically release all the files that the CL had obtained from the DFR.
you may note that a CL can connect with multiple connection to the DFR, using different ports, and creating more and more of these threads. this means that the DFR is vulnerable to a DoS (Denial of Service) attack by a CL using a lot of connection... a future extension of the DFR project should solve this problem.
the choice of using a sequential request server for requests coming from the same CL was preferred because the DFR must have a way to identify clients in the repository:
sock | | socket descriptor for communicating, passed as a (void*) for semplicity. we are assuming that sizeof(int)=sizeof(void*) |
Definition at line 99 of file DFR_CL.cpp.
References end_file_transfer, command::file_name, command::id, INT_AS_STRING_BYTES, LOG, receive_command(), reg_notification, repository_class::release_file(), serve_end_file_transfer(), serve_reg_notification(), serve_start_file_transfer(), and start_file_transfer.
Referenced by CL_s_body().
void* CL_s_body | ( | void * | sock | ) |
body of the CL_s thread
this is the body of the CL_s, there is just one thread with this body running at any time, it accepts connections from clients. each connection corresponds to a client, and it must stay up until the client has finished his work. for each connection, this thread creates a new thread for that particular CL connection.
sock | | socket descriptor for listening, passed as a (void*) for semplicity. we are assuming that sizeof(int) = sizeof(void*) |
Definition at line 154 of file DFR_CL.cpp.
References CL_req_s_body(), LOG, and MAX_ERR_COUNT_CL.
Referenced by main().
void serve_end_file_transfer | ( | int | req_sock, | |
string | file_name, | |||
string | CL_address, | |||
list< string > * | obtained_files, | |||
bool * | error | |||
) |
support function for command end_file_transfer
this function executes all operation necessary for the end_file_transfer command, it must be called when an end_file_transfer command arrives
req_sock | | socket to speak with the CL | |
file_name | | file the CL wants to transfer | |
CL_address | | address and port of the CL | |
obtained_files | | pointer to the list the calling thread is using to keep track of client operations | |
error | | pointer to the boolean variable the calling thread is using to keep track of errors |
Definition at line 45 of file DFR_CL.cpp.
References ERR_NO_TRANSFER, LOG, OK, repository_class::release_file(), and reply_command().
Referenced by CL_req_s_body().
void serve_reg_notification | ( | int | req_sock, | |
string | file_name, | |||
string | CL_address, | |||
list< string > * | obtained_files, | |||
bool * | error | |||
) |
support function for command reg_notification
this function executes all operation necessary for the reg_notification command, it must be called when an reg_notification command arrives
this function uses the serve_start_file_transfer() function when the client is notified and replies with an OK response message
req_sock | | socket to speak with the CL | |
file_name | | file the CL wants to transfer | |
CL_address | | address and port of the CL | |
obtained_files | | pointer to the list the calling thread is using to keep track of client operations | |
error | | pointer to the boolean variable the calling thread is using to keep track of errors |
Definition at line 72 of file DFR_CL.cpp.
References ERR_NO_NOTIFICATION, LOG, notify, OK, reply_command(), send_command(), serve_start_file_transfer(), and repository_class::wait_file().
Referenced by CL_req_s_body().
void serve_start_file_transfer | ( | int | req_sock, | |
string | file_name, | |||
string | CL_address, | |||
list< string > * | obtained_files, | |||
bool * | error | |||
) |
support function for command start_file_transfer
this function executes all operation necessary for the start_file_transfer command, it can be called when a start_file_transfer command arrives, or it can be called if the DFR sent a notify command to the CL and a response was received with the OK state
req_sock | | socket to speak with the CL | |
file_name | | file the CL wants to transfer | |
CL_address | | address and port of the CL | |
obtained_files | | pointer to the list the calling thread is using to keep track of client operations | |
error | | pointer to the boolean variable the calling thread is using to keep track of errors |
Definition at line 13 of file DFR_CL.cpp.
References ERR_FILE_NOT_EXISTS, ERR_TOO_MANY_CLIENTS, INT_AS_STRING_BYTES, LOG, repository_class::obtain_file(), OK, and reply_command().
Referenced by CL_req_s_body(), and serve_reg_notification().