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
|
// 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.");
|
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 is the same as this node's id then we only update seqno
|
||||||
if(id == NODE_ID) {
|
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;
|
node_data->seqno = seqno ^ 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy data
|
// 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->data = (void*) new_data;
|
||||||
data_list->next = NULL;
|
data_list->next = NULL;
|
||||||
|
|
||||||
return;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find correct position for new data
|
// 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->data = (void*) new_data;
|
||||||
data_list->next = tmp;
|
data_list->next = tmp;
|
||||||
|
|
||||||
return;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Else, we update the last node
|
// 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 old data
|
||||||
free(cur_data);
|
free(cur_data);
|
||||||
|
|
||||||
return;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// seqno is smaller so the new data allocated is freed and nothing else is done
|
// seqno is smaller so the new data allocated is freed and nothing else is done
|
||||||
free(new_data);
|
free(new_data);
|
||||||
|
|
||||||
return;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get next node in list
|
// 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->data = (void*) new_data;
|
||||||
new_node->next = NULL;
|
new_node->next = NULL;
|
||||||
last->next = new_node;
|
last->next = new_node;
|
||||||
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---- Fin fonctions utilitaires ---- */
|
/* ---- 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 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;
|
return 0;
|
||||||
}
|
}
|
||||||
// We then look at the differents TLVs in the packet.
|
// 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) {
|
if (DEBUG_LEVEL > 0) {
|
||||||
printf("\n\t %s \n", (char *) cur_tlv.node_state->data);
|
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
|
// The position is updated
|
||||||
tlv_len = data[pos+1];
|
tlv_len = data[pos+1];
|
||||||
pos += tlv_len + 2;
|
pos += tlv_len + 2;
|
||||||
|
@ -62,7 +62,7 @@ typedef struct list {
|
|||||||
|
|
||||||
// The adress of the main peer
|
// The adress of the main peer
|
||||||
#define ROOT_PEER_ADDR "2001:660:3301:9200::51c2:1b9b"
|
#define ROOT_PEER_ADDR "2001:660:3301:9200::51c2:1b9b"
|
||||||
|
|
||||||
|
|
||||||
// fonctions signatures
|
// fonctions signatures
|
||||||
int listen_for_packets(char * received_data_buffer, int received_data_len, struct sockaddr_in6 * sender, int sock_fd);
|
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);
|
pub_data *copy_data(unsigned char len, int64_t id, int16_t seqno, char *data);
|
||||||
|
|
||||||
// add new data to data list
|
// 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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user