#ifndef HELPERS_H_ #define HELPERS_H_ #define _GNU_SOURCE #include #include "types.h" #include "node.h" #include "message.h" #include "circ_buff.h" // Macros to turn a numeric macro into a string literal #define xstr(s) str(s) #define str(s) #s // AEMs file related definitions #define AEM_ID_LEN 4 #define AEM_BUFFER_LEN 5 // Format for fscanf() to read the AEM numbers #define AEM_LINE_FORMAT "%" xstr(AEM_ID_LEN) "s\n" node_id_t extract_id_from_ip(const ipv4_t ip); void set_timer_and_handler(void (*handler)(int), long int timer_interval); uint16_t create_message(char *new_message, uint16_t max_message_length, node_handle_t *neighbors, uint8_t num_neighbors, node_id_t own_id); int create_socket_and_listen(port_t port, uint8_t backlog_size); void send_message(node_handle_t peer, message_handle_t message); node_id_t accept_connection(int sock, address_t *client_name, fd_set *active_fd_set, int *listens_on); uint16_t checkAddNode(node_handle_t **neighbors, uint16_t num_neighbors , address_t peer_name, node_id_t node_id); void write_to_peer(int filedes, const char *message); int read_from_peer(int file_des, uint16_t max_line, cbuf_handle_t *message_buffer, node_handle_t **neighbors, uint16_t num_neighbors); uint16_t fread_neighbors(char *AEM_file, node_handle_t **neighbors, port_t port); void init_sockaddr(address_t *peer_name, const ipv4_t hostname, port_t port); #endif //HELPERS_H_