Merge branch 'add-message' of gaufre.informatique.univ-paris-diderot.fr:perdriau/dazibao into add-message

This commit is contained in:
n07070 2020-04-29 14:22:14 +02:00
commit 704ed2a523
2 changed files with 10 additions and 10 deletions

View File

@ -835,7 +835,7 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s
memset(&new_neighbour, 0, sizeof(new_neighbour)); memset(&new_neighbour, 0, sizeof(new_neighbour));
new_neighbour.sin6_family = AF_INET6; new_neighbour.sin6_family = AF_INET6;
memcpy(&new_neighbour.sin6_addr, &cur_tlv.neighbour->ip, 16); memcpy(&new_neighbour.sin6_addr, &cur_tlv.neighbour->ip, 16);
new_neighbour.sin6_port = htons(LISTEN_PORT); new_neighbour.sin6_port = ntohs(cur_tlv.neighbour->port);
new_neighbour.sin6_scope_id = ifindex; new_neighbour.sin6_scope_id = ifindex;
// Build network hash // Build network hash
@ -906,7 +906,7 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s
//if the hashes are identical nothing has to be done //if the hashes are identical nothing has to be done
print_debug(">> Received node hash, updating message entry..."); print_debug(">> Received node hash, updating message entry...");
cur_tlv.node_hash = (node_hash*) (data + pos); cur_tlv.node_hash = (node_hash*) (data + pos);
pdata = get_data(cur_tlv.node_hash->node_id); pdata = get_data(ntohl(cur_tlv.node_hash->node_id));
// If data is found for this id then we check that both hashes are the same // If data is found for this id then we check that both hashes are the same
if(pdata != NULL) { if(pdata != NULL) {
@ -925,7 +925,7 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s
} }
// If no pub_data was found or the hashes differ then we send a node state request // If no pub_data was found or the hashes differ then we send a node state request
build_node_state_req(&new_tlv, cur_tlv.node_hash->node_id); build_node_state_req(&new_tlv, ntohl(cur_tlv.node_hash->node_id));
add_tlv(&pack, &new_tlv, sender, socket_num); add_tlv(&pack, &new_tlv, sender, socket_num);
// The position is updated // The position is updated
@ -939,7 +939,7 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s
// if no pub_data exists for this id nothing is sent // if no pub_data exists for this id nothing is sent
print_debug(">> Received node state request. Processing..."); print_debug(">> Received node state request. Processing...");
cur_tlv.node_state_req = (node_state_req*) (data + pos); cur_tlv.node_state_req = (node_state_req*) (data + pos);
pdata = get_data(cur_tlv.node_state_req->node_id); pdata = get_data(ntohl(cur_tlv.node_state_req->node_id));
if(pdata != NULL) { if(pdata != NULL) {
build_node_state(&new_tlv, pdata->id, pdata->seqno, pdata->data, pdata->length); build_node_state(&new_tlv, pdata->id, pdata->seqno, pdata->data, pdata->length);
@ -962,7 +962,7 @@ 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);
} }
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); 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) {
print_debug(">> Error while adding note state !"); print_debug(">> Error while adding note state !");
} }

View File

@ -145,8 +145,8 @@ int build_node_hash(tlv *tlv, int64_t node_id, int16_t seqno, char *data) {
new->type = 6; new->type = 6;
new->length = 26; new->length = 26;
new->node_id = node_id; new->node_id = htonl(node_id);
new->seqno = seqno; new->seqno = htons(seqno);
pub_data pdata = (pub_data) {.id = node_id, .seqno = seqno, .data = data}; pub_data pdata = (pub_data) {.id = node_id, .seqno = seqno, .data = data};
hash_data(&pdata, (unsigned char*) new->node_hash); hash_data(&pdata, (unsigned char*) new->node_hash);
@ -167,7 +167,7 @@ int build_node_state_req(tlv *tlv, int64_t node_id) {
new->type = 7; new->type = 7;
new->length = 8; new->length = 8;
new->node_id = node_id; new->node_id = htonl(node_id);
tlv->node_state_req = new; tlv->node_state_req = new;
@ -192,8 +192,8 @@ int build_node_state(tlv *tlv, int64_t node_id, int16_t seqno, char *data, size_
new->type = 8; new->type = 8;
new->length = 26 + len; new->length = 26 + len;
new->node_id = node_id; new->node_id = htonl(node_id);
new->seqno = seqno; new->seqno = htons(seqno);
memcpy(new->data, data, len); memcpy(new->data, data, len);
pub_data pdata = (pub_data) {.id = node_id, .seqno = seqno, .data = data}; pub_data pdata = (pub_data) {.id = node_id, .seqno = seqno, .data = data};