aboutsummaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2015-09-22 01:20:28 +0000
committerFlorian Dold <florian.dold@gmail.com>2015-09-22 01:20:28 +0000
commitafc7d17dc798216e89506fb4e66aabb7e0f0077b (patch)
tree786d44d7852795f9f20549466f39683e32e6abea /src/set
parenta8bb50dcefdab19f4990995ded586b237501b2c1 (diff)
downloadgnunet-afc7d17dc798216e89506fb4e66aabb7e0f0077b.tar.gz
gnunet-afc7d17dc798216e89506fb4e66aabb7e0f0077b.zip
work on CONSENSUS and SET
- byzantine consensus work in progress - fix SET generation handling
Diffstat (limited to 'src/set')
-rw-r--r--src/set/gnunet-service-set.c43
-rw-r--r--src/set/gnunet-service-set.h3
2 files changed, 34 insertions, 12 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c
index 75b33536d..d8e8dfb78 100644
--- a/src/set/gnunet-service-set.c
+++ b/src/set/gnunet-service-set.c
@@ -339,7 +339,12 @@ is_element_of_generation (struct ElementEntry *ee,
339{ 339{
340 struct MutationEvent *mut; 340 struct MutationEvent *mut;
341 int is_present; 341 int is_present;
342 unsigned int i;
342 343
344 /* If ee->mutations is NULL,
345 the element was added in generation 0,
346 and there are no removes, thus the element
347 is part of any generation we query. */
343 if (NULL == ee->mutations) 348 if (NULL == ee->mutations)
344 return GNUNET_YES; 349 return GNUNET_YES;
345 350
@@ -349,22 +354,38 @@ is_element_of_generation (struct ElementEntry *ee,
349 return GNUNET_NO; 354 return GNUNET_NO;
350 } 355 }
351 356
352 is_present = GNUNET_YES; 357 is_present = GNUNET_NO;
353 358
354 // Could be made faster with binary search, but lists 359 /* Could be made faster with binary search, but lists
355 // are small, so why bother. 360 are small, so why bother. */
356 for (mut = ee->mutations; 0 != mut->generation; mut++) 361 for (i = 0; i < ee->mutations_size; i++)
357 { 362 {
358 if ( (mut->generation > query_generation) || 363 mut = &ee->mutations[i];
359 (GNUNET_YES == is_excluded_generation (mut->generation, excluded, excluded_size)) ) 364
365 if (mut->generation > query_generation)
366 {
367 /* The mutation doesn't apply to our generation
368 anymore. We can'b break here, since mutations aren't
369 sorted by generation. */
370 continue;
371 }
372
373 if (GNUNET_YES == is_excluded_generation (mut->generation, excluded, excluded_size))
360 { 374 {
375 /* The generation is excluded (because it belongs to another
376 fork via a lazy copy) and thus mutations aren't considered
377 for membership testing. */
361 continue; 378 continue;
362 } 379 }
363 380
364 // This would be an inconsistency in how we manage mutations. 381 /* This would be an inconsistency in how we manage mutations. */
365 if ( (GNUNET_YES == is_present) && (GNUNET_YES == mut->added) ) 382 if ( (GNUNET_YES == is_present) && (GNUNET_YES == mut->added) )
366 GNUNET_assert (0); 383 GNUNET_assert (0);
367 384
385 /* Likewise. */
386 if ( (GNUNET_NO == is_present) && (GNUNET_NO == mut->added) )
387 GNUNET_assert (0);
388
368 is_present = mut->added; 389 is_present = mut->added;
369 } 390 }
370 391
@@ -816,7 +837,9 @@ execute_add (struct Set *set,
816 ee->mutations = NULL; 837 ee->mutations = NULL;
817 ee->mutations_size = 0; 838 ee->mutations_size = 0;
818 ee->element_hash = hash; 839 ee->element_hash = hash;
819 } else if (GNUNET_YES == _GSS_is_element_of_set (ee, set)) { 840 }
841 else if (GNUNET_YES == _GSS_is_element_of_set (ee, set))
842 {
820 /* same element inserted twice */ 843 /* same element inserted twice */
821 GNUNET_break (0); 844 GNUNET_break (0);
822 return; 845 return;
@@ -829,7 +852,6 @@ execute_add (struct Set *set,
829 .added = GNUNET_YES 852 .added = GNUNET_YES
830 }; 853 };
831 GNUNET_array_append (ee->mutations, ee->mutations_size, mut); 854 GNUNET_array_append (ee->mutations, ee->mutations_size, mut);
832 ee->mutations_size += 1;
833 } 855 }
834 856
835 GNUNET_break (GNUNET_YES == 857 GNUNET_break (GNUNET_YES ==
@@ -888,7 +910,6 @@ execute_remove (struct Set *set,
888 .added = GNUNET_NO 910 .added = GNUNET_NO
889 }; 911 };
890 GNUNET_array_append (ee->mutations, ee->mutations_size, mut); 912 GNUNET_array_append (ee->mutations, ee->mutations_size, mut);
891 ee->mutations_size += 1;
892 } 913 }
893 set->vt->remove (set->state, ee); 914 set->vt->remove (set->state, ee);
894} 915}
@@ -1263,8 +1284,6 @@ advance_generation (struct Set *set)
1263 GNUNET_array_append (set->excluded_generations, 1284 GNUNET_array_append (set->excluded_generations,
1264 set->excluded_generations_size, 1285 set->excluded_generations_size,
1265 r); 1286 r);
1266
1267 set->excluded_generations_size += 1;
1268} 1287}
1269 1288
1270/** 1289/**
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h
index fb079d03f..c3650aa9b 100644
--- a/src/set/gnunet-service-set.h
+++ b/src/set/gnunet-service-set.h
@@ -323,6 +323,9 @@ struct ElementEntry
323 */ 323 */
324 struct MutationEvent *mutations; 324 struct MutationEvent *mutations;
325 325
326 /**
327 * Number of elements in the array @a mutations.
328 */
326 unsigned int mutations_size; 329 unsigned int mutations_size;
327 330
328 /** 331 /**