diff options
author | Florian Dold <florian.dold@gmail.com> | 2015-10-05 23:16:17 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2015-10-05 23:16:17 +0000 |
commit | 1526a366e98d0f7ac4f82c548273c9f2c06f553f (patch) | |
tree | b59434fda2636116c27ef161ac0bef5f2e51d15c /src/set/set_api.c | |
parent | 2b8265dc5cbf796f01d40c6b1e82fd0852364d16 (diff) | |
download | gnunet-1526a366e98d0f7ac4f82c548273c9f2c06f553f.tar.gz gnunet-1526a366e98d0f7ac4f82c548273c9f2c06f553f.zip |
include element type in hash
Diffstat (limited to 'src/set/set_api.c')
-rw-r--r-- | src/set/set_api.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/set/set_api.c b/src/set/set_api.c index 6cbee9a57..cd880f688 100644 --- a/src/set/set_api.c +++ b/src/set/set_api.c | |||
@@ -330,7 +330,7 @@ handle_iter_element (void *cls, | |||
330 | if (NULL != iter) | 330 | if (NULL != iter) |
331 | { | 331 | { |
332 | element.size = msize - sizeof (struct GNUNET_SET_IterResponseMessage); | 332 | element.size = msize - sizeof (struct GNUNET_SET_IterResponseMessage); |
333 | element.element_type = htons (msg->element_type); | 333 | element.element_type = ntohs (msg->element_type); |
334 | element.data = &msg[1]; | 334 | element.data = &msg[1]; |
335 | iter (set->iterator_cls, | 335 | iter (set->iterator_cls, |
336 | &element); | 336 | &element); |
@@ -443,7 +443,7 @@ do_element: | |||
443 | "Treating result as element\n"); | 443 | "Treating result as element\n"); |
444 | e.data = &msg[1]; | 444 | e.data = &msg[1]; |
445 | e.size = ntohs (mh->size) - sizeof (struct GNUNET_SET_ResultMessage); | 445 | e.size = ntohs (mh->size) - sizeof (struct GNUNET_SET_ResultMessage); |
446 | e.element_type = msg->element_type; | 446 | e.element_type = ntohs (msg->element_type); |
447 | if (NULL != oh->result_cb) | 447 | if (NULL != oh->result_cb) |
448 | oh->result_cb (oh->result_cls, | 448 | oh->result_cb (oh->result_cls, |
449 | &e, | 449 | &e, |
@@ -655,7 +655,7 @@ GNUNET_SET_add_element (struct GNUNET_SET_Handle *set, | |||
655 | } | 655 | } |
656 | mqm = GNUNET_MQ_msg_extra (msg, element->size, | 656 | mqm = GNUNET_MQ_msg_extra (msg, element->size, |
657 | GNUNET_MESSAGE_TYPE_SET_ADD); | 657 | GNUNET_MESSAGE_TYPE_SET_ADD); |
658 | msg->element_type = element->element_type; | 658 | msg->element_type = htons (element->element_type); |
659 | memcpy (&msg[1], | 659 | memcpy (&msg[1], |
660 | element->data, | 660 | element->data, |
661 | element->size); | 661 | element->size); |
@@ -697,7 +697,7 @@ GNUNET_SET_remove_element (struct GNUNET_SET_Handle *set, | |||
697 | mqm = GNUNET_MQ_msg_extra (msg, | 697 | mqm = GNUNET_MQ_msg_extra (msg, |
698 | element->size, | 698 | element->size, |
699 | GNUNET_MESSAGE_TYPE_SET_REMOVE); | 699 | GNUNET_MESSAGE_TYPE_SET_REMOVE); |
700 | msg->element_type = element->element_type; | 700 | msg->element_type = htons (element->element_type); |
701 | memcpy (&msg[1], | 701 | memcpy (&msg[1], |
702 | element->data, | 702 | element->data, |
703 | element->size); | 703 | element->size); |
@@ -1144,8 +1144,14 @@ GNUNET_SET_element_dup (const struct GNUNET_SET_Element *element) | |||
1144 | void | 1144 | void |
1145 | GNUNET_SET_element_hash (const struct GNUNET_SET_Element *element, struct GNUNET_HashCode *ret_hash) | 1145 | GNUNET_SET_element_hash (const struct GNUNET_SET_Element *element, struct GNUNET_HashCode *ret_hash) |
1146 | { | 1146 | { |
1147 | /* FIXME: The element type should also be hashed. */ | 1147 | struct GNUNET_HashContext *ctx = GNUNET_CRYPTO_hash_context_start (); |
1148 | GNUNET_CRYPTO_hash (element->data, element->size, ret_hash); | 1148 | |
1149 | /* It's not guaranteed that the element data is always after the element header, | ||
1150 | so we need to hash the chunks separately. */ | ||
1151 | GNUNET_CRYPTO_hash_context_read (ctx, &element->size, sizeof (uint16_t)); | ||
1152 | GNUNET_CRYPTO_hash_context_read (ctx, &element->element_type, sizeof (uint16_t)); | ||
1153 | GNUNET_CRYPTO_hash_context_read (ctx, element->data, element->size); | ||
1154 | GNUNET_CRYPTO_hash_context_finish (ctx, ret_hash); | ||
1149 | } | 1155 | } |
1150 | 1156 | ||
1151 | /* end of set_api.c */ | 1157 | /* end of set_api.c */ |