messages are now added to the data_list

This commit is contained in:
n07070 2020-04-28 19:36:30 +02:00
parent 956b249259
commit 88e15dea3a

View File

@ -219,22 +219,6 @@ int add_data(unsigned char len, int64_t id, int16_t seqno, char *data) {
// If id is the same as this node's id then we only update seqno // If id is the same as this node's id then we only update seqno
if(id == NODE_ID) { if(id == NODE_ID) {
// pub_data *node_data = get_data(NODE_ID);
//
// if (node_data == NULL) {
// if (datagram == NULL) {
// data_list = (list*) malloc(sizeof(list));
// }
// data_list->data = (void*) new_data;
// data_list->next = NULL;
// }
//
// if(seqno >= node_data->seqno) {
// node_data->seqno = seqno ^ 1;
// }
//
// return 1;
// We create our pub_data. // We create our pub_data.
pub_data * message = malloc(sizeof(struct pub_data)); pub_data * message = malloc(sizeof(struct pub_data));
message->length = len; message->length = len;
@ -243,12 +227,11 @@ int add_data(unsigned char len, int64_t id, int16_t seqno, char *data) {
message->data = data; message->data = data;
// If the data list has never been used, or is empty ( same thing ) // If the data list has never been used, or is empty ( same thing )
if (data_list = NULL) { if (data_list == NULL) {
data_list = (list*) malloc(sizeof(list)); data_list = (list*) malloc(sizeof(struct list));
} else { }
// Otherwise, we move until the last element of the dala_list, // we move until the last element of the dala_list,
// and add or data there. // and add or data there.
// We use a temporary address to avoid writing to the static list. // We use a temporary address to avoid writing to the static list.
// Seems weird but ok. // Seems weird but ok.
list *tmp = data_list; list *tmp = data_list;
@ -262,11 +245,9 @@ int add_data(unsigned char len, int64_t id, int16_t seqno, char *data) {
// Adding the message to the list. // Adding the message to the list.
tmp->next = (void *) new_node; tmp->next = (void *) new_node;
}
return 1;
} else { } else {
}
// Copy data // Copy data
pub_data *new_data = copy_data(len, id, seqno, data); pub_data *new_data = copy_data(len, id, seqno, data);
@ -341,6 +322,7 @@ int add_data(unsigned char len, int64_t id, int16_t seqno, char *data) {
last->next = new_node; last->next = new_node;
return 3; return 3;
} }
}
/* ---- Fin fonctions utilitaires ---- */ /* ---- Fin fonctions utilitaires ---- */