Added basic add_message function
This commit is contained in:
parent
a178c76116
commit
25e703b993
24
src/node.c
24
src/node.c
@ -214,7 +214,7 @@ pub_data *copy_data(unsigned char len, int64_t id, int16_t seqno, char *data) {
|
||||
}
|
||||
|
||||
// Add new data to data list
|
||||
void add_data(unsigned char len, int64_t id, int16_t seqno, char *data) {
|
||||
int add_data(unsigned char len, int64_t id, int16_t seqno, char *data) {
|
||||
print_debug(">> Adding data to the data list.");
|
||||
// If id is the same as this node's id then we only update seqno
|
||||
if(id == NODE_ID) {
|
||||
@ -224,7 +224,7 @@ void add_data(unsigned char len, int64_t id, int16_t seqno, char *data) {
|
||||
node_data->seqno = seqno ^ 1;
|
||||
}
|
||||
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Copy data
|
||||
@ -236,7 +236,7 @@ void add_data(unsigned char len, int64_t id, int16_t seqno, char *data) {
|
||||
data_list->data = (void*) new_data;
|
||||
data_list->next = NULL;
|
||||
|
||||
return;
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Find correct position for new data
|
||||
@ -257,7 +257,7 @@ void add_data(unsigned char len, int64_t id, int16_t seqno, char *data) {
|
||||
data_list->data = (void*) new_data;
|
||||
data_list->next = tmp;
|
||||
|
||||
return;
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Else, we update the last node
|
||||
@ -278,13 +278,13 @@ void add_data(unsigned char len, int64_t id, int16_t seqno, char *data) {
|
||||
// Free old data
|
||||
free(cur_data);
|
||||
|
||||
return;
|
||||
return 2;
|
||||
}
|
||||
|
||||
// seqno is smaller so the new data allocated is freed and nothing else is done
|
||||
free(new_data);
|
||||
|
||||
return;
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Get next node in list
|
||||
@ -299,6 +299,7 @@ void add_data(unsigned char len, int64_t id, int16_t seqno, char *data) {
|
||||
new_node->data = (void*) new_data;
|
||||
new_node->next = NULL;
|
||||
last->next = new_node;
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* ---- Fin fonctions utilitaires ---- */
|
||||
@ -723,6 +724,11 @@ int check_header(char * received_data_buffer, int received_data_len, struct pack
|
||||
}
|
||||
|
||||
int add_message(char * message, int message_len){
|
||||
int seqno = 0;
|
||||
int rc = add_data(message_len, NODE_ID ,seqno, message);
|
||||
if (rc > 0) {
|
||||
print_debug(">> Message added.");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// We then look at the differents TLVs in the packet.
|
||||
@ -925,8 +931,10 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s
|
||||
if (DEBUG_LEVEL > 0) {
|
||||
printf("\n\t %s \n", (char *) cur_tlv.node_state->data);
|
||||
}
|
||||
add_data(cur_tlv.node_state->length - 26, cur_tlv.node_state->node_id, cur_tlv.node_state->seqno, cur_tlv.node_state->data);
|
||||
|
||||
int rc = add_data(cur_tlv.node_state->length - 26, cur_tlv.node_state->node_id, cur_tlv.node_state->seqno, cur_tlv.node_state->data);
|
||||
if (rc < 0) {
|
||||
print_debug(">> Error while adding note state !");
|
||||
}
|
||||
// The position is updated
|
||||
tlv_len = data[pos+1];
|
||||
pos += tlv_len + 2;
|
||||
|
@ -62,7 +62,7 @@ typedef struct list {
|
||||
|
||||
// The adress of the main peer
|
||||
#define ROOT_PEER_ADDR "2001:660:3301:9200::51c2:1b9b"
|
||||
|
||||
|
||||
|
||||
// fonctions signatures
|
||||
int listen_for_packets(char * received_data_buffer, int received_data_len, struct sockaddr_in6 * sender, int sock_fd);
|
||||
@ -136,6 +136,6 @@ pub_data *get_data(int64_t id);
|
||||
pub_data *copy_data(unsigned char len, int64_t id, int16_t seqno, char *data);
|
||||
|
||||
// add new data to data list
|
||||
void add_data(unsigned char len, int64_t id, int16_t seqno, char *data);
|
||||
int add_data(unsigned char len, int64_t id, int16_t seqno, char *data);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user