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 == 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.
pub_data * message = malloc(sizeof(struct pub_data));
message->length = len;
@ -243,12 +227,11 @@ int add_data(unsigned char len, int64_t id, int16_t seqno, char *data) {
message->data = data;
// If the data list has never been used, or is empty ( same thing )
if (data_list = NULL) {
data_list = (list*) malloc(sizeof(list));
} else {
// Otherwise, we move until the last element of the dala_list,
if (data_list == NULL) {
data_list = (list*) malloc(sizeof(struct list));
}
// we move until the last element of the dala_list,
// and add or data there.
// We use a temporary address to avoid writing to the static list.
// Seems weird but ok.
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.
tmp->next = (void *) new_node;
}
return 1;
} else {
}
// Copy data
pub_data *new_data = copy_data(len, id, seqno, data);
@ -340,6 +321,7 @@ int add_data(unsigned char len, int64_t id, int16_t seqno, char *data) {
new_node->next = NULL;
last->next = new_node;
return 3;
}
}
/* ---- Fin fonctions utilitaires ---- */