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 | |
parent | 2b8265dc5cbf796f01d40c6b1e82fd0852364d16 (diff) | |
download | gnunet-1526a366e98d0f7ac4f82c548273c9f2c06f553f.tar.gz gnunet-1526a366e98d0f7ac4f82c548273c9f2c06f553f.zip |
include element type in hash
Diffstat (limited to 'src/set')
-rw-r--r-- | src/set/Makefile.am | 1 | ||||
-rw-r--r-- | src/set/gnunet-service-set.c | 13 | ||||
-rw-r--r-- | src/set/gnunet-service-set_union.c | 4 | ||||
-rw-r--r-- | src/set/set.h | 1 | ||||
-rw-r--r-- | src/set/set_api.c | 18 |
5 files changed, 21 insertions, 16 deletions
diff --git a/src/set/Makefile.am b/src/set/Makefile.am index b7617db25..47c9231c2 100644 --- a/src/set/Makefile.am +++ b/src/set/Makefile.am | |||
@@ -53,6 +53,7 @@ gnunet_service_set_LDADD = \ | |||
53 | $(top_builddir)/src/core/libgnunetcore.la \ | 53 | $(top_builddir)/src/core/libgnunetcore.la \ |
54 | $(top_builddir)/src/cadet/libgnunetcadet.la \ | 54 | $(top_builddir)/src/cadet/libgnunetcadet.la \ |
55 | $(top_builddir)/src/block/libgnunetblock.la \ | 55 | $(top_builddir)/src/block/libgnunetblock.la \ |
56 | $(top_builddir)/src/set/libgnunetset.la \ | ||
56 | $(GN_LIBINTL) | 57 | $(GN_LIBINTL) |
57 | 58 | ||
58 | libgnunetset_la_SOURCES = \ | 59 | libgnunetset_la_SOURCES = \ |
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index 986f52982..0557bc1f2 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c | |||
@@ -825,9 +825,8 @@ execute_add (struct Set *set, | |||
825 | "Client inserts element of size %u\n", | 825 | "Client inserts element of size %u\n", |
826 | el.size); | 826 | el.size); |
827 | el.data = &msg[1]; | 827 | el.data = &msg[1]; |
828 | GNUNET_CRYPTO_hash (el.data, | 828 | el.element_type = ntohs (msg->element_type); |
829 | el.size, | 829 | GNUNET_SET_element_hash (&el, &hash); |
830 | &hash); | ||
831 | 830 | ||
832 | ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, | 831 | ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, |
833 | &hash); | 832 | &hash); |
@@ -840,6 +839,7 @@ execute_add (struct Set *set, | |||
840 | el.data, | 839 | el.data, |
841 | el.size); | 840 | el.size); |
842 | ee->element.data = &ee[1]; | 841 | ee->element.data = &ee[1]; |
842 | ee->element.element_type = el.element_type; | ||
843 | ee->remote = GNUNET_NO; | 843 | ee->remote = GNUNET_NO; |
844 | ee->mutations = NULL; | 844 | ee->mutations = NULL; |
845 | ee->mutations_size = 0; | 845 | ee->mutations_size = 0; |
@@ -885,9 +885,8 @@ execute_remove (struct Set *set, | |||
885 | "Client removes element of size %u\n", | 885 | "Client removes element of size %u\n", |
886 | el.size); | 886 | el.size); |
887 | el.data = &msg[1]; | 887 | el.data = &msg[1]; |
888 | GNUNET_CRYPTO_hash (el.data, | 888 | el.element_type = ntohs (msg->element_type); |
889 | el.size, | 889 | GNUNET_SET_element_hash (&el, &hash); |
890 | &hash); | ||
891 | ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, | 890 | ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, |
892 | &hash); | 891 | &hash); |
893 | if (NULL == ee) | 892 | if (NULL == ee) |
@@ -1009,7 +1008,7 @@ again: | |||
1009 | memcpy (&msg[1], | 1008 | memcpy (&msg[1], |
1010 | ee->element.data, | 1009 | ee->element.data, |
1011 | ee->element.size); | 1010 | ee->element.size); |
1012 | msg->element_type = ee->element.element_type; | 1011 | msg->element_type = htons (ee->element.element_type); |
1013 | msg->iteration_id = htons (set->iteration_id); | 1012 | msg->iteration_id = htons (set->iteration_id); |
1014 | } | 1013 | } |
1015 | GNUNET_MQ_send (set->client_mq, ev); | 1014 | GNUNET_MQ_send (set->client_mq, ev); |
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index c32acc1e6..2940c3c2d 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c | |||
@@ -1078,9 +1078,7 @@ handle_p2p_elements (void *cls, | |||
1078 | ee->element.data = &ee[1]; | 1078 | ee->element.data = &ee[1]; |
1079 | ee->element.element_type = ntohs (emsg->element_type); | 1079 | ee->element.element_type = ntohs (emsg->element_type); |
1080 | ee->remote = GNUNET_YES; | 1080 | ee->remote = GNUNET_YES; |
1081 | GNUNET_CRYPTO_hash (ee->element.data, | 1081 | GNUNET_SET_element_hash (&ee->element, &ee->element_hash); |
1082 | ee->element.size, | ||
1083 | &ee->element_hash); | ||
1084 | 1082 | ||
1085 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (op->state->demanded_hashes, &ee->element_hash, NULL)) | 1083 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (op->state->demanded_hashes, &ee->element_hash, NULL)) |
1086 | { | 1084 | { |
diff --git a/src/set/set.h b/src/set/set.h index 0dccf2a51..2df1b5926 100644 --- a/src/set/set.h +++ b/src/set/set.h | |||
@@ -28,6 +28,7 @@ | |||
28 | 28 | ||
29 | #include "platform.h" | 29 | #include "platform.h" |
30 | #include "gnunet_common.h" | 30 | #include "gnunet_common.h" |
31 | #include "gnunet_set_service.h" | ||
31 | 32 | ||
32 | GNUNET_NETWORK_STRUCT_BEGIN | 33 | GNUNET_NETWORK_STRUCT_BEGIN |
33 | 34 | ||
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 */ |