Functions
Table of Contents:
-
Socket and Connection Functions:
- void connect_to_naming_server(char *ip, int *sock, struct sockaddr_in *addr)
- void open_naming_server_port(int port_number, int *server_sock, struct sockaddr_in *server_addr)
- void connect_to_SS_from_NS(int *ns_sock, struct sockaddr_in *ns_addr, int port_num)
- void connect_to_SS_from_client(int *sock, struct sockaddr_in *addr, char *ns_ip, int ns_port)
- void make_socket_non_blocking(int socket)
- void MakeSSsend_vital(int *naming_server_sock, char *ip, int client_port, int server_port)
- void SendInfo(int *sock, struct sockaddr_in *addr, char *path, char *op)
Tree Data Structure Functions:
Tree MakeNode(char *name)
-
Description: Allocates memory for a new tree node and initializes its path and pointers.
-
Parameters:
name
: A string representing the name of the node.
-
Returns: A pointer to the newly created tree node.
Tree Insert(Tree parent, char *path)
-
Description: Inserts a new node with the given path as a child of the parent node.
-
Parameters:
parent
: Pointer to the parent tree node.path
: A string representing the path for the new node.
-
Returns: Pointer to the newly inserted tree node.
Tree Search_Till_Parent(Tree T, char *path, int insert)
-
Description: Searches for a node with the given path. If not found and
insert
is 1, it creates and inserts a new node. -
Parameters:
T
: Pointer to the root tree node.path
: A string representing the path to search for.insert
: Integer flag (1 or 0) indicating whether to insert a new node if not found.
-
Returns: Pointer to the parent node of the found/inserted node, or NULL if path not found.
void PrintTree(Tree T)
-
Description: Recursively prints the tree starting from the given node.
-
Parameters:
T
: Pointer to the tree node to start printing from.
-
Returns: None.
void Del_Rec(Tree T)
-
Description: Recursively deletes the tree starting from the given node.
-
Parameters:
T
: Pointer to the tree node to start deletion from.
-
Returns: None.
int Delete_Path(Tree T, char *path)
-
Description: Deletes the node with the given path from the tree.
-
Parameters:
T
: Pointer to the root tree node.path
: A string representing the path to delete.
-
Returns: 0 if successful, -1 if path not found.
Storage Server Functions:
storage_servers MakeNode_ss(char *ip_addr, int client_port, int server_port)
-
Description: Allocates memory for a new storage server node and initializes its IP address, client port, server port, and file tree.
-
Parameters:
ip_addr
: A string representing the IP address of the storage server.client_port
: Integer representing the client port number.server_port
: Integer representing the server port number.
-
Returns: Pointer to the newly created storage server node.
void load_SS(Tree T, char *file_name)
-
Description: Loads storage server information from a file and constructs the file tree.
-
Parameters:
T
: Pointer to the root tree node (files and directories) of the storage server.file_name
: A string representing the name of the file containing storage server information.
-
Returns: None.
int initialize_SS(int *ss_sock)
-
Description: Initializes a storage server by receiving vital information (IP, ports, paths) from the naming server and constructs its file tree.
-
Parameters:
ss_sock
: Pointer to the storage server socket.
-
Returns: 0 if successful, -1 on error.
File and Directory Manipulation Functions:
int create_file(char *file_path)
-
Description: Creates a new file at the specified file path.
-
Parameters:
file_path
: A string representing the path of the file to be created.
-
Returns: 0 if successful, -1 on error.
int create_directory(char *file_path)
-
Description: Creates a new directory at the specified path.
-
Parameters:
file_path
: A string representing the path of the directory to be created.
-
Returns: 0 if successful, -1 on error.
int delete_file(char *file_path)
-
Description: Deletes the file at the specified path.
-
Parameters:
file_path
: A string representing the path of the file to be deleted.
-
Returns: 0 if successful, -1 on error.
int delete_directory(char *file_path)
-
Description: Deletes the directory at the specified path.
-
Parameters:
file_path
: A string representing the path of the directory to be deleted.
-
Returns: 0 if successful, -1 on error.
Socket and Connection Functions:
void connect_to_naming_server(char *ip, int *sock, struct sockaddr_in *addr)
-
Description: Establishes a connection to the naming server.
-
Parameters:
ip
: A string representing the IP address of the naming server.sock
: Pointer to the socket used for the connection.addr
: Pointer to the sockaddr_in structure for naming server address.
-
Returns: None.
void open_naming_server_port(int port_number, int *server_sock, struct sockaddr_in *server_addr)
-
Description: Opens a port for the naming server to listen to incoming connections.
-
Parameters:
port_number
: Integer representing the port number to be opened.server_sock
: Pointer to the socket used for the server.server_addr
: Pointer to the sockaddr_in structure for server address.
-
Returns: None.
void connect_to_SS_from_NS(int *ns_sock, struct sockaddr_in *ns_addr, int port_num)
-
Description: Establishes a connection from the naming server to a storage server.
-
Parameters:
ns_sock
: Pointer to the socket used for the connection from the naming server.ns_addr
: Pointer to the sockaddr_in structure for storage server address.port_num
: Integer representing the port number of the storage server.
-
Returns: None.
void connect_to_SS_from_client(int *sock, struct sockaddr_in *addr, char *ns_ip, int ns_port)
-
Description: Establishes a connection from the client to a storage server.
-
Parameters:
sock
: Pointer to the socket used for the connection.addr
: Pointer to the sockaddr_in structure for storage server address.ns_ip
: A string representing the IP address of the storage server.ns_port
: Integer representing the port number of the storage server.
-
Returns: None.
void make_socket_non_blocking(int socket)
-
Description: Configures a socket to be non-blocking.
-
Parameters:
socket
: Integer representing the socket to be configured.
-
Returns: None.
`void MakeSSsend_vital(int *naming_server_sock, char *ip
, int client_port, int server_port)`
-
Description: Sends vital information (IP, ports) from the storage server to the naming server.
-
Parameters:
naming_server_sock
: Pointer to the socket used for communication with the naming server.ip
: A string representing the IP address of the storage server.client_port
: Integer representing the client port number of the storage server.server_port
: Integer representing the server port number of the storage server.
-
Returns: None.
void SendInfo(int *sock, struct sockaddr_in *addr, char *path, char *op)
-
Description: Sends file or directory information from the naming server to the client or from the client to the storage server.
-
Parameters:
sock
: Pointer to the socket used for communication.addr
: Pointer to the sockaddr_in structure for the destination address.path
: A string representing the file or directory path.op
: A string representing the operation (get or put).
-
Returns: None.