Trying to fix print_out, but too many memory errors
This commit is contained in:
parent
72b00cb07d
commit
c19f5e7c3c
33
src/debug.c
33
src/debug.c
@ -1,7 +1,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <uchar.h>
|
||||||
|
#include <locale.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include <arpa/inet.h>
|
|
||||||
|
|
||||||
void print_debug(char * msg){
|
void print_debug(char * msg){
|
||||||
if (DEBUG_LEVEL > 0) {
|
if (DEBUG_LEVEL > 0) {
|
||||||
@ -13,19 +16,12 @@ void print_debug(char * msg){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void print_error(char * msg){
|
void print_error(char * msg){
|
||||||
printf("\x1b[41m[97m[ERROR] %s \x1b[0m\n", msg);
|
printf("\x1b[41m\x1b[97m[ERROR] >> %s \x1b[0m\n", msg);
|
||||||
if (DEBUG_LEVEL > 1) {
|
if (DEBUG_LEVEL > 1) {
|
||||||
getchar();
|
getchar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// typedef struct neighbour_peer {
|
|
||||||
// struct in6_addr ip;
|
|
||||||
// int16_t port;
|
|
||||||
// char is_temporary;
|
|
||||||
// time_t last_seen;
|
|
||||||
// } neighbour_peer;
|
|
||||||
|
|
||||||
void print_peers(list * l){
|
void print_peers(list * l){
|
||||||
// Print out the peers we have in the neighbour_list
|
// Print out the peers we have in the neighbour_list
|
||||||
int nbr_peers = 0;
|
int nbr_peers = 0;
|
||||||
@ -53,5 +49,24 @@ void print_peers(list * l){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void print_data(list * l){
|
void print_data(list * l){
|
||||||
|
if (l == NULL) {
|
||||||
|
print_error("Message list is empty !");
|
||||||
|
} else {
|
||||||
|
print_debug(">> Printing messages we know of so far :");
|
||||||
|
int nbr_msg = 0;
|
||||||
|
setlocale(LC_ALL, "en_US.utf8");
|
||||||
|
print_debug(">> 🏂🏂🏂🏂 Peer ID | Seqno | Length | Message ");
|
||||||
|
while(l != NULL){
|
||||||
|
pub_data * message = l->data;
|
||||||
|
printf("\x1b[31m[DEBUG]\x1b[0m >> %li | %i | %i | “%s” \n", message->id, message->seqno, message->length, message->data);
|
||||||
|
nbr_msg++;
|
||||||
|
if (l->next == NULL) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
l = l->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\x1b[31m[DEBUG]\x1b[0m >> Found %i messages.\n", nbr_msg);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
20
src/node.c
20
src/node.c
@ -9,9 +9,11 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <wchar.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <locale.h>
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
@ -1029,7 +1031,8 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s
|
|||||||
print_error("The data in the current node is NULL !");
|
print_error("The data in the current node is NULL !");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
printf("\x1b[31m[DEBUG]\x1b[0m >> “%s”\n", cur_tlv.node_state->data);
|
printf("%s\n", data + pos );
|
||||||
|
printf("\x1b[31m[DEBUG]\x1b[0m >> “%ls\0”\n", (const wchar_t*) cur_tlv.node_state->data);
|
||||||
}
|
}
|
||||||
int rc = add_data(cur_tlv.node_state->length - 26, ntohl(cur_tlv.node_state->node_id), ntohs(cur_tlv.node_state->seqno), cur_tlv.node_state->data);
|
int rc = add_data(cur_tlv.node_state->length - 26, ntohl(cur_tlv.node_state->node_id), ntohs(cur_tlv.node_state->seqno), cur_tlv.node_state->data);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
@ -1105,7 +1108,7 @@ int listen_for_packets(char * received_data_buffer, int received_data_len, struc
|
|||||||
if (nbr_success_tlv < 0){
|
if (nbr_success_tlv < 0){
|
||||||
print_debug(">> Error while treating the TLVs of the packet.");
|
print_debug(">> Error while treating the TLVs of the packet.");
|
||||||
if (DEBUG_LEVEL > 1) {
|
if (DEBUG_LEVEL > 1) {
|
||||||
printf("\x1b[31m[DEBUG]\x1b[0m >> Managed to deal with %i TLVs", -nbr_success_tlv );
|
printf("\x1b[31m[DEBUG]\x1b[0m >> Managed to deal with %i TLVs\n", -nbr_success_tlv );
|
||||||
}
|
}
|
||||||
return -2;
|
return -2;
|
||||||
} else {
|
} else {
|
||||||
@ -1116,12 +1119,20 @@ int listen_for_packets(char * received_data_buffer, int received_data_len, struc
|
|||||||
}
|
}
|
||||||
|
|
||||||
int t_ask_for_more_peers(int sock_fd){
|
int t_ask_for_more_peers(int sock_fd){
|
||||||
print_peers(neighbour_list);
|
if (DEBUG_LEVEL > 1) {
|
||||||
|
print_peers(neighbour_list);
|
||||||
|
sleep(3);
|
||||||
|
}
|
||||||
return ask_for_peers(sock_fd);
|
return ask_for_peers(sock_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
int t_get_network_state(int sock_fd){
|
int t_get_network_state(int sock_fd){
|
||||||
print_debug(">> Getting network state...");
|
print_debug(">> Getting network state...");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1157,6 +1168,8 @@ int run_node(int sock_fd){
|
|||||||
t_ask_for_more_peers(sock_fd);
|
t_ask_for_more_peers(sock_fd);
|
||||||
t_update_neighbours();
|
t_update_neighbours();
|
||||||
t_get_network_state(sock_fd);
|
t_get_network_state(sock_fd);
|
||||||
|
print_data(data_list);
|
||||||
|
sleep(3);
|
||||||
delay = time(NULL) + 20 + (rand() % 10);
|
delay = time(NULL) + 20 + (rand() % 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1303,6 +1316,7 @@ int bootstrap_node(int * sock_fd){
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, const char *argv[]) {
|
int main(int argc, const char *argv[]) {
|
||||||
|
setlocale(LC_ALL, "");
|
||||||
print_debug(">> Starting node");
|
print_debug(">> Starting node");
|
||||||
|
|
||||||
int sock_fd;
|
int sock_fd;
|
||||||
|
Loading…
Reference in New Issue
Block a user