diff options
author | Florian Dold <florian.dold@gmail.com> | 2015-10-06 16:17:08 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2015-10-06 16:17:08 +0000 |
commit | a67168e803fd2231cd20c2d16fdc8956a81a6b56 (patch) | |
tree | 40e0f8c5e8cabe507d7c5abb65c2875d806eb0a6 /src/consensus | |
parent | c81d7e1199cf2779973900677ffb3d12e12ca96f (diff) | |
download | gnunet-a67168e803fd2231cd20c2d16fdc8956a81a6b56.tar.gz gnunet-a67168e803fd2231cd20c2d16fdc8956a81a6b56.zip |
fix contestation handling / blacklisting
Diffstat (limited to 'src/consensus')
-rw-r--r-- | src/consensus/gnunet-service-consensus.c | 64 |
1 files changed, 49 insertions, 15 deletions
diff --git a/src/consensus/gnunet-service-consensus.c b/src/consensus/gnunet-service-consensus.c index 2d2725b64..6cd0244b5 100644 --- a/src/consensus/gnunet-service-consensus.c +++ b/src/consensus/gnunet-service-consensus.c | |||
@@ -793,6 +793,21 @@ rfn_contest (struct ReferendumEntry *rfn, | |||
793 | rfn->peer_contested[contested_peer] = GNUNET_YES; | 793 | rfn->peer_contested[contested_peer] = GNUNET_YES; |
794 | } | 794 | } |
795 | 795 | ||
796 | |||
797 | static uint16_t | ||
798 | rfn_noncontested (struct ReferendumEntry *rfn) | ||
799 | { | ||
800 | uint16_t i; | ||
801 | uint16_t ret; | ||
802 | |||
803 | ret = 0; | ||
804 | for (i = 0; i < rfn->num_peers; i++) | ||
805 | if ( (GNUNET_YES == rfn->peer_commited[i]) && (GNUNET_NO == rfn->peer_contested[i]) ) | ||
806 | ret++; | ||
807 | |||
808 | return ret; | ||
809 | } | ||
810 | |||
796 | static void | 811 | static void |
797 | rfn_vote (struct ReferendumEntry *rfn, | 812 | rfn_vote (struct ReferendumEntry *rfn, |
798 | uint16_t voting_peer, | 813 | uint16_t voting_peer, |
@@ -879,15 +894,7 @@ set_result_cb (void *cls, | |||
879 | return; | 894 | return; |
880 | } | 895 | } |
881 | 896 | ||
882 | if (task->key.peer1 == session->local_peer_idx) | 897 | other_idx = task_other_peer (task); |
883 | other_idx = task->key.peer2; | ||
884 | else if (task->key.peer2 == session->local_peer_idx) | ||
885 | other_idx = task->key.peer1; | ||
886 | else | ||
887 | { | ||
888 | /* error in task graph construction */ | ||
889 | GNUNET_assert (0); | ||
890 | } | ||
891 | 898 | ||
892 | if (SET_KIND_NONE != setop->output_set.set_kind) | 899 | if (SET_KIND_NONE != setop->output_set.set_kind) |
893 | { | 900 | { |
@@ -909,10 +916,12 @@ set_result_cb (void *cls, | |||
909 | 916 | ||
910 | if (GNUNET_YES == session->peers_blacklisted[other_idx]) | 917 | if (GNUNET_YES == session->peers_blacklisted[other_idx]) |
911 | { | 918 | { |
912 | /* We should have never started or commited to an operation | 919 | /* Peer might have been blacklisted |
913 | with a blacklisted peer. */ | 920 | by a gradecast running in parallel, ignore elements from now */ |
914 | GNUNET_break (0); | 921 | if (GNUNET_SET_STATUS_ADD_LOCAL == status) |
915 | return; | 922 | return; |
923 | if (GNUNET_SET_STATUS_ADD_REMOTE == status) | ||
924 | return; | ||
916 | } | 925 | } |
917 | 926 | ||
918 | if ( (GNUNET_SET_STATUS_ADD_LOCAL == status) || (GNUNET_SET_STATUS_ADD_REMOTE == status) ) | 927 | if ( (GNUNET_SET_STATUS_ADD_LOCAL == status) || (GNUNET_SET_STATUS_ADD_REMOTE == status) ) |
@@ -1036,7 +1045,8 @@ set_result_cb (void *cls, | |||
1036 | break; | 1045 | break; |
1037 | case GNUNET_SET_STATUS_FAILURE: | 1046 | case GNUNET_SET_STATUS_FAILURE: |
1038 | // XXX: cleanup | 1047 | // XXX: cleanup |
1039 | GNUNET_break (0); | 1048 | GNUNET_break_op (0); |
1049 | finish_task (task); | ||
1040 | return; | 1050 | return; |
1041 | default: | 1051 | default: |
1042 | /* not reached */ | 1052 | /* not reached */ |
@@ -1201,7 +1211,17 @@ commit_set (struct ConsensusSession *session, | |||
1201 | element.element_type = ELEMENT_TYPE_CONTESTED_MARKER; | 1211 | element.element_type = ELEMENT_TYPE_CONTESTED_MARKER; |
1202 | GNUNET_SET_add_element (set->h, &element, NULL, NULL); | 1212 | GNUNET_SET_add_element (set->h, &element, NULL, NULL); |
1203 | } | 1213 | } |
1204 | GNUNET_SET_commit (setop->op, set->h); | 1214 | if (GNUNET_NO == session->peers_blacklisted[task_other_peer (task)]) |
1215 | { | ||
1216 | GNUNET_SET_commit (setop->op, set->h); | ||
1217 | } | ||
1218 | else | ||
1219 | { | ||
1220 | /* For our testcases, we don't want the blacklisted | ||
1221 | peers to wait. */ | ||
1222 | GNUNET_SET_operation_cancel (setop->op); | ||
1223 | setop->op = NULL; | ||
1224 | } | ||
1205 | #endif | 1225 | #endif |
1206 | } | 1226 | } |
1207 | 1227 | ||
@@ -1338,6 +1358,7 @@ rfn_create (uint16_t size) | |||
1338 | rfn = GNUNET_new (struct ReferendumEntry); | 1358 | rfn = GNUNET_new (struct ReferendumEntry); |
1339 | rfn->rfn_elements = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | 1359 | rfn->rfn_elements = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); |
1340 | rfn->peer_commited = GNUNET_new_array (size, int); | 1360 | rfn->peer_commited = GNUNET_new_array (size, int); |
1361 | rfn->peer_contested = GNUNET_new_array (size, int); | ||
1341 | rfn->num_peers = size; | 1362 | rfn->num_peers = size; |
1342 | 1363 | ||
1343 | return rfn; | 1364 | return rfn; |
@@ -1615,6 +1636,19 @@ task_start_grade (struct TaskEntry *task) | |||
1615 | } | 1636 | } |
1616 | } | 1637 | } |
1617 | 1638 | ||
1639 | { | ||
1640 | uint16_t noncontested; | ||
1641 | noncontested = rfn_noncontested (input_rfn); | ||
1642 | if (noncontested < (session->num_peers / 3) * 2) | ||
1643 | { | ||
1644 | gradecast_confidence = GNUNET_MIN(1, gradecast_confidence); | ||
1645 | } | ||
1646 | if (noncontested < (session->num_peers / 3) + 1) | ||
1647 | { | ||
1648 | gradecast_confidence = 0; | ||
1649 | } | ||
1650 | } | ||
1651 | |||
1618 | if (gradecast_confidence >= 1) | 1652 | if (gradecast_confidence >= 1) |
1619 | rfn_commit (output_rfn, task->key.leader); | 1653 | rfn_commit (output_rfn, task->key.leader); |
1620 | 1654 | ||