diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-07 22:57:59 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-07 22:57:59 +0000 |
commit | bc7f4b972d82bfe08fbce7972041f62e67949088 (patch) | |
tree | 83913085553cfbeea9777c7ee724727c92098d03 /src/dv | |
parent | 4a25afcbc1cd57637f340a5b5369b999429b79f9 (diff) | |
download | gnunet-bc7f4b972d82bfe08fbce7972041f62e67949088.tar.gz gnunet-bc7f4b972d82bfe08fbce7972041f62e67949088.zip |
-correct use of consensi
Diffstat (limited to 'src/dv')
-rw-r--r-- | src/dv/gnunet-service-dv.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index e15d30ead..04176d747 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c | |||
@@ -349,7 +349,7 @@ static struct GNUNET_CONTAINER_MultiPeerMap *all_routes; | |||
349 | * Array of consensus sets we expose to the outside world. Sets | 349 | * Array of consensus sets we expose to the outside world. Sets |
350 | * are structured by the distance to the target. | 350 | * are structured by the distance to the target. |
351 | */ | 351 | */ |
352 | static struct ConsensusSet consensi[DEFAULT_FISHEYE_DEPTH - 1]; | 352 | static struct ConsensusSet consensi[DEFAULT_FISHEYE_DEPTH]; |
353 | 353 | ||
354 | /** | 354 | /** |
355 | * Handle to the core service api. | 355 | * Handle to the core service api. |
@@ -485,7 +485,7 @@ send_control_to_plugin (const struct GNUNET_MessageHeader *message) | |||
485 | * | 485 | * |
486 | * @param target peer that received the message | 486 | * @param target peer that received the message |
487 | * @param uid plugin-chosen UID for the message | 487 | * @param uid plugin-chosen UID for the message |
488 | * @param nack GNUNET_NO to send ACK, GNUNET_YES to send NACK | 488 | * @param nack #GNUNET_NO to send ACK, #GNUNET_YES to send NACK |
489 | */ | 489 | */ |
490 | static void | 490 | static void |
491 | send_ack_to_plugin (const struct GNUNET_PeerIdentity *target, | 491 | send_ack_to_plugin (const struct GNUNET_PeerIdentity *target, |
@@ -705,7 +705,7 @@ get_consensus_slot (uint32_t distance) | |||
705 | struct ConsensusSet *cs; | 705 | struct ConsensusSet *cs; |
706 | unsigned int i; | 706 | unsigned int i; |
707 | 707 | ||
708 | GNUNET_assert (distance < DEFAULT_FISHEYE_DEPTH - 1); | 708 | GNUNET_assert (distance < DEFAULT_FISHEYE_DEPTH); |
709 | cs = &consensi[distance]; | 709 | cs = &consensi[distance]; |
710 | i = 0; | 710 | i = 0; |
711 | while ( (i < cs->array_length) && | 711 | while ( (i < cs->array_length) && |
@@ -732,7 +732,11 @@ allocate_route (struct Route *route, | |||
732 | { | 732 | { |
733 | unsigned int i; | 733 | unsigned int i; |
734 | 734 | ||
735 | GNUNET_assert (distance < DEFAULT_FISHEYE_DEPTH - 1); | 735 | if (distance >= DEFAULT_FISHEYE_DEPTH) |
736 | { | ||
737 | route->set_offset = UINT_MAX; /* invalid slot */ | ||
738 | return; | ||
739 | } | ||
736 | i = get_consensus_slot (distance); | 740 | i = get_consensus_slot (distance); |
737 | route->set_offset = i; | 741 | route->set_offset = i; |
738 | consensi[distance].targets[i] = route; | 742 | consensi[distance].targets[i] = route; |
@@ -748,6 +752,9 @@ allocate_route (struct Route *route, | |||
748 | static void | 752 | static void |
749 | release_route (struct Route *route) | 753 | release_route (struct Route *route) |
750 | { | 754 | { |
755 | if (UINT_MAX == route->set_offset) | ||
756 | return; | ||
757 | GNUNET_assert (ntohl (route->target.distance) < DEFAULT_FISHEYE_DEPTH); | ||
751 | consensi[ntohl (route->target.distance)].targets[route->set_offset] = NULL; | 758 | consensi[ntohl (route->target.distance)].targets[route->set_offset] = NULL; |
752 | route->set_offset = UINT_MAX; /* indicate invalid slot */ | 759 | route->set_offset = UINT_MAX; /* indicate invalid slot */ |
753 | } | 760 | } |
@@ -766,6 +773,8 @@ move_route (struct Route *route, | |||
766 | unsigned int i; | 773 | unsigned int i; |
767 | 774 | ||
768 | release_route (route); | 775 | release_route (route); |
776 | if (new_distance >= DEFAULT_FISHEYE_DEPTH) | ||
777 | return; /* no longer interesting for 'consensi' */ | ||
769 | i = get_consensus_slot (new_distance); | 778 | i = get_consensus_slot (new_distance); |
770 | route->set_offset = i; | 779 | route->set_offset = i; |
771 | consensi[new_distance].targets[i] = route; | 780 | consensi[new_distance].targets[i] = route; |
@@ -791,24 +800,24 @@ build_set (void *cls) | |||
791 | struct GNUNET_SET_Element element; | 800 | struct GNUNET_SET_Element element; |
792 | struct Target *target; | 801 | struct Target *target; |
793 | target = NULL; | 802 | target = NULL; |
794 | while ( (DEFAULT_FISHEYE_DEPTH - 1 > neighbor->consensus_insertion_distance) && | 803 | while ( (DEFAULT_FISHEYE_DEPTH > neighbor->consensus_insertion_distance) && |
795 | (consensi[neighbor->consensus_insertion_distance].array_length == neighbor->consensus_insertion_offset) ) | 804 | (consensi[neighbor->consensus_insertion_distance].array_length == neighbor->consensus_insertion_offset) ) |
796 | { | 805 | { |
797 | /* If we reached the last element of a consensus array element: increase distance and start with next array */ | 806 | /* If we reached the last element of a consensus array element: increase distance and start with next array */ |
798 | neighbor->consensus_insertion_offset = 0; | 807 | neighbor->consensus_insertion_offset = 0; |
799 | neighbor->consensus_insertion_distance++; | 808 | neighbor->consensus_insertion_distance++; |
800 | /* skip over NULL entries */ | 809 | /* skip over NULL entries */ |
801 | while ( (DEFAULT_FISHEYE_DEPTH - 1 > neighbor->consensus_insertion_distance) && | 810 | while ( (DEFAULT_FISHEYE_DEPTH > neighbor->consensus_insertion_distance) && |
802 | (consensi[neighbor->consensus_insertion_distance].array_length > neighbor->consensus_insertion_offset) && | 811 | (consensi[neighbor->consensus_insertion_distance].array_length > neighbor->consensus_insertion_offset) && |
803 | (NULL == consensi[neighbor->consensus_insertion_distance].targets[neighbor->consensus_insertion_offset]) ) | 812 | (NULL == consensi[neighbor->consensus_insertion_distance].targets[neighbor->consensus_insertion_offset]) ) |
804 | neighbor->consensus_insertion_offset++; | 813 | neighbor->consensus_insertion_offset++; |
805 | } | 814 | } |
806 | if (DEFAULT_FISHEYE_DEPTH - 1 == neighbor->consensus_insertion_distance) | 815 | if (DEFAULT_FISHEYE_DEPTH == neighbor->consensus_insertion_distance) |
807 | { | 816 | { |
808 | /* we have added all elements to the set, run the operation */ | 817 | /* we have added all elements to the set, run the operation */ |
809 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 818 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
810 | "Finished building my SET for peer `%s' with %u elements, committing\n", | 819 | "Finished building my SET for peer `%s' with %u elements, committing\n", |
811 | GNUNET_i2s(&neighbor->peer), | 820 | GNUNET_i2s (&neighbor->peer), |
812 | neighbor->consensus_elements); | 821 | neighbor->consensus_elements); |
813 | GNUNET_SET_commit (neighbor->set_op, | 822 | GNUNET_SET_commit (neighbor->set_op, |
814 | neighbor->my_set); | 823 | neighbor->my_set); |
@@ -825,7 +834,7 @@ build_set (void *cls) | |||
825 | /* Find next non-NULL entry */ | 834 | /* Find next non-NULL entry */ |
826 | neighbor->consensus_insertion_offset++; | 835 | neighbor->consensus_insertion_offset++; |
827 | /* skip over NULL entries */ | 836 | /* skip over NULL entries */ |
828 | while ( (DEFAULT_FISHEYE_DEPTH - 1 > neighbor->consensus_insertion_distance) && | 837 | while ( (DEFAULT_FISHEYE_DEPTH > neighbor->consensus_insertion_distance) && |
829 | (consensi[neighbor->consensus_insertion_distance].array_length > neighbor->consensus_insertion_offset) && | 838 | (consensi[neighbor->consensus_insertion_distance].array_length > neighbor->consensus_insertion_offset) && |
830 | (NULL == consensi[neighbor->consensus_insertion_distance].targets[neighbor->consensus_insertion_offset]) ) | 839 | (NULL == consensi[neighbor->consensus_insertion_distance].targets[neighbor->consensus_insertion_offset]) ) |
831 | { | 840 | { |
@@ -1035,7 +1044,7 @@ check_possible_route (void *cls, | |||
1035 | } | 1044 | } |
1036 | return GNUNET_YES; /* got a route to this target already */ | 1045 | return GNUNET_YES; /* got a route to this target already */ |
1037 | } | 1046 | } |
1038 | if (ntohl (target->distance) >= DEFAULT_FISHEYE_DEPTH - 1) | 1047 | if (ntohl (target->distance) >= DEFAULT_FISHEYE_DEPTH) |
1039 | return GNUNET_YES; /* distance is too large to be interesting */ | 1048 | return GNUNET_YES; /* distance is too large to be interesting */ |
1040 | route = GNUNET_new (struct Route); | 1049 | route = GNUNET_new (struct Route); |
1041 | route->next_hop = neighbor; | 1050 | route->next_hop = neighbor; |
@@ -1425,6 +1434,7 @@ check_target_added (void *cls, | |||
1425 | current_route->next_hop = neighbor; | 1434 | current_route->next_hop = neighbor; |
1426 | current_route->target.peer = target->peer; | 1435 | current_route->target.peer = target->peer; |
1427 | current_route->target.distance = htonl (ntohl (target->distance) + 1); | 1436 | current_route->target.distance = htonl (ntohl (target->distance) + 1); |
1437 | allocate_route (current_route, ntohl (current_route->target.distance)); | ||
1428 | GNUNET_assert (GNUNET_YES == | 1438 | GNUNET_assert (GNUNET_YES == |
1429 | GNUNET_CONTAINER_multipeermap_put (all_routes, | 1439 | GNUNET_CONTAINER_multipeermap_put (all_routes, |
1430 | ¤t_route->target.peer, | 1440 | ¤t_route->target.peer, |
@@ -1941,7 +1951,7 @@ shutdown_task (void *cls, | |||
1941 | stats = NULL; | 1951 | stats = NULL; |
1942 | GNUNET_SERVER_notification_context_destroy (nc); | 1952 | GNUNET_SERVER_notification_context_destroy (nc); |
1943 | nc = NULL; | 1953 | nc = NULL; |
1944 | for (i=0;i<DEFAULT_FISHEYE_DEPTH - 1;i++) | 1954 | for (i=0;i<DEFAULT_FISHEYE_DEPTH;i++) |
1945 | { | 1955 | { |
1946 | GNUNET_array_grow (consensi[i].targets, | 1956 | GNUNET_array_grow (consensi[i].targets, |
1947 | consensi[i].array_length, | 1957 | consensi[i].array_length, |