#ifndef HELPERS_H_ #define HELPERS_H_ #define _GNU_SOURCE #include #include "types.h" #include "node.h" #include "message.h" #include "circ_buff.h" // Macros for logging #ifdef RELEASE //This is a release build #define logD(msg) do{ _zlog(DEBUG, msg, __FILE__, __LINE__) } while( false ) #define logI(msg) do{ _zlog(INFO, msg, __FILE__, __LINE__) } while( false ) #define logW(msg) do{ _zlog(WARN, msg, __FILE__, __LINE__) } while( false ) #define logE(msg) do{ _zlog(ERROR, msg, __FILE__, __LINE__) } while( false ) #else #define logD(msg) #define logW(msg) #define logI(msg) #define logE(msg) #endif // 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" // Colors for console output #define RED "[0;31m " #define RED_BOLD "[1;31m " #define YELLOW "[0;33m " #define YELLOW_BOLD "[01;33m " #define BLUE "[0;34m " #define BLUE_BOLD "[1;34m " #define MAGENTA "[0;35m " #define MAGENTA_BOLD "[1;35m " #define CYAN "[0;36m " #define CYAN_BOLD "[1;36m " #define COLOR_RESET "[0m" 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); char *build_ip_from_id(char *id); void _zlog(LOG_LEVEL level, char *message, char *file, int line); #endif //HELPERS_H_