aboutsummaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-02-18 18:59:45 +0100
committerChristian Grothoff <christian@grothoff.org>2017-02-18 19:00:18 +0100
commit2beedf90ffdc6d9eb3d13e0868411cf371d06ff6 (patch)
treeccc70760b7f19c9ecd73a1bcc92a21e4217cde2d /src/set
parent6fa8e1c652f447ebd94e144314ce55412dab80c8 (diff)
downloadgnunet-2beedf90ffdc6d9eb3d13e0868411cf371d06ff6.tar.gz
gnunet-2beedf90ffdc6d9eb3d13e0868411cf371d06ff6.zip
append to TAIL of mutation list for processing in right order
Diffstat (limited to 'src/set')
-rw-r--r--src/set/gnunet-service-set.c41
-rw-r--r--src/set/set_api.c3
-rw-r--r--src/set/test_set_union_copy.c65
3 files changed, 77 insertions, 32 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c
index 5633561ac..a545e8a06 100644
--- a/src/set/gnunet-service-set.c
+++ b/src/set/gnunet-service-set.c
@@ -805,16 +805,16 @@ execute_add (struct Set *set,
805 el.data = &msg[1]; 805 el.data = &msg[1];
806 el.element_type = ntohs (msg->element_type); 806 el.element_type = ntohs (msg->element_type);
807 GNUNET_SET_element_hash (&el, &hash); 807 GNUNET_SET_element_hash (&el, &hash);
808 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
809 "Client inserts element %s of size %u\n",
810 GNUNET_h2s (&hash),
811 el.size);
812 808
813 ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, 809 ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements,
814 &hash); 810 &hash);
815 811
816 if (NULL == ee) 812 if (NULL == ee)
817 { 813 {
814 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
815 "Client inserts element %s of size %u\n",
816 GNUNET_h2s (&hash),
817 el.size);
818 ee = GNUNET_malloc (el.size + sizeof *ee); 818 ee = GNUNET_malloc (el.size + sizeof *ee);
819 ee->element.size = el.size; 819 ee->element.size = el.size;
820 GNUNET_memcpy (&ee[1], 820 GNUNET_memcpy (&ee[1],
@@ -834,6 +834,11 @@ execute_add (struct Set *set,
834 } 834 }
835 else if (GNUNET_YES == _GSS_is_element_of_set (ee, set)) 835 else if (GNUNET_YES == _GSS_is_element_of_set (ee, set))
836 { 836 {
837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
838 "Client inserted element %s of size %u twice (ignored)\n",
839 GNUNET_h2s (&hash),
840 el.size);
841
837 /* same element inserted twice */ 842 /* same element inserted twice */
838 return; 843 return;
839 } 844 }
@@ -843,7 +848,9 @@ execute_add (struct Set *set,
843 .generation = set->current_generation, 848 .generation = set->current_generation,
844 .added = GNUNET_YES 849 .added = GNUNET_YES
845 }; 850 };
846 GNUNET_array_append (ee->mutations, ee->mutations_size, mut); 851 GNUNET_array_append (ee->mutations,
852 ee->mutations_size,
853 mut);
847 } 854 }
848 855
849 set->vt->add (set->state, ee); 856 set->vt->add (set->state, ee);
@@ -863,9 +870,6 @@ execute_remove (struct Set *set,
863 870
864 msg = (const struct GNUNET_SET_ElementMessage *) m; 871 msg = (const struct GNUNET_SET_ElementMessage *) m;
865 el.size = ntohs (m->size) - sizeof *msg; 872 el.size = ntohs (m->size) - sizeof *msg;
866 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
867 "Client removes element of size %u\n",
868 el.size);
869 el.data = &msg[1]; 873 el.data = &msg[1];
870 el.element_type = ntohs (msg->element_type); 874 el.element_type = ntohs (msg->element_type);
871 GNUNET_SET_element_hash (&el, &hash); 875 GNUNET_SET_element_hash (&el, &hash);
@@ -874,11 +878,17 @@ execute_remove (struct Set *set,
874 if (NULL == ee) 878 if (NULL == ee)
875 { 879 {
876 /* Client tried to remove non-existing element. */ 880 /* Client tried to remove non-existing element. */
881 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
882 "Client removes non-existing element of size %u\n",
883 el.size);
877 return; 884 return;
878 } 885 }
879 if (GNUNET_NO == _GSS_is_element_of_set (ee, set)) 886 if (GNUNET_NO == _GSS_is_element_of_set (ee, set))
880 { 887 {
881 /* Client tried to remove element twice */ 888 /* Client tried to remove element twice */
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
890 "Client removed element of size %u twice (ignored)\n",
891 el.size);
882 return; 892 return;
883 } 893 }
884 else 894 else
@@ -887,7 +897,14 @@ execute_remove (struct Set *set,
887 .generation = set->current_generation, 897 .generation = set->current_generation,
888 .added = GNUNET_NO 898 .added = GNUNET_NO
889 }; 899 };
890 GNUNET_array_append (ee->mutations, ee->mutations_size, mut); 900
901 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
902 "Client removes element of size %u\n",
903 el.size);
904
905 GNUNET_array_append (ee->mutations,
906 ee->mutations_size,
907 mut);
891 } 908 }
892 set->vt->remove (set->state, ee); 909 set->vt->remove (set->state, ee);
893} 910}
@@ -1505,9 +1522,9 @@ handle_client_mutation (void *cls,
1505 pm = GNUNET_new (struct PendingMutation); 1522 pm = GNUNET_new (struct PendingMutation);
1506 pm->mutation_message = GNUNET_copy_message (m); 1523 pm->mutation_message = GNUNET_copy_message (m);
1507 pm->set = set; 1524 pm->set = set;
1508 GNUNET_CONTAINER_DLL_insert (set->content->pending_mutations_head, 1525 GNUNET_CONTAINER_DLL_insert_tail (set->content->pending_mutations_head,
1509 set->content->pending_mutations_tail, 1526 set->content->pending_mutations_tail,
1510 pm); 1527 pm);
1511 return; 1528 return;
1512 } 1529 }
1513 execute_mutation (set, m); 1530 execute_mutation (set, m);
diff --git a/src/set/set_api.c b/src/set/set_api.c
index 90dd708df..769be82d2 100644
--- a/src/set/set_api.c
+++ b/src/set/set_api.c
@@ -660,7 +660,8 @@ GNUNET_SET_add_element (struct GNUNET_SET_Handle *set,
660 cont (cont_cls); 660 cont (cont_cls);
661 return GNUNET_SYSERR; 661 return GNUNET_SYSERR;
662 } 662 }
663 mqm = GNUNET_MQ_msg_extra (msg, element->size, 663 mqm = GNUNET_MQ_msg_extra (msg,
664 element->size,
664 GNUNET_MESSAGE_TYPE_SET_ADD); 665 GNUNET_MESSAGE_TYPE_SET_ADD);
665 msg->element_type = htons (element->element_type); 666 msg->element_type = htons (element->element_type);
666 GNUNET_memcpy (&msg[1], 667 GNUNET_memcpy (&msg[1],
diff --git a/src/set/test_set_union_copy.c b/src/set/test_set_union_copy.c
index 83a5862dd..c887a8958 100644
--- a/src/set/test_set_union_copy.c
+++ b/src/set/test_set_union_copy.c
@@ -115,7 +115,8 @@ check_count_iter (void *cls,
115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
116 "Expected count (what: %s) to be %u, but it's actually %u\n", 116 "Expected count (what: %s) to be %u, but it's actually %u\n",
117 ci_cls->what, 117 ci_cls->what,
118 ci_cls->expected_count, ci_cls->ongoing_count); 118 ci_cls->expected_count,
119 ci_cls->ongoing_count);
119 ret = 1; 120 ret = 1;
120 GNUNET_SCHEDULER_shutdown (); 121 GNUNET_SCHEDULER_shutdown ();
121 return GNUNET_NO; 122 return GNUNET_NO;
@@ -123,8 +124,13 @@ check_count_iter (void *cls,
123 ci_cls->cont (ci_cls->cont_cls); 124 ci_cls->cont (ci_cls->cont_cls);
124 return GNUNET_NO; 125 return GNUNET_NO;
125 } 126 }
127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
128 "Set `%s' has element %.*s\n",
129 ci_cls->what,
130 (int) element->size,
131 (const char *) element->data);
126 132
127 ci_cls->ongoing_count += 1; 133 ci_cls->ongoing_count++;
128 return GNUNET_YES; 134 return GNUNET_YES;
129} 135}
130 136
@@ -138,6 +144,10 @@ check_count (struct GNUNET_SET_Handle *set,
138{ 144{
139 struct CountIterClosure *ci_cls = GNUNET_new (struct CountIterClosure); 145 struct CountIterClosure *ci_cls = GNUNET_new (struct CountIterClosure);
140 146
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
148 "Checking count of %s\n",
149 what);
150
141 ci_cls->expected_count = expected_count; 151 ci_cls->expected_count = expected_count;
142 ci_cls->ongoing_count = 0; 152 ci_cls->ongoing_count = 0;
143 ci_cls->cont = cont; 153 ci_cls->cont = cont;
@@ -163,7 +173,7 @@ check_new_set_count (void *cls)
163{ 173{
164 check_count (set2, 174 check_count (set2,
165 "new set", 175 "new set",
166 4, 176 3,
167 &test_done, 177 &test_done,
168 NULL); 178 NULL);
169} 179}
@@ -173,15 +183,23 @@ static void
173copy_done (void *cls, 183copy_done (void *cls,
174 struct GNUNET_SET_Handle *new_set) 184 struct GNUNET_SET_Handle *new_set)
175{ 185{
176 printf ("copy done\n"); 186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187 "copy done\n");
177 set2 = new_set; 188 set2 = new_set;
178 remove_element_str (set2, "spam"); 189 remove_element_str (set2,
179 add_element_str (set2, "new1"); 190 "k5555");
180 add_element_str (set2, "new2"); 191 add_element_str (set2,
181 remove_element_str (set2, "new2"); 192 "n66666");
182 remove_element_str (set2, "new3"); 193 add_element_str (set2,
194 "new2butremoved");
195 remove_element_str (set2,
196 "new2butremoved");
197 remove_element_str (set2,
198 "new3justremoved");
183 // Check that set1 didn't change. 199 // Check that set1 didn't change.
184 check_count (set1, "old set", 3, 200 check_count (set1,
201 "old set",
202 3,
185 &check_new_set_count, 203 &check_new_set_count,
186 NULL); 204 NULL);
187} 205}
@@ -190,7 +208,8 @@ copy_done (void *cls,
190static void 208static void
191test_copy (void *cls) 209test_copy (void *cls)
192{ 210{
193 printf ("about to copy\n"); 211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
212 "about to copy\n");
194 GNUNET_SET_copy_lazy (set1, 213 GNUNET_SET_copy_lazy (set1,
195 &copy_done, 214 &copy_done,
196 NULL); 215 NULL);
@@ -246,17 +265,25 @@ run (void *cls,
246 &local_id); 265 &local_id);
247 266
248 set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); 267 set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION);
249 add_element_str (set1, "foo"); 268 add_element_str (set1,
250 add_element_str (set1, "bar"); 269 "333");
270 add_element_str (set1,
271 "k444");
251 /* duplicate -- ignored */ 272 /* duplicate -- ignored */
252 add_element_str (set1, "bar"); 273 add_element_str (set1,
253 remove_element_str (set1, "foo"); 274 "k444");
275 remove_element_str (set1,
276 "333");
254 /* non-existent -- ignored */ 277 /* non-existent -- ignored */
255 remove_element_str (set1, "nonexist1"); 278 remove_element_str (set1,
256 add_element_str (set1, "spam"); 279 "999999999");
280 add_element_str (set1,
281 "k5555");
257 /* duplicate -- ignored */ 282 /* duplicate -- ignored */
258 remove_element_str (set1, "foo"); 283 remove_element_str (set1,
259 add_element_str (set1, "eggs"); 284 "333");
285 add_element_str (set1,
286 "k2");
260 287
261 check_count (set1, 288 check_count (set1,
262 "initial test", 289 "initial test",