aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2020-08-31 09:24:07 +0200
committert3sserakt <t3ss@posteo.de>2020-08-31 09:30:46 +0200
commit4887fa044a7792d367b0cf9d48b3d6d3b0adfd17 (patch)
tree97f19bff30d18d52b61cc84483059f64fa225c9d
parent72cb328c689aacf5a20a0107e5762c1749ea2886 (diff)
parent38e90f057952ed81492d6ee3db0bc87cef9e4207 (diff)
downloadgnunet-4887fa044a7792d367b0cf9d48b3d6d3b0adfd17.tar.gz
gnunet-4887fa044a7792d367b0cf9d48b3d6d3b0adfd17.zip
Merge branch 'master' of ssh://gnunet.org/gnunet
-rw-r--r--src/consensus/consensus_protocol.h1
-rw-r--r--src/consensus/gnunet-service-consensus.c552
-rw-r--r--src/consensus/plugin_block_consensus.c13
-rw-r--r--src/include/gnunet_crypto_lib.h2
-rw-r--r--src/util/crypto_hash.c2
5 files changed, 295 insertions, 275 deletions
diff --git a/src/consensus/consensus_protocol.h b/src/consensus/consensus_protocol.h
index a40162fb8..0afd56b27 100644
--- a/src/consensus/consensus_protocol.h
+++ b/src/consensus/consensus_protocol.h
@@ -124,6 +124,7 @@ struct ConsensusSizeElement
124 uint8_t sender_index; 124 uint8_t sender_index;
125}; 125};
126 126
127
127struct ConsensusStuffedElement 128struct ConsensusStuffedElement
128{ 129{
129 struct ConsensusElement ce; 130 struct ConsensusElement ce;
diff --git a/src/consensus/gnunet-service-consensus.c b/src/consensus/gnunet-service-consensus.c
index 13fa0d0e7..371b7f67f 100644
--- a/src/consensus/gnunet-service-consensus.c
+++ b/src/consensus/gnunet-service-consensus.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2012, 2013, 2017 GNUnet e.V. 3 Copyright (C) 2012, 2013, 2017, 2020 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -17,13 +17,11 @@
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20
21/** 20/**
22 * @file consensus/gnunet-service-consensus.c 21 * @file consensus/gnunet-service-consensus.c
23 * @brief multi-peer set reconciliation 22 * @brief multi-peer set reconciliation
24 * @author Florian Dold <flo@dold.me> 23 * @author Florian Dold <flo@dold.me>
25 */ 24 */
26
27#include "platform.h" 25#include "platform.h"
28#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
29#include "gnunet_block_lib.h" 27#include "gnunet_block_lib.h"
@@ -62,11 +60,57 @@ enum EarlyStoppingPhase
62}; 60};
63 61
64 62
63enum PhaseKind
64{
65 PHASE_KIND_ALL_TO_ALL,
66 PHASE_KIND_ALL_TO_ALL_2,
67 PHASE_KIND_GRADECAST_LEADER,
68 PHASE_KIND_GRADECAST_ECHO,
69 PHASE_KIND_GRADECAST_ECHO_GRADE,
70 PHASE_KIND_GRADECAST_CONFIRM,
71 PHASE_KIND_GRADECAST_CONFIRM_GRADE,
72 /**
73 * Apply a repetition of the all-to-all
74 * gradecast to the current set.
75 */
76 PHASE_KIND_APPLY_REP,
77 PHASE_KIND_FINISH,
78};
79
80
81enum SetKind
82{
83 SET_KIND_NONE = 0,
84 SET_KIND_CURRENT,
85 /**
86 * Last result set from a gradecast
87 */
88 SET_KIND_LAST_GRADECAST,
89 SET_KIND_LEADER_PROPOSAL,
90 SET_KIND_ECHO_RESULT,
91};
92
93enum DiffKind
94{
95 DIFF_KIND_NONE = 0,
96 DIFF_KIND_LEADER_PROPOSAL,
97 DIFF_KIND_LEADER_CONSENSUS,
98 DIFF_KIND_GRADECAST_RESULT,
99};
100
101enum RfnKind
102{
103 RFN_KIND_NONE = 0,
104 RFN_KIND_ECHO,
105 RFN_KIND_CONFIRM,
106 RFN_KIND_GRADECAST_RESULT
107};
108
109
65GNUNET_NETWORK_STRUCT_BEGIN 110GNUNET_NETWORK_STRUCT_BEGIN
66 111
67/** 112/**
68 * Tuple of integers that together 113 * Tuple of integers that together identify a task uniquely.
69 * identify a task uniquely.
70 */ 114 */
71struct TaskKey 115struct TaskKey
72{ 116{
@@ -102,8 +146,14 @@ struct TaskKey
102 146
103struct SetKey 147struct SetKey
104{ 148{
105 int set_kind GNUNET_PACKED; 149 enum SetKind set_kind GNUNET_PACKED;
150 /**
151 * Repetition counter.
152 */
106 int k1 GNUNET_PACKED; 153 int k1 GNUNET_PACKED;
154 /**
155 * Leader (or 0).
156 */
107 int k2 GNUNET_PACKED; 157 int k2 GNUNET_PACKED;
108}; 158};
109 159
@@ -112,9 +162,9 @@ struct SetEntry
112{ 162{
113 struct SetKey key; 163 struct SetKey key;
114 struct GNUNET_SET_Handle *h; 164 struct GNUNET_SET_Handle *h;
165
115 /** 166 /**
116 * GNUNET_YES if the set resulted 167 * #GNUNET_YES if the set resulted from applying a referendum with contested
117 * from applying a referendum with contested
118 * elements. 168 * elements.
119 */ 169 */
120 int is_contested; 170 int is_contested;
@@ -123,14 +173,16 @@ struct SetEntry
123 173
124struct DiffKey 174struct DiffKey
125{ 175{
126 int diff_kind GNUNET_PACKED; 176 enum DiffKind diff_kind GNUNET_PACKED;
177
127 int k1 GNUNET_PACKED; 178 int k1 GNUNET_PACKED;
179
128 int k2 GNUNET_PACKED; 180 int k2 GNUNET_PACKED;
129}; 181};
130 182
131struct RfnKey 183struct RfnKey
132{ 184{
133 int rfn_kind GNUNET_PACKED; 185 enum RfnKind rfn_kind GNUNET_PACKED;
134 int k1 GNUNET_PACKED; 186 int k1 GNUNET_PACKED;
135 int k2 GNUNET_PACKED; 187 int k2 GNUNET_PACKED;
136}; 188};
@@ -138,52 +190,6 @@ struct RfnKey
138 190
139GNUNET_NETWORK_STRUCT_END 191GNUNET_NETWORK_STRUCT_END
140 192
141enum PhaseKind
142{
143 PHASE_KIND_ALL_TO_ALL,
144 PHASE_KIND_ALL_TO_ALL_2,
145 PHASE_KIND_GRADECAST_LEADER,
146 PHASE_KIND_GRADECAST_ECHO,
147 PHASE_KIND_GRADECAST_ECHO_GRADE,
148 PHASE_KIND_GRADECAST_CONFIRM,
149 PHASE_KIND_GRADECAST_CONFIRM_GRADE,
150 /**
151 * Apply a repetition of the all-to-all
152 * gradecast to the current set.
153 */
154 PHASE_KIND_APPLY_REP,
155 PHASE_KIND_FINISH,
156};
157
158
159enum SetKind
160{
161 SET_KIND_NONE = 0,
162 SET_KIND_CURRENT,
163 /**
164 * Last result set from a gradecast
165 */
166 SET_KIND_LAST_GRADECAST,
167 SET_KIND_LEADER_PROPOSAL,
168 SET_KIND_ECHO_RESULT,
169};
170
171enum DiffKind
172{
173 DIFF_KIND_NONE = 0,
174 DIFF_KIND_LEADER_PROPOSAL,
175 DIFF_KIND_LEADER_CONSENSUS,
176 DIFF_KIND_GRADECAST_RESULT,
177};
178
179enum RfnKind
180{
181 RFN_KIND_NONE = 0,
182 RFN_KIND_ECHO,
183 RFN_KIND_CONFIRM,
184 RFN_KIND_GRADECAST_RESULT
185};
186
187 193
188struct SetOpCls 194struct SetOpCls
189{ 195{
@@ -216,9 +222,13 @@ union TaskFuncCls
216 struct FinishCls finish; 222 struct FinishCls finish;
217}; 223};
218 224
225
219struct TaskEntry; 226struct TaskEntry;
220 227
221typedef void (*TaskFunc) (struct TaskEntry *task); 228
229typedef void
230(*TaskFunc) (struct TaskEntry *task);
231
222 232
223/* 233/*
224 * Node in the consensus task graph. 234 * Node in the consensus task graph.
@@ -277,14 +287,12 @@ struct Step
277 unsigned int subordinates_cap; 287 unsigned int subordinates_cap;
278 288
279 /** 289 /**
280 * Counter for the prerequisites of 290 * Counter for the prerequisites of this step.
281 * this step.
282 */ 291 */
283 size_t pending_prereq; 292 size_t pending_prereq;
284 293
285 /* 294 /**
286 * Task that will run this step despite 295 * Task that will run this step despite any pending prerequisites.
287 * any pending prerequisites.
288 */ 296 */
289 struct GNUNET_SCHEDULER_Task *timeout_task; 297 struct GNUNET_SCHEDULER_Task *timeout_task;
290 298
@@ -292,28 +300,23 @@ struct Step
292 300
293 unsigned int is_finished; 301 unsigned int is_finished;
294 302
295 /* 303 /**
296 * Synchrony round of the task. 304 * Synchrony round of the task. Determines the deadline for the task.
297 * Determines the deadline for the task.
298 */ 305 */
299 unsigned int round; 306 unsigned int round;
300 307
301 /** 308 /**
302 * Human-readable name for 309 * Human-readable name for the task, used for debugging.
303 * the task, used for debugging.
304 */ 310 */
305 char *debug_name; 311 char *debug_name;
306 312
307 /** 313 /**
308 * When we're doing an early finish, how should this step be 314 * When we're doing an early finish, how should this step be treated? If
309 * treated? 315 * #GNUNET_YES, the step will be marked as finished without actually running
310 * If GNUNET_YES, the step will be marked as finished 316 * its tasks. Otherwise, the step will still be run even after an early
311 * without actually running its tasks. 317 * finish.
312 * Otherwise, the step will still be run even after
313 * an early finish.
314 * 318 *
315 * Note that a task may never be finished early if 319 * Note that a task may never be finished early if it is already running.
316 * it is already running.
317 */ 320 */
318 int early_finishable; 321 int early_finishable;
319}; 322};
@@ -323,14 +326,13 @@ struct RfnElementInfo
323{ 326{
324 const struct GNUNET_SET_Element *element; 327 const struct GNUNET_SET_Element *element;
325 328
326 /* 329 /**
327 * GNUNET_YES if the peer votes for the proposal. 330 * #GNUNET_YES if the peer votes for the proposal.
328 */ 331 */
329 int *votes; 332 int *votes;
330 333
331 /** 334 /**
332 * Proposal for this element, 335 * Proposal for this element, can only be #VOTE_ADD or #VOTE_REMOVE.
333 * can only be VOTE_ADD or VOTE_REMOVE.
334 */ 336 */
335 enum ReferendumVote proposal; 337 enum ReferendumVote proposal;
336}; 338};
@@ -638,7 +640,7 @@ debug_str_element (const struct GNUNET_SET_Element *el)
638 640
639 641
640static const char * 642static const char *
641debug_str_task_key (struct TaskKey *tk) 643debug_str_task_key (const struct TaskKey *tk)
642{ 644{
643 static char buf[256]; 645 static char buf[256];
644 646
@@ -652,7 +654,7 @@ debug_str_task_key (struct TaskKey *tk)
652 654
653 655
654static const char * 656static const char *
655debug_str_diff_key (struct DiffKey *dk) 657debug_str_diff_key (const struct DiffKey *dk)
656{ 658{
657 static char buf[256]; 659 static char buf[256];
658 660
@@ -671,8 +673,9 @@ debug_str_set_key (const struct SetKey *sk)
671 673
672 snprintf (buf, sizeof(buf), 674 snprintf (buf, sizeof(buf),
673 "SetKey kind=%s, k1=%d, k2=%d", 675 "SetKey kind=%s, k1=%d, k2=%d",
674 setname (sk->set_kind), sk->k1, sk->k2); 676 setname (sk->set_kind),
675 677 sk->k1,
678 sk->k2);
676 return buf; 679 return buf;
677} 680}
678 681
@@ -684,8 +687,9 @@ debug_str_rfn_key (const struct RfnKey *rk)
684 687
685 snprintf (buf, sizeof(buf), 688 snprintf (buf, sizeof(buf),
686 "RfnKey kind=%s, k1=%d, k2=%d", 689 "RfnKey kind=%s, k1=%d, k2=%d",
687 rfnname (rk->rfn_kind), rk->k1, rk->k2); 690 rfnname (rk->rfn_kind),
688 691 rk->k1,
692 rk->k2);
689 return buf; 693 return buf;
690} 694}
691 695
@@ -730,13 +734,15 @@ send_to_client_iter (void *cls,
730 session->local_peer_idx, 734 session->local_peer_idx,
731 debug_str_element (element)); 735 debug_str_element (element));
732 736
733 ev = GNUNET_MQ_msg_extra (m, element->size - sizeof(struct 737 ev = GNUNET_MQ_msg_extra (m,
734 ConsensusElement), 738 element->size - sizeof(struct ConsensusElement),
735 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT); 739 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT);
736 m->element_type = ce->payload_type; 740 m->element_type = ce->payload_type;
737 GNUNET_memcpy (&m[1], &ce[1], element->size - sizeof(struct 741 GNUNET_memcpy (&m[1],
738 ConsensusElement)); 742 &ce[1],
739 GNUNET_MQ_send (session->client_mq, ev); 743 element->size - sizeof(struct ConsensusElement));
744 GNUNET_MQ_send (session->client_mq,
745 ev);
740 } 746 }
741 else 747 else
742 { 748 {
@@ -745,14 +751,16 @@ send_to_client_iter (void *cls,
745 session->local_peer_idx); 751 session->local_peer_idx);
746 ev = GNUNET_MQ_msg_header ( 752 ev = GNUNET_MQ_msg_header (
747 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE_DONE); 753 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE_DONE);
748 GNUNET_MQ_send (session->client_mq, ev); 754 GNUNET_MQ_send (session->client_mq,
755 ev);
749 } 756 }
750 return GNUNET_YES; 757 return GNUNET_YES;
751} 758}
752 759
753 760
754static struct SetEntry * 761static struct SetEntry *
755lookup_set (struct ConsensusSession *session, struct SetKey *key) 762lookup_set (struct ConsensusSession *session,
763 const struct SetKey *key)
756{ 764{
757 struct GNUNET_HashCode hash; 765 struct GNUNET_HashCode hash;
758 766
@@ -762,13 +770,17 @@ lookup_set (struct ConsensusSession *session, struct SetKey *key)
762 debug_str_set_key (key)); 770 debug_str_set_key (key));
763 771
764 GNUNET_assert (SET_KIND_NONE != key->set_kind); 772 GNUNET_assert (SET_KIND_NONE != key->set_kind);
765 GNUNET_CRYPTO_hash (key, sizeof(struct SetKey), &hash); 773 GNUNET_CRYPTO_hash (key,
766 return GNUNET_CONTAINER_multihashmap_get (session->setmap, &hash); 774 sizeof(struct SetKey),
775 &hash);
776 return GNUNET_CONTAINER_multihashmap_get (session->setmap,
777 &hash);
767} 778}
768 779
769 780
770static struct DiffEntry * 781static struct DiffEntry *
771lookup_diff (struct ConsensusSession *session, struct DiffKey *key) 782lookup_diff (struct ConsensusSession *session,
783 const struct DiffKey *key)
772{ 784{
773 struct GNUNET_HashCode hash; 785 struct GNUNET_HashCode hash;
774 786
@@ -776,15 +788,18 @@ lookup_diff (struct ConsensusSession *session, struct DiffKey *key)
776 "P%u: looking up diff {%s}\n", 788 "P%u: looking up diff {%s}\n",
777 session->local_peer_idx, 789 session->local_peer_idx,
778 debug_str_diff_key (key)); 790 debug_str_diff_key (key));
779
780 GNUNET_assert (DIFF_KIND_NONE != key->diff_kind); 791 GNUNET_assert (DIFF_KIND_NONE != key->diff_kind);
781 GNUNET_CRYPTO_hash (key, sizeof(struct DiffKey), &hash); 792 GNUNET_CRYPTO_hash (key,
782 return GNUNET_CONTAINER_multihashmap_get (session->diffmap, &hash); 793 sizeof(struct DiffKey),
794 &hash);
795 return GNUNET_CONTAINER_multihashmap_get (session->diffmap,
796 &hash);
783} 797}
784 798
785 799
786static struct ReferendumEntry * 800static struct ReferendumEntry *
787lookup_rfn (struct ConsensusSession *session, struct RfnKey *key) 801lookup_rfn (struct ConsensusSession *session,
802 const struct RfnKey *key)
788{ 803{
789 struct GNUNET_HashCode hash; 804 struct GNUNET_HashCode hash;
790 805
@@ -792,10 +807,12 @@ lookup_rfn (struct ConsensusSession *session, struct RfnKey *key)
792 "P%u: looking up rfn {%s}\n", 807 "P%u: looking up rfn {%s}\n",
793 session->local_peer_idx, 808 session->local_peer_idx,
794 debug_str_rfn_key (key)); 809 debug_str_rfn_key (key));
795
796 GNUNET_assert (RFN_KIND_NONE != key->rfn_kind); 810 GNUNET_assert (RFN_KIND_NONE != key->rfn_kind);
797 GNUNET_CRYPTO_hash (key, sizeof(struct RfnKey), &hash); 811 GNUNET_CRYPTO_hash (key,
798 return GNUNET_CONTAINER_multihashmap_get (session->rfnmap, &hash); 812 sizeof(struct RfnKey),
813 &hash);
814 return GNUNET_CONTAINER_multihashmap_get (session->rfnmap,
815 &hash);
799} 816}
800 817
801 818
@@ -829,7 +846,8 @@ diff_insert (struct DiffEntry *diff,
829 di->element = GNUNET_SET_element_dup (element); 846 di->element = GNUNET_SET_element_dup (element);
830 GNUNET_assert (GNUNET_OK == 847 GNUNET_assert (GNUNET_OK ==
831 GNUNET_CONTAINER_multihashmap_put (diff->changes, 848 GNUNET_CONTAINER_multihashmap_put (diff->changes,
832 &hash, di, 849 &hash,
850 di,
833 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 851 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
834 } 852 }
835 853
@@ -860,11 +878,10 @@ rfn_contest (struct ReferendumEntry *rfn,
860static uint16_t 878static uint16_t
861rfn_noncontested (struct ReferendumEntry *rfn) 879rfn_noncontested (struct ReferendumEntry *rfn)
862{ 880{
863 uint16_t i;
864 uint16_t ret; 881 uint16_t ret;
865 882
866 ret = 0; 883 ret = 0;
867 for (i = 0; i < rfn->num_peers; i++) 884 for (uint16_t i = 0; i < rfn->num_peers; i++)
868 if ((GNUNET_YES == rfn->peer_commited[i]) && (GNUNET_NO == 885 if ((GNUNET_YES == rfn->peer_commited[i]) && (GNUNET_NO ==
869 rfn->peer_contested[i])) 886 rfn->peer_contested[i]))
870 ret++; 887 ret++;
@@ -993,7 +1010,8 @@ set_result_cb (void *cls,
993 1010
994 if (SET_KIND_NONE != setop->output_set.set_kind) 1011 if (SET_KIND_NONE != setop->output_set.set_kind)
995 { 1012 {
996 output_set = lookup_set (session, &setop->output_set); 1013 output_set = lookup_set (session,
1014 &setop->output_set);
997 GNUNET_assert (NULL != output_set); 1015 GNUNET_assert (NULL != output_set);
998 } 1016 }
999 1017
@@ -1226,8 +1244,8 @@ struct Evilness
1226 1244
1227 1245
1228static int 1246static int
1229parse_evilness_cram_subtype (const char *evil_subtype_str, struct 1247parse_evilness_cram_subtype (const char *evil_subtype_str,
1230 Evilness *evil) 1248 struct Evilness *evil)
1231{ 1249{
1232 if (0 == strcmp ("replace", evil_subtype_str)) 1250 if (0 == strcmp ("replace", evil_subtype_str))
1233 { 1251 {
@@ -1360,8 +1378,7 @@ cleanup:
1360 1378
1361 1379
1362/** 1380/**
1363 * Commit the appropriate set for a 1381 * Commit the appropriate set for a task.
1364 * task.
1365 */ 1382 */
1366static void 1383static void
1367commit_set (struct ConsensusSession *session, 1384commit_set (struct ConsensusSession *session,
@@ -1379,6 +1396,7 @@ commit_set (struct ConsensusSession *session,
1379 { 1396 {
1380 struct GNUNET_SET_Element element; 1397 struct GNUNET_SET_Element element;
1381 struct ConsensusElement ce = { 0 }; 1398 struct ConsensusElement ce = { 0 };
1399
1382 ce.marker = CONSENSUS_MARKER_CONTESTED; 1400 ce.marker = CONSENSUS_MARKER_CONTESTED;
1383 element.data = &ce; 1401 element.data = &ce;
1384 element.size = sizeof(struct ConsensusElement); 1402 element.size = sizeof(struct ConsensusElement);
@@ -1405,7 +1423,6 @@ commit_set (struct ConsensusSession *session,
1405 1423
1406#ifdef EVIL 1424#ifdef EVIL
1407 { 1425 {
1408 unsigned int i;
1409 struct Evilness evil; 1426 struct Evilness evil;
1410 1427
1411 get_evilness (session, &evil); 1428 get_evilness (session, &evil);
@@ -1444,7 +1461,7 @@ commit_set (struct ConsensusSession *session,
1444 GNUNET_SET_commit (setop->op, set->h); 1461 GNUNET_SET_commit (setop->op, set->h);
1445 break; 1462 break;
1446 } 1463 }
1447 for (i = 0; i < evil.num; i++) 1464 for (unsigned int i = 0; i < evil.num; i++)
1448 { 1465 {
1449 struct GNUNET_SET_Element element; 1466 struct GNUNET_SET_Element element;
1450 struct ConsensusStuffedElement se = { 1467 struct ConsensusStuffedElement se = {
@@ -1504,12 +1521,14 @@ commit_set (struct ConsensusSession *session,
1504 } 1521 }
1505 else 1522 else
1506 { 1523 {
1507 GNUNET_SET_commit (setop->op, set->h); 1524 GNUNET_SET_commit (setop->op,
1525 set->h);
1508 } 1526 }
1509 break; 1527 break;
1510 1528
1511 case EVILNESS_NONE: 1529 case EVILNESS_NONE:
1512 GNUNET_SET_commit (setop->op, set->h); 1530 GNUNET_SET_commit (setop->op,
1531 set->h);
1513 break; 1532 break;
1514 } 1533 }
1515 } 1534 }
@@ -1536,11 +1555,12 @@ put_diff (struct ConsensusSession *session,
1536{ 1555{
1537 struct GNUNET_HashCode hash; 1556 struct GNUNET_HashCode hash;
1538 1557
1539 GNUNET_assert (NULL != diff); 1558 GNUNET_CRYPTO_hash (&diff->key,
1540 1559 sizeof(struct DiffKey),
1541 GNUNET_CRYPTO_hash (&diff->key, sizeof(struct DiffKey), &hash); 1560 &hash);
1542 GNUNET_assert (GNUNET_OK == 1561 GNUNET_assert (GNUNET_OK ==
1543 GNUNET_CONTAINER_multihashmap_put (session->diffmap, &hash, 1562 GNUNET_CONTAINER_multihashmap_put (session->diffmap,
1563 &hash,
1544 diff, 1564 diff,
1545 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1565 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1546} 1566}
@@ -1553,14 +1573,16 @@ put_set (struct ConsensusSession *session,
1553 struct GNUNET_HashCode hash; 1573 struct GNUNET_HashCode hash;
1554 1574
1555 GNUNET_assert (NULL != set->h); 1575 GNUNET_assert (NULL != set->h);
1556
1557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1576 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1558 "Putting set %s\n", 1577 "Putting set %s\n",
1559 debug_str_set_key (&set->key)); 1578 debug_str_set_key (&set->key));
1560 1579 GNUNET_CRYPTO_hash (&set->key,
1561 GNUNET_CRYPTO_hash (&set->key, sizeof(struct SetKey), &hash); 1580 sizeof(struct SetKey),
1581 &hash);
1562 GNUNET_assert (GNUNET_SYSERR != 1582 GNUNET_assert (GNUNET_SYSERR !=
1563 GNUNET_CONTAINER_multihashmap_put (session->setmap, &hash, set, 1583 GNUNET_CONTAINER_multihashmap_put (session->setmap,
1584 &hash,
1585 set,
1564 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); 1586 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
1565} 1587}
1566 1588
@@ -1573,7 +1595,9 @@ put_rfn (struct ConsensusSession *session,
1573 1595
1574 GNUNET_CRYPTO_hash (&rfn->key, sizeof(struct RfnKey), &hash); 1596 GNUNET_CRYPTO_hash (&rfn->key, sizeof(struct RfnKey), &hash);
1575 GNUNET_assert (GNUNET_OK == 1597 GNUNET_assert (GNUNET_OK ==
1576 GNUNET_CONTAINER_multihashmap_put (session->rfnmap, &hash, rfn, 1598 GNUNET_CONTAINER_multihashmap_put (session->rfnmap,
1599 &hash,
1600 rfn,
1577 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1601 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1578} 1602}
1579 1603
@@ -1616,18 +1640,20 @@ apply_diff_to_rfn (struct DiffEntry *diff,
1616} 1640}
1617 1641
1618 1642
1619struct DiffEntry * 1643static struct DiffEntry *
1620diff_create () 1644diff_create (void)
1621{ 1645{
1622 struct DiffEntry *d = GNUNET_new (struct DiffEntry); 1646 struct DiffEntry *d = GNUNET_new (struct DiffEntry);
1623 1647
1624 d->changes = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); 1648 d->changes = GNUNET_CONTAINER_multihashmap_create (8,
1649 GNUNET_NO);
1625 1650
1626 return d; 1651 return d;
1627} 1652}
1628 1653
1629 1654
1630struct DiffEntry * 1655#if 0
1656static struct DiffEntry *
1631diff_compose (struct DiffEntry *diff_1, 1657diff_compose (struct DiffEntry *diff_1,
1632 struct DiffEntry *diff_2) 1658 struct DiffEntry *diff_2)
1633{ 1659{
@@ -1638,22 +1664,26 @@ diff_compose (struct DiffEntry *diff_1,
1638 diff_new = diff_create (); 1664 diff_new = diff_create ();
1639 1665
1640 iter = GNUNET_CONTAINER_multihashmap_iterator_create (diff_1->changes); 1666 iter = GNUNET_CONTAINER_multihashmap_iterator_create (diff_1->changes);
1641 while (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next (iter, NULL, 1667 while (GNUNET_YES ==
1642 (const 1668 GNUNET_CONTAINER_multihashmap_iterator_next (iter,
1643 void **) & 1669 NULL,
1644 di)) 1670 (const void **) &di))
1645 { 1671 {
1646 diff_insert (diff_new, di->weight, di->element); 1672 diff_insert (diff_new,
1673 di->weight,
1674 di->element);
1647 } 1675 }
1648 GNUNET_CONTAINER_multihashmap_iterator_destroy (iter); 1676 GNUNET_CONTAINER_multihashmap_iterator_destroy (iter);
1649 1677
1650 iter = GNUNET_CONTAINER_multihashmap_iterator_create (diff_2->changes); 1678 iter = GNUNET_CONTAINER_multihashmap_iterator_create (diff_2->changes);
1651 while (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next (iter, NULL, 1679 while (GNUNET_YES ==
1652 (const 1680 GNUNET_CONTAINER_multihashmap_iterator_next (iter,
1653 void **) & 1681 NULL,
1654 di)) 1682 (const void **) &di))
1655 { 1683 {
1656 diff_insert (diff_new, di->weight, di->element); 1684 diff_insert (diff_new,
1685 di->weight,
1686 di->element);
1657 } 1687 }
1658 GNUNET_CONTAINER_multihashmap_iterator_destroy (iter); 1688 GNUNET_CONTAINER_multihashmap_iterator_destroy (iter);
1659 1689
@@ -1661,6 +1691,9 @@ diff_compose (struct DiffEntry *diff_1,
1661} 1691}
1662 1692
1663 1693
1694#endif
1695
1696
1664struct ReferendumEntry * 1697struct ReferendumEntry *
1665rfn_create (uint16_t size) 1698rfn_create (uint16_t size)
1666{ 1699{
@@ -1701,14 +1734,13 @@ rfn_majority (const struct ReferendumEntry *rfn,
1701{ 1734{
1702 uint16_t votes_yes = 0; 1735 uint16_t votes_yes = 0;
1703 uint16_t num_commited = 0; 1736 uint16_t num_commited = 0;
1704 uint16_t i;
1705 1737
1706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1707 "Computing rfn majority for element %s of rfn {%s}\n", 1739 "Computing rfn majority for element %s of rfn {%s}\n",
1708 debug_str_element (ri->element), 1740 debug_str_element (ri->element),
1709 debug_str_rfn_key (&rfn->key)); 1741 debug_str_rfn_key (&rfn->key));
1710 1742
1711 for (i = 0; i < rfn->num_peers; i++) 1743 for (uint16_t i = 0; i < rfn->num_peers; i++)
1712 { 1744 {
1713 if (GNUNET_NO == rfn->peer_commited[i]) 1745 if (GNUNET_NO == rfn->peer_commited[i])
1714 continue; 1746 continue;
@@ -1739,7 +1771,8 @@ struct SetCopyCls
1739 1771
1740 1772
1741static void 1773static void
1742set_copy_cb (void *cls, struct GNUNET_SET_Handle *copy) 1774set_copy_cb (void *cls,
1775 struct GNUNET_SET_Handle *copy)
1743{ 1776{
1744 struct SetCopyCls *scc = cls; 1777 struct SetCopyCls *scc = cls;
1745 struct TaskEntry *task = scc->task; 1778 struct TaskEntry *task = scc->task;
@@ -1821,8 +1854,6 @@ set_mutation_done (void *cls)
1821static void 1854static void
1822try_finish_step_early (struct Step *step) 1855try_finish_step_early (struct Step *step)
1823{ 1856{
1824 unsigned int i;
1825
1826 if (GNUNET_YES == step->is_running) 1857 if (GNUNET_YES == step->is_running)
1827 return; 1858 return;
1828 if (GNUNET_YES == step->is_finished) 1859 if (GNUNET_YES == step->is_finished)
@@ -1838,7 +1869,7 @@ try_finish_step_early (struct Step *step)
1838 step->debug_name); 1869 step->debug_name);
1839#endif 1870#endif
1840 1871
1841 for (i = 0; i < step->subordinates_len; i++) 1872 for (unsigned int i = 0; i < step->subordinates_len; i++)
1842 { 1873 {
1843 GNUNET_assert (step->subordinates[i]->pending_prereq > 0); 1874 GNUNET_assert (step->subordinates[i]->pending_prereq > 0);
1844 step->subordinates[i]->pending_prereq--; 1875 step->subordinates[i]->pending_prereq--;
@@ -1859,8 +1890,6 @@ try_finish_step_early (struct Step *step)
1859static void 1890static void
1860finish_step (struct Step *step) 1891finish_step (struct Step *step)
1861{ 1892{
1862 unsigned int i;
1863
1864 GNUNET_assert (step->finished_tasks == step->tasks_len); 1893 GNUNET_assert (step->finished_tasks == step->tasks_len);
1865 GNUNET_assert (GNUNET_YES == step->is_running); 1894 GNUNET_assert (GNUNET_YES == step->is_running);
1866 GNUNET_assert (GNUNET_NO == step->is_finished); 1895 GNUNET_assert (GNUNET_NO == step->is_finished);
@@ -1872,7 +1901,7 @@ finish_step (struct Step *step)
1872 step->subordinates_len); 1901 step->subordinates_len);
1873#endif 1902#endif
1874 1903
1875 for (i = 0; i < step->subordinates_len; i++) 1904 for (unsigned int i = 0; i < step->subordinates_len; i++)
1876 { 1905 {
1877 GNUNET_assert (step->subordinates[i]->pending_prereq > 0); 1906 GNUNET_assert (step->subordinates[i]->pending_prereq > 0);
1878 step->subordinates[i]->pending_prereq--; 1907 step->subordinates[i]->pending_prereq--;
@@ -1918,7 +1947,9 @@ task_start_apply_round (struct TaskEntry *task)
1918 set_out = lookup_set (session, &sk_out); 1947 set_out = lookup_set (session, &sk_out);
1919 if (NULL == set_out) 1948 if (NULL == set_out)
1920 { 1949 {
1921 create_set_copy_for_task (task, &sk_in, &sk_out); 1950 create_set_copy_for_task (task,
1951 &sk_in,
1952 &sk_out);
1922 return; 1953 return;
1923 } 1954 }
1924 1955
@@ -2162,7 +2193,9 @@ task_start_reconcile (struct TaskEntry *task)
2162 we clone the input set. */ 2193 we clone the input set. */
2163 if (NULL == lookup_set (session, &setop->output_set)) 2194 if (NULL == lookup_set (session, &setop->output_set))
2164 { 2195 {
2165 create_set_copy_for_task (task, &setop->input_set, &setop->output_set); 2196 create_set_copy_for_task (task,
2197 &setop->input_set,
2198 &setop->output_set);
2166 return; 2199 return;
2167 } 2200 }
2168 } 2201 }
@@ -2212,11 +2245,8 @@ task_start_reconcile (struct TaskEntry *task)
2212 "P%u: Looking up set {%s} to run remote union\n", 2245 "P%u: Looking up set {%s} to run remote union\n",
2213 session->local_peer_idx, 2246 session->local_peer_idx,
2214 debug_str_set_key (&setop->input_set)); 2247 debug_str_set_key (&setop->input_set));
2215
2216 rcm.header.type = htons (GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT); 2248 rcm.header.type = htons (GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT);
2217 rcm.header.size = htons (sizeof(struct 2249 rcm.header.size = htons (sizeof(rcm));
2218 GNUNET_CONSENSUS_RoundContextMessage));
2219
2220 rcm.kind = htons (task->key.kind); 2250 rcm.kind = htons (task->key.kind);
2221 rcm.peer1 = htons (task->key.peer1); 2251 rcm.peer1 = htons (task->key.peer1);
2222 rcm.peer2 = htons (task->key.peer2); 2252 rcm.peer2 = htons (task->key.peer2);
@@ -2227,8 +2257,9 @@ task_start_reconcile (struct TaskEntry *task)
2227 GNUNET_assert (NULL == setop->op); 2257 GNUNET_assert (NULL == setop->op);
2228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2229 "P%u: initiating set op with P%u, our set is %s\n", 2259 "P%u: initiating set op with P%u, our set is %s\n",
2230 session->local_peer_idx, task->key.peer2, debug_str_set_key ( 2260 session->local_peer_idx,
2231 &setop->input_set)); 2261 task->key.peer2,
2262 debug_str_set_key (&setop->input_set));
2232 2263
2233 struct GNUNET_SET_Option opts[] = { 2264 struct GNUNET_SET_Option opts[] = {
2234 { GNUNET_SET_OPTION_BYZANTINE, { .num = session->lower_bound } }, 2265 { GNUNET_SET_OPTION_BYZANTINE, { .num = session->lower_bound } },
@@ -2286,15 +2317,17 @@ task_start_eval_echo (struct TaskEntry *task)
2286 output_set = lookup_set (session, &sk_out); 2317 output_set = lookup_set (session, &sk_out);
2287 if (NULL == output_set) 2318 if (NULL == output_set)
2288 { 2319 {
2289 create_set_copy_for_task (task, &sk_in, &sk_out); 2320 create_set_copy_for_task (task,
2321 &sk_in,
2322 &sk_out);
2290 return; 2323 return;
2291 } 2324 }
2292 2325
2293
2294 { 2326 {
2295 // FIXME: should be marked as a shallow copy, so 2327 // FIXME: should be marked as a shallow copy, so
2296 // we can destroy everything correctly 2328 // we can destroy everything correctly
2297 struct SetEntry *last_set = GNUNET_new (struct SetEntry); 2329 struct SetEntry *last_set = GNUNET_new (struct SetEntry);
2330
2298 last_set->h = output_set->h; 2331 last_set->h = output_set->h;
2299 last_set->key = (struct SetKey) { SET_KIND_LAST_GRADECAST }; 2332 last_set->key = (struct SetKey) { SET_KIND_LAST_GRADECAST };
2300 put_set (session, last_set); 2333 put_set (session, last_set);
@@ -2306,13 +2339,10 @@ task_start_eval_echo (struct TaskEntry *task)
2306 2339
2307 progress_cls = GNUNET_new (struct SetMutationProgressCls); 2340 progress_cls = GNUNET_new (struct SetMutationProgressCls);
2308 progress_cls->task = task; 2341 progress_cls->task = task;
2309
2310 rk_in = (struct RfnKey) { RFN_KIND_ECHO, task->key.repetition, 2342 rk_in = (struct RfnKey) { RFN_KIND_ECHO, task->key.repetition,
2311 task->key.leader }; 2343 task->key.leader };
2312 input_rfn = lookup_rfn (session, &rk_in); 2344 input_rfn = lookup_rfn (session, &rk_in);
2313
2314 GNUNET_assert (NULL != input_rfn); 2345 GNUNET_assert (NULL != input_rfn);
2315
2316 iter = GNUNET_CONTAINER_multihashmap_iterator_create ( 2346 iter = GNUNET_CONTAINER_multihashmap_iterator_create (
2317 input_rfn->rfn_elements); 2347 input_rfn->rfn_elements);
2318 GNUNET_assert (NULL != iter); 2348 GNUNET_assert (NULL != iter);
@@ -2334,7 +2364,8 @@ task_start_eval_echo (struct TaskEntry *task)
2334 can't simply send "nothing" for the value. Thus we mark our 'confirm' 2364 can't simply send "nothing" for the value. Thus we mark our 'confirm'
2335 reconciliation as contested. Other peers might not know that the 2365 reconciliation as contested. Other peers might not know that the
2336 leader is faulty, thus we still re-distribute in the confirmation 2366 leader is faulty, thus we still re-distribute in the confirmation
2337 round. */output_set->is_contested = GNUNET_YES; 2367 round. *///
2368 output_set->is_contested = GNUNET_YES;
2338 } 2369 }
2339 2370
2340 switch (majority_vote) 2371 switch (majority_vote)
@@ -2384,29 +2415,27 @@ task_start_finish (struct TaskEntry *task)
2384 struct SetEntry *final_set; 2415 struct SetEntry *final_set;
2385 struct ConsensusSession *session = task->step->session; 2416 struct ConsensusSession *session = task->step->session;
2386 2417
2387 final_set = lookup_set (session, &task->cls.finish.input_set); 2418 final_set = lookup_set (session,
2388 2419 &task->cls.finish.input_set);
2389 GNUNET_assert (NULL != final_set); 2420 GNUNET_assert (NULL != final_set);
2390
2391
2392 GNUNET_SET_iterate (final_set->h, 2421 GNUNET_SET_iterate (final_set->h,
2393 send_to_client_iter, 2422 &send_to_client_iter,
2394 task); 2423 task);
2395} 2424}
2396 2425
2397 2426
2398static void 2427static void
2399start_task (struct ConsensusSession *session, struct TaskEntry *task) 2428start_task (struct ConsensusSession *session,
2429 struct TaskEntry *task)
2400{ 2430{
2401 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: starting task {%s}\n", 2431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2402 session->local_peer_idx, debug_str_task_key (&task->key)); 2432 "P%u: starting task {%s}\n",
2403 2433 session->local_peer_idx,
2434 debug_str_task_key (&task->key));
2404 GNUNET_assert (GNUNET_NO == task->is_started); 2435 GNUNET_assert (GNUNET_NO == task->is_started);
2405 GNUNET_assert (GNUNET_NO == task->is_finished); 2436 GNUNET_assert (GNUNET_NO == task->is_finished);
2406 GNUNET_assert (NULL != task->start); 2437 GNUNET_assert (NULL != task->start);
2407
2408 task->start (task); 2438 task->start (task);
2409
2410 task->is_started = GNUNET_YES; 2439 task->is_started = GNUNET_YES;
2411} 2440}
2412 2441
@@ -2427,8 +2456,6 @@ run_ready_steps (struct ConsensusSession *session)
2427 if ((GNUNET_NO == step->is_running) && (0 == step->pending_prereq) && 2456 if ((GNUNET_NO == step->is_running) && (0 == step->pending_prereq) &&
2428 (GNUNET_NO == step->is_finished)) 2457 (GNUNET_NO == step->is_finished))
2429 { 2458 {
2430 size_t i;
2431
2432 GNUNET_assert (0 == step->finished_tasks); 2459 GNUNET_assert (0 == step->finished_tasks);
2433 2460
2434#ifdef GNUNET_EXTRA_LOGGING 2461#ifdef GNUNET_EXTRA_LOGGING
@@ -2440,7 +2467,7 @@ run_ready_steps (struct ConsensusSession *session)
2440#endif 2467#endif
2441 2468
2442 step->is_running = GNUNET_YES; 2469 step->is_running = GNUNET_YES;
2443 for (i = 0; i < step->tasks_len; i++) 2470 for (size_t i = 0; i < step->tasks_len; i++)
2444 start_task (session, step->tasks[i]); 2471 start_task (session, step->tasks[i]);
2445 2472
2446 /* Sometimes there is no task to trigger finishing the step, so we have to do it here. */ 2473 /* Sometimes there is no task to trigger finishing the step, so we have to do it here. */
@@ -2463,9 +2490,7 @@ finish_task (struct TaskEntry *task)
2463{ 2490{
2464 GNUNET_assert (GNUNET_NO == task->is_finished); 2491 GNUNET_assert (GNUNET_NO == task->is_finished);
2465 task->is_finished = GNUNET_YES; 2492 task->is_finished = GNUNET_YES;
2466
2467 task->step->finished_tasks++; 2493 task->step->finished_tasks++;
2468
2469 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2494 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2470 "P%u: Finishing Task {%s} (now %u/%u tasks finished in step)\n", 2495 "P%u: Finishing Task {%s} (now %u/%u tasks finished in step)\n",
2471 task->step->session->local_peer_idx, 2496 task->step->session->local_peer_idx,
@@ -2486,12 +2511,10 @@ finish_task (struct TaskEntry *task)
2486 * @return index of peer, -1 if peer is not in session 2511 * @return index of peer, -1 if peer is not in session
2487 */ 2512 */
2488static int 2513static int
2489get_peer_idx (const struct GNUNET_PeerIdentity *peer, const struct 2514get_peer_idx (const struct GNUNET_PeerIdentity *peer,
2490 ConsensusSession *session) 2515 const struct ConsensusSession *session)
2491{ 2516{
2492 int i; 2517 for (int i = 0; i < session->num_peers; i++)
2493
2494 for (i = 0; i < session->num_peers; i++)
2495 if (0 == GNUNET_memcmp (peer, &session->peers[i])) 2518 if (0 == GNUNET_memcmp (peer, &session->peers[i]))
2496 return i; 2519 return i;
2497 return -1; 2520 return -1;
@@ -2528,14 +2551,15 @@ compute_global_id (struct ConsensusSession *session,
2528 2551
2529 2552
2530/** 2553/**
2531 * Compare two peer identities. 2554 * Compare two peer identities (for qsort()).
2532 * 2555 *
2533 * @param h1 some peer identity 2556 * @param h1 some peer identity
2534 * @param h2 some peer identity 2557 * @param h2 some peer identity
2535 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. 2558 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.
2536 */ 2559 */
2537static int 2560static int
2538peer_id_cmp (const void *h1, const void *h2) 2561peer_id_cmp (const void *h1,
2562 const void *h2)
2539{ 2563{
2540 return memcmp (h1, h2, sizeof(struct GNUNET_PeerIdentity)); 2564 return memcmp (h1, h2, sizeof(struct GNUNET_PeerIdentity));
2541} 2565}
@@ -2549,9 +2573,9 @@ peer_id_cmp (const void *h1, const void *h2)
2549 * @param join_msg join message with the list of peers participating at the end 2573 * @param join_msg join message with the list of peers participating at the end
2550 */ 2574 */
2551static void 2575static void
2552initialize_session_peer_list (struct ConsensusSession *session, 2576initialize_session_peer_list (
2553 const struct 2577 struct ConsensusSession *session,
2554 GNUNET_CONSENSUS_JoinMessage *join_msg) 2578 const struct GNUNET_CONSENSUS_JoinMessage *join_msg)
2555{ 2579{
2556 const struct GNUNET_PeerIdentity *msg_peers 2580 const struct GNUNET_PeerIdentity *msg_peers
2557 = (const struct GNUNET_PeerIdentity *) &join_msg[1]; 2581 = (const struct GNUNET_PeerIdentity *) &join_msg[1];
@@ -2578,29 +2602,31 @@ initialize_session_peer_list (struct ConsensusSession *session,
2578 struct GNUNET_PeerIdentity); 2602 struct GNUNET_PeerIdentity);
2579 if (GNUNET_NO == local_peer_in_list) 2603 if (GNUNET_NO == local_peer_in_list)
2580 session->peers[session->num_peers - 1] = my_peer; 2604 session->peers[session->num_peers - 1] = my_peer;
2581
2582 GNUNET_memcpy (session->peers, 2605 GNUNET_memcpy (session->peers,
2583 msg_peers, 2606 msg_peers,
2584 ntohl (join_msg->num_peers) * sizeof(struct 2607 ntohl (join_msg->num_peers)
2585 GNUNET_PeerIdentity)); 2608 * sizeof(struct GNUNET_PeerIdentity));
2586 qsort (session->peers, 2609 qsort (session->peers,
2587 session->num_peers, 2610 session->num_peers,
2588 sizeof(struct GNUNET_PeerIdentity), 2611 sizeof (struct GNUNET_PeerIdentity),
2589 &peer_id_cmp); 2612 &peer_id_cmp);
2590} 2613}
2591 2614
2592 2615
2593static struct TaskEntry * 2616static struct TaskEntry *
2594lookup_task (struct ConsensusSession *session, 2617lookup_task (const struct ConsensusSession *session,
2595 struct TaskKey *key) 2618 const struct TaskKey *key)
2596{ 2619{
2597 struct GNUNET_HashCode hash; 2620 struct GNUNET_HashCode hash;
2598 2621
2599 2622 GNUNET_CRYPTO_hash (key,
2600 GNUNET_CRYPTO_hash (key, sizeof(struct TaskKey), &hash); 2623 sizeof(struct TaskKey),
2601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up task hash %s\n", 2624 &hash);
2625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2626 "Looking up task hash %s\n",
2602 GNUNET_h2s (&hash)); 2627 GNUNET_h2s (&hash));
2603 return GNUNET_CONTAINER_multihashmap_get (session->taskmap, &hash); 2628 return GNUNET_CONTAINER_multihashmap_get (session->taskmap,
2629 &hash);
2604} 2630}
2605 2631
2606 2632
@@ -2695,7 +2721,7 @@ set_listen_cb (void *cls,
2695 task->cls.setop.op = GNUNET_SET_accept (request, 2721 task->cls.setop.op = GNUNET_SET_accept (request,
2696 GNUNET_SET_RESULT_SYMMETRIC, 2722 GNUNET_SET_RESULT_SYMMETRIC,
2697 opts, 2723 opts,
2698 set_result_cb, 2724 &set_result_cb,
2699 task); 2725 task);
2700 2726
2701 /* If the task hasn't been started yet, 2727 /* If the task hasn't been started yet,
@@ -2716,11 +2742,8 @@ put_task (struct GNUNET_CONTAINER_MultiHashMap *taskmap,
2716 struct Step *s; 2742 struct Step *s;
2717 2743
2718 GNUNET_assert (NULL != t->step); 2744 GNUNET_assert (NULL != t->step);
2719
2720 t = GNUNET_memdup (t, sizeof(struct TaskEntry)); 2745 t = GNUNET_memdup (t, sizeof(struct TaskEntry));
2721
2722 s = t->step; 2746 s = t->step;
2723
2724 if (s->tasks_len == s->tasks_cap) 2747 if (s->tasks_len == s->tasks_cap)
2725 { 2748 {
2726 unsigned int target_size = 3 * (s->tasks_cap + 1) / 2; 2749 unsigned int target_size = 3 * (s->tasks_cap + 1) / 2;
@@ -2739,9 +2762,13 @@ put_task (struct GNUNET_CONTAINER_MultiHashMap *taskmap,
2739 s->tasks[s->tasks_len] = t; 2762 s->tasks[s->tasks_len] = t;
2740 s->tasks_len++; 2763 s->tasks_len++;
2741 2764
2742 GNUNET_CRYPTO_hash (&t->key, sizeof(struct TaskKey), &round_hash); 2765 GNUNET_CRYPTO_hash (&t->key,
2766 sizeof(struct TaskKey),
2767 &round_hash);
2743 GNUNET_assert (GNUNET_OK == 2768 GNUNET_assert (GNUNET_OK ==
2744 GNUNET_CONTAINER_multihashmap_put (taskmap, &round_hash, t, 2769 GNUNET_CONTAINER_multihashmap_put (taskmap,
2770 &round_hash,
2771 t,
2745 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 2772 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2746} 2773}
2747 2774
@@ -2762,7 +2789,9 @@ install_step_timeouts (struct ConsensusSession *session)
2762 * Arrange two peers in some canonical order. 2789 * Arrange two peers in some canonical order.
2763 */ 2790 */
2764static void 2791static void
2765arrange_peers (uint16_t *p1, uint16_t *p2, uint16_t n) 2792arrange_peers (uint16_t *p1,
2793 uint16_t *p2,
2794 uint16_t n)
2766{ 2795{
2767 uint16_t a; 2796 uint16_t a;
2768 uint16_t b; 2797 uint16_t b;
@@ -2800,7 +2829,8 @@ arrange_peers (uint16_t *p1, uint16_t *p2, uint16_t n)
2800 * Record @a dep as a dependency of @a step. 2829 * Record @a dep as a dependency of @a step.
2801 */ 2830 */
2802static void 2831static void
2803step_depend_on (struct Step *step, struct Step *dep) 2832step_depend_on (struct Step *step,
2833 struct Step *dep)
2804{ 2834{
2805 /* We're not checking for cyclic dependencies, 2835 /* We're not checking for cyclic dependencies,
2806 but this is a cheap sanity check. */ 2836 but this is a cheap sanity check. */
@@ -2839,7 +2869,9 @@ step_depend_on (struct Step *step, struct Step *dep)
2839 2869
2840 2870
2841static struct Step * 2871static struct Step *
2842create_step (struct ConsensusSession *session, int round, int early_finishable) 2872create_step (struct ConsensusSession *session,
2873 int round,
2874 int early_finishable)
2843{ 2875{
2844 struct Step *step; 2876 struct Step *step;
2845 2877
@@ -2855,8 +2887,7 @@ create_step (struct ConsensusSession *session, int round, int early_finishable)
2855 2887
2856 2888
2857/** 2889/**
2858 * Construct the task graph for a single 2890 * Construct the task graph for a single gradecast.
2859 * gradecast.
2860 */ 2891 */
2861static void 2892static void
2862construct_task_graph_gradecast (struct ConsensusSession *session, 2893construct_task_graph_gradecast (struct ConsensusSession *session,
@@ -2867,35 +2898,32 @@ construct_task_graph_gradecast (struct ConsensusSession *session,
2867{ 2898{
2868 uint16_t n = session->num_peers; 2899 uint16_t n = session->num_peers;
2869 uint16_t me = session->local_peer_idx; 2900 uint16_t me = session->local_peer_idx;
2870
2871 uint16_t p1; 2901 uint16_t p1;
2872 uint16_t p2; 2902 uint16_t p2;
2873
2874 /* The task we're currently setting up. */ 2903 /* The task we're currently setting up. */
2875 struct TaskEntry task; 2904 struct TaskEntry task;
2876
2877 struct Step *step; 2905 struct Step *step;
2878 struct Step *prev_step; 2906 struct Step *prev_step;
2879
2880 uint16_t round; 2907 uint16_t round;
2881 2908
2882 unsigned int k;
2883
2884 round = step_before->round + 1; 2909 round = step_before->round + 1;
2885 2910
2886 /* gcast step 1: leader disseminates */ 2911 /* gcast step 1: leader disseminates */
2887 2912 step = create_step (session,
2888 step = create_step (session, round, GNUNET_YES); 2913 round,
2889 2914 GNUNET_YES);
2890#ifdef GNUNET_EXTRA_LOGGING 2915#ifdef GNUNET_EXTRA_LOGGING
2891 GNUNET_asprintf (&step->debug_name, "disseminate leader %u rep %u", lead, 2916 GNUNET_asprintf (&step->debug_name,
2917 "disseminate leader %u rep %u",
2918 lead,
2892 rep); 2919 rep);
2893#endif 2920#endif
2894 step_depend_on (step, step_before); 2921 step_depend_on (step,
2922 step_before);
2895 2923
2896 if (lead == me) 2924 if (lead == me)
2897 { 2925 {
2898 for (k = 0; k < n; k++) 2926 for (unsigned int k = 0; k < n; k++)
2899 { 2927 {
2900 if (k == me) 2928 if (k == me)
2901 continue; 2929 continue;
@@ -2952,13 +2980,19 @@ construct_task_graph_gradecast (struct ConsensusSession *session,
2952 /* gcast phase 2: echo */ 2980 /* gcast phase 2: echo */
2953 prev_step = step; 2981 prev_step = step;
2954 round += 1; 2982 round += 1;
2955 step = create_step (session, round, GNUNET_YES); 2983 step = create_step (session,
2984 round,
2985 GNUNET_YES);
2956#ifdef GNUNET_EXTRA_LOGGING 2986#ifdef GNUNET_EXTRA_LOGGING
2957 GNUNET_asprintf (&step->debug_name, "echo leader %u rep %u", lead, rep); 2987 GNUNET_asprintf (&step->debug_name,
2988 "echo leader %u rep %u",
2989 lead,
2990 rep);
2958#endif 2991#endif
2959 step_depend_on (step, prev_step); 2992 step_depend_on (step,
2993 prev_step);
2960 2994
2961 for (k = 0; k < n; k++) 2995 for (unsigned int k = 0; k < n; k++)
2962 { 2996 {
2963 p1 = k; 2997 p1 = k;
2964 p2 = me; 2998 p2 = me;
@@ -3001,7 +3035,7 @@ construct_task_graph_gradecast (struct ConsensusSession *session,
3001 step_depend_on (step, prev_step); 3035 step_depend_on (step, prev_step);
3002 3036
3003 /* gcast phase 3: confirmation and grading */ 3037 /* gcast phase 3: confirmation and grading */
3004 for (k = 0; k < n; k++) 3038 for (unsigned int k = 0; k < n; k++)
3005 { 3039 {
3006 p1 = k; 3040 p1 = k;
3007 p2 = me; 3041 p2 = me;
@@ -3050,22 +3084,15 @@ construct_task_graph (struct ConsensusSession *session)
3050{ 3084{
3051 uint16_t n = session->num_peers; 3085 uint16_t n = session->num_peers;
3052 uint16_t t = n / 3; 3086 uint16_t t = n / 3;
3053
3054 uint16_t me = session->local_peer_idx; 3087 uint16_t me = session->local_peer_idx;
3055
3056 /* The task we're currently setting up. */ 3088 /* The task we're currently setting up. */
3057 struct TaskEntry task; 3089 struct TaskEntry task;
3058
3059 /* Current leader */ 3090 /* Current leader */
3060 unsigned int lead; 3091 unsigned int lead;
3061
3062 struct Step *step; 3092 struct Step *step;
3063 struct Step *prev_step; 3093 struct Step *prev_step;
3064
3065 unsigned int round = 0; 3094 unsigned int round = 0;
3066 3095
3067 unsigned int i;
3068
3069 // XXX: introduce first step, 3096 // XXX: introduce first step,
3070 // where we wait for all insert acks 3097 // where we wait for all insert acks
3071 // from the set service 3098 // from the set service
@@ -3082,7 +3109,7 @@ construct_task_graph (struct ConsensusSession *session)
3082 step->debug_name = GNUNET_strdup ("all to all"); 3109 step->debug_name = GNUNET_strdup ("all to all");
3083#endif 3110#endif
3084 3111
3085 for (i = 0; i < n; i++) 3112 for (unsigned int i = 0; i < n; i++)
3086 { 3113 {
3087 uint16_t p1; 3114 uint16_t p1;
3088 uint16_t p2; 3115 uint16_t p2;
@@ -3111,7 +3138,7 @@ construct_task_graph (struct ConsensusSession *session)
3111 step_depend_on (step, prev_step); 3138 step_depend_on (step, prev_step);
3112 3139
3113 3140
3114 for (i = 0; i < n; i++) 3141 for (unsigned int i = 0; i < n; i++)
3115 { 3142 {
3116 uint16_t p1; 3143 uint16_t p1;
3117 uint16_t p2; 3144 uint16_t p2;
@@ -3140,7 +3167,7 @@ construct_task_graph (struct ConsensusSession *session)
3140 /* Byzantine union */ 3167 /* Byzantine union */
3141 3168
3142 /* sequential repetitions of the gradecasts */ 3169 /* sequential repetitions of the gradecasts */
3143 for (i = 0; i < t + 1; i++) 3170 for (unsigned int i = 0; i < t + 1; i++)
3144 { 3171 {
3145 struct Step *step_rep_start; 3172 struct Step *step_rep_start;
3146 struct Step *step_rep_end; 3173 struct Step *step_rep_end;
@@ -3243,9 +3270,9 @@ handle_client_join (void *cls,
3243 NULL != other_session; 3270 NULL != other_session;
3244 other_session = other_session->next) 3271 other_session = other_session->next)
3245 { 3272 {
3246 if ((other_session != session) && 3273 if ( (other_session != session) &&
3247 (0 == GNUNET_CRYPTO_hash_cmp (&session->global_id, 3274 (0 == GNUNET_CRYPTO_hash_cmp (&session->global_id,
3248 &other_session->global_id))) 3275 &other_session->global_id)) )
3249 break; 3276 break;
3250 } 3277 }
3251 3278
@@ -3262,9 +3289,9 @@ handle_client_join (void *cls,
3262 GNUNET_h2s (&m->session_id), 3289 GNUNET_h2s (&m->session_id),
3263 session->num_peers, 3290 session->num_peers,
3264 session->local_peer_idx, 3291 session->local_peer_idx,
3265 GNUNET_STRINGS_relative_time_to_string 3292 GNUNET_STRINGS_relative_time_to_string (
3266 (GNUNET_TIME_absolute_get_difference (session->conclude_start, 3293 GNUNET_TIME_absolute_get_difference (session->conclude_start,
3267 session->conclude_deadline), 3294 session->conclude_deadline),
3268 GNUNET_YES)); 3295 GNUNET_YES));
3269 3296
3270 session->set_listener 3297 session->set_listener
@@ -3309,13 +3336,6 @@ handle_client_join (void *cls,
3309} 3336}
3310 3337
3311 3338
3312static void
3313client_insert_done (void *cls)
3314{
3315 // FIXME: implement
3316}
3317
3318
3319/** 3339/**
3320 * Called when a client performs an insert operation. 3340 * Called when a client performs an insert operation.
3321 * 3341 *
@@ -3352,19 +3372,13 @@ handle_client_insert (void *cls,
3352 GNUNET_SERVICE_client_drop (session->client); 3372 GNUNET_SERVICE_client_drop (session->client);
3353 return; 3373 return;
3354 } 3374 }
3355 3375 element_size = ntohs (msg->header.size) - sizeof(*msg);
3356 element_size = ntohs (msg->header.size) - sizeof(struct
3357 GNUNET_CONSENSUS_ElementMessage);
3358 ce = GNUNET_malloc (sizeof(struct ConsensusElement) + element_size); 3376 ce = GNUNET_malloc (sizeof(struct ConsensusElement) + element_size);
3359 GNUNET_memcpy (&ce[1], &msg[1], element_size); 3377 GNUNET_memcpy (&ce[1],
3378 &msg[1],
3379 element_size);
3360 ce->payload_type = msg->element_type; 3380 ce->payload_type = msg->element_type;
3361 3381
3362 struct GNUNET_SET_Element element = {
3363 .element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT,
3364 .size = sizeof(struct ConsensusElement) + element_size,
3365 .data = ce,
3366 };
3367
3368 { 3382 {
3369 struct SetKey key = { SET_KIND_CURRENT, 0, 0 }; 3383 struct SetKey key = { SET_KIND_CURRENT, 0, 0 };
3370 struct SetEntry *entry; 3384 struct SetEntry *entry;
@@ -3376,19 +3390,25 @@ handle_client_insert (void *cls,
3376 } 3390 }
3377 3391
3378 session->num_client_insert_pending++; 3392 session->num_client_insert_pending++;
3379 GNUNET_SET_add_element (initial_set,
3380 &element,
3381 &client_insert_done,
3382 session);
3383 3393
3384#ifdef GNUNET_EXTRA_LOGGING
3385 { 3394 {
3395 struct GNUNET_SET_Element element = {
3396 .element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT,
3397 .size = sizeof(struct ConsensusElement) + element_size,
3398 .data = ce,
3399 };
3400
3401 GNUNET_SET_add_element (initial_set,
3402 &element,
3403 NULL,
3404 NULL);
3405#ifdef GNUNET_EXTRA_LOGGING
3386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3406 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3387 "P%u: element %s added\n", 3407 "P%u: element %s added\n",
3388 session->local_peer_idx, 3408 session->local_peer_idx,
3389 debug_str_element (&element)); 3409 debug_str_element (&element));
3390 }
3391#endif 3410#endif
3411 }
3392 GNUNET_free (ce); 3412 GNUNET_free (ce);
3393 GNUNET_SERVICE_client_continue (session->client); 3413 GNUNET_SERVICE_client_continue (session->client);
3394} 3414}
@@ -3513,10 +3533,10 @@ client_disconnect_cb (void *cls,
3513 GNUNET_CONTAINER_DLL_remove (sessions_head, 3533 GNUNET_CONTAINER_DLL_remove (sessions_head,
3514 sessions_tail, 3534 sessions_tail,
3515 session); 3535 session);
3516
3517 while (session->set_handles_head) 3536 while (session->set_handles_head)
3518 { 3537 {
3519 struct SetHandle *sh = session->set_handles_head; 3538 struct SetHandle *sh = session->set_handles_head;
3539
3520 session->set_handles_head = sh->next; 3540 session->set_handles_head = sh->next;
3521 GNUNET_SET_destroy (sh->h); 3541 GNUNET_SET_destroy (sh->h);
3522 GNUNET_free (sh); 3542 GNUNET_free (sh);
@@ -3528,8 +3548,8 @@ client_disconnect_cb (void *cls,
3528/** 3548/**
3529 * Define "main" method using service macro. 3549 * Define "main" method using service macro.
3530 */ 3550 */
3531GNUNET_SERVICE_MAIN 3551GNUNET_SERVICE_MAIN (
3532 ("consensus", 3552 "consensus",
3533 GNUNET_SERVICE_OPTION_NONE, 3553 GNUNET_SERVICE_OPTION_NONE,
3534 &run, 3554 &run,
3535 &client_connect_cb, 3555 &client_connect_cb,
diff --git a/src/consensus/plugin_block_consensus.c b/src/consensus/plugin_block_consensus.c
index fb6da5bcd..cdac12ed5 100644
--- a/src/consensus/plugin_block_consensus.c
+++ b/src/consensus/plugin_block_consensus.c
@@ -58,13 +58,12 @@ block_plugin_consensus_evaluate (void *cls,
58 const void *reply_block, 58 const void *reply_block,
59 size_t reply_block_size) 59 size_t reply_block_size)
60{ 60{
61 if (reply_block_size < sizeof(struct ConsensusElement))
62 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
63
64 const struct ConsensusElement *ce = reply_block; 61 const struct ConsensusElement *ce = reply_block;
65 62
66 if ((0 != ce->marker) || 63 if (reply_block_size < sizeof(struct ConsensusElement))
67 (0 == ce->payload_type)) 64 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
65 if ( (0 != ce->marker) ||
66 (0 == ce->payload_type) )
68 return GNUNET_BLOCK_EVALUATION_OK_MORE; 67 return GNUNET_BLOCK_EVALUATION_OK_MORE;
69 68
70 return GNUNET_BLOCK_evaluate (ctx, 69 return GNUNET_BLOCK_evaluate (ctx,
@@ -75,8 +74,8 @@ block_plugin_consensus_evaluate (void *cls,
75 xquery, 74 xquery,
76 xquery_size, 75 xquery_size,
77 &ce[1], 76 &ce[1],
78 reply_block_size - sizeof(struct 77 reply_block_size
79 ConsensusElement)); 78 - sizeof(struct ConsensusElement));
80} 79}
81 80
82 81
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 8c3f4f058..03fb16a43 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -619,7 +619,7 @@ GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode *block,
619 * @param result where to store the hash code 619 * @param result where to store the hash code
620 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding 620 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
621 */ 621 */
622int 622enum GNUNET_GenericReturnValue
623GNUNET_CRYPTO_hash_from_string2 (const char *enc, 623GNUNET_CRYPTO_hash_from_string2 (const char *enc,
624 size_t enclen, 624 size_t enclen,
625 struct GNUNET_HashCode *result); 625 struct GNUNET_HashCode *result);
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 0dbe9dbe8..94b6f5099 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -94,7 +94,7 @@ GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode *block,
94 * @param result where to store the hash code 94 * @param result where to store the hash code
95 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding 95 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
96 */ 96 */
97int 97enum GNUNET_GenericReturnValue
98GNUNET_CRYPTO_hash_from_string2 (const char *enc, 98GNUNET_CRYPTO_hash_from_string2 (const char *enc,
99 size_t enclen, 99 size_t enclen,
100 struct GNUNET_HashCode *result) 100 struct GNUNET_HashCode *result)