aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/consensus/gnunet-service-consensus.c502
1 files changed, 261 insertions, 241 deletions
diff --git a/src/consensus/gnunet-service-consensus.c b/src/consensus/gnunet-service-consensus.c
index 13fa0d0e7..3a8356635 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
@@ -62,11 +62,57 @@ enum EarlyStoppingPhase
62}; 62};
63 63
64 64
65enum PhaseKind
66{
67 PHASE_KIND_ALL_TO_ALL,
68 PHASE_KIND_ALL_TO_ALL_2,
69 PHASE_KIND_GRADECAST_LEADER,
70 PHASE_KIND_GRADECAST_ECHO,
71 PHASE_KIND_GRADECAST_ECHO_GRADE,
72 PHASE_KIND_GRADECAST_CONFIRM,
73 PHASE_KIND_GRADECAST_CONFIRM_GRADE,
74 /**
75 * Apply a repetition of the all-to-all
76 * gradecast to the current set.
77 */
78 PHASE_KIND_APPLY_REP,
79 PHASE_KIND_FINISH,
80};
81
82
83enum SetKind
84{
85 SET_KIND_NONE = 0,
86 SET_KIND_CURRENT,
87 /**
88 * Last result set from a gradecast
89 */
90 SET_KIND_LAST_GRADECAST,
91 SET_KIND_LEADER_PROPOSAL,
92 SET_KIND_ECHO_RESULT,
93};
94
95enum DiffKind
96{
97 DIFF_KIND_NONE = 0,
98 DIFF_KIND_LEADER_PROPOSAL,
99 DIFF_KIND_LEADER_CONSENSUS,
100 DIFF_KIND_GRADECAST_RESULT,
101};
102
103enum RfnKind
104{
105 RFN_KIND_NONE = 0,
106 RFN_KIND_ECHO,
107 RFN_KIND_CONFIRM,
108 RFN_KIND_GRADECAST_RESULT
109};
110
111
65GNUNET_NETWORK_STRUCT_BEGIN 112GNUNET_NETWORK_STRUCT_BEGIN
66 113
67/** 114/**
68 * Tuple of integers that together 115 * Tuple of integers that together identify a task uniquely.
69 * identify a task uniquely.
70 */ 116 */
71struct TaskKey 117struct TaskKey
72{ 118{
@@ -102,8 +148,14 @@ struct TaskKey
102 148
103struct SetKey 149struct SetKey
104{ 150{
105 int set_kind GNUNET_PACKED; 151 enum SetKind set_kind GNUNET_PACKED;
152 /**
153 * Repetition counter.
154 */
106 int k1 GNUNET_PACKED; 155 int k1 GNUNET_PACKED;
156 /**
157 * Leader (or 0).
158 */
107 int k2 GNUNET_PACKED; 159 int k2 GNUNET_PACKED;
108}; 160};
109 161
@@ -112,9 +164,9 @@ struct SetEntry
112{ 164{
113 struct SetKey key; 165 struct SetKey key;
114 struct GNUNET_SET_Handle *h; 166 struct GNUNET_SET_Handle *h;
167
115 /** 168 /**
116 * GNUNET_YES if the set resulted 169 * #GNUNET_YES if the set resulted from applying a referendum with contested
117 * from applying a referendum with contested
118 * elements. 170 * elements.
119 */ 171 */
120 int is_contested; 172 int is_contested;
@@ -123,14 +175,16 @@ struct SetEntry
123 175
124struct DiffKey 176struct DiffKey
125{ 177{
126 int diff_kind GNUNET_PACKED; 178 enum DiffKind diff_kind GNUNET_PACKED;
179
127 int k1 GNUNET_PACKED; 180 int k1 GNUNET_PACKED;
181
128 int k2 GNUNET_PACKED; 182 int k2 GNUNET_PACKED;
129}; 183};
130 184
131struct RfnKey 185struct RfnKey
132{ 186{
133 int rfn_kind GNUNET_PACKED; 187 enum RfnKind rfn_kind GNUNET_PACKED;
134 int k1 GNUNET_PACKED; 188 int k1 GNUNET_PACKED;
135 int k2 GNUNET_PACKED; 189 int k2 GNUNET_PACKED;
136}; 190};
@@ -138,52 +192,6 @@ struct RfnKey
138 192
139GNUNET_NETWORK_STRUCT_END 193GNUNET_NETWORK_STRUCT_END
140 194
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 195
188struct SetOpCls 196struct SetOpCls
189{ 197{
@@ -216,9 +224,13 @@ union TaskFuncCls
216 struct FinishCls finish; 224 struct FinishCls finish;
217}; 225};
218 226
227
219struct TaskEntry; 228struct TaskEntry;
220 229
221typedef void (*TaskFunc) (struct TaskEntry *task); 230
231typedef void
232(*TaskFunc) (struct TaskEntry *task);
233
222 234
223/* 235/*
224 * Node in the consensus task graph. 236 * Node in the consensus task graph.
@@ -277,14 +289,12 @@ struct Step
277 unsigned int subordinates_cap; 289 unsigned int subordinates_cap;
278 290
279 /** 291 /**
280 * Counter for the prerequisites of 292 * Counter for the prerequisites of this step.
281 * this step.
282 */ 293 */
283 size_t pending_prereq; 294 size_t pending_prereq;
284 295
285 /* 296 /**
286 * Task that will run this step despite 297 * Task that will run this step despite any pending prerequisites.
287 * any pending prerequisites.
288 */ 298 */
289 struct GNUNET_SCHEDULER_Task *timeout_task; 299 struct GNUNET_SCHEDULER_Task *timeout_task;
290 300
@@ -292,28 +302,23 @@ struct Step
292 302
293 unsigned int is_finished; 303 unsigned int is_finished;
294 304
295 /* 305 /**
296 * Synchrony round of the task. 306 * Synchrony round of the task. Determines the deadline for the task.
297 * Determines the deadline for the task.
298 */ 307 */
299 unsigned int round; 308 unsigned int round;
300 309
301 /** 310 /**
302 * Human-readable name for 311 * Human-readable name for the task, used for debugging.
303 * the task, used for debugging.
304 */ 312 */
305 char *debug_name; 313 char *debug_name;
306 314
307 /** 315 /**
308 * When we're doing an early finish, how should this step be 316 * When we're doing an early finish, how should this step be treated? If
309 * treated? 317 * #GNUNET_YES, the step will be marked as finished without actually running
310 * If GNUNET_YES, the step will be marked as finished 318 * its tasks. Otherwise, the step will still be run even after an early
311 * without actually running its tasks. 319 * finish.
312 * Otherwise, the step will still be run even after
313 * an early finish.
314 * 320 *
315 * Note that a task may never be finished early if 321 * Note that a task may never be finished early if it is already running.
316 * it is already running.
317 */ 322 */
318 int early_finishable; 323 int early_finishable;
319}; 324};
@@ -323,14 +328,13 @@ struct RfnElementInfo
323{ 328{
324 const struct GNUNET_SET_Element *element; 329 const struct GNUNET_SET_Element *element;
325 330
326 /* 331 /**
327 * GNUNET_YES if the peer votes for the proposal. 332 * #GNUNET_YES if the peer votes for the proposal.
328 */ 333 */
329 int *votes; 334 int *votes;
330 335
331 /** 336 /**
332 * Proposal for this element, 337 * Proposal for this element, can only be #VOTE_ADD or #VOTE_REMOVE.
333 * can only be VOTE_ADD or VOTE_REMOVE.
334 */ 338 */
335 enum ReferendumVote proposal; 339 enum ReferendumVote proposal;
336}; 340};
@@ -638,7 +642,7 @@ debug_str_element (const struct GNUNET_SET_Element *el)
638 642
639 643
640static const char * 644static const char *
641debug_str_task_key (struct TaskKey *tk) 645debug_str_task_key (const struct TaskKey *tk)
642{ 646{
643 static char buf[256]; 647 static char buf[256];
644 648
@@ -652,7 +656,7 @@ debug_str_task_key (struct TaskKey *tk)
652 656
653 657
654static const char * 658static const char *
655debug_str_diff_key (struct DiffKey *dk) 659debug_str_diff_key (const struct DiffKey *dk)
656{ 660{
657 static char buf[256]; 661 static char buf[256];
658 662
@@ -671,8 +675,9 @@ debug_str_set_key (const struct SetKey *sk)
671 675
672 snprintf (buf, sizeof(buf), 676 snprintf (buf, sizeof(buf),
673 "SetKey kind=%s, k1=%d, k2=%d", 677 "SetKey kind=%s, k1=%d, k2=%d",
674 setname (sk->set_kind), sk->k1, sk->k2); 678 setname (sk->set_kind),
675 679 sk->k1,
680 sk->k2);
676 return buf; 681 return buf;
677} 682}
678 683
@@ -684,8 +689,9 @@ debug_str_rfn_key (const struct RfnKey *rk)
684 689
685 snprintf (buf, sizeof(buf), 690 snprintf (buf, sizeof(buf),
686 "RfnKey kind=%s, k1=%d, k2=%d", 691 "RfnKey kind=%s, k1=%d, k2=%d",
687 rfnname (rk->rfn_kind), rk->k1, rk->k2); 692 rfnname (rk->rfn_kind),
688 693 rk->k1,
694 rk->k2);
689 return buf; 695 return buf;
690} 696}
691 697
@@ -730,13 +736,15 @@ send_to_client_iter (void *cls,
730 session->local_peer_idx, 736 session->local_peer_idx,
731 debug_str_element (element)); 737 debug_str_element (element));
732 738
733 ev = GNUNET_MQ_msg_extra (m, element->size - sizeof(struct 739 ev = GNUNET_MQ_msg_extra (m,
734 ConsensusElement), 740 element->size - sizeof(struct ConsensusElement),
735 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT); 741 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT);
736 m->element_type = ce->payload_type; 742 m->element_type = ce->payload_type;
737 GNUNET_memcpy (&m[1], &ce[1], element->size - sizeof(struct 743 GNUNET_memcpy (&m[1],
738 ConsensusElement)); 744 &ce[1],
739 GNUNET_MQ_send (session->client_mq, ev); 745 element->size - sizeof(struct ConsensusElement));
746 GNUNET_MQ_send (session->client_mq,
747 ev);
740 } 748 }
741 else 749 else
742 { 750 {
@@ -745,14 +753,16 @@ send_to_client_iter (void *cls,
745 session->local_peer_idx); 753 session->local_peer_idx);
746 ev = GNUNET_MQ_msg_header ( 754 ev = GNUNET_MQ_msg_header (
747 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE_DONE); 755 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE_DONE);
748 GNUNET_MQ_send (session->client_mq, ev); 756 GNUNET_MQ_send (session->client_mq,
757 ev);
749 } 758 }
750 return GNUNET_YES; 759 return GNUNET_YES;
751} 760}
752 761
753 762
754static struct SetEntry * 763static struct SetEntry *
755lookup_set (struct ConsensusSession *session, struct SetKey *key) 764lookup_set (struct ConsensusSession *session,
765 const struct SetKey *key)
756{ 766{
757 struct GNUNET_HashCode hash; 767 struct GNUNET_HashCode hash;
758 768
@@ -762,13 +772,17 @@ lookup_set (struct ConsensusSession *session, struct SetKey *key)
762 debug_str_set_key (key)); 772 debug_str_set_key (key));
763 773
764 GNUNET_assert (SET_KIND_NONE != key->set_kind); 774 GNUNET_assert (SET_KIND_NONE != key->set_kind);
765 GNUNET_CRYPTO_hash (key, sizeof(struct SetKey), &hash); 775 GNUNET_CRYPTO_hash (key,
766 return GNUNET_CONTAINER_multihashmap_get (session->setmap, &hash); 776 sizeof(struct SetKey),
777 &hash);
778 return GNUNET_CONTAINER_multihashmap_get (session->setmap,
779 &hash);
767} 780}
768 781
769 782
770static struct DiffEntry * 783static struct DiffEntry *
771lookup_diff (struct ConsensusSession *session, struct DiffKey *key) 784lookup_diff (struct ConsensusSession *session,
785 const struct DiffKey *key)
772{ 786{
773 struct GNUNET_HashCode hash; 787 struct GNUNET_HashCode hash;
774 788
@@ -776,15 +790,18 @@ lookup_diff (struct ConsensusSession *session, struct DiffKey *key)
776 "P%u: looking up diff {%s}\n", 790 "P%u: looking up diff {%s}\n",
777 session->local_peer_idx, 791 session->local_peer_idx,
778 debug_str_diff_key (key)); 792 debug_str_diff_key (key));
779
780 GNUNET_assert (DIFF_KIND_NONE != key->diff_kind); 793 GNUNET_assert (DIFF_KIND_NONE != key->diff_kind);
781 GNUNET_CRYPTO_hash (key, sizeof(struct DiffKey), &hash); 794 GNUNET_CRYPTO_hash (key,
782 return GNUNET_CONTAINER_multihashmap_get (session->diffmap, &hash); 795 sizeof(struct DiffKey),
796 &hash);
797 return GNUNET_CONTAINER_multihashmap_get (session->diffmap,
798 &hash);
783} 799}
784 800
785 801
786static struct ReferendumEntry * 802static struct ReferendumEntry *
787lookup_rfn (struct ConsensusSession *session, struct RfnKey *key) 803lookup_rfn (struct ConsensusSession *session,
804 const struct RfnKey *key)
788{ 805{
789 struct GNUNET_HashCode hash; 806 struct GNUNET_HashCode hash;
790 807
@@ -792,10 +809,12 @@ lookup_rfn (struct ConsensusSession *session, struct RfnKey *key)
792 "P%u: looking up rfn {%s}\n", 809 "P%u: looking up rfn {%s}\n",
793 session->local_peer_idx, 810 session->local_peer_idx,
794 debug_str_rfn_key (key)); 811 debug_str_rfn_key (key));
795
796 GNUNET_assert (RFN_KIND_NONE != key->rfn_kind); 812 GNUNET_assert (RFN_KIND_NONE != key->rfn_kind);
797 GNUNET_CRYPTO_hash (key, sizeof(struct RfnKey), &hash); 813 GNUNET_CRYPTO_hash (key,
798 return GNUNET_CONTAINER_multihashmap_get (session->rfnmap, &hash); 814 sizeof(struct RfnKey),
815 &hash);
816 return GNUNET_CONTAINER_multihashmap_get (session->rfnmap,
817 &hash);
799} 818}
800 819
801 820
@@ -860,11 +879,10 @@ rfn_contest (struct ReferendumEntry *rfn,
860static uint16_t 879static uint16_t
861rfn_noncontested (struct ReferendumEntry *rfn) 880rfn_noncontested (struct ReferendumEntry *rfn)
862{ 881{
863 uint16_t i;
864 uint16_t ret; 882 uint16_t ret;
865 883
866 ret = 0; 884 ret = 0;
867 for (i = 0; i < rfn->num_peers; i++) 885 for (uint16_t i = 0; i < rfn->num_peers; i++)
868 if ((GNUNET_YES == rfn->peer_commited[i]) && (GNUNET_NO == 886 if ((GNUNET_YES == rfn->peer_commited[i]) && (GNUNET_NO ==
869 rfn->peer_contested[i])) 887 rfn->peer_contested[i]))
870 ret++; 888 ret++;
@@ -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,
@@ -1405,7 +1422,6 @@ commit_set (struct ConsensusSession *session,
1405 1422
1406#ifdef EVIL 1423#ifdef EVIL
1407 { 1424 {
1408 unsigned int i;
1409 struct Evilness evil; 1425 struct Evilness evil;
1410 1426
1411 get_evilness (session, &evil); 1427 get_evilness (session, &evil);
@@ -1444,7 +1460,7 @@ commit_set (struct ConsensusSession *session,
1444 GNUNET_SET_commit (setop->op, set->h); 1460 GNUNET_SET_commit (setop->op, set->h);
1445 break; 1461 break;
1446 } 1462 }
1447 for (i = 0; i < evil.num; i++) 1463 for (unsigned int i = 0; i < evil.num; i++)
1448 { 1464 {
1449 struct GNUNET_SET_Element element; 1465 struct GNUNET_SET_Element element;
1450 struct ConsensusStuffedElement se = { 1466 struct ConsensusStuffedElement se = {
@@ -1504,12 +1520,14 @@ commit_set (struct ConsensusSession *session,
1504 } 1520 }
1505 else 1521 else
1506 { 1522 {
1507 GNUNET_SET_commit (setop->op, set->h); 1523 GNUNET_SET_commit (setop->op,
1524 set->h);
1508 } 1525 }
1509 break; 1526 break;
1510 1527
1511 case EVILNESS_NONE: 1528 case EVILNESS_NONE:
1512 GNUNET_SET_commit (setop->op, set->h); 1529 GNUNET_SET_commit (setop->op,
1530 set->h);
1513 break; 1531 break;
1514 } 1532 }
1515 } 1533 }
@@ -1536,11 +1554,12 @@ put_diff (struct ConsensusSession *session,
1536{ 1554{
1537 struct GNUNET_HashCode hash; 1555 struct GNUNET_HashCode hash;
1538 1556
1539 GNUNET_assert (NULL != diff); 1557 GNUNET_CRYPTO_hash (&diff->key,
1540 1558 sizeof(struct DiffKey),
1541 GNUNET_CRYPTO_hash (&diff->key, sizeof(struct DiffKey), &hash); 1559 &hash);
1542 GNUNET_assert (GNUNET_OK == 1560 GNUNET_assert (GNUNET_OK ==
1543 GNUNET_CONTAINER_multihashmap_put (session->diffmap, &hash, 1561 GNUNET_CONTAINER_multihashmap_put (session->diffmap,
1562 &hash,
1544 diff, 1563 diff,
1545 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1564 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1546} 1565}
@@ -1553,14 +1572,16 @@ put_set (struct ConsensusSession *session,
1553 struct GNUNET_HashCode hash; 1572 struct GNUNET_HashCode hash;
1554 1573
1555 GNUNET_assert (NULL != set->h); 1574 GNUNET_assert (NULL != set->h);
1556
1557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1558 "Putting set %s\n", 1576 "Putting set %s\n",
1559 debug_str_set_key (&set->key)); 1577 debug_str_set_key (&set->key));
1560 1578 GNUNET_CRYPTO_hash (&set->key,
1561 GNUNET_CRYPTO_hash (&set->key, sizeof(struct SetKey), &hash); 1579 sizeof(struct SetKey),
1580 &hash);
1562 GNUNET_assert (GNUNET_SYSERR != 1581 GNUNET_assert (GNUNET_SYSERR !=
1563 GNUNET_CONTAINER_multihashmap_put (session->setmap, &hash, set, 1582 GNUNET_CONTAINER_multihashmap_put (session->setmap,
1583 &hash,
1584 set,
1564 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); 1585 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
1565} 1586}
1566 1587
@@ -1573,7 +1594,9 @@ put_rfn (struct ConsensusSession *session,
1573 1594
1574 GNUNET_CRYPTO_hash (&rfn->key, sizeof(struct RfnKey), &hash); 1595 GNUNET_CRYPTO_hash (&rfn->key, sizeof(struct RfnKey), &hash);
1575 GNUNET_assert (GNUNET_OK == 1596 GNUNET_assert (GNUNET_OK ==
1576 GNUNET_CONTAINER_multihashmap_put (session->rfnmap, &hash, rfn, 1597 GNUNET_CONTAINER_multihashmap_put (session->rfnmap,
1598 &hash,
1599 rfn,
1577 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1600 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1578} 1601}
1579 1602
@@ -1616,18 +1639,20 @@ apply_diff_to_rfn (struct DiffEntry *diff,
1616} 1639}
1617 1640
1618 1641
1619struct DiffEntry * 1642static struct DiffEntry *
1620diff_create () 1643diff_create (void)
1621{ 1644{
1622 struct DiffEntry *d = GNUNET_new (struct DiffEntry); 1645 struct DiffEntry *d = GNUNET_new (struct DiffEntry);
1623 1646
1624 d->changes = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); 1647 d->changes = GNUNET_CONTAINER_multihashmap_create (8,
1648 GNUNET_NO);
1625 1649
1626 return d; 1650 return d;
1627} 1651}
1628 1652
1629 1653
1630struct DiffEntry * 1654#if 0
1655static struct DiffEntry *
1631diff_compose (struct DiffEntry *diff_1, 1656diff_compose (struct DiffEntry *diff_1,
1632 struct DiffEntry *diff_2) 1657 struct DiffEntry *diff_2)
1633{ 1658{
@@ -1638,22 +1663,26 @@ diff_compose (struct DiffEntry *diff_1,
1638 diff_new = diff_create (); 1663 diff_new = diff_create ();
1639 1664
1640 iter = GNUNET_CONTAINER_multihashmap_iterator_create (diff_1->changes); 1665 iter = GNUNET_CONTAINER_multihashmap_iterator_create (diff_1->changes);
1641 while (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next (iter, NULL, 1666 while (GNUNET_YES ==
1642 (const 1667 GNUNET_CONTAINER_multihashmap_iterator_next (iter,
1643 void **) & 1668 NULL,
1644 di)) 1669 (const void **) &di))
1645 { 1670 {
1646 diff_insert (diff_new, di->weight, di->element); 1671 diff_insert (diff_new,
1672 di->weight,
1673 di->element);
1647 } 1674 }
1648 GNUNET_CONTAINER_multihashmap_iterator_destroy (iter); 1675 GNUNET_CONTAINER_multihashmap_iterator_destroy (iter);
1649 1676
1650 iter = GNUNET_CONTAINER_multihashmap_iterator_create (diff_2->changes); 1677 iter = GNUNET_CONTAINER_multihashmap_iterator_create (diff_2->changes);
1651 while (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next (iter, NULL, 1678 while (GNUNET_YES ==
1652 (const 1679 GNUNET_CONTAINER_multihashmap_iterator_next (iter,
1653 void **) & 1680 NULL,
1654 di)) 1681 (const void **) &di))
1655 { 1682 {
1656 diff_insert (diff_new, di->weight, di->element); 1683 diff_insert (diff_new,
1684 di->weight,
1685 di->element);
1657 } 1686 }
1658 GNUNET_CONTAINER_multihashmap_iterator_destroy (iter); 1687 GNUNET_CONTAINER_multihashmap_iterator_destroy (iter);
1659 1688
@@ -1661,6 +1690,9 @@ diff_compose (struct DiffEntry *diff_1,
1661} 1690}
1662 1691
1663 1692
1693#endif
1694
1695
1664struct ReferendumEntry * 1696struct ReferendumEntry *
1665rfn_create (uint16_t size) 1697rfn_create (uint16_t size)
1666{ 1698{
@@ -1701,14 +1733,13 @@ rfn_majority (const struct ReferendumEntry *rfn,
1701{ 1733{
1702 uint16_t votes_yes = 0; 1734 uint16_t votes_yes = 0;
1703 uint16_t num_commited = 0; 1735 uint16_t num_commited = 0;
1704 uint16_t i;
1705 1736
1706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1737 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1707 "Computing rfn majority for element %s of rfn {%s}\n", 1738 "Computing rfn majority for element %s of rfn {%s}\n",
1708 debug_str_element (ri->element), 1739 debug_str_element (ri->element),
1709 debug_str_rfn_key (&rfn->key)); 1740 debug_str_rfn_key (&rfn->key));
1710 1741
1711 for (i = 0; i < rfn->num_peers; i++) 1742 for (uint16_t i = 0; i < rfn->num_peers; i++)
1712 { 1743 {
1713 if (GNUNET_NO == rfn->peer_commited[i]) 1744 if (GNUNET_NO == rfn->peer_commited[i])
1714 continue; 1745 continue;
@@ -1739,7 +1770,8 @@ struct SetCopyCls
1739 1770
1740 1771
1741static void 1772static void
1742set_copy_cb (void *cls, struct GNUNET_SET_Handle *copy) 1773set_copy_cb (void *cls,
1774 struct GNUNET_SET_Handle *copy)
1743{ 1775{
1744 struct SetCopyCls *scc = cls; 1776 struct SetCopyCls *scc = cls;
1745 struct TaskEntry *task = scc->task; 1777 struct TaskEntry *task = scc->task;
@@ -1821,8 +1853,6 @@ set_mutation_done (void *cls)
1821static void 1853static void
1822try_finish_step_early (struct Step *step) 1854try_finish_step_early (struct Step *step)
1823{ 1855{
1824 unsigned int i;
1825
1826 if (GNUNET_YES == step->is_running) 1856 if (GNUNET_YES == step->is_running)
1827 return; 1857 return;
1828 if (GNUNET_YES == step->is_finished) 1858 if (GNUNET_YES == step->is_finished)
@@ -1838,7 +1868,7 @@ try_finish_step_early (struct Step *step)
1838 step->debug_name); 1868 step->debug_name);
1839#endif 1869#endif
1840 1870
1841 for (i = 0; i < step->subordinates_len; i++) 1871 for (unsigned int i = 0; i < step->subordinates_len; i++)
1842 { 1872 {
1843 GNUNET_assert (step->subordinates[i]->pending_prereq > 0); 1873 GNUNET_assert (step->subordinates[i]->pending_prereq > 0);
1844 step->subordinates[i]->pending_prereq--; 1874 step->subordinates[i]->pending_prereq--;
@@ -1859,8 +1889,6 @@ try_finish_step_early (struct Step *step)
1859static void 1889static void
1860finish_step (struct Step *step) 1890finish_step (struct Step *step)
1861{ 1891{
1862 unsigned int i;
1863
1864 GNUNET_assert (step->finished_tasks == step->tasks_len); 1892 GNUNET_assert (step->finished_tasks == step->tasks_len);
1865 GNUNET_assert (GNUNET_YES == step->is_running); 1893 GNUNET_assert (GNUNET_YES == step->is_running);
1866 GNUNET_assert (GNUNET_NO == step->is_finished); 1894 GNUNET_assert (GNUNET_NO == step->is_finished);
@@ -1872,7 +1900,7 @@ finish_step (struct Step *step)
1872 step->subordinates_len); 1900 step->subordinates_len);
1873#endif 1901#endif
1874 1902
1875 for (i = 0; i < step->subordinates_len; i++) 1903 for (unsigned int i = 0; i < step->subordinates_len; i++)
1876 { 1904 {
1877 GNUNET_assert (step->subordinates[i]->pending_prereq > 0); 1905 GNUNET_assert (step->subordinates[i]->pending_prereq > 0);
1878 step->subordinates[i]->pending_prereq--; 1906 step->subordinates[i]->pending_prereq--;
@@ -1918,7 +1946,9 @@ task_start_apply_round (struct TaskEntry *task)
1918 set_out = lookup_set (session, &sk_out); 1946 set_out = lookup_set (session, &sk_out);
1919 if (NULL == set_out) 1947 if (NULL == set_out)
1920 { 1948 {
1921 create_set_copy_for_task (task, &sk_in, &sk_out); 1949 create_set_copy_for_task (task,
1950 &sk_in,
1951 &sk_out);
1922 return; 1952 return;
1923 } 1953 }
1924 1954
@@ -2290,7 +2320,6 @@ task_start_eval_echo (struct TaskEntry *task)
2290 return; 2320 return;
2291 } 2321 }
2292 2322
2293
2294 { 2323 {
2295 // FIXME: should be marked as a shallow copy, so 2324 // FIXME: should be marked as a shallow copy, so
2296 // we can destroy everything correctly 2325 // we can destroy everything correctly
@@ -2306,13 +2335,10 @@ task_start_eval_echo (struct TaskEntry *task)
2306 2335
2307 progress_cls = GNUNET_new (struct SetMutationProgressCls); 2336 progress_cls = GNUNET_new (struct SetMutationProgressCls);
2308 progress_cls->task = task; 2337 progress_cls->task = task;
2309
2310 rk_in = (struct RfnKey) { RFN_KIND_ECHO, task->key.repetition, 2338 rk_in = (struct RfnKey) { RFN_KIND_ECHO, task->key.repetition,
2311 task->key.leader }; 2339 task->key.leader };
2312 input_rfn = lookup_rfn (session, &rk_in); 2340 input_rfn = lookup_rfn (session, &rk_in);
2313
2314 GNUNET_assert (NULL != input_rfn); 2341 GNUNET_assert (NULL != input_rfn);
2315
2316 iter = GNUNET_CONTAINER_multihashmap_iterator_create ( 2342 iter = GNUNET_CONTAINER_multihashmap_iterator_create (
2317 input_rfn->rfn_elements); 2343 input_rfn->rfn_elements);
2318 GNUNET_assert (NULL != iter); 2344 GNUNET_assert (NULL != iter);
@@ -2334,7 +2360,8 @@ task_start_eval_echo (struct TaskEntry *task)
2334 can't simply send "nothing" for the value. Thus we mark our 'confirm' 2360 can't simply send "nothing" for the value. Thus we mark our 'confirm'
2335 reconciliation as contested. Other peers might not know that the 2361 reconciliation as contested. Other peers might not know that the
2336 leader is faulty, thus we still re-distribute in the confirmation 2362 leader is faulty, thus we still re-distribute in the confirmation
2337 round. */output_set->is_contested = GNUNET_YES; 2363 round. *///
2364 output_set->is_contested = GNUNET_YES;
2338 } 2365 }
2339 2366
2340 switch (majority_vote) 2367 switch (majority_vote)
@@ -2384,29 +2411,27 @@ task_start_finish (struct TaskEntry *task)
2384 struct SetEntry *final_set; 2411 struct SetEntry *final_set;
2385 struct ConsensusSession *session = task->step->session; 2412 struct ConsensusSession *session = task->step->session;
2386 2413
2387 final_set = lookup_set (session, &task->cls.finish.input_set); 2414 final_set = lookup_set (session,
2388 2415 &task->cls.finish.input_set);
2389 GNUNET_assert (NULL != final_set); 2416 GNUNET_assert (NULL != final_set);
2390
2391
2392 GNUNET_SET_iterate (final_set->h, 2417 GNUNET_SET_iterate (final_set->h,
2393 send_to_client_iter, 2418 &send_to_client_iter,
2394 task); 2419 task);
2395} 2420}
2396 2421
2397 2422
2398static void 2423static void
2399start_task (struct ConsensusSession *session, struct TaskEntry *task) 2424start_task (struct ConsensusSession *session,
2425 struct TaskEntry *task)
2400{ 2426{
2401 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: starting task {%s}\n", 2427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2402 session->local_peer_idx, debug_str_task_key (&task->key)); 2428 "P%u: starting task {%s}\n",
2403 2429 session->local_peer_idx,
2430 debug_str_task_key (&task->key));
2404 GNUNET_assert (GNUNET_NO == task->is_started); 2431 GNUNET_assert (GNUNET_NO == task->is_started);
2405 GNUNET_assert (GNUNET_NO == task->is_finished); 2432 GNUNET_assert (GNUNET_NO == task->is_finished);
2406 GNUNET_assert (NULL != task->start); 2433 GNUNET_assert (NULL != task->start);
2407
2408 task->start (task); 2434 task->start (task);
2409
2410 task->is_started = GNUNET_YES; 2435 task->is_started = GNUNET_YES;
2411} 2436}
2412 2437
@@ -2427,8 +2452,6 @@ run_ready_steps (struct ConsensusSession *session)
2427 if ((GNUNET_NO == step->is_running) && (0 == step->pending_prereq) && 2452 if ((GNUNET_NO == step->is_running) && (0 == step->pending_prereq) &&
2428 (GNUNET_NO == step->is_finished)) 2453 (GNUNET_NO == step->is_finished))
2429 { 2454 {
2430 size_t i;
2431
2432 GNUNET_assert (0 == step->finished_tasks); 2455 GNUNET_assert (0 == step->finished_tasks);
2433 2456
2434#ifdef GNUNET_EXTRA_LOGGING 2457#ifdef GNUNET_EXTRA_LOGGING
@@ -2440,7 +2463,7 @@ run_ready_steps (struct ConsensusSession *session)
2440#endif 2463#endif
2441 2464
2442 step->is_running = GNUNET_YES; 2465 step->is_running = GNUNET_YES;
2443 for (i = 0; i < step->tasks_len; i++) 2466 for (size_t i = 0; i < step->tasks_len; i++)
2444 start_task (session, step->tasks[i]); 2467 start_task (session, step->tasks[i]);
2445 2468
2446 /* Sometimes there is no task to trigger finishing the step, so we have to do it here. */ 2469 /* Sometimes there is no task to trigger finishing the step, so we have to do it here. */
@@ -2463,9 +2486,7 @@ finish_task (struct TaskEntry *task)
2463{ 2486{
2464 GNUNET_assert (GNUNET_NO == task->is_finished); 2487 GNUNET_assert (GNUNET_NO == task->is_finished);
2465 task->is_finished = GNUNET_YES; 2488 task->is_finished = GNUNET_YES;
2466
2467 task->step->finished_tasks++; 2489 task->step->finished_tasks++;
2468
2469 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2490 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2470 "P%u: Finishing Task {%s} (now %u/%u tasks finished in step)\n", 2491 "P%u: Finishing Task {%s} (now %u/%u tasks finished in step)\n",
2471 task->step->session->local_peer_idx, 2492 task->step->session->local_peer_idx,
@@ -2486,12 +2507,10 @@ finish_task (struct TaskEntry *task)
2486 * @return index of peer, -1 if peer is not in session 2507 * @return index of peer, -1 if peer is not in session
2487 */ 2508 */
2488static int 2509static int
2489get_peer_idx (const struct GNUNET_PeerIdentity *peer, const struct 2510get_peer_idx (const struct GNUNET_PeerIdentity *peer,
2490 ConsensusSession *session) 2511 const struct ConsensusSession *session)
2491{ 2512{
2492 int i; 2513 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])) 2514 if (0 == GNUNET_memcmp (peer, &session->peers[i]))
2496 return i; 2515 return i;
2497 return -1; 2516 return -1;
@@ -2528,14 +2547,15 @@ compute_global_id (struct ConsensusSession *session,
2528 2547
2529 2548
2530/** 2549/**
2531 * Compare two peer identities. 2550 * Compare two peer identities (for qsort()).
2532 * 2551 *
2533 * @param h1 some peer identity 2552 * @param h1 some peer identity
2534 * @param h2 some peer identity 2553 * @param h2 some peer identity
2535 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. 2554 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.
2536 */ 2555 */
2537static int 2556static int
2538peer_id_cmp (const void *h1, const void *h2) 2557peer_id_cmp (const void *h1,
2558 const void *h2)
2539{ 2559{
2540 return memcmp (h1, h2, sizeof(struct GNUNET_PeerIdentity)); 2560 return memcmp (h1, h2, sizeof(struct GNUNET_PeerIdentity));
2541} 2561}
@@ -2549,9 +2569,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 2569 * @param join_msg join message with the list of peers participating at the end
2550 */ 2570 */
2551static void 2571static void
2552initialize_session_peer_list (struct ConsensusSession *session, 2572initialize_session_peer_list (
2553 const struct 2573 struct ConsensusSession *session,
2554 GNUNET_CONSENSUS_JoinMessage *join_msg) 2574 const struct GNUNET_CONSENSUS_JoinMessage *join_msg)
2555{ 2575{
2556 const struct GNUNET_PeerIdentity *msg_peers 2576 const struct GNUNET_PeerIdentity *msg_peers
2557 = (const struct GNUNET_PeerIdentity *) &join_msg[1]; 2577 = (const struct GNUNET_PeerIdentity *) &join_msg[1];
@@ -2578,29 +2598,31 @@ initialize_session_peer_list (struct ConsensusSession *session,
2578 struct GNUNET_PeerIdentity); 2598 struct GNUNET_PeerIdentity);
2579 if (GNUNET_NO == local_peer_in_list) 2599 if (GNUNET_NO == local_peer_in_list)
2580 session->peers[session->num_peers - 1] = my_peer; 2600 session->peers[session->num_peers - 1] = my_peer;
2581
2582 GNUNET_memcpy (session->peers, 2601 GNUNET_memcpy (session->peers,
2583 msg_peers, 2602 msg_peers,
2584 ntohl (join_msg->num_peers) * sizeof(struct 2603 ntohl (join_msg->num_peers)
2585 GNUNET_PeerIdentity)); 2604 * sizeof(struct GNUNET_PeerIdentity));
2586 qsort (session->peers, 2605 qsort (session->peers,
2587 session->num_peers, 2606 session->num_peers,
2588 sizeof(struct GNUNET_PeerIdentity), 2607 sizeof (struct GNUNET_PeerIdentity),
2589 &peer_id_cmp); 2608 &peer_id_cmp);
2590} 2609}
2591 2610
2592 2611
2593static struct TaskEntry * 2612static struct TaskEntry *
2594lookup_task (struct ConsensusSession *session, 2613lookup_task (const struct ConsensusSession *session,
2595 struct TaskKey *key) 2614 const struct TaskKey *key)
2596{ 2615{
2597 struct GNUNET_HashCode hash; 2616 struct GNUNET_HashCode hash;
2598 2617
2599 2618 GNUNET_CRYPTO_hash (key,
2600 GNUNET_CRYPTO_hash (key, sizeof(struct TaskKey), &hash); 2619 sizeof(struct TaskKey),
2601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up task hash %s\n", 2620 &hash);
2621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2622 "Looking up task hash %s\n",
2602 GNUNET_h2s (&hash)); 2623 GNUNET_h2s (&hash));
2603 return GNUNET_CONTAINER_multihashmap_get (session->taskmap, &hash); 2624 return GNUNET_CONTAINER_multihashmap_get (session->taskmap,
2625 &hash);
2604} 2626}
2605 2627
2606 2628
@@ -2718,9 +2740,7 @@ put_task (struct GNUNET_CONTAINER_MultiHashMap *taskmap,
2718 GNUNET_assert (NULL != t->step); 2740 GNUNET_assert (NULL != t->step);
2719 2741
2720 t = GNUNET_memdup (t, sizeof(struct TaskEntry)); 2742 t = GNUNET_memdup (t, sizeof(struct TaskEntry));
2721
2722 s = t->step; 2743 s = t->step;
2723
2724 if (s->tasks_len == s->tasks_cap) 2744 if (s->tasks_len == s->tasks_cap)
2725 { 2745 {
2726 unsigned int target_size = 3 * (s->tasks_cap + 1) / 2; 2746 unsigned int target_size = 3 * (s->tasks_cap + 1) / 2;
@@ -2762,7 +2782,9 @@ install_step_timeouts (struct ConsensusSession *session)
2762 * Arrange two peers in some canonical order. 2782 * Arrange two peers in some canonical order.
2763 */ 2783 */
2764static void 2784static void
2765arrange_peers (uint16_t *p1, uint16_t *p2, uint16_t n) 2785arrange_peers (uint16_t *p1,
2786 uint16_t *p2,
2787 uint16_t n)
2766{ 2788{
2767 uint16_t a; 2789 uint16_t a;
2768 uint16_t b; 2790 uint16_t b;
@@ -2800,7 +2822,8 @@ arrange_peers (uint16_t *p1, uint16_t *p2, uint16_t n)
2800 * Record @a dep as a dependency of @a step. 2822 * Record @a dep as a dependency of @a step.
2801 */ 2823 */
2802static void 2824static void
2803step_depend_on (struct Step *step, struct Step *dep) 2825step_depend_on (struct Step *step,
2826 struct Step *dep)
2804{ 2827{
2805 /* We're not checking for cyclic dependencies, 2828 /* We're not checking for cyclic dependencies,
2806 but this is a cheap sanity check. */ 2829 but this is a cheap sanity check. */
@@ -2839,7 +2862,9 @@ step_depend_on (struct Step *step, struct Step *dep)
2839 2862
2840 2863
2841static struct Step * 2864static struct Step *
2842create_step (struct ConsensusSession *session, int round, int early_finishable) 2865create_step (struct ConsensusSession *session,
2866 int round,
2867 int early_finishable)
2843{ 2868{
2844 struct Step *step; 2869 struct Step *step;
2845 2870
@@ -2855,8 +2880,7 @@ create_step (struct ConsensusSession *session, int round, int early_finishable)
2855 2880
2856 2881
2857/** 2882/**
2858 * Construct the task graph for a single 2883 * Construct the task graph for a single gradecast.
2859 * gradecast.
2860 */ 2884 */
2861static void 2885static void
2862construct_task_graph_gradecast (struct ConsensusSession *session, 2886construct_task_graph_gradecast (struct ConsensusSession *session,
@@ -2867,35 +2891,32 @@ construct_task_graph_gradecast (struct ConsensusSession *session,
2867{ 2891{
2868 uint16_t n = session->num_peers; 2892 uint16_t n = session->num_peers;
2869 uint16_t me = session->local_peer_idx; 2893 uint16_t me = session->local_peer_idx;
2870
2871 uint16_t p1; 2894 uint16_t p1;
2872 uint16_t p2; 2895 uint16_t p2;
2873
2874 /* The task we're currently setting up. */ 2896 /* The task we're currently setting up. */
2875 struct TaskEntry task; 2897 struct TaskEntry task;
2876
2877 struct Step *step; 2898 struct Step *step;
2878 struct Step *prev_step; 2899 struct Step *prev_step;
2879
2880 uint16_t round; 2900 uint16_t round;
2881 2901
2882 unsigned int k;
2883
2884 round = step_before->round + 1; 2902 round = step_before->round + 1;
2885 2903
2886 /* gcast step 1: leader disseminates */ 2904 /* gcast step 1: leader disseminates */
2887 2905 step = create_step (session,
2888 step = create_step (session, round, GNUNET_YES); 2906 round,
2889 2907 GNUNET_YES);
2890#ifdef GNUNET_EXTRA_LOGGING 2908#ifdef GNUNET_EXTRA_LOGGING
2891 GNUNET_asprintf (&step->debug_name, "disseminate leader %u rep %u", lead, 2909 GNUNET_asprintf (&step->debug_name,
2910 "disseminate leader %u rep %u",
2911 lead,
2892 rep); 2912 rep);
2893#endif 2913#endif
2894 step_depend_on (step, step_before); 2914 step_depend_on (step,
2915 step_before);
2895 2916
2896 if (lead == me) 2917 if (lead == me)
2897 { 2918 {
2898 for (k = 0; k < n; k++) 2919 for (unsigned int k = 0; k < n; k++)
2899 { 2920 {
2900 if (k == me) 2921 if (k == me)
2901 continue; 2922 continue;
@@ -2952,13 +2973,19 @@ construct_task_graph_gradecast (struct ConsensusSession *session,
2952 /* gcast phase 2: echo */ 2973 /* gcast phase 2: echo */
2953 prev_step = step; 2974 prev_step = step;
2954 round += 1; 2975 round += 1;
2955 step = create_step (session, round, GNUNET_YES); 2976 step = create_step (session,
2977 round,
2978 GNUNET_YES);
2956#ifdef GNUNET_EXTRA_LOGGING 2979#ifdef GNUNET_EXTRA_LOGGING
2957 GNUNET_asprintf (&step->debug_name, "echo leader %u rep %u", lead, rep); 2980 GNUNET_asprintf (&step->debug_name,
2981 "echo leader %u rep %u",
2982 lead,
2983 rep);
2958#endif 2984#endif
2959 step_depend_on (step, prev_step); 2985 step_depend_on (step,
2986 prev_step);
2960 2987
2961 for (k = 0; k < n; k++) 2988 for (unsigned int k = 0; k < n; k++)
2962 { 2989 {
2963 p1 = k; 2990 p1 = k;
2964 p2 = me; 2991 p2 = me;
@@ -3001,7 +3028,7 @@ construct_task_graph_gradecast (struct ConsensusSession *session,
3001 step_depend_on (step, prev_step); 3028 step_depend_on (step, prev_step);
3002 3029
3003 /* gcast phase 3: confirmation and grading */ 3030 /* gcast phase 3: confirmation and grading */
3004 for (k = 0; k < n; k++) 3031 for (unsigned int k = 0; k < n; k++)
3005 { 3032 {
3006 p1 = k; 3033 p1 = k;
3007 p2 = me; 3034 p2 = me;
@@ -3050,22 +3077,15 @@ construct_task_graph (struct ConsensusSession *session)
3050{ 3077{
3051 uint16_t n = session->num_peers; 3078 uint16_t n = session->num_peers;
3052 uint16_t t = n / 3; 3079 uint16_t t = n / 3;
3053
3054 uint16_t me = session->local_peer_idx; 3080 uint16_t me = session->local_peer_idx;
3055
3056 /* The task we're currently setting up. */ 3081 /* The task we're currently setting up. */
3057 struct TaskEntry task; 3082 struct TaskEntry task;
3058
3059 /* Current leader */ 3083 /* Current leader */
3060 unsigned int lead; 3084 unsigned int lead;
3061
3062 struct Step *step; 3085 struct Step *step;
3063 struct Step *prev_step; 3086 struct Step *prev_step;
3064
3065 unsigned int round = 0; 3087 unsigned int round = 0;
3066 3088
3067 unsigned int i;
3068
3069 // XXX: introduce first step, 3089 // XXX: introduce first step,
3070 // where we wait for all insert acks 3090 // where we wait for all insert acks
3071 // from the set service 3091 // from the set service
@@ -3082,7 +3102,7 @@ construct_task_graph (struct ConsensusSession *session)
3082 step->debug_name = GNUNET_strdup ("all to all"); 3102 step->debug_name = GNUNET_strdup ("all to all");
3083#endif 3103#endif
3084 3104
3085 for (i = 0; i < n; i++) 3105 for (unsigned int i = 0; i < n; i++)
3086 { 3106 {
3087 uint16_t p1; 3107 uint16_t p1;
3088 uint16_t p2; 3108 uint16_t p2;
@@ -3111,7 +3131,7 @@ construct_task_graph (struct ConsensusSession *session)
3111 step_depend_on (step, prev_step); 3131 step_depend_on (step, prev_step);
3112 3132
3113 3133
3114 for (i = 0; i < n; i++) 3134 for (unsigned int i = 0; i < n; i++)
3115 { 3135 {
3116 uint16_t p1; 3136 uint16_t p1;
3117 uint16_t p2; 3137 uint16_t p2;
@@ -3140,7 +3160,7 @@ construct_task_graph (struct ConsensusSession *session)
3140 /* Byzantine union */ 3160 /* Byzantine union */
3141 3161
3142 /* sequential repetitions of the gradecasts */ 3162 /* sequential repetitions of the gradecasts */
3143 for (i = 0; i < t + 1; i++) 3163 for (unsigned int i = 0; i < t + 1; i++)
3144 { 3164 {
3145 struct Step *step_rep_start; 3165 struct Step *step_rep_start;
3146 struct Step *step_rep_end; 3166 struct Step *step_rep_end;
@@ -3243,9 +3263,9 @@ handle_client_join (void *cls,
3243 NULL != other_session; 3263 NULL != other_session;
3244 other_session = other_session->next) 3264 other_session = other_session->next)
3245 { 3265 {
3246 if ((other_session != session) && 3266 if ( (other_session != session) &&
3247 (0 == GNUNET_CRYPTO_hash_cmp (&session->global_id, 3267 (0 == GNUNET_CRYPTO_hash_cmp (&session->global_id,
3248 &other_session->global_id))) 3268 &other_session->global_id)) )
3249 break; 3269 break;
3250 } 3270 }
3251 3271
@@ -3262,9 +3282,9 @@ handle_client_join (void *cls,
3262 GNUNET_h2s (&m->session_id), 3282 GNUNET_h2s (&m->session_id),
3263 session->num_peers, 3283 session->num_peers,
3264 session->local_peer_idx, 3284 session->local_peer_idx,
3265 GNUNET_STRINGS_relative_time_to_string 3285 GNUNET_STRINGS_relative_time_to_string (
3266 (GNUNET_TIME_absolute_get_difference (session->conclude_start, 3286 GNUNET_TIME_absolute_get_difference (session->conclude_start,
3267 session->conclude_deadline), 3287 session->conclude_deadline),
3268 GNUNET_YES)); 3288 GNUNET_YES));
3269 3289
3270 session->set_listener 3290 session->set_listener
@@ -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 &client_insert_done,
3404 session);
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,