diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/consensus/gnunet-service-consensus.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/consensus/gnunet-service-consensus.c')
-rw-r--r-- | src/consensus/gnunet-service-consensus.c | 2972 |
1 files changed, 1492 insertions, 1480 deletions
diff --git a/src/consensus/gnunet-service-consensus.c b/src/consensus/gnunet-service-consensus.c index 912d3de6a..98fd551b2 100644 --- a/src/consensus/gnunet-service-consensus.c +++ b/src/consensus/gnunet-service-consensus.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file consensus/gnunet-service-consensus.c | 22 | * @file consensus/gnunet-service-consensus.c |
@@ -36,8 +36,7 @@ | |||
36 | #include "consensus.h" | 36 | #include "consensus.h" |
37 | 37 | ||
38 | 38 | ||
39 | enum ReferendumVote | 39 | enum ReferendumVote { |
40 | { | ||
41 | /** | 40 | /** |
42 | * Vote that nothing should change. | 41 | * Vote that nothing should change. |
43 | * This option is never voted explicitly. | 42 | * This option is never voted explicitly. |
@@ -54,8 +53,7 @@ enum ReferendumVote | |||
54 | }; | 53 | }; |
55 | 54 | ||
56 | 55 | ||
57 | enum EarlyStoppingPhase | 56 | enum EarlyStoppingPhase { |
58 | { | ||
59 | EARLY_STOPPING_NONE = 0, | 57 | EARLY_STOPPING_NONE = 0, |
60 | EARLY_STOPPING_ONE_MORE = 1, | 58 | EARLY_STOPPING_ONE_MORE = 1, |
61 | EARLY_STOPPING_DONE = 2, | 59 | EARLY_STOPPING_DONE = 2, |
@@ -100,16 +98,14 @@ struct TaskKey { | |||
100 | 98 | ||
101 | 99 | ||
102 | 100 | ||
103 | struct SetKey | 101 | struct SetKey { |
104 | { | ||
105 | int set_kind GNUNET_PACKED; | 102 | int set_kind GNUNET_PACKED; |
106 | int k1 GNUNET_PACKED; | 103 | int k1 GNUNET_PACKED; |
107 | int k2 GNUNET_PACKED; | 104 | int k2 GNUNET_PACKED; |
108 | }; | 105 | }; |
109 | 106 | ||
110 | 107 | ||
111 | struct SetEntry | 108 | struct SetEntry { |
112 | { | ||
113 | struct SetKey key; | 109 | struct SetKey key; |
114 | struct GNUNET_SET_Handle *h; | 110 | struct GNUNET_SET_Handle *h; |
115 | /** | 111 | /** |
@@ -121,15 +117,13 @@ struct SetEntry | |||
121 | }; | 117 | }; |
122 | 118 | ||
123 | 119 | ||
124 | struct DiffKey | 120 | struct DiffKey { |
125 | { | ||
126 | int diff_kind GNUNET_PACKED; | 121 | int diff_kind GNUNET_PACKED; |
127 | int k1 GNUNET_PACKED; | 122 | int k1 GNUNET_PACKED; |
128 | int k2 GNUNET_PACKED; | 123 | int k2 GNUNET_PACKED; |
129 | }; | 124 | }; |
130 | 125 | ||
131 | struct RfnKey | 126 | struct RfnKey { |
132 | { | ||
133 | int rfn_kind GNUNET_PACKED; | 127 | int rfn_kind GNUNET_PACKED; |
134 | int k1 GNUNET_PACKED; | 128 | int k1 GNUNET_PACKED; |
135 | int k2 GNUNET_PACKED; | 129 | int k2 GNUNET_PACKED; |
@@ -138,8 +132,7 @@ struct RfnKey | |||
138 | 132 | ||
139 | GNUNET_NETWORK_STRUCT_END | 133 | GNUNET_NETWORK_STRUCT_END |
140 | 134 | ||
141 | enum PhaseKind | 135 | enum PhaseKind { |
142 | { | ||
143 | PHASE_KIND_ALL_TO_ALL, | 136 | PHASE_KIND_ALL_TO_ALL, |
144 | PHASE_KIND_ALL_TO_ALL_2, | 137 | PHASE_KIND_ALL_TO_ALL_2, |
145 | PHASE_KIND_GRADECAST_LEADER, | 138 | PHASE_KIND_GRADECAST_LEADER, |
@@ -156,8 +149,7 @@ enum PhaseKind | |||
156 | }; | 149 | }; |
157 | 150 | ||
158 | 151 | ||
159 | enum SetKind | 152 | enum SetKind { |
160 | { | ||
161 | SET_KIND_NONE = 0, | 153 | SET_KIND_NONE = 0, |
162 | SET_KIND_CURRENT, | 154 | SET_KIND_CURRENT, |
163 | /** | 155 | /** |
@@ -168,16 +160,14 @@ enum SetKind | |||
168 | SET_KIND_ECHO_RESULT, | 160 | SET_KIND_ECHO_RESULT, |
169 | }; | 161 | }; |
170 | 162 | ||
171 | enum DiffKind | 163 | enum DiffKind { |
172 | { | ||
173 | DIFF_KIND_NONE = 0, | 164 | DIFF_KIND_NONE = 0, |
174 | DIFF_KIND_LEADER_PROPOSAL, | 165 | DIFF_KIND_LEADER_PROPOSAL, |
175 | DIFF_KIND_LEADER_CONSENSUS, | 166 | DIFF_KIND_LEADER_CONSENSUS, |
176 | DIFF_KIND_GRADECAST_RESULT, | 167 | DIFF_KIND_GRADECAST_RESULT, |
177 | }; | 168 | }; |
178 | 169 | ||
179 | enum RfnKind | 170 | enum RfnKind { |
180 | { | ||
181 | RFN_KIND_NONE = 0, | 171 | RFN_KIND_NONE = 0, |
182 | RFN_KIND_ECHO, | 172 | RFN_KIND_ECHO, |
183 | RFN_KIND_CONFIRM, | 173 | RFN_KIND_CONFIRM, |
@@ -185,8 +175,7 @@ enum RfnKind | |||
185 | }; | 175 | }; |
186 | 176 | ||
187 | 177 | ||
188 | struct SetOpCls | 178 | struct SetOpCls { |
189 | { | ||
190 | struct SetKey input_set; | 179 | struct SetKey input_set; |
191 | 180 | ||
192 | struct SetKey output_set; | 181 | struct SetKey output_set; |
@@ -201,8 +190,7 @@ struct SetOpCls | |||
201 | }; | 190 | }; |
202 | 191 | ||
203 | 192 | ||
204 | struct FinishCls | 193 | struct FinishCls { |
205 | { | ||
206 | struct SetKey input_set; | 194 | struct SetKey input_set; |
207 | }; | 195 | }; |
208 | 196 | ||
@@ -210,8 +198,7 @@ struct FinishCls | |||
210 | * Closure for both @a start_task | 198 | * Closure for both @a start_task |
211 | * and @a cancel_task. | 199 | * and @a cancel_task. |
212 | */ | 200 | */ |
213 | union TaskFuncCls | 201 | union TaskFuncCls { |
214 | { | ||
215 | struct SetOpCls setop; | 202 | struct SetOpCls setop; |
216 | struct FinishCls finish; | 203 | struct FinishCls finish; |
217 | }; | 204 | }; |
@@ -223,8 +210,7 @@ typedef void (*TaskFunc) (struct TaskEntry *task); | |||
223 | /* | 210 | /* |
224 | * Node in the consensus task graph. | 211 | * Node in the consensus task graph. |
225 | */ | 212 | */ |
226 | struct TaskEntry | 213 | struct TaskEntry { |
227 | { | ||
228 | struct TaskKey key; | 214 | struct TaskKey key; |
229 | 215 | ||
230 | struct Step *step; | 216 | struct Step *step; |
@@ -240,8 +226,7 @@ struct TaskEntry | |||
240 | }; | 226 | }; |
241 | 227 | ||
242 | 228 | ||
243 | struct Step | 229 | struct Step { |
244 | { | ||
245 | /** | 230 | /** |
246 | * All steps of one session are in a | 231 | * All steps of one session are in a |
247 | * linked list for easier deallocation. | 232 | * linked list for easier deallocation. |
@@ -319,8 +304,7 @@ struct Step | |||
319 | }; | 304 | }; |
320 | 305 | ||
321 | 306 | ||
322 | struct RfnElementInfo | 307 | struct RfnElementInfo { |
323 | { | ||
324 | const struct GNUNET_SET_Element *element; | 308 | const struct GNUNET_SET_Element *element; |
325 | 309 | ||
326 | /* | 310 | /* |
@@ -336,8 +320,7 @@ struct RfnElementInfo | |||
336 | }; | 320 | }; |
337 | 321 | ||
338 | 322 | ||
339 | struct ReferendumEntry | 323 | struct ReferendumEntry { |
340 | { | ||
341 | struct RfnKey key; | 324 | struct RfnKey key; |
342 | 325 | ||
343 | /* | 326 | /* |
@@ -372,8 +355,7 @@ struct ReferendumEntry | |||
372 | }; | 355 | }; |
373 | 356 | ||
374 | 357 | ||
375 | struct DiffElementInfo | 358 | struct DiffElementInfo { |
376 | { | ||
377 | const struct GNUNET_SET_Element *element; | 359 | const struct GNUNET_SET_Element *element; |
378 | 360 | ||
379 | /** | 361 | /** |
@@ -387,14 +369,12 @@ struct DiffElementInfo | |||
387 | /** | 369 | /** |
388 | * Weighted diff. | 370 | * Weighted diff. |
389 | */ | 371 | */ |
390 | struct DiffEntry | 372 | struct DiffEntry { |
391 | { | ||
392 | struct DiffKey key; | 373 | struct DiffKey key; |
393 | struct GNUNET_CONTAINER_MultiHashMap *changes; | 374 | struct GNUNET_CONTAINER_MultiHashMap *changes; |
394 | }; | 375 | }; |
395 | 376 | ||
396 | struct SetHandle | 377 | struct SetHandle { |
397 | { | ||
398 | struct SetHandle *prev; | 378 | struct SetHandle *prev; |
399 | struct SetHandle *next; | 379 | struct SetHandle *next; |
400 | 380 | ||
@@ -406,8 +386,7 @@ struct SetHandle | |||
406 | /** | 386 | /** |
407 | * A consensus session consists of one local client and the remote authorities. | 387 | * A consensus session consists of one local client and the remote authorities. |
408 | */ | 388 | */ |
409 | struct ConsensusSession | 389 | struct ConsensusSession { |
410 | { | ||
411 | /** | 390 | /** |
412 | * Consensus sessions are kept in a DLL. | 391 | * Consensus sessions are kept in a DLL. |
413 | */ | 392 | */ |
@@ -446,9 +425,9 @@ struct ConsensusSession | |||
446 | int conclude_done; | 425 | int conclude_done; |
447 | 426 | ||
448 | /** | 427 | /** |
449 | * Global consensus identification, computed | 428 | * Global consensus identification, computed |
450 | * from the session id and participating authorities. | 429 | * from the session id and participating authorities. |
451 | */ | 430 | */ |
452 | struct GNUNET_HashCode global_id; | 431 | struct GNUNET_HashCode global_id; |
453 | 432 | ||
454 | /** | 433 | /** |
@@ -539,128 +518,147 @@ struct GNUNET_STATISTICS_Handle *statistics; | |||
539 | 518 | ||
540 | 519 | ||
541 | static void | 520 | static void |
542 | finish_task (struct TaskEntry *task); | 521 | finish_task(struct TaskEntry *task); |
543 | 522 | ||
544 | 523 | ||
545 | static void | 524 | static void |
546 | run_ready_steps (struct ConsensusSession *session); | 525 | run_ready_steps(struct ConsensusSession *session); |
547 | 526 | ||
548 | 527 | ||
549 | static const char * | 528 | static const char * |
550 | phasename (uint16_t phase) | 529 | phasename(uint16_t phase) |
551 | { | 530 | { |
552 | switch (phase) | 531 | switch (phase) |
553 | { | 532 | { |
554 | case PHASE_KIND_ALL_TO_ALL: return "ALL_TO_ALL"; | 533 | case PHASE_KIND_ALL_TO_ALL: return "ALL_TO_ALL"; |
534 | |||
555 | case PHASE_KIND_ALL_TO_ALL_2: return "ALL_TO_ALL_2"; | 535 | case PHASE_KIND_ALL_TO_ALL_2: return "ALL_TO_ALL_2"; |
536 | |||
556 | case PHASE_KIND_FINISH: return "FINISH"; | 537 | case PHASE_KIND_FINISH: return "FINISH"; |
538 | |||
557 | case PHASE_KIND_GRADECAST_LEADER: return "GRADECAST_LEADER"; | 539 | case PHASE_KIND_GRADECAST_LEADER: return "GRADECAST_LEADER"; |
540 | |||
558 | case PHASE_KIND_GRADECAST_ECHO: return "GRADECAST_ECHO"; | 541 | case PHASE_KIND_GRADECAST_ECHO: return "GRADECAST_ECHO"; |
542 | |||
559 | case PHASE_KIND_GRADECAST_ECHO_GRADE: return "GRADECAST_ECHO_GRADE"; | 543 | case PHASE_KIND_GRADECAST_ECHO_GRADE: return "GRADECAST_ECHO_GRADE"; |
544 | |||
560 | case PHASE_KIND_GRADECAST_CONFIRM: return "GRADECAST_CONFIRM"; | 545 | case PHASE_KIND_GRADECAST_CONFIRM: return "GRADECAST_CONFIRM"; |
546 | |||
561 | case PHASE_KIND_GRADECAST_CONFIRM_GRADE: return "GRADECAST_CONFIRM_GRADE"; | 547 | case PHASE_KIND_GRADECAST_CONFIRM_GRADE: return "GRADECAST_CONFIRM_GRADE"; |
548 | |||
562 | case PHASE_KIND_APPLY_REP: return "APPLY_REP"; | 549 | case PHASE_KIND_APPLY_REP: return "APPLY_REP"; |
550 | |||
563 | default: return "(unknown)"; | 551 | default: return "(unknown)"; |
564 | } | 552 | } |
565 | } | 553 | } |
566 | 554 | ||
567 | 555 | ||
568 | static const char * | 556 | static const char * |
569 | setname (uint16_t kind) | 557 | setname(uint16_t kind) |
570 | { | 558 | { |
571 | switch (kind) | 559 | switch (kind) |
572 | { | 560 | { |
573 | case SET_KIND_CURRENT: return "CURRENT"; | 561 | case SET_KIND_CURRENT: return "CURRENT"; |
562 | |||
574 | case SET_KIND_LEADER_PROPOSAL: return "LEADER_PROPOSAL"; | 563 | case SET_KIND_LEADER_PROPOSAL: return "LEADER_PROPOSAL"; |
564 | |||
575 | case SET_KIND_NONE: return "NONE"; | 565 | case SET_KIND_NONE: return "NONE"; |
566 | |||
576 | default: return "(unknown)"; | 567 | default: return "(unknown)"; |
577 | } | 568 | } |
578 | } | 569 | } |
579 | 570 | ||
580 | static const char * | 571 | static const char * |
581 | rfnname (uint16_t kind) | 572 | rfnname(uint16_t kind) |
582 | { | 573 | { |
583 | switch (kind) | 574 | switch (kind) |
584 | { | 575 | { |
585 | case RFN_KIND_NONE: return "NONE"; | 576 | case RFN_KIND_NONE: return "NONE"; |
577 | |||
586 | case RFN_KIND_ECHO: return "ECHO"; | 578 | case RFN_KIND_ECHO: return "ECHO"; |
579 | |||
587 | case RFN_KIND_CONFIRM: return "CONFIRM"; | 580 | case RFN_KIND_CONFIRM: return "CONFIRM"; |
581 | |||
588 | default: return "(unknown)"; | 582 | default: return "(unknown)"; |
589 | } | 583 | } |
590 | } | 584 | } |
591 | 585 | ||
592 | static const char * | 586 | static const char * |
593 | diffname (uint16_t kind) | 587 | diffname(uint16_t kind) |
594 | { | 588 | { |
595 | switch (kind) | 589 | switch (kind) |
596 | { | 590 | { |
597 | case DIFF_KIND_NONE: return "NONE"; | 591 | case DIFF_KIND_NONE: return "NONE"; |
592 | |||
598 | case DIFF_KIND_LEADER_CONSENSUS: return "LEADER_CONSENSUS"; | 593 | case DIFF_KIND_LEADER_CONSENSUS: return "LEADER_CONSENSUS"; |
594 | |||
599 | case DIFF_KIND_GRADECAST_RESULT: return "GRADECAST_RESULT"; | 595 | case DIFF_KIND_GRADECAST_RESULT: return "GRADECAST_RESULT"; |
596 | |||
600 | case DIFF_KIND_LEADER_PROPOSAL: return "LEADER_PROPOSAL"; | 597 | case DIFF_KIND_LEADER_PROPOSAL: return "LEADER_PROPOSAL"; |
598 | |||
601 | default: return "(unknown)"; | 599 | default: return "(unknown)"; |
602 | } | 600 | } |
603 | } | 601 | } |
604 | 602 | ||
605 | #ifdef GNUNET_EXTRA_LOGGING | 603 | #ifdef GNUNET_EXTRA_LOGGING |
606 | 604 | ||
607 | 605 | ||
608 | static const char * | 606 | static const char * |
609 | debug_str_element (const struct GNUNET_SET_Element *el) | 607 | debug_str_element(const struct GNUNET_SET_Element *el) |
610 | { | 608 | { |
611 | struct GNUNET_HashCode hash; | 609 | struct GNUNET_HashCode hash; |
612 | 610 | ||
613 | GNUNET_SET_element_hash (el, &hash); | 611 | GNUNET_SET_element_hash(el, &hash); |
614 | 612 | ||
615 | return GNUNET_h2s (&hash); | 613 | return GNUNET_h2s(&hash); |
616 | } | 614 | } |
617 | 615 | ||
618 | static const char * | 616 | static const char * |
619 | debug_str_task_key (struct TaskKey *tk) | 617 | debug_str_task_key(struct TaskKey *tk) |
620 | { | 618 | { |
621 | static char buf[256]; | 619 | static char buf[256]; |
622 | 620 | ||
623 | snprintf (buf, sizeof (buf), | 621 | snprintf(buf, sizeof(buf), |
624 | "TaskKey kind=%s, p1=%d, p2=%d, l=%d, rep=%d", | 622 | "TaskKey kind=%s, p1=%d, p2=%d, l=%d, rep=%d", |
625 | phasename (tk->kind), tk->peer1, tk->peer2, | 623 | phasename(tk->kind), tk->peer1, tk->peer2, |
626 | tk->leader, tk->repetition); | 624 | tk->leader, tk->repetition); |
627 | 625 | ||
628 | return buf; | 626 | return buf; |
629 | } | 627 | } |
630 | 628 | ||
631 | static const char * | 629 | static const char * |
632 | debug_str_diff_key (struct DiffKey *dk) | 630 | debug_str_diff_key(struct DiffKey *dk) |
633 | { | 631 | { |
634 | static char buf[256]; | 632 | static char buf[256]; |
635 | 633 | ||
636 | snprintf (buf, sizeof (buf), | 634 | snprintf(buf, sizeof(buf), |
637 | "DiffKey kind=%s, k1=%d, k2=%d", | 635 | "DiffKey kind=%s, k1=%d, k2=%d", |
638 | diffname (dk->diff_kind), dk->k1, dk->k2); | 636 | diffname(dk->diff_kind), dk->k1, dk->k2); |
639 | 637 | ||
640 | return buf; | 638 | return buf; |
641 | } | 639 | } |
642 | 640 | ||
643 | static const char * | 641 | static const char * |
644 | debug_str_set_key (const struct SetKey *sk) | 642 | debug_str_set_key(const struct SetKey *sk) |
645 | { | 643 | { |
646 | static char buf[256]; | 644 | static char buf[256]; |
647 | 645 | ||
648 | snprintf (buf, sizeof (buf), | 646 | snprintf(buf, sizeof(buf), |
649 | "SetKey kind=%s, k1=%d, k2=%d", | 647 | "SetKey kind=%s, k1=%d, k2=%d", |
650 | setname (sk->set_kind), sk->k1, sk->k2); | 648 | setname(sk->set_kind), sk->k1, sk->k2); |
651 | 649 | ||
652 | return buf; | 650 | return buf; |
653 | } | 651 | } |
654 | 652 | ||
655 | 653 | ||
656 | static const char * | 654 | static const char * |
657 | debug_str_rfn_key (const struct RfnKey *rk) | 655 | debug_str_rfn_key(const struct RfnKey *rk) |
658 | { | 656 | { |
659 | static char buf[256]; | 657 | static char buf[256]; |
660 | 658 | ||
661 | snprintf (buf, sizeof (buf), | 659 | snprintf(buf, sizeof(buf), |
662 | "RfnKey kind=%s, k1=%d, k2=%d", | 660 | "RfnKey kind=%s, k1=%d, k2=%d", |
663 | rfnname (rk->rfn_kind), rk->k1, rk->k2); | 661 | rfnname(rk->rfn_kind), rk->k1, rk->k2); |
664 | 662 | ||
665 | return buf; | 663 | return buf; |
666 | } | 664 | } |
@@ -678,164 +676,164 @@ debug_str_rfn_key (const struct RfnKey *rk) | |||
678 | * @return #GNUNET_YES to continue iterating, #GNUNET_NO to stop. | 676 | * @return #GNUNET_YES to continue iterating, #GNUNET_NO to stop. |
679 | */ | 677 | */ |
680 | static int | 678 | static int |
681 | send_to_client_iter (void *cls, | 679 | send_to_client_iter(void *cls, |
682 | const struct GNUNET_SET_Element *element) | 680 | const struct GNUNET_SET_Element *element) |
683 | { | 681 | { |
684 | struct TaskEntry *task = (struct TaskEntry *) cls; | 682 | struct TaskEntry *task = (struct TaskEntry *)cls; |
685 | struct ConsensusSession *session = task->step->session; | 683 | struct ConsensusSession *session = task->step->session; |
686 | struct GNUNET_MQ_Envelope *ev; | 684 | struct GNUNET_MQ_Envelope *ev; |
687 | 685 | ||
688 | if (NULL != element) | 686 | if (NULL != element) |
689 | { | 687 | { |
690 | struct GNUNET_CONSENSUS_ElementMessage *m; | 688 | struct GNUNET_CONSENSUS_ElementMessage *m; |
691 | const struct ConsensusElement *ce; | 689 | const struct ConsensusElement *ce; |
692 | 690 | ||
693 | GNUNET_assert (GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT == element->element_type); | 691 | GNUNET_assert(GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT == element->element_type); |
694 | ce = element->data; | 692 | ce = element->data; |
695 | 693 | ||
696 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "marker is %u\n", (unsigned) ce->marker); | 694 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "marker is %u\n", (unsigned)ce->marker); |
697 | 695 | ||
698 | if (0 != ce->marker) | 696 | if (0 != ce->marker) |
699 | return GNUNET_YES; | 697 | return GNUNET_YES; |
700 | 698 | ||
701 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 699 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
702 | "P%d: sending element %s to client\n", | 700 | "P%d: sending element %s to client\n", |
703 | session->local_peer_idx, | 701 | session->local_peer_idx, |
704 | debug_str_element (element)); | 702 | debug_str_element(element)); |
705 | 703 | ||
706 | ev = GNUNET_MQ_msg_extra (m, element->size - sizeof (struct ConsensusElement), | 704 | ev = GNUNET_MQ_msg_extra(m, element->size - sizeof(struct ConsensusElement), |
707 | GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT); | 705 | GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT); |
708 | m->element_type = ce->payload_type; | 706 | m->element_type = ce->payload_type; |
709 | GNUNET_memcpy (&m[1], &ce[1], element->size - sizeof (struct ConsensusElement)); | 707 | GNUNET_memcpy(&m[1], &ce[1], element->size - sizeof(struct ConsensusElement)); |
710 | GNUNET_MQ_send (session->client_mq, ev); | 708 | GNUNET_MQ_send(session->client_mq, ev); |
711 | } | 709 | } |
712 | else | 710 | else |
713 | { | 711 | { |
714 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 712 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
715 | "P%d: finished iterating elements for client\n", | 713 | "P%d: finished iterating elements for client\n", |
716 | session->local_peer_idx); | 714 | session->local_peer_idx); |
717 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE_DONE); | 715 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE_DONE); |
718 | GNUNET_MQ_send (session->client_mq, ev); | 716 | GNUNET_MQ_send(session->client_mq, ev); |
719 | } | 717 | } |
720 | return GNUNET_YES; | 718 | return GNUNET_YES; |
721 | } | 719 | } |
722 | 720 | ||
723 | 721 | ||
724 | static struct SetEntry * | 722 | static struct SetEntry * |
725 | lookup_set (struct ConsensusSession *session, struct SetKey *key) | 723 | lookup_set(struct ConsensusSession *session, struct SetKey *key) |
726 | { | 724 | { |
727 | struct GNUNET_HashCode hash; | 725 | struct GNUNET_HashCode hash; |
728 | 726 | ||
729 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 727 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
730 | "P%u: looking up set {%s}\n", | 728 | "P%u: looking up set {%s}\n", |
731 | session->local_peer_idx, | 729 | session->local_peer_idx, |
732 | debug_str_set_key (key)); | 730 | debug_str_set_key(key)); |
733 | 731 | ||
734 | GNUNET_assert (SET_KIND_NONE != key->set_kind); | 732 | GNUNET_assert(SET_KIND_NONE != key->set_kind); |
735 | GNUNET_CRYPTO_hash (key, sizeof (struct SetKey), &hash); | 733 | GNUNET_CRYPTO_hash(key, sizeof(struct SetKey), &hash); |
736 | return GNUNET_CONTAINER_multihashmap_get (session->setmap, &hash); | 734 | return GNUNET_CONTAINER_multihashmap_get(session->setmap, &hash); |
737 | } | 735 | } |
738 | 736 | ||
739 | 737 | ||
740 | static struct DiffEntry * | 738 | static struct DiffEntry * |
741 | lookup_diff (struct ConsensusSession *session, struct DiffKey *key) | 739 | lookup_diff(struct ConsensusSession *session, struct DiffKey *key) |
742 | { | 740 | { |
743 | struct GNUNET_HashCode hash; | 741 | struct GNUNET_HashCode hash; |
744 | 742 | ||
745 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 743 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
746 | "P%u: looking up diff {%s}\n", | 744 | "P%u: looking up diff {%s}\n", |
747 | session->local_peer_idx, | 745 | session->local_peer_idx, |
748 | debug_str_diff_key (key)); | 746 | debug_str_diff_key(key)); |
749 | 747 | ||
750 | GNUNET_assert (DIFF_KIND_NONE != key->diff_kind); | 748 | GNUNET_assert(DIFF_KIND_NONE != key->diff_kind); |
751 | GNUNET_CRYPTO_hash (key, sizeof (struct DiffKey), &hash); | 749 | GNUNET_CRYPTO_hash(key, sizeof(struct DiffKey), &hash); |
752 | return GNUNET_CONTAINER_multihashmap_get (session->diffmap, &hash); | 750 | return GNUNET_CONTAINER_multihashmap_get(session->diffmap, &hash); |
753 | } | 751 | } |
754 | 752 | ||
755 | 753 | ||
756 | static struct ReferendumEntry * | 754 | static struct ReferendumEntry * |
757 | lookup_rfn (struct ConsensusSession *session, struct RfnKey *key) | 755 | lookup_rfn(struct ConsensusSession *session, struct RfnKey *key) |
758 | { | 756 | { |
759 | struct GNUNET_HashCode hash; | 757 | struct GNUNET_HashCode hash; |
760 | 758 | ||
761 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 759 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
762 | "P%u: looking up rfn {%s}\n", | 760 | "P%u: looking up rfn {%s}\n", |
763 | session->local_peer_idx, | 761 | session->local_peer_idx, |
764 | debug_str_rfn_key (key)); | 762 | debug_str_rfn_key(key)); |
765 | 763 | ||
766 | GNUNET_assert (RFN_KIND_NONE != key->rfn_kind); | 764 | GNUNET_assert(RFN_KIND_NONE != key->rfn_kind); |
767 | GNUNET_CRYPTO_hash (key, sizeof (struct RfnKey), &hash); | 765 | GNUNET_CRYPTO_hash(key, sizeof(struct RfnKey), &hash); |
768 | return GNUNET_CONTAINER_multihashmap_get (session->rfnmap, &hash); | 766 | return GNUNET_CONTAINER_multihashmap_get(session->rfnmap, &hash); |
769 | } | 767 | } |
770 | 768 | ||
771 | 769 | ||
772 | static void | 770 | static void |
773 | diff_insert (struct DiffEntry *diff, | 771 | diff_insert(struct DiffEntry *diff, |
774 | int weight, | 772 | int weight, |
775 | const struct GNUNET_SET_Element *element) | 773 | const struct GNUNET_SET_Element *element) |
776 | { | 774 | { |
777 | struct DiffElementInfo *di; | 775 | struct DiffElementInfo *di; |
778 | struct GNUNET_HashCode hash; | 776 | struct GNUNET_HashCode hash; |
779 | 777 | ||
780 | GNUNET_assert ( (1 == weight) || (-1 == weight)); | 778 | GNUNET_assert((1 == weight) || (-1 == weight)); |
781 | 779 | ||
782 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 780 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
783 | "diff_insert with element size %u\n", | 781 | "diff_insert with element size %u\n", |
784 | element->size); | 782 | element->size); |
785 | 783 | ||
786 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 784 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
787 | "hashing element\n"); | 785 | "hashing element\n"); |
788 | 786 | ||
789 | GNUNET_SET_element_hash (element, &hash); | 787 | GNUNET_SET_element_hash(element, &hash); |
790 | 788 | ||
791 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 789 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
792 | "hashed element\n"); | 790 | "hashed element\n"); |
793 | 791 | ||
794 | di = GNUNET_CONTAINER_multihashmap_get (diff->changes, &hash); | 792 | di = GNUNET_CONTAINER_multihashmap_get(diff->changes, &hash); |
795 | 793 | ||
796 | if (NULL == di) | 794 | if (NULL == di) |
797 | { | 795 | { |
798 | di = GNUNET_new (struct DiffElementInfo); | 796 | di = GNUNET_new(struct DiffElementInfo); |
799 | di->element = GNUNET_SET_element_dup (element); | 797 | di->element = GNUNET_SET_element_dup(element); |
800 | GNUNET_assert (GNUNET_OK == | 798 | GNUNET_assert(GNUNET_OK == |
801 | GNUNET_CONTAINER_multihashmap_put (diff->changes, | 799 | GNUNET_CONTAINER_multihashmap_put(diff->changes, |
802 | &hash, di, | 800 | &hash, di, |
803 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 801 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
804 | } | 802 | } |
805 | 803 | ||
806 | di->weight = weight; | 804 | di->weight = weight; |
807 | } | 805 | } |
808 | 806 | ||
809 | 807 | ||
810 | static void | 808 | static void |
811 | rfn_commit (struct ReferendumEntry *rfn, | 809 | rfn_commit(struct ReferendumEntry *rfn, |
812 | uint16_t commit_peer) | 810 | uint16_t commit_peer) |
813 | { | 811 | { |
814 | GNUNET_assert (commit_peer < rfn->num_peers); | 812 | GNUNET_assert(commit_peer < rfn->num_peers); |
815 | 813 | ||
816 | rfn->peer_commited[commit_peer] = GNUNET_YES; | 814 | rfn->peer_commited[commit_peer] = GNUNET_YES; |
817 | } | 815 | } |
818 | 816 | ||
819 | 817 | ||
820 | static void | 818 | static void |
821 | rfn_contest (struct ReferendumEntry *rfn, | 819 | rfn_contest(struct ReferendumEntry *rfn, |
822 | uint16_t contested_peer) | 820 | uint16_t contested_peer) |
823 | { | 821 | { |
824 | GNUNET_assert (contested_peer < rfn->num_peers); | 822 | GNUNET_assert(contested_peer < rfn->num_peers); |
825 | 823 | ||
826 | rfn->peer_contested[contested_peer] = GNUNET_YES; | 824 | rfn->peer_contested[contested_peer] = GNUNET_YES; |
827 | } | 825 | } |
828 | 826 | ||
829 | 827 | ||
830 | static uint16_t | 828 | static uint16_t |
831 | rfn_noncontested (struct ReferendumEntry *rfn) | 829 | rfn_noncontested(struct ReferendumEntry *rfn) |
832 | { | 830 | { |
833 | uint16_t i; | 831 | uint16_t i; |
834 | uint16_t ret; | 832 | uint16_t ret; |
835 | 833 | ||
836 | ret = 0; | 834 | ret = 0; |
837 | for (i = 0; i < rfn->num_peers; i++) | 835 | for (i = 0; i < rfn->num_peers; i++) |
838 | if ( (GNUNET_YES == rfn->peer_commited[i]) && (GNUNET_NO == rfn->peer_contested[i]) ) | 836 | if ((GNUNET_YES == rfn->peer_commited[i]) && (GNUNET_NO == rfn->peer_contested[i])) |
839 | ret++; | 837 | ret++; |
840 | 838 | ||
841 | return ret; | 839 | return ret; |
@@ -843,33 +841,33 @@ rfn_noncontested (struct ReferendumEntry *rfn) | |||
843 | 841 | ||
844 | 842 | ||
845 | static void | 843 | static void |
846 | rfn_vote (struct ReferendumEntry *rfn, | 844 | rfn_vote(struct ReferendumEntry *rfn, |
847 | uint16_t voting_peer, | 845 | uint16_t voting_peer, |
848 | enum ReferendumVote vote, | 846 | enum ReferendumVote vote, |
849 | const struct GNUNET_SET_Element *element) | 847 | const struct GNUNET_SET_Element *element) |
850 | { | 848 | { |
851 | struct RfnElementInfo *ri; | 849 | struct RfnElementInfo *ri; |
852 | struct GNUNET_HashCode hash; | 850 | struct GNUNET_HashCode hash; |
853 | 851 | ||
854 | GNUNET_assert (voting_peer < rfn->num_peers); | 852 | GNUNET_assert(voting_peer < rfn->num_peers); |
855 | 853 | ||
856 | /* Explicit voting only makes sense with VOTE_ADD or VOTE_REMOTE, | 854 | /* Explicit voting only makes sense with VOTE_ADD or VOTE_REMOTE, |
857 | since VOTE_KEEP is implicit in not voting. */ | 855 | since VOTE_KEEP is implicit in not voting. */ |
858 | GNUNET_assert ( (VOTE_ADD == vote) || (VOTE_REMOVE == vote) ); | 856 | GNUNET_assert((VOTE_ADD == vote) || (VOTE_REMOVE == vote)); |
859 | 857 | ||
860 | GNUNET_SET_element_hash (element, &hash); | 858 | GNUNET_SET_element_hash(element, &hash); |
861 | ri = GNUNET_CONTAINER_multihashmap_get (rfn->rfn_elements, &hash); | 859 | ri = GNUNET_CONTAINER_multihashmap_get(rfn->rfn_elements, &hash); |
862 | 860 | ||
863 | if (NULL == ri) | 861 | if (NULL == ri) |
864 | { | 862 | { |
865 | ri = GNUNET_new (struct RfnElementInfo); | 863 | ri = GNUNET_new(struct RfnElementInfo); |
866 | ri->element = GNUNET_SET_element_dup (element); | 864 | ri->element = GNUNET_SET_element_dup(element); |
867 | ri->votes = GNUNET_new_array (rfn->num_peers, int); | 865 | ri->votes = GNUNET_new_array(rfn->num_peers, int); |
868 | GNUNET_assert (GNUNET_OK == | 866 | GNUNET_assert(GNUNET_OK == |
869 | GNUNET_CONTAINER_multihashmap_put (rfn->rfn_elements, | 867 | GNUNET_CONTAINER_multihashmap_put(rfn->rfn_elements, |
870 | &hash, ri, | 868 | &hash, ri, |
871 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 869 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
872 | } | 870 | } |
873 | 871 | ||
874 | ri->votes[voting_peer] = GNUNET_YES; | 872 | ri->votes[voting_peer] = GNUNET_YES; |
875 | ri->proposal = vote; | 873 | ri->proposal = vote; |
@@ -877,9 +875,10 @@ rfn_vote (struct ReferendumEntry *rfn, | |||
877 | 875 | ||
878 | 876 | ||
879 | static uint16_t | 877 | static uint16_t |
880 | task_other_peer (struct TaskEntry *task) | 878 | task_other_peer(struct TaskEntry *task) |
881 | { | 879 | { |
882 | uint16_t me = task->step->session->local_peer_idx; | 880 | uint16_t me = task->step->session->local_peer_idx; |
881 | |||
883 | if (task->key.peer1 == me) | 882 | if (task->key.peer1 == me) |
884 | return task->key.peer2; | 883 | return task->key.peer2; |
885 | return task->key.peer1; | 884 | return task->key.peer1; |
@@ -887,10 +886,10 @@ task_other_peer (struct TaskEntry *task) | |||
887 | 886 | ||
888 | 887 | ||
889 | static int | 888 | static int |
890 | cmp_uint64_t (const void *pa, const void *pb) | 889 | cmp_uint64_t(const void *pa, const void *pb) |
891 | { | 890 | { |
892 | uint64_t a = *(uint64_t *) pa; | 891 | uint64_t a = *(uint64_t *)pa; |
893 | uint64_t b = *(uint64_t *) pb; | 892 | uint64_t b = *(uint64_t *)pb; |
894 | 893 | ||
895 | if (a == b) | 894 | if (a == b) |
896 | return 0; | 895 | return 0; |
@@ -910,10 +909,10 @@ cmp_uint64_t (const void *pa, const void *pb) | |||
910 | * @param status see enum GNUNET_SET_Status | 909 | * @param status see enum GNUNET_SET_Status |
911 | */ | 910 | */ |
912 | static void | 911 | static void |
913 | set_result_cb (void *cls, | 912 | set_result_cb(void *cls, |
914 | const struct GNUNET_SET_Element *element, | 913 | const struct GNUNET_SET_Element *element, |
915 | uint64_t current_size, | 914 | uint64_t current_size, |
916 | enum GNUNET_SET_Status status) | 915 | enum GNUNET_SET_Status status) |
917 | { | 916 | { |
918 | struct TaskEntry *task = cls; | 917 | struct TaskEntry *task = cls; |
919 | struct ConsensusSession *session = task->step->session; | 918 | struct ConsensusSession *session = task->step->session; |
@@ -925,244 +924,246 @@ set_result_cb (void *cls, | |||
925 | const struct ConsensusElement *consensus_element = NULL; | 924 | const struct ConsensusElement *consensus_element = NULL; |
926 | 925 | ||
927 | if (NULL != element) | 926 | if (NULL != element) |
928 | { | 927 | { |
929 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 928 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
930 | "P%u: got element of type %u, status %u\n", | 929 | "P%u: got element of type %u, status %u\n", |
931 | session->local_peer_idx, | 930 | session->local_peer_idx, |
932 | (unsigned) element->element_type, | 931 | (unsigned)element->element_type, |
933 | (unsigned) status); | 932 | (unsigned)status); |
934 | GNUNET_assert (GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT == element->element_type); | 933 | GNUNET_assert(GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT == element->element_type); |
935 | consensus_element = element->data; | 934 | consensus_element = element->data; |
936 | } | 935 | } |
937 | 936 | ||
938 | setop = &task->cls.setop; | 937 | setop = &task->cls.setop; |
939 | 938 | ||
940 | 939 | ||
941 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 940 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
942 | "P%u: got set result for {%s}, status %u\n", | 941 | "P%u: got set result for {%s}, status %u\n", |
943 | session->local_peer_idx, | 942 | session->local_peer_idx, |
944 | debug_str_task_key (&task->key), | 943 | debug_str_task_key(&task->key), |
945 | status); | 944 | status); |
946 | 945 | ||
947 | if (GNUNET_NO == task->is_started) | 946 | if (GNUNET_NO == task->is_started) |
948 | { | 947 | { |
949 | GNUNET_break_op (0); | 948 | GNUNET_break_op(0); |
950 | return; | 949 | return; |
951 | } | 950 | } |
952 | 951 | ||
953 | if (GNUNET_YES == task->is_finished) | 952 | if (GNUNET_YES == task->is_finished) |
954 | { | 953 | { |
955 | GNUNET_break_op (0); | 954 | GNUNET_break_op(0); |
956 | return; | 955 | return; |
957 | } | 956 | } |
958 | 957 | ||
959 | other_idx = task_other_peer (task); | 958 | other_idx = task_other_peer(task); |
960 | 959 | ||
961 | if (SET_KIND_NONE != setop->output_set.set_kind) | 960 | if (SET_KIND_NONE != setop->output_set.set_kind) |
962 | { | 961 | { |
963 | output_set = lookup_set (session, &setop->output_set); | 962 | output_set = lookup_set(session, &setop->output_set); |
964 | GNUNET_assert (NULL != output_set); | 963 | GNUNET_assert(NULL != output_set); |
965 | } | 964 | } |
966 | 965 | ||
967 | if (DIFF_KIND_NONE != setop->output_diff.diff_kind) | 966 | if (DIFF_KIND_NONE != setop->output_diff.diff_kind) |
968 | { | 967 | { |
969 | output_diff = lookup_diff (session, &setop->output_diff); | 968 | output_diff = lookup_diff(session, &setop->output_diff); |
970 | GNUNET_assert (NULL != output_diff); | 969 | GNUNET_assert(NULL != output_diff); |
971 | } | 970 | } |
972 | 971 | ||
973 | if (RFN_KIND_NONE != setop->output_rfn.rfn_kind) | 972 | if (RFN_KIND_NONE != setop->output_rfn.rfn_kind) |
974 | { | 973 | { |
975 | output_rfn = lookup_rfn (session, &setop->output_rfn); | 974 | output_rfn = lookup_rfn(session, &setop->output_rfn); |
976 | GNUNET_assert (NULL != output_rfn); | 975 | GNUNET_assert(NULL != output_rfn); |
977 | } | 976 | } |
978 | 977 | ||
979 | if (GNUNET_YES == session->peers_blacklisted[other_idx]) | 978 | if (GNUNET_YES == session->peers_blacklisted[other_idx]) |
980 | { | 979 | { |
981 | /* Peer might have been blacklisted | 980 | /* Peer might have been blacklisted |
982 | by a gradecast running in parallel, ignore elements from now */ | 981 | by a gradecast running in parallel, ignore elements from now */ |
983 | if (GNUNET_SET_STATUS_ADD_LOCAL == status) | 982 | if (GNUNET_SET_STATUS_ADD_LOCAL == status) |
984 | return; | 983 | return; |
985 | if (GNUNET_SET_STATUS_ADD_REMOTE == status) | 984 | if (GNUNET_SET_STATUS_ADD_REMOTE == status) |
986 | return; | 985 | return; |
987 | } | ||
988 | |||
989 | if ( (NULL != consensus_element) && (0 != consensus_element->marker) ) | ||
990 | { | ||
991 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
992 | "P%u: got some marker\n", | ||
993 | session->local_peer_idx); | ||
994 | if ( (GNUNET_YES == setop->transceive_contested) && | ||
995 | (CONSENSUS_MARKER_CONTESTED == consensus_element->marker) ) | ||
996 | { | ||
997 | GNUNET_assert (NULL != output_rfn); | ||
998 | rfn_contest (output_rfn, task_other_peer (task)); | ||
999 | return; | ||
1000 | } | 986 | } |
1001 | 987 | ||
1002 | if (CONSENSUS_MARKER_SIZE == consensus_element->marker) | 988 | if ((NULL != consensus_element) && (0 != consensus_element->marker)) |
1003 | { | 989 | { |
990 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
991 | "P%u: got some marker\n", | ||
992 | session->local_peer_idx); | ||
993 | if ((GNUNET_YES == setop->transceive_contested) && | ||
994 | (CONSENSUS_MARKER_CONTESTED == consensus_element->marker)) | ||
995 | { | ||
996 | GNUNET_assert(NULL != output_rfn); | ||
997 | rfn_contest(output_rfn, task_other_peer(task)); | ||
998 | return; | ||
999 | } | ||
1004 | 1000 | ||
1005 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1001 | if (CONSENSUS_MARKER_SIZE == consensus_element->marker) |
1006 | "P%u: got size marker\n", | 1002 | { |
1007 | session->local_peer_idx); | 1003 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1008 | 1004 | "P%u: got size marker\n", | |
1009 | 1005 | session->local_peer_idx); | |
1010 | struct ConsensusSizeElement *cse = (void *) consensus_element; | 1006 | |
1007 | |||
1008 | struct ConsensusSizeElement *cse = (void *)consensus_element; | ||
1009 | |||
1010 | if (cse->sender_index == other_idx) | ||
1011 | { | ||
1012 | if (NULL == session->first_sizes_received) | ||
1013 | session->first_sizes_received = GNUNET_new_array(session->num_peers, uint64_t); | ||
1014 | session->first_sizes_received[other_idx] = GNUNET_ntohll(cse->size); | ||
1015 | |||
1016 | uint64_t *copy = GNUNET_memdup(session->first_sizes_received, sizeof(uint64_t) * session->num_peers); | ||
1017 | qsort(copy, session->num_peers, sizeof(uint64_t), cmp_uint64_t); | ||
1018 | session->lower_bound = copy[session->num_peers / 3 + 1]; | ||
1019 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1020 | "P%u: lower bound %llu\n", | ||
1021 | session->local_peer_idx, | ||
1022 | (long long)session->lower_bound); | ||
1023 | GNUNET_free(copy); | ||
1024 | } | ||
1025 | return; | ||
1026 | } | ||
1011 | 1027 | ||
1012 | if (cse->sender_index == other_idx) | ||
1013 | { | ||
1014 | if (NULL == session->first_sizes_received) | ||
1015 | session->first_sizes_received = GNUNET_new_array (session->num_peers, uint64_t); | ||
1016 | session->first_sizes_received[other_idx] = GNUNET_ntohll (cse->size); | ||
1017 | |||
1018 | uint64_t *copy = GNUNET_memdup (session->first_sizes_received, sizeof (uint64_t) * session->num_peers); | ||
1019 | qsort (copy, session->num_peers, sizeof (uint64_t), cmp_uint64_t); | ||
1020 | session->lower_bound = copy[session->num_peers / 3 + 1]; | ||
1021 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1022 | "P%u: lower bound %llu\n", | ||
1023 | session->local_peer_idx, | ||
1024 | (long long) session->lower_bound); | ||
1025 | GNUNET_free (copy); | ||
1026 | } | ||
1027 | return; | 1028 | return; |
1028 | } | 1029 | } |
1029 | 1030 | ||
1030 | return; | ||
1031 | } | ||
1032 | |||
1033 | switch (status) | 1031 | switch (status) |
1034 | { | 1032 | { |
1035 | case GNUNET_SET_STATUS_ADD_LOCAL: | 1033 | case GNUNET_SET_STATUS_ADD_LOCAL: |
1036 | GNUNET_assert (NULL != consensus_element); | 1034 | GNUNET_assert(NULL != consensus_element); |
1037 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1035 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1038 | "Adding element in Task {%s}\n", | 1036 | "Adding element in Task {%s}\n", |
1039 | debug_str_task_key (&task->key)); | 1037 | debug_str_task_key(&task->key)); |
1040 | if (NULL != output_set) | 1038 | if (NULL != output_set) |
1041 | { | 1039 | { |
1042 | // FIXME: record pending adds, use callback | 1040 | // FIXME: record pending adds, use callback |
1043 | GNUNET_SET_add_element (output_set->h, | 1041 | GNUNET_SET_add_element(output_set->h, |
1044 | element, | 1042 | element, |
1045 | NULL, | 1043 | NULL, |
1046 | NULL); | 1044 | NULL); |
1047 | #ifdef GNUNET_EXTRA_LOGGING | 1045 | #ifdef GNUNET_EXTRA_LOGGING |
1048 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1046 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1049 | "P%u: adding element %s into set {%s} of task {%s}\n", | 1047 | "P%u: adding element %s into set {%s} of task {%s}\n", |
1050 | session->local_peer_idx, | 1048 | session->local_peer_idx, |
1051 | debug_str_element (element), | 1049 | debug_str_element(element), |
1052 | debug_str_set_key (&setop->output_set), | 1050 | debug_str_set_key(&setop->output_set), |
1053 | debug_str_task_key (&task->key)); | 1051 | debug_str_task_key(&task->key)); |
1054 | #endif | 1052 | #endif |
1055 | } | 1053 | } |
1056 | if (NULL != output_diff) | 1054 | if (NULL != output_diff) |
1057 | { | 1055 | { |
1058 | diff_insert (output_diff, 1, element); | 1056 | diff_insert(output_diff, 1, element); |
1059 | #ifdef GNUNET_EXTRA_LOGGING | 1057 | #ifdef GNUNET_EXTRA_LOGGING |
1060 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1058 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1061 | "P%u: adding element %s into diff {%s} of task {%s}\n", | 1059 | "P%u: adding element %s into diff {%s} of task {%s}\n", |
1062 | session->local_peer_idx, | 1060 | session->local_peer_idx, |
1063 | debug_str_element (element), | 1061 | debug_str_element(element), |
1064 | debug_str_diff_key (&setop->output_diff), | 1062 | debug_str_diff_key(&setop->output_diff), |
1065 | debug_str_task_key (&task->key)); | 1063 | debug_str_task_key(&task->key)); |
1066 | #endif | 1064 | #endif |
1067 | } | 1065 | } |
1068 | if (NULL != output_rfn) | 1066 | if (NULL != output_rfn) |
1069 | { | 1067 | { |
1070 | rfn_vote (output_rfn, task_other_peer (task), VOTE_ADD, element); | 1068 | rfn_vote(output_rfn, task_other_peer(task), VOTE_ADD, element); |
1071 | #ifdef GNUNET_EXTRA_LOGGING | 1069 | #ifdef GNUNET_EXTRA_LOGGING |
1072 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1070 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1073 | "P%u: adding element %s into rfn {%s} of task {%s}\n", | 1071 | "P%u: adding element %s into rfn {%s} of task {%s}\n", |
1074 | session->local_peer_idx, | 1072 | session->local_peer_idx, |
1075 | debug_str_element (element), | 1073 | debug_str_element(element), |
1076 | debug_str_rfn_key (&setop->output_rfn), | 1074 | debug_str_rfn_key(&setop->output_rfn), |
1077 | debug_str_task_key (&task->key)); | 1075 | debug_str_task_key(&task->key)); |
1078 | #endif | 1076 | #endif |
1079 | } | 1077 | } |
1080 | // XXX: add result to structures in task | 1078 | // XXX: add result to structures in task |
1081 | break; | 1079 | break; |
1080 | |||
1082 | case GNUNET_SET_STATUS_ADD_REMOTE: | 1081 | case GNUNET_SET_STATUS_ADD_REMOTE: |
1083 | GNUNET_assert (NULL != consensus_element); | 1082 | GNUNET_assert(NULL != consensus_element); |
1084 | if (GNUNET_YES == setop->do_not_remove) | 1083 | if (GNUNET_YES == setop->do_not_remove) |
1085 | break; | 1084 | break; |
1086 | if (CONSENSUS_MARKER_CONTESTED == consensus_element->marker) | 1085 | if (CONSENSUS_MARKER_CONTESTED == consensus_element->marker) |
1087 | break; | 1086 | break; |
1088 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1087 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1089 | "Removing element in Task {%s}\n", | 1088 | "Removing element in Task {%s}\n", |
1090 | debug_str_task_key (&task->key)); | 1089 | debug_str_task_key(&task->key)); |
1091 | if (NULL != output_set) | 1090 | if (NULL != output_set) |
1092 | { | 1091 | { |
1093 | // FIXME: record pending adds, use callback | 1092 | // FIXME: record pending adds, use callback |
1094 | GNUNET_SET_remove_element (output_set->h, | 1093 | GNUNET_SET_remove_element(output_set->h, |
1095 | element, | 1094 | element, |
1096 | NULL, | 1095 | NULL, |
1097 | NULL); | 1096 | NULL); |
1098 | #ifdef GNUNET_EXTRA_LOGGING | 1097 | #ifdef GNUNET_EXTRA_LOGGING |
1099 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1098 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1100 | "P%u: removing element %s from set {%s} of task {%s}\n", | 1099 | "P%u: removing element %s from set {%s} of task {%s}\n", |
1101 | session->local_peer_idx, | 1100 | session->local_peer_idx, |
1102 | debug_str_element (element), | 1101 | debug_str_element(element), |
1103 | debug_str_set_key (&setop->output_set), | 1102 | debug_str_set_key(&setop->output_set), |
1104 | debug_str_task_key (&task->key)); | 1103 | debug_str_task_key(&task->key)); |
1105 | #endif | 1104 | #endif |
1106 | } | 1105 | } |
1107 | if (NULL != output_diff) | 1106 | if (NULL != output_diff) |
1108 | { | 1107 | { |
1109 | diff_insert (output_diff, -1, element); | 1108 | diff_insert(output_diff, -1, element); |
1110 | #ifdef GNUNET_EXTRA_LOGGING | 1109 | #ifdef GNUNET_EXTRA_LOGGING |
1111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1110 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1112 | "P%u: removing element %s from diff {%s} of task {%s}\n", | 1111 | "P%u: removing element %s from diff {%s} of task {%s}\n", |
1113 | session->local_peer_idx, | 1112 | session->local_peer_idx, |
1114 | debug_str_element (element), | 1113 | debug_str_element(element), |
1115 | debug_str_diff_key (&setop->output_diff), | 1114 | debug_str_diff_key(&setop->output_diff), |
1116 | debug_str_task_key (&task->key)); | 1115 | debug_str_task_key(&task->key)); |
1117 | #endif | 1116 | #endif |
1118 | } | 1117 | } |
1119 | if (NULL != output_rfn) | 1118 | if (NULL != output_rfn) |
1120 | { | 1119 | { |
1121 | rfn_vote (output_rfn, task_other_peer (task), VOTE_REMOVE, element); | 1120 | rfn_vote(output_rfn, task_other_peer(task), VOTE_REMOVE, element); |
1122 | #ifdef GNUNET_EXTRA_LOGGING | 1121 | #ifdef GNUNET_EXTRA_LOGGING |
1123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1122 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1124 | "P%u: removing element %s from rfn {%s} of task {%s}\n", | 1123 | "P%u: removing element %s from rfn {%s} of task {%s}\n", |
1125 | session->local_peer_idx, | 1124 | session->local_peer_idx, |
1126 | debug_str_element (element), | 1125 | debug_str_element(element), |
1127 | debug_str_rfn_key (&setop->output_rfn), | 1126 | debug_str_rfn_key(&setop->output_rfn), |
1128 | debug_str_task_key (&task->key)); | 1127 | debug_str_task_key(&task->key)); |
1129 | #endif | 1128 | #endif |
1130 | } | 1129 | } |
1131 | break; | 1130 | break; |
1131 | |||
1132 | case GNUNET_SET_STATUS_DONE: | 1132 | case GNUNET_SET_STATUS_DONE: |
1133 | // XXX: check first if any changes to the underlying | 1133 | // XXX: check first if any changes to the underlying |
1134 | // set are still pending | 1134 | // set are still pending |
1135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1135 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1136 | "P%u: Finishing setop in Task {%s} (%u/%u)\n", | 1136 | "P%u: Finishing setop in Task {%s} (%u/%u)\n", |
1137 | session->local_peer_idx, | 1137 | session->local_peer_idx, |
1138 | debug_str_task_key (&task->key), | 1138 | debug_str_task_key(&task->key), |
1139 | (unsigned int) task->step->finished_tasks, | 1139 | (unsigned int)task->step->finished_tasks, |
1140 | (unsigned int) task->step->tasks_len); | 1140 | (unsigned int)task->step->tasks_len); |
1141 | if (NULL != output_rfn) | 1141 | if (NULL != output_rfn) |
1142 | { | 1142 | { |
1143 | rfn_commit (output_rfn, task_other_peer (task)); | 1143 | rfn_commit(output_rfn, task_other_peer(task)); |
1144 | } | 1144 | } |
1145 | if (PHASE_KIND_ALL_TO_ALL == task->key.kind) | 1145 | if (PHASE_KIND_ALL_TO_ALL == task->key.kind) |
1146 | { | 1146 | { |
1147 | session->first_size = current_size; | 1147 | session->first_size = current_size; |
1148 | } | 1148 | } |
1149 | finish_task (task); | 1149 | finish_task(task); |
1150 | break; | 1150 | break; |
1151 | |||
1151 | case GNUNET_SET_STATUS_FAILURE: | 1152 | case GNUNET_SET_STATUS_FAILURE: |
1152 | // XXX: cleanup | 1153 | // XXX: cleanup |
1153 | GNUNET_break_op (0); | 1154 | GNUNET_break_op(0); |
1154 | finish_task (task); | 1155 | finish_task(task); |
1155 | return; | 1156 | return; |
1157 | |||
1156 | default: | 1158 | default: |
1157 | /* not reached */ | 1159 | /* not reached */ |
1158 | GNUNET_assert (0); | 1160 | GNUNET_assert(0); |
1159 | } | 1161 | } |
1160 | } | 1162 | } |
1161 | 1163 | ||
1162 | #ifdef EVIL | 1164 | #ifdef EVIL |
1163 | 1165 | ||
1164 | enum EvilnessType | 1166 | enum EvilnessType { |
1165 | { | ||
1166 | EVILNESS_NONE, | 1167 | EVILNESS_NONE, |
1167 | EVILNESS_CRAM_ALL, | 1168 | EVILNESS_CRAM_ALL, |
1168 | EVILNESS_CRAM_LEAD, | 1169 | EVILNESS_CRAM_LEAD, |
@@ -1171,15 +1172,13 @@ enum EvilnessType | |||
1171 | EVILNESS_SLACK_A2A, | 1172 | EVILNESS_SLACK_A2A, |
1172 | }; | 1173 | }; |
1173 | 1174 | ||
1174 | enum EvilnessSubType | 1175 | enum EvilnessSubType { |
1175 | { | ||
1176 | EVILNESS_SUB_NONE, | 1176 | EVILNESS_SUB_NONE, |
1177 | EVILNESS_SUB_REPLACEMENT, | 1177 | EVILNESS_SUB_REPLACEMENT, |
1178 | EVILNESS_SUB_NO_REPLACEMENT, | 1178 | EVILNESS_SUB_NO_REPLACEMENT, |
1179 | }; | 1179 | }; |
1180 | 1180 | ||
1181 | struct Evilness | 1181 | struct Evilness { |
1182 | { | ||
1183 | enum EvilnessType type; | 1182 | enum EvilnessType type; |
1184 | enum EvilnessSubType subtype; | 1183 | enum EvilnessSubType subtype; |
1185 | unsigned int num; | 1184 | unsigned int num; |
@@ -1187,129 +1186,129 @@ struct Evilness | |||
1187 | 1186 | ||
1188 | 1187 | ||
1189 | static int | 1188 | static int |
1190 | parse_evilness_cram_subtype (const char *evil_subtype_str, struct Evilness *evil) | 1189 | parse_evilness_cram_subtype(const char *evil_subtype_str, struct Evilness *evil) |
1191 | { | 1190 | { |
1192 | if (0 == strcmp ("replace", evil_subtype_str)) | 1191 | if (0 == strcmp("replace", evil_subtype_str)) |
1193 | { | 1192 | { |
1194 | evil->subtype = EVILNESS_SUB_REPLACEMENT; | 1193 | evil->subtype = EVILNESS_SUB_REPLACEMENT; |
1195 | } | 1194 | } |
1196 | else if (0 == strcmp ("noreplace", evil_subtype_str)) | 1195 | else if (0 == strcmp("noreplace", evil_subtype_str)) |
1197 | { | 1196 | { |
1198 | evil->subtype = EVILNESS_SUB_NO_REPLACEMENT; | 1197 | evil->subtype = EVILNESS_SUB_NO_REPLACEMENT; |
1199 | } | 1198 | } |
1200 | else | 1199 | else |
1201 | { | 1200 | { |
1202 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1201 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1203 | "Malformed field '%s' in EVIL_SPEC (unknown subtype), behaving like a good peer.\n", | 1202 | "Malformed field '%s' in EVIL_SPEC (unknown subtype), behaving like a good peer.\n", |
1204 | evil_subtype_str); | 1203 | evil_subtype_str); |
1205 | return GNUNET_SYSERR; | 1204 | return GNUNET_SYSERR; |
1206 | } | 1205 | } |
1207 | return GNUNET_OK; | 1206 | return GNUNET_OK; |
1208 | } | 1207 | } |
1209 | 1208 | ||
1210 | 1209 | ||
1211 | static void | 1210 | static void |
1212 | get_evilness (struct ConsensusSession *session, struct Evilness *evil) | 1211 | get_evilness(struct ConsensusSession *session, struct Evilness *evil) |
1213 | { | 1212 | { |
1214 | char *evil_spec; | 1213 | char *evil_spec; |
1215 | char *field; | 1214 | char *field; |
1216 | char *evil_type_str = NULL; | 1215 | char *evil_type_str = NULL; |
1217 | char *evil_subtype_str = NULL; | 1216 | char *evil_subtype_str = NULL; |
1218 | 1217 | ||
1219 | GNUNET_assert (NULL != evil); | 1218 | GNUNET_assert(NULL != evil); |
1220 | 1219 | ||
1221 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "consensus", "EVIL_SPEC", &evil_spec)) | 1220 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "consensus", "EVIL_SPEC", &evil_spec)) |
1222 | { | 1221 | { |
1223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1222 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1224 | "P%u: no evilness\n", | 1223 | "P%u: no evilness\n", |
1225 | session->local_peer_idx); | 1224 | session->local_peer_idx); |
1226 | evil->type = EVILNESS_NONE; | 1225 | evil->type = EVILNESS_NONE; |
1227 | return; | 1226 | return; |
1228 | } | 1227 | } |
1229 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1228 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1230 | "P%u: got evilness spec\n", | 1229 | "P%u: got evilness spec\n", |
1231 | session->local_peer_idx); | 1230 | session->local_peer_idx); |
1232 | 1231 | ||
1233 | for (field = strtok (evil_spec, "/"); | 1232 | for (field = strtok(evil_spec, "/"); |
1234 | NULL != field; | 1233 | NULL != field; |
1235 | field = strtok (NULL, "/")) | 1234 | field = strtok(NULL, "/")) |
1236 | { | 1235 | { |
1237 | unsigned int peer_num; | 1236 | unsigned int peer_num; |
1238 | unsigned int evil_num; | 1237 | unsigned int evil_num; |
1239 | int ret; | 1238 | int ret; |
1240 | 1239 | ||
1241 | evil_type_str = NULL; | 1240 | evil_type_str = NULL; |
1242 | evil_subtype_str = NULL; | 1241 | evil_subtype_str = NULL; |
1243 | 1242 | ||
1244 | ret = sscanf (field, "%u;%m[a-z-];%m[a-z-];%u", &peer_num, &evil_type_str, &evil_subtype_str, &evil_num); | 1243 | ret = sscanf(field, "%u;%m[a-z-];%m[a-z-];%u", &peer_num, &evil_type_str, &evil_subtype_str, &evil_num); |
1245 | 1244 | ||
1246 | if (ret != 4) | 1245 | if (ret != 4) |
1247 | { | 1246 | { |
1248 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1247 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1249 | "Malformed field '%s' in EVIL_SPEC (expected 4 components got %d), behaving like a good peer.\n", | 1248 | "Malformed field '%s' in EVIL_SPEC (expected 4 components got %d), behaving like a good peer.\n", |
1250 | field, | 1249 | field, |
1251 | ret); | 1250 | ret); |
1252 | goto not_evil; | 1251 | goto not_evil; |
1253 | } | 1252 | } |
1254 | 1253 | ||
1255 | GNUNET_assert (NULL != evil_type_str); | 1254 | GNUNET_assert(NULL != evil_type_str); |
1256 | GNUNET_assert (NULL != evil_subtype_str); | 1255 | GNUNET_assert(NULL != evil_subtype_str); |
1257 | 1256 | ||
1258 | if (peer_num == session->local_peer_idx) | 1257 | if (peer_num == session->local_peer_idx) |
1259 | { | 1258 | { |
1260 | if (0 == strcmp ("slack", evil_type_str)) | 1259 | if (0 == strcmp("slack", evil_type_str)) |
1261 | { | 1260 | { |
1262 | evil->type = EVILNESS_SLACK; | 1261 | evil->type = EVILNESS_SLACK; |
1263 | } | 1262 | } |
1264 | if (0 == strcmp ("slack-a2a", evil_type_str)) | 1263 | if (0 == strcmp("slack-a2a", evil_type_str)) |
1265 | { | 1264 | { |
1266 | evil->type = EVILNESS_SLACK_A2A; | 1265 | evil->type = EVILNESS_SLACK_A2A; |
1267 | } | 1266 | } |
1268 | else if (0 == strcmp ("cram-all", evil_type_str)) | 1267 | else if (0 == strcmp("cram-all", evil_type_str)) |
1269 | { | 1268 | { |
1270 | evil->type = EVILNESS_CRAM_ALL; | 1269 | evil->type = EVILNESS_CRAM_ALL; |
1271 | evil->num = evil_num; | 1270 | evil->num = evil_num; |
1272 | if (GNUNET_OK != parse_evilness_cram_subtype (evil_subtype_str, evil)) | 1271 | if (GNUNET_OK != parse_evilness_cram_subtype(evil_subtype_str, evil)) |
1273 | goto not_evil; | 1272 | goto not_evil; |
1274 | } | 1273 | } |
1275 | else if (0 == strcmp ("cram-lead", evil_type_str)) | 1274 | else if (0 == strcmp("cram-lead", evil_type_str)) |
1276 | { | 1275 | { |
1277 | evil->type = EVILNESS_CRAM_LEAD; | 1276 | evil->type = EVILNESS_CRAM_LEAD; |
1278 | evil->num = evil_num; | 1277 | evil->num = evil_num; |
1279 | if (GNUNET_OK != parse_evilness_cram_subtype (evil_subtype_str, evil)) | 1278 | if (GNUNET_OK != parse_evilness_cram_subtype(evil_subtype_str, evil)) |
1280 | goto not_evil; | 1279 | goto not_evil; |
1281 | } | 1280 | } |
1282 | else if (0 == strcmp ("cram-echo", evil_type_str)) | 1281 | else if (0 == strcmp("cram-echo", evil_type_str)) |
1283 | { | 1282 | { |
1284 | evil->type = EVILNESS_CRAM_ECHO; | 1283 | evil->type = EVILNESS_CRAM_ECHO; |
1285 | evil->num = evil_num; | 1284 | evil->num = evil_num; |
1286 | if (GNUNET_OK != parse_evilness_cram_subtype (evil_subtype_str, evil)) | 1285 | if (GNUNET_OK != parse_evilness_cram_subtype(evil_subtype_str, evil)) |
1287 | goto not_evil; | 1286 | goto not_evil; |
1288 | } | 1287 | } |
1289 | else | 1288 | else |
1290 | { | 1289 | { |
1291 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1290 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1292 | "Malformed field '%s' in EVIL_SPEC (unknown type), behaving like a good peer.\n", | 1291 | "Malformed field '%s' in EVIL_SPEC (unknown type), behaving like a good peer.\n", |
1293 | evil_type_str); | 1292 | evil_type_str); |
1294 | goto not_evil; | 1293 | goto not_evil; |
1295 | } | 1294 | } |
1296 | goto cleanup; | 1295 | goto cleanup; |
1296 | } | ||
1297 | /* No GNUNET_free since memory was allocated by libc */ | ||
1298 | free(evil_type_str); | ||
1299 | evil_type_str = NULL; | ||
1300 | evil_subtype_str = NULL; | ||
1297 | } | 1301 | } |
1298 | /* No GNUNET_free since memory was allocated by libc */ | ||
1299 | free (evil_type_str); | ||
1300 | evil_type_str = NULL; | ||
1301 | evil_subtype_str = NULL; | ||
1302 | } | ||
1303 | not_evil: | 1302 | not_evil: |
1304 | evil->type = EVILNESS_NONE; | 1303 | evil->type = EVILNESS_NONE; |
1305 | cleanup: | 1304 | cleanup: |
1306 | GNUNET_free (evil_spec); | 1305 | GNUNET_free(evil_spec); |
1307 | /* no GNUNET_free_non_null since it wasn't | 1306 | /* no GNUNET_free_non_null since it wasn't |
1308 | * allocated with GNUNET_malloc */ | 1307 | * allocated with GNUNET_malloc */ |
1309 | if (NULL != evil_type_str) | 1308 | if (NULL != evil_type_str) |
1310 | free (evil_type_str); | 1309 | free(evil_type_str); |
1311 | if (NULL != evil_subtype_str) | 1310 | if (NULL != evil_subtype_str) |
1312 | free (evil_subtype_str); | 1311 | free(evil_subtype_str); |
1313 | } | 1312 | } |
1314 | 1313 | ||
1315 | #endif | 1314 | #endif |
@@ -1320,60 +1319,60 @@ cleanup: | |||
1320 | * task. | 1319 | * task. |
1321 | */ | 1320 | */ |
1322 | static void | 1321 | static void |
1323 | commit_set (struct ConsensusSession *session, | 1322 | commit_set(struct ConsensusSession *session, |
1324 | struct TaskEntry *task) | 1323 | struct TaskEntry *task) |
1325 | { | 1324 | { |
1326 | struct SetEntry *set; | 1325 | struct SetEntry *set; |
1327 | struct SetOpCls *setop = &task->cls.setop; | 1326 | struct SetOpCls *setop = &task->cls.setop; |
1328 | 1327 | ||
1329 | GNUNET_assert (NULL != setop->op); | 1328 | GNUNET_assert(NULL != setop->op); |
1330 | set = lookup_set (session, &setop->input_set); | 1329 | set = lookup_set(session, &setop->input_set); |
1331 | GNUNET_assert (NULL != set); | 1330 | GNUNET_assert(NULL != set); |
1332 | 1331 | ||
1333 | if ( (GNUNET_YES == setop->transceive_contested) && (GNUNET_YES == set->is_contested) ) | 1332 | if ((GNUNET_YES == setop->transceive_contested) && (GNUNET_YES == set->is_contested)) |
1334 | { | 1333 | { |
1335 | struct GNUNET_SET_Element element; | 1334 | struct GNUNET_SET_Element element; |
1336 | struct ConsensusElement ce = { 0 }; | 1335 | struct ConsensusElement ce = { 0 }; |
1337 | ce.marker = CONSENSUS_MARKER_CONTESTED; | 1336 | ce.marker = CONSENSUS_MARKER_CONTESTED; |
1338 | element.data = &ce; | 1337 | element.data = &ce; |
1339 | element.size = sizeof (struct ConsensusElement); | 1338 | element.size = sizeof(struct ConsensusElement); |
1340 | element.element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT; | 1339 | element.element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT; |
1341 | GNUNET_SET_add_element (set->h, &element, NULL, NULL); | 1340 | GNUNET_SET_add_element(set->h, &element, NULL, NULL); |
1342 | } | 1341 | } |
1343 | 1342 | ||
1344 | if (PHASE_KIND_ALL_TO_ALL_2 == task->key.kind) | 1343 | if (PHASE_KIND_ALL_TO_ALL_2 == task->key.kind) |
1345 | { | 1344 | { |
1346 | struct GNUNET_SET_Element element; | 1345 | struct GNUNET_SET_Element element; |
1347 | struct ConsensusSizeElement cse = { | 1346 | struct ConsensusSizeElement cse = { |
1348 | .size = 0, | 1347 | .size = 0, |
1349 | .sender_index = 0 | 1348 | .sender_index = 0 |
1350 | }; | 1349 | }; |
1351 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "inserting size marker\n"); | 1350 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "inserting size marker\n"); |
1352 | cse.ce.marker = CONSENSUS_MARKER_SIZE; | 1351 | cse.ce.marker = CONSENSUS_MARKER_SIZE; |
1353 | cse.size = GNUNET_htonll (session->first_size); | 1352 | cse.size = GNUNET_htonll(session->first_size); |
1354 | cse.sender_index = session->local_peer_idx; | 1353 | cse.sender_index = session->local_peer_idx; |
1355 | element.data = &cse; | 1354 | element.data = &cse; |
1356 | element.size = sizeof (struct ConsensusSizeElement); | 1355 | element.size = sizeof(struct ConsensusSizeElement); |
1357 | element.element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT; | 1356 | element.element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT; |
1358 | GNUNET_SET_add_element (set->h, &element, NULL, NULL); | 1357 | GNUNET_SET_add_element(set->h, &element, NULL, NULL); |
1359 | } | 1358 | } |
1360 | 1359 | ||
1361 | #ifdef EVIL | 1360 | #ifdef EVIL |
1362 | { | 1361 | { |
1363 | unsigned int i; | 1362 | unsigned int i; |
1364 | struct Evilness evil; | 1363 | struct Evilness evil; |
1365 | 1364 | ||
1366 | get_evilness (session, &evil); | 1365 | get_evilness(session, &evil); |
1367 | if (EVILNESS_NONE != evil.type) | 1366 | if (EVILNESS_NONE != evil.type) |
1368 | { | 1367 | { |
1369 | /* Useful for evaluation */ | 1368 | /* Useful for evaluation */ |
1370 | GNUNET_STATISTICS_set (statistics, | 1369 | GNUNET_STATISTICS_set(statistics, |
1371 | "is evil", | 1370 | "is evil", |
1372 | 1, | 1371 | 1, |
1373 | GNUNET_NO); | 1372 | GNUNET_NO); |
1374 | } | 1373 | } |
1375 | switch (evil.type) | 1374 | switch (evil.type) |
1376 | { | 1375 | { |
1377 | case EVILNESS_CRAM_ALL: | 1376 | case EVILNESS_CRAM_ALL: |
1378 | case EVILNESS_CRAM_LEAD: | 1377 | case EVILNESS_CRAM_LEAD: |
1379 | case EVILNESS_CRAM_ECHO: | 1378 | case EVILNESS_CRAM_ECHO: |
@@ -1382,236 +1381,239 @@ commit_set (struct ConsensusSession *session, | |||
1382 | add more elements to the result set, but | 1381 | add more elements to the result set, but |
1383 | wouldn't test robustness. */ | 1382 | wouldn't test robustness. */ |
1384 | if (PHASE_KIND_ALL_TO_ALL == task->key.kind) | 1383 | if (PHASE_KIND_ALL_TO_ALL == task->key.kind) |
1385 | { | 1384 | { |
1386 | GNUNET_SET_commit (setop->op, set->h); | 1385 | GNUNET_SET_commit(setop->op, set->h); |
1387 | break; | 1386 | break; |
1388 | } | 1387 | } |
1389 | if ((EVILNESS_CRAM_LEAD == evil.type) && | 1388 | if ((EVILNESS_CRAM_LEAD == evil.type) && |
1390 | ((PHASE_KIND_GRADECAST_LEADER != task->key.kind) || SET_KIND_CURRENT != set->key.set_kind)) | 1389 | ((PHASE_KIND_GRADECAST_LEADER != task->key.kind) || SET_KIND_CURRENT != set->key.set_kind)) |
1391 | { | ||
1392 | GNUNET_SET_commit (setop->op, set->h); | ||
1393 | break; | ||
1394 | } | ||
1395 | if (EVILNESS_CRAM_ECHO == evil.type && (PHASE_KIND_GRADECAST_ECHO != task->key.kind)) | ||
1396 | { | ||
1397 | GNUNET_SET_commit (setop->op, set->h); | ||
1398 | break; | ||
1399 | } | ||
1400 | for (i = 0; i < evil.num; i++) | ||
1401 | { | ||
1402 | struct GNUNET_SET_Element element; | ||
1403 | struct ConsensusStuffedElement se = { | ||
1404 | .ce.payload_type = 0, | ||
1405 | .ce.marker = 0, | ||
1406 | }; | ||
1407 | element.data = &se; | ||
1408 | element.size = sizeof (struct ConsensusStuffedElement); | ||
1409 | element.element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT; | ||
1410 | |||
1411 | if (EVILNESS_SUB_REPLACEMENT == evil.subtype) | ||
1412 | { | 1390 | { |
1413 | /* Always generate a new element. */ | 1391 | GNUNET_SET_commit(setop->op, set->h); |
1414 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &se.rand); | 1392 | break; |
1415 | } | 1393 | } |
1416 | else if (EVILNESS_SUB_NO_REPLACEMENT == evil.subtype) | 1394 | if (EVILNESS_CRAM_ECHO == evil.type && (PHASE_KIND_GRADECAST_ECHO != task->key.kind)) |
1417 | { | 1395 | { |
1418 | /* Always cram the same elements, derived from counter. */ | 1396 | GNUNET_SET_commit(setop->op, set->h); |
1419 | GNUNET_CRYPTO_hash (&i, sizeof (i), &se.rand); | 1397 | break; |
1420 | } | 1398 | } |
1421 | else | 1399 | for (i = 0; i < evil.num; i++) |
1422 | { | 1400 | { |
1423 | GNUNET_assert (0); | 1401 | struct GNUNET_SET_Element element; |
1424 | } | 1402 | struct ConsensusStuffedElement se = { |
1425 | GNUNET_SET_add_element (set->h, &element, NULL, NULL); | 1403 | .ce.payload_type = 0, |
1404 | .ce.marker = 0, | ||
1405 | }; | ||
1406 | element.data = &se; | ||
1407 | element.size = sizeof(struct ConsensusStuffedElement); | ||
1408 | element.element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT; | ||
1409 | |||
1410 | if (EVILNESS_SUB_REPLACEMENT == evil.subtype) | ||
1411 | { | ||
1412 | /* Always generate a new element. */ | ||
1413 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &se.rand); | ||
1414 | } | ||
1415 | else if (EVILNESS_SUB_NO_REPLACEMENT == evil.subtype) | ||
1416 | { | ||
1417 | /* Always cram the same elements, derived from counter. */ | ||
1418 | GNUNET_CRYPTO_hash(&i, sizeof(i), &se.rand); | ||
1419 | } | ||
1420 | else | ||
1421 | { | ||
1422 | GNUNET_assert(0); | ||
1423 | } | ||
1424 | GNUNET_SET_add_element(set->h, &element, NULL, NULL); | ||
1426 | #ifdef GNUNET_EXTRA_LOGGING | 1425 | #ifdef GNUNET_EXTRA_LOGGING |
1427 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1426 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1428 | "P%u: evil peer: cramming element %s into set {%s} of task {%s}\n", | 1427 | "P%u: evil peer: cramming element %s into set {%s} of task {%s}\n", |
1429 | session->local_peer_idx, | 1428 | session->local_peer_idx, |
1430 | debug_str_element (&element), | 1429 | debug_str_element(&element), |
1431 | debug_str_set_key (&setop->input_set), | 1430 | debug_str_set_key(&setop->input_set), |
1432 | debug_str_task_key (&task->key)); | 1431 | debug_str_task_key(&task->key)); |
1433 | #endif | 1432 | #endif |
1434 | } | 1433 | } |
1435 | GNUNET_STATISTICS_update (statistics, | 1434 | GNUNET_STATISTICS_update(statistics, |
1436 | "# stuffed elements", | 1435 | "# stuffed elements", |
1437 | evil.num, | 1436 | evil.num, |
1438 | GNUNET_NO); | 1437 | GNUNET_NO); |
1439 | GNUNET_SET_commit (setop->op, set->h); | 1438 | GNUNET_SET_commit(setop->op, set->h); |
1440 | break; | 1439 | break; |
1440 | |||
1441 | case EVILNESS_SLACK: | 1441 | case EVILNESS_SLACK: |
1442 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1442 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1443 | "P%u: evil peer: slacking\n", | 1443 | "P%u: evil peer: slacking\n", |
1444 | (unsigned int) session->local_peer_idx); | 1444 | (unsigned int)session->local_peer_idx); |
1445 | /* Do nothing. */ | 1445 | |
1446 | /* Do nothing. */ | ||
1446 | case EVILNESS_SLACK_A2A: | 1447 | case EVILNESS_SLACK_A2A: |
1447 | if ( (PHASE_KIND_ALL_TO_ALL_2 == task->key.kind ) || | 1448 | if ((PHASE_KIND_ALL_TO_ALL_2 == task->key.kind) || |
1448 | (PHASE_KIND_ALL_TO_ALL == task->key.kind) ) | 1449 | (PHASE_KIND_ALL_TO_ALL == task->key.kind)) |
1449 | { | 1450 | { |
1450 | struct GNUNET_SET_Handle *empty_set; | 1451 | struct GNUNET_SET_Handle *empty_set; |
1451 | empty_set = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); | 1452 | empty_set = GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_UNION); |
1452 | GNUNET_SET_commit (setop->op, empty_set); | 1453 | GNUNET_SET_commit(setop->op, empty_set); |
1453 | GNUNET_SET_destroy (empty_set); | 1454 | GNUNET_SET_destroy(empty_set); |
1454 | } | 1455 | } |
1455 | else | 1456 | else |
1456 | { | 1457 | { |
1457 | GNUNET_SET_commit (setop->op, set->h); | 1458 | GNUNET_SET_commit(setop->op, set->h); |
1458 | } | 1459 | } |
1459 | break; | 1460 | break; |
1461 | |||
1460 | case EVILNESS_NONE: | 1462 | case EVILNESS_NONE: |
1461 | GNUNET_SET_commit (setop->op, set->h); | 1463 | GNUNET_SET_commit(setop->op, set->h); |
1462 | break; | 1464 | break; |
1463 | } | 1465 | } |
1464 | } | 1466 | } |
1465 | #else | 1467 | #else |
1466 | if (GNUNET_NO == session->peers_blacklisted[task_other_peer (task)]) | 1468 | if (GNUNET_NO == session->peers_blacklisted[task_other_peer(task)]) |
1467 | { | 1469 | { |
1468 | GNUNET_SET_commit (setop->op, set->h); | 1470 | GNUNET_SET_commit(setop->op, set->h); |
1469 | } | 1471 | } |
1470 | else | 1472 | else |
1471 | { | 1473 | { |
1472 | /* For our testcases, we don't want the blacklisted | 1474 | /* For our testcases, we don't want the blacklisted |
1473 | peers to wait. */ | 1475 | peers to wait. */ |
1474 | GNUNET_SET_operation_cancel (setop->op); | 1476 | GNUNET_SET_operation_cancel(setop->op); |
1475 | setop->op = NULL; | 1477 | setop->op = NULL; |
1476 | finish_task (task); | 1478 | finish_task(task); |
1477 | } | 1479 | } |
1478 | #endif | 1480 | #endif |
1479 | } | 1481 | } |
1480 | 1482 | ||
1481 | 1483 | ||
1482 | static void | 1484 | static void |
1483 | put_diff (struct ConsensusSession *session, | 1485 | put_diff(struct ConsensusSession *session, |
1484 | struct DiffEntry *diff) | 1486 | struct DiffEntry *diff) |
1485 | { | 1487 | { |
1486 | struct GNUNET_HashCode hash; | 1488 | struct GNUNET_HashCode hash; |
1487 | 1489 | ||
1488 | GNUNET_assert (NULL != diff); | 1490 | GNUNET_assert(NULL != diff); |
1489 | 1491 | ||
1490 | GNUNET_CRYPTO_hash (&diff->key, sizeof (struct DiffKey), &hash); | 1492 | GNUNET_CRYPTO_hash(&diff->key, sizeof(struct DiffKey), &hash); |
1491 | GNUNET_assert (GNUNET_OK == | 1493 | GNUNET_assert(GNUNET_OK == |
1492 | GNUNET_CONTAINER_multihashmap_put (session->diffmap, &hash, diff, | 1494 | GNUNET_CONTAINER_multihashmap_put(session->diffmap, &hash, diff, |
1493 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1495 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1494 | } | 1496 | } |
1495 | 1497 | ||
1496 | static void | 1498 | static void |
1497 | put_set (struct ConsensusSession *session, | 1499 | put_set(struct ConsensusSession *session, |
1498 | struct SetEntry *set) | 1500 | struct SetEntry *set) |
1499 | { | 1501 | { |
1500 | struct GNUNET_HashCode hash; | 1502 | struct GNUNET_HashCode hash; |
1501 | 1503 | ||
1502 | GNUNET_assert (NULL != set->h); | 1504 | GNUNET_assert(NULL != set->h); |
1503 | 1505 | ||
1504 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1506 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1505 | "Putting set %s\n", | 1507 | "Putting set %s\n", |
1506 | debug_str_set_key (&set->key)); | 1508 | debug_str_set_key(&set->key)); |
1507 | 1509 | ||
1508 | GNUNET_CRYPTO_hash (&set->key, sizeof (struct SetKey), &hash); | 1510 | GNUNET_CRYPTO_hash(&set->key, sizeof(struct SetKey), &hash); |
1509 | GNUNET_assert (GNUNET_SYSERR != | 1511 | GNUNET_assert(GNUNET_SYSERR != |
1510 | GNUNET_CONTAINER_multihashmap_put (session->setmap, &hash, set, | 1512 | GNUNET_CONTAINER_multihashmap_put(session->setmap, &hash, set, |
1511 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); | 1513 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); |
1512 | } | 1514 | } |
1513 | 1515 | ||
1514 | 1516 | ||
1515 | static void | 1517 | static void |
1516 | put_rfn (struct ConsensusSession *session, | 1518 | put_rfn(struct ConsensusSession *session, |
1517 | struct ReferendumEntry *rfn) | 1519 | struct ReferendumEntry *rfn) |
1518 | { | 1520 | { |
1519 | struct GNUNET_HashCode hash; | 1521 | struct GNUNET_HashCode hash; |
1520 | 1522 | ||
1521 | GNUNET_CRYPTO_hash (&rfn->key, sizeof (struct RfnKey), &hash); | 1523 | GNUNET_CRYPTO_hash(&rfn->key, sizeof(struct RfnKey), &hash); |
1522 | GNUNET_assert (GNUNET_OK == | 1524 | GNUNET_assert(GNUNET_OK == |
1523 | GNUNET_CONTAINER_multihashmap_put (session->rfnmap, &hash, rfn, | 1525 | GNUNET_CONTAINER_multihashmap_put(session->rfnmap, &hash, rfn, |
1524 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1526 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1525 | } | 1527 | } |
1526 | 1528 | ||
1527 | 1529 | ||
1528 | 1530 | ||
1529 | static void | 1531 | static void |
1530 | task_cancel_reconcile (struct TaskEntry *task) | 1532 | task_cancel_reconcile(struct TaskEntry *task) |
1531 | { | 1533 | { |
1532 | /* not implemented yet */ | 1534 | /* not implemented yet */ |
1533 | GNUNET_assert (0); | 1535 | GNUNET_assert(0); |
1534 | } | 1536 | } |
1535 | 1537 | ||
1536 | 1538 | ||
1537 | static void | 1539 | static void |
1538 | apply_diff_to_rfn (struct DiffEntry *diff, | 1540 | apply_diff_to_rfn(struct DiffEntry *diff, |
1539 | struct ReferendumEntry *rfn, | 1541 | struct ReferendumEntry *rfn, |
1540 | uint16_t voting_peer, | 1542 | uint16_t voting_peer, |
1541 | uint16_t num_peers) | 1543 | uint16_t num_peers) |
1542 | { | 1544 | { |
1543 | struct GNUNET_CONTAINER_MultiHashMapIterator *iter; | 1545 | struct GNUNET_CONTAINER_MultiHashMapIterator *iter; |
1544 | struct DiffElementInfo *di; | 1546 | struct DiffElementInfo *di; |
1545 | 1547 | ||
1546 | iter = GNUNET_CONTAINER_multihashmap_iterator_create (diff->changes); | 1548 | iter = GNUNET_CONTAINER_multihashmap_iterator_create(diff->changes); |
1547 | 1549 | ||
1548 | while (GNUNET_YES == | 1550 | while (GNUNET_YES == |
1549 | GNUNET_CONTAINER_multihashmap_iterator_next (iter, | 1551 | GNUNET_CONTAINER_multihashmap_iterator_next(iter, |
1550 | NULL, | 1552 | NULL, |
1551 | (const void **) &di)) | 1553 | (const void **)&di)) |
1552 | { | ||
1553 | if (di->weight > 0) | ||
1554 | { | 1554 | { |
1555 | rfn_vote (rfn, voting_peer, VOTE_ADD, di->element); | 1555 | if (di->weight > 0) |
1556 | } | 1556 | { |
1557 | if (di->weight < 0) | 1557 | rfn_vote(rfn, voting_peer, VOTE_ADD, di->element); |
1558 | { | 1558 | } |
1559 | rfn_vote (rfn, voting_peer, VOTE_REMOVE, di->element); | 1559 | if (di->weight < 0) |
1560 | { | ||
1561 | rfn_vote(rfn, voting_peer, VOTE_REMOVE, di->element); | ||
1562 | } | ||
1560 | } | 1563 | } |
1561 | } | ||
1562 | 1564 | ||
1563 | GNUNET_CONTAINER_multihashmap_iterator_destroy (iter); | 1565 | GNUNET_CONTAINER_multihashmap_iterator_destroy(iter); |
1564 | } | 1566 | } |
1565 | 1567 | ||
1566 | 1568 | ||
1567 | struct DiffEntry * | 1569 | struct DiffEntry * |
1568 | diff_create () | 1570 | diff_create() |
1569 | { | 1571 | { |
1570 | struct DiffEntry *d = GNUNET_new (struct DiffEntry); | 1572 | struct DiffEntry *d = GNUNET_new(struct DiffEntry); |
1571 | 1573 | ||
1572 | d->changes = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | 1574 | d->changes = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); |
1573 | 1575 | ||
1574 | return d; | 1576 | return d; |
1575 | } | 1577 | } |
1576 | 1578 | ||
1577 | 1579 | ||
1578 | struct DiffEntry * | 1580 | struct DiffEntry * |
1579 | diff_compose (struct DiffEntry *diff_1, | 1581 | diff_compose(struct DiffEntry *diff_1, |
1580 | struct DiffEntry *diff_2) | 1582 | struct DiffEntry *diff_2) |
1581 | { | 1583 | { |
1582 | struct DiffEntry *diff_new; | 1584 | struct DiffEntry *diff_new; |
1583 | struct GNUNET_CONTAINER_MultiHashMapIterator *iter; | 1585 | struct GNUNET_CONTAINER_MultiHashMapIterator *iter; |
1584 | struct DiffElementInfo *di; | 1586 | struct DiffElementInfo *di; |
1585 | 1587 | ||
1586 | diff_new = diff_create (); | 1588 | diff_new = diff_create(); |
1587 | 1589 | ||
1588 | iter = GNUNET_CONTAINER_multihashmap_iterator_create (diff_1->changes); | 1590 | iter = GNUNET_CONTAINER_multihashmap_iterator_create(diff_1->changes); |
1589 | while (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next (iter, NULL, (const void **) &di)) | 1591 | while (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next(iter, NULL, (const void **)&di)) |
1590 | { | 1592 | { |
1591 | diff_insert (diff_new, di->weight, di->element); | 1593 | diff_insert(diff_new, di->weight, di->element); |
1592 | } | 1594 | } |
1593 | GNUNET_CONTAINER_multihashmap_iterator_destroy (iter); | 1595 | GNUNET_CONTAINER_multihashmap_iterator_destroy(iter); |
1594 | 1596 | ||
1595 | iter = GNUNET_CONTAINER_multihashmap_iterator_create (diff_2->changes); | 1597 | iter = GNUNET_CONTAINER_multihashmap_iterator_create(diff_2->changes); |
1596 | while (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next (iter, NULL, (const void **) &di)) | 1598 | while (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next(iter, NULL, (const void **)&di)) |
1597 | { | 1599 | { |
1598 | diff_insert (diff_new, di->weight, di->element); | 1600 | diff_insert(diff_new, di->weight, di->element); |
1599 | } | 1601 | } |
1600 | GNUNET_CONTAINER_multihashmap_iterator_destroy (iter); | 1602 | GNUNET_CONTAINER_multihashmap_iterator_destroy(iter); |
1601 | 1603 | ||
1602 | return diff_new; | 1604 | return diff_new; |
1603 | } | 1605 | } |
1604 | 1606 | ||
1605 | 1607 | ||
1606 | struct ReferendumEntry * | 1608 | struct ReferendumEntry * |
1607 | rfn_create (uint16_t size) | 1609 | rfn_create(uint16_t size) |
1608 | { | 1610 | { |
1609 | struct ReferendumEntry *rfn; | 1611 | struct ReferendumEntry *rfn; |
1610 | 1612 | ||
1611 | rfn = GNUNET_new (struct ReferendumEntry); | 1613 | rfn = GNUNET_new(struct ReferendumEntry); |
1612 | rfn->rfn_elements = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | 1614 | rfn->rfn_elements = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); |
1613 | rfn->peer_commited = GNUNET_new_array (size, int); | 1615 | rfn->peer_commited = GNUNET_new_array(size, int); |
1614 | rfn->peer_contested = GNUNET_new_array (size, int); | 1616 | rfn->peer_contested = GNUNET_new_array(size, int); |
1615 | rfn->num_peers = size; | 1617 | rfn->num_peers = size; |
1616 | 1618 | ||
1617 | return rfn; | 1619 | return rfn; |
@@ -1620,10 +1622,10 @@ rfn_create (uint16_t size) | |||
1620 | 1622 | ||
1621 | #if UNUSED | 1623 | #if UNUSED |
1622 | static void | 1624 | static void |
1623 | diff_destroy (struct DiffEntry *diff) | 1625 | diff_destroy(struct DiffEntry *diff) |
1624 | { | 1626 | { |
1625 | GNUNET_CONTAINER_multihashmap_destroy (diff->changes); | 1627 | GNUNET_CONTAINER_multihashmap_destroy(diff->changes); |
1626 | GNUNET_free (diff); | 1628 | GNUNET_free(diff); |
1627 | } | 1629 | } |
1628 | #endif | 1630 | #endif |
1629 | 1631 | ||
@@ -1634,71 +1636,70 @@ diff_destroy (struct DiffEntry *diff) | |||
1634 | * of peers that voted for this outcome. | 1636 | * of peers that voted for this outcome. |
1635 | */ | 1637 | */ |
1636 | static void | 1638 | static void |
1637 | rfn_majority (const struct ReferendumEntry *rfn, | 1639 | rfn_majority(const struct ReferendumEntry *rfn, |
1638 | const struct RfnElementInfo *ri, | 1640 | const struct RfnElementInfo *ri, |
1639 | uint16_t *ret_majority, | 1641 | uint16_t *ret_majority, |
1640 | enum ReferendumVote *ret_vote) | 1642 | enum ReferendumVote *ret_vote) |
1641 | { | 1643 | { |
1642 | uint16_t votes_yes = 0; | 1644 | uint16_t votes_yes = 0; |
1643 | uint16_t num_commited = 0; | 1645 | uint16_t num_commited = 0; |
1644 | uint16_t i; | 1646 | uint16_t i; |
1645 | 1647 | ||
1646 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1648 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1647 | "Computing rfn majority for element %s of rfn {%s}\n", | 1649 | "Computing rfn majority for element %s of rfn {%s}\n", |
1648 | debug_str_element (ri->element), | 1650 | debug_str_element(ri->element), |
1649 | debug_str_rfn_key (&rfn->key)); | 1651 | debug_str_rfn_key(&rfn->key)); |
1650 | 1652 | ||
1651 | for (i = 0; i < rfn->num_peers; i++) | 1653 | for (i = 0; i < rfn->num_peers; i++) |
1652 | { | 1654 | { |
1653 | if (GNUNET_NO == rfn->peer_commited[i]) | 1655 | if (GNUNET_NO == rfn->peer_commited[i]) |
1654 | continue; | 1656 | continue; |
1655 | num_commited++; | 1657 | num_commited++; |
1656 | 1658 | ||
1657 | if (GNUNET_YES == ri->votes[i]) | 1659 | if (GNUNET_YES == ri->votes[i]) |
1658 | votes_yes++; | 1660 | votes_yes++; |
1659 | } | 1661 | } |
1660 | 1662 | ||
1661 | if (votes_yes > (num_commited) / 2) | 1663 | if (votes_yes > (num_commited) / 2) |
1662 | { | 1664 | { |
1663 | *ret_vote = ri->proposal; | 1665 | *ret_vote = ri->proposal; |
1664 | *ret_majority = votes_yes; | 1666 | *ret_majority = votes_yes; |
1665 | } | 1667 | } |
1666 | else | 1668 | else |
1667 | { | 1669 | { |
1668 | *ret_vote = VOTE_STAY; | 1670 | *ret_vote = VOTE_STAY; |
1669 | *ret_majority = num_commited - votes_yes; | 1671 | *ret_majority = num_commited - votes_yes; |
1670 | } | 1672 | } |
1671 | } | 1673 | } |
1672 | 1674 | ||
1673 | 1675 | ||
1674 | struct SetCopyCls | 1676 | struct SetCopyCls { |
1675 | { | ||
1676 | struct TaskEntry *task; | 1677 | struct TaskEntry *task; |
1677 | struct SetKey dst_set_key; | 1678 | struct SetKey dst_set_key; |
1678 | }; | 1679 | }; |
1679 | 1680 | ||
1680 | 1681 | ||
1681 | static void | 1682 | static void |
1682 | set_copy_cb (void *cls, struct GNUNET_SET_Handle *copy) | 1683 | set_copy_cb(void *cls, struct GNUNET_SET_Handle *copy) |
1683 | { | 1684 | { |
1684 | struct SetCopyCls *scc = cls; | 1685 | struct SetCopyCls *scc = cls; |
1685 | struct TaskEntry *task = scc->task; | 1686 | struct TaskEntry *task = scc->task; |
1686 | struct SetKey dst_set_key = scc->dst_set_key; | 1687 | struct SetKey dst_set_key = scc->dst_set_key; |
1687 | struct SetEntry *set; | 1688 | struct SetEntry *set; |
1688 | struct SetHandle *sh = GNUNET_new (struct SetHandle); | 1689 | struct SetHandle *sh = GNUNET_new(struct SetHandle); |
1689 | 1690 | ||
1690 | sh->h = copy; | 1691 | sh->h = copy; |
1691 | GNUNET_CONTAINER_DLL_insert (task->step->session->set_handles_head, | 1692 | GNUNET_CONTAINER_DLL_insert(task->step->session->set_handles_head, |
1692 | task->step->session->set_handles_tail, | 1693 | task->step->session->set_handles_tail, |
1693 | sh); | 1694 | sh); |
1694 | 1695 | ||
1695 | GNUNET_free (scc); | 1696 | GNUNET_free(scc); |
1696 | set = GNUNET_new (struct SetEntry); | 1697 | set = GNUNET_new(struct SetEntry); |
1697 | set->h = copy; | 1698 | set->h = copy; |
1698 | set->key = dst_set_key; | 1699 | set->key = dst_set_key; |
1699 | put_set (task->step->session, set); | 1700 | put_set(task->step->session, set); |
1700 | 1701 | ||
1701 | task->start (task); | 1702 | task->start(task); |
1702 | } | 1703 | } |
1703 | 1704 | ||
1704 | 1705 | ||
@@ -1707,31 +1708,30 @@ set_copy_cb (void *cls, struct GNUNET_SET_Handle *copy) | |||
1707 | * task again after we created a copy of the given set. | 1708 | * task again after we created a copy of the given set. |
1708 | */ | 1709 | */ |
1709 | static void | 1710 | static void |
1710 | create_set_copy_for_task (struct TaskEntry *task, | 1711 | create_set_copy_for_task(struct TaskEntry *task, |
1711 | struct SetKey *src_set_key, | 1712 | struct SetKey *src_set_key, |
1712 | struct SetKey *dst_set_key) | 1713 | struct SetKey *dst_set_key) |
1713 | { | 1714 | { |
1714 | struct SetEntry *src_set; | 1715 | struct SetEntry *src_set; |
1715 | struct SetCopyCls *scc = GNUNET_new (struct SetCopyCls); | 1716 | struct SetCopyCls *scc = GNUNET_new(struct SetCopyCls); |
1716 | 1717 | ||
1717 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1718 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1718 | "Copying set {%s} to {%s} for task {%s}\n", | 1719 | "Copying set {%s} to {%s} for task {%s}\n", |
1719 | debug_str_set_key (src_set_key), | 1720 | debug_str_set_key(src_set_key), |
1720 | debug_str_set_key (dst_set_key), | 1721 | debug_str_set_key(dst_set_key), |
1721 | debug_str_task_key (&task->key)); | 1722 | debug_str_task_key(&task->key)); |
1722 | 1723 | ||
1723 | scc->task = task; | 1724 | scc->task = task; |
1724 | scc->dst_set_key = *dst_set_key; | 1725 | scc->dst_set_key = *dst_set_key; |
1725 | src_set = lookup_set (task->step->session, src_set_key); | 1726 | src_set = lookup_set(task->step->session, src_set_key); |
1726 | GNUNET_assert (NULL != src_set); | 1727 | GNUNET_assert(NULL != src_set); |
1727 | GNUNET_SET_copy_lazy (src_set->h, | 1728 | GNUNET_SET_copy_lazy(src_set->h, |
1728 | set_copy_cb, | 1729 | set_copy_cb, |
1729 | scc); | 1730 | scc); |
1730 | } | 1731 | } |
1731 | 1732 | ||
1732 | 1733 | ||
1733 | struct SetMutationProgressCls | 1734 | struct SetMutationProgressCls { |
1734 | { | ||
1735 | int num_pending; | 1735 | int num_pending; |
1736 | /** | 1736 | /** |
1737 | * Task to finish once all changes are through. | 1737 | * Task to finish once all changes are through. |
@@ -1741,25 +1741,25 @@ struct SetMutationProgressCls | |||
1741 | 1741 | ||
1742 | 1742 | ||
1743 | static void | 1743 | static void |
1744 | set_mutation_done (void *cls) | 1744 | set_mutation_done(void *cls) |
1745 | { | 1745 | { |
1746 | struct SetMutationProgressCls *pc = cls; | 1746 | struct SetMutationProgressCls *pc = cls; |
1747 | 1747 | ||
1748 | GNUNET_assert (pc->num_pending > 0); | 1748 | GNUNET_assert(pc->num_pending > 0); |
1749 | 1749 | ||
1750 | pc->num_pending--; | 1750 | pc->num_pending--; |
1751 | 1751 | ||
1752 | if (0 == pc->num_pending) | 1752 | if (0 == pc->num_pending) |
1753 | { | 1753 | { |
1754 | struct TaskEntry *task = pc->task; | 1754 | struct TaskEntry *task = pc->task; |
1755 | GNUNET_free (pc); | 1755 | GNUNET_free(pc); |
1756 | finish_task (task); | 1756 | finish_task(task); |
1757 | } | 1757 | } |
1758 | } | 1758 | } |
1759 | 1759 | ||
1760 | 1760 | ||
1761 | static void | 1761 | static void |
1762 | try_finish_step_early (struct Step *step) | 1762 | try_finish_step_early(struct Step *step) |
1763 | { | 1763 | { |
1764 | unsigned int i; | 1764 | unsigned int i; |
1765 | 1765 | ||
@@ -1773,63 +1773,61 @@ try_finish_step_early (struct Step *step) | |||
1773 | step->is_finished = GNUNET_YES; | 1773 | step->is_finished = GNUNET_YES; |
1774 | 1774 | ||
1775 | #ifdef GNUNET_EXTRA_LOGGING | 1775 | #ifdef GNUNET_EXTRA_LOGGING |
1776 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1776 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1777 | "Finishing step `%s' early.\n", | 1777 | "Finishing step `%s' early.\n", |
1778 | step->debug_name); | 1778 | step->debug_name); |
1779 | #endif | 1779 | #endif |
1780 | 1780 | ||
1781 | for (i = 0; i < step->subordinates_len; i++) | 1781 | for (i = 0; i < step->subordinates_len; i++) |
1782 | { | 1782 | { |
1783 | GNUNET_assert (step->subordinates[i]->pending_prereq > 0); | 1783 | GNUNET_assert(step->subordinates[i]->pending_prereq > 0); |
1784 | step->subordinates[i]->pending_prereq--; | 1784 | step->subordinates[i]->pending_prereq--; |
1785 | #ifdef GNUNET_EXTRA_LOGGING | 1785 | #ifdef GNUNET_EXTRA_LOGGING |
1786 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1786 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1787 | "Decreased pending_prereq to %u for step `%s'.\n", | 1787 | "Decreased pending_prereq to %u for step `%s'.\n", |
1788 | (unsigned int) step->subordinates[i]->pending_prereq, | 1788 | (unsigned int)step->subordinates[i]->pending_prereq, |
1789 | step->subordinates[i]->debug_name); | 1789 | step->subordinates[i]->debug_name); |
1790 | |||
1791 | #endif | 1790 | #endif |
1792 | try_finish_step_early (step->subordinates[i]); | 1791 | try_finish_step_early(step->subordinates[i]); |
1793 | } | 1792 | } |
1794 | 1793 | ||
1795 | // XXX: maybe schedule as task to avoid recursion? | 1794 | // XXX: maybe schedule as task to avoid recursion? |
1796 | run_ready_steps (step->session); | 1795 | run_ready_steps(step->session); |
1797 | } | 1796 | } |
1798 | 1797 | ||
1799 | 1798 | ||
1800 | static void | 1799 | static void |
1801 | finish_step (struct Step *step) | 1800 | finish_step(struct Step *step) |
1802 | { | 1801 | { |
1803 | unsigned int i; | 1802 | unsigned int i; |
1804 | 1803 | ||
1805 | GNUNET_assert (step->finished_tasks == step->tasks_len); | 1804 | GNUNET_assert(step->finished_tasks == step->tasks_len); |
1806 | GNUNET_assert (GNUNET_YES == step->is_running); | 1805 | GNUNET_assert(GNUNET_YES == step->is_running); |
1807 | GNUNET_assert (GNUNET_NO == step->is_finished); | 1806 | GNUNET_assert(GNUNET_NO == step->is_finished); |
1808 | 1807 | ||
1809 | #ifdef GNUNET_EXTRA_LOGGING | 1808 | #ifdef GNUNET_EXTRA_LOGGING |
1810 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1809 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1811 | "All tasks of step `%s' with %u subordinates finished.\n", | 1810 | "All tasks of step `%s' with %u subordinates finished.\n", |
1812 | step->debug_name, | 1811 | step->debug_name, |
1813 | step->subordinates_len); | 1812 | step->subordinates_len); |
1814 | #endif | 1813 | #endif |
1815 | 1814 | ||
1816 | for (i = 0; i < step->subordinates_len; i++) | 1815 | for (i = 0; i < step->subordinates_len; i++) |
1817 | { | 1816 | { |
1818 | GNUNET_assert (step->subordinates[i]->pending_prereq > 0); | 1817 | GNUNET_assert(step->subordinates[i]->pending_prereq > 0); |
1819 | step->subordinates[i]->pending_prereq--; | 1818 | step->subordinates[i]->pending_prereq--; |
1820 | #ifdef GNUNET_EXTRA_LOGGING | 1819 | #ifdef GNUNET_EXTRA_LOGGING |
1821 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1820 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1822 | "Decreased pending_prereq to %u for step `%s'.\n", | 1821 | "Decreased pending_prereq to %u for step `%s'.\n", |
1823 | (unsigned int) step->subordinates[i]->pending_prereq, | 1822 | (unsigned int)step->subordinates[i]->pending_prereq, |
1824 | step->subordinates[i]->debug_name); | 1823 | step->subordinates[i]->debug_name); |
1825 | |||
1826 | #endif | 1824 | #endif |
1827 | } | 1825 | } |
1828 | 1826 | ||
1829 | step->is_finished = GNUNET_YES; | 1827 | step->is_finished = GNUNET_YES; |
1830 | 1828 | ||
1831 | // XXX: maybe schedule as task to avoid recursion? | 1829 | // XXX: maybe schedule as task to avoid recursion? |
1832 | run_ready_steps (step->session); | 1830 | run_ready_steps(step->session); |
1833 | } | 1831 | } |
1834 | 1832 | ||
1835 | 1833 | ||
@@ -1841,7 +1839,7 @@ finish_step (struct Step *step) | |||
1841 | * @param task the task with context information | 1839 | * @param task the task with context information |
1842 | */ | 1840 | */ |
1843 | static void | 1841 | static void |
1844 | task_start_apply_round (struct TaskEntry *task) | 1842 | task_start_apply_round(struct TaskEntry *task) |
1845 | { | 1843 | { |
1846 | struct ConsensusSession *session = task->step->session; | 1844 | struct ConsensusSession *session = task->step->session; |
1847 | struct SetKey sk_in; | 1845 | struct SetKey sk_in; |
@@ -1858,130 +1856,136 @@ task_start_apply_round (struct TaskEntry *task) | |||
1858 | rk_in = (struct RfnKey) { RFN_KIND_GRADECAST_RESULT, task->key.repetition }; | 1856 | rk_in = (struct RfnKey) { RFN_KIND_GRADECAST_RESULT, task->key.repetition }; |
1859 | sk_out = (struct SetKey) { SET_KIND_CURRENT, task->key.repetition + 1 }; | 1857 | sk_out = (struct SetKey) { SET_KIND_CURRENT, task->key.repetition + 1 }; |
1860 | 1858 | ||
1861 | set_out = lookup_set (session, &sk_out); | 1859 | set_out = lookup_set(session, &sk_out); |
1862 | if (NULL == set_out) | 1860 | if (NULL == set_out) |
1863 | { | 1861 | { |
1864 | create_set_copy_for_task (task, &sk_in, &sk_out); | 1862 | create_set_copy_for_task(task, &sk_in, &sk_out); |
1865 | return; | 1863 | return; |
1866 | } | 1864 | } |
1867 | 1865 | ||
1868 | rfn_in = lookup_rfn (session, &rk_in); | 1866 | rfn_in = lookup_rfn(session, &rk_in); |
1869 | GNUNET_assert (NULL != rfn_in); | 1867 | GNUNET_assert(NULL != rfn_in); |
1870 | 1868 | ||
1871 | progress_cls = GNUNET_new (struct SetMutationProgressCls); | 1869 | progress_cls = GNUNET_new(struct SetMutationProgressCls); |
1872 | progress_cls->task = task; | 1870 | progress_cls->task = task; |
1873 | 1871 | ||
1874 | iter = GNUNET_CONTAINER_multihashmap_iterator_create (rfn_in->rfn_elements); | 1872 | iter = GNUNET_CONTAINER_multihashmap_iterator_create(rfn_in->rfn_elements); |
1875 | 1873 | ||
1876 | while (GNUNET_YES == | 1874 | while (GNUNET_YES == |
1877 | GNUNET_CONTAINER_multihashmap_iterator_next (iter, | 1875 | GNUNET_CONTAINER_multihashmap_iterator_next(iter, |
1878 | NULL, | 1876 | NULL, |
1879 | (const void **) &ri)) | 1877 | (const void **)&ri)) |
1880 | { | 1878 | { |
1881 | uint16_t majority_num; | 1879 | uint16_t majority_num; |
1882 | enum ReferendumVote majority_vote; | 1880 | enum ReferendumVote majority_vote; |
1883 | 1881 | ||
1884 | rfn_majority (rfn_in, ri, &majority_num, &majority_vote); | 1882 | rfn_majority(rfn_in, ri, &majority_num, &majority_vote); |
1885 | 1883 | ||
1886 | if (worst_majority > majority_num) | 1884 | if (worst_majority > majority_num) |
1887 | worst_majority = majority_num; | 1885 | worst_majority = majority_num; |
1888 | 1886 | ||
1889 | switch (majority_vote) | 1887 | switch (majority_vote) |
1890 | { | 1888 | { |
1891 | case VOTE_ADD: | 1889 | case VOTE_ADD: |
1892 | progress_cls->num_pending++; | 1890 | progress_cls->num_pending++; |
1893 | GNUNET_assert (GNUNET_OK == | 1891 | GNUNET_assert(GNUNET_OK == |
1894 | GNUNET_SET_add_element (set_out->h, | 1892 | GNUNET_SET_add_element(set_out->h, |
1895 | ri->element, | 1893 | ri->element, |
1896 | &set_mutation_done, | 1894 | &set_mutation_done, |
1897 | progress_cls)); | 1895 | progress_cls)); |
1898 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1896 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1899 | "P%u: apply round: adding element %s with %u-majority.\n", | 1897 | "P%u: apply round: adding element %s with %u-majority.\n", |
1900 | session->local_peer_idx, | 1898 | session->local_peer_idx, |
1901 | debug_str_element (ri->element), majority_num); | 1899 | debug_str_element(ri->element), majority_num); |
1902 | break; | 1900 | break; |
1903 | case VOTE_REMOVE: | 1901 | |
1904 | progress_cls->num_pending++; | 1902 | case VOTE_REMOVE: |
1905 | GNUNET_assert (GNUNET_OK == | 1903 | progress_cls->num_pending++; |
1906 | GNUNET_SET_remove_element (set_out->h, | 1904 | GNUNET_assert(GNUNET_OK == |
1905 | GNUNET_SET_remove_element(set_out->h, | ||
1907 | ri->element, | 1906 | ri->element, |
1908 | &set_mutation_done, | 1907 | &set_mutation_done, |
1909 | progress_cls)); | 1908 | progress_cls)); |
1910 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1909 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1911 | "P%u: apply round: deleting element %s with %u-majority.\n", | 1910 | "P%u: apply round: deleting element %s with %u-majority.\n", |
1912 | session->local_peer_idx, | 1911 | session->local_peer_idx, |
1913 | debug_str_element (ri->element), majority_num); | 1912 | debug_str_element(ri->element), majority_num); |
1914 | break; | 1913 | break; |
1915 | case VOTE_STAY: | 1914 | |
1916 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1915 | case VOTE_STAY: |
1917 | "P%u: apply round: keeping element %s with %u-majority.\n", | 1916 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1918 | session->local_peer_idx, | 1917 | "P%u: apply round: keeping element %s with %u-majority.\n", |
1919 | debug_str_element (ri->element), majority_num); | 1918 | session->local_peer_idx, |
1920 | // do nothing | 1919 | debug_str_element(ri->element), majority_num); |
1921 | break; | 1920 | // do nothing |
1922 | default: | 1921 | break; |
1923 | GNUNET_assert (0); | 1922 | |
1924 | break; | 1923 | default: |
1924 | GNUNET_assert(0); | ||
1925 | break; | ||
1926 | } | ||
1925 | } | 1927 | } |
1926 | } | ||
1927 | 1928 | ||
1928 | if (0 == progress_cls->num_pending) | 1929 | if (0 == progress_cls->num_pending) |
1929 | { | 1930 | { |
1930 | // call closure right now, no pending ops | 1931 | // call closure right now, no pending ops |
1931 | GNUNET_free (progress_cls); | 1932 | GNUNET_free(progress_cls); |
1932 | finish_task (task); | 1933 | finish_task(task); |
1933 | } | 1934 | } |
1934 | 1935 | ||
1935 | { | 1936 | { |
1936 | uint16_t thresh = (session->num_peers / 3) * 2; | 1937 | uint16_t thresh = (session->num_peers / 3) * 2; |
1937 | 1938 | ||
1938 | if (worst_majority >= thresh) | 1939 | if (worst_majority >= thresh) |
1939 | { | ||
1940 | switch (session->early_stopping) | ||
1941 | { | 1940 | { |
1942 | case EARLY_STOPPING_NONE: | 1941 | switch (session->early_stopping) |
1943 | session->early_stopping = EARLY_STOPPING_ONE_MORE; | ||
1944 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1945 | "P%u: Stopping early (after one more superround)\n", | ||
1946 | session->local_peer_idx); | ||
1947 | break; | ||
1948 | case EARLY_STOPPING_ONE_MORE: | ||
1949 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "P%u: finishing steps due to early finish\n", | ||
1950 | session->local_peer_idx); | ||
1951 | session->early_stopping = EARLY_STOPPING_DONE; | ||
1952 | { | 1942 | { |
1953 | struct Step *step; | 1943 | case EARLY_STOPPING_NONE: |
1954 | for (step = session->steps_head; NULL != step; step = step->next) | 1944 | session->early_stopping = EARLY_STOPPING_ONE_MORE; |
1955 | try_finish_step_early (step); | 1945 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1946 | "P%u: Stopping early (after one more superround)\n", | ||
1947 | session->local_peer_idx); | ||
1948 | break; | ||
1949 | |||
1950 | case EARLY_STOPPING_ONE_MORE: | ||
1951 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "P%u: finishing steps due to early finish\n", | ||
1952 | session->local_peer_idx); | ||
1953 | session->early_stopping = EARLY_STOPPING_DONE; | ||
1954 | { | ||
1955 | struct Step *step; | ||
1956 | for (step = session->steps_head; NULL != step; step = step->next) | ||
1957 | try_finish_step_early(step); | ||
1958 | } | ||
1959 | break; | ||
1960 | |||
1961 | case EARLY_STOPPING_DONE: | ||
1962 | /* We shouldn't be here anymore after early stopping */ | ||
1963 | GNUNET_break(0); | ||
1964 | break; | ||
1965 | |||
1966 | default: | ||
1967 | GNUNET_assert(0); | ||
1968 | break; | ||
1956 | } | 1969 | } |
1957 | break; | ||
1958 | case EARLY_STOPPING_DONE: | ||
1959 | /* We shouldn't be here anymore after early stopping */ | ||
1960 | GNUNET_break (0); | ||
1961 | break; | ||
1962 | default: | ||
1963 | GNUNET_assert (0); | ||
1964 | break; | ||
1965 | } | 1970 | } |
1966 | } | ||
1967 | else if (EARLY_STOPPING_NONE != session->early_stopping) | 1971 | else if (EARLY_STOPPING_NONE != session->early_stopping) |
1968 | { | 1972 | { |
1969 | // Our assumption about the number of bad peers | 1973 | // Our assumption about the number of bad peers |
1970 | // has been broken. | 1974 | // has been broken. |
1971 | GNUNET_break_op (0); | 1975 | GNUNET_break_op(0); |
1972 | } | 1976 | } |
1973 | else | 1977 | else |
1974 | { | 1978 | { |
1975 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "P%u: NOT finishing early (majority not good enough)\n", | 1979 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "P%u: NOT finishing early (majority not good enough)\n", |
1976 | session->local_peer_idx); | 1980 | session->local_peer_idx); |
1977 | } | 1981 | } |
1978 | } | 1982 | } |
1979 | GNUNET_CONTAINER_multihashmap_iterator_destroy (iter); | 1983 | GNUNET_CONTAINER_multihashmap_iterator_destroy(iter); |
1980 | } | 1984 | } |
1981 | 1985 | ||
1982 | 1986 | ||
1983 | static void | 1987 | static void |
1984 | task_start_grade (struct TaskEntry *task) | 1988 | task_start_grade(struct TaskEntry *task) |
1985 | { | 1989 | { |
1986 | struct ConsensusSession *session = task->step->session; | 1990 | struct ConsensusSession *session = task->step->session; |
1987 | struct ReferendumEntry *output_rfn; | 1991 | struct ReferendumEntry *output_rfn; |
@@ -1994,90 +1998,93 @@ task_start_grade (struct TaskEntry *task) | |||
1994 | unsigned int gradecast_confidence = 2; | 1998 | unsigned int gradecast_confidence = 2; |
1995 | 1999 | ||
1996 | rfn_key = (struct RfnKey) { RFN_KIND_GRADECAST_RESULT, task->key.repetition }; | 2000 | rfn_key = (struct RfnKey) { RFN_KIND_GRADECAST_RESULT, task->key.repetition }; |
1997 | output_rfn = lookup_rfn (session, &rfn_key); | 2001 | output_rfn = lookup_rfn(session, &rfn_key); |
1998 | if (NULL == output_rfn) | 2002 | if (NULL == output_rfn) |
1999 | { | 2003 | { |
2000 | output_rfn = rfn_create (session->num_peers); | 2004 | output_rfn = rfn_create(session->num_peers); |
2001 | output_rfn->key = rfn_key; | 2005 | output_rfn->key = rfn_key; |
2002 | put_rfn (session, output_rfn); | 2006 | put_rfn(session, output_rfn); |
2003 | } | 2007 | } |
2004 | 2008 | ||
2005 | diff_key = (struct DiffKey) { DIFF_KIND_LEADER_PROPOSAL, task->key.repetition, task->key.leader }; | 2009 | diff_key = (struct DiffKey) { DIFF_KIND_LEADER_PROPOSAL, task->key.repetition, task->key.leader }; |
2006 | input_diff = lookup_diff (session, &diff_key); | 2010 | input_diff = lookup_diff(session, &diff_key); |
2007 | GNUNET_assert (NULL != input_diff); | 2011 | GNUNET_assert(NULL != input_diff); |
2008 | 2012 | ||
2009 | rfn_key = (struct RfnKey) { RFN_KIND_ECHO, task->key.repetition, task->key.leader }; | 2013 | rfn_key = (struct RfnKey) { RFN_KIND_ECHO, task->key.repetition, task->key.leader }; |
2010 | input_rfn = lookup_rfn (session, &rfn_key); | 2014 | input_rfn = lookup_rfn(session, &rfn_key); |
2011 | GNUNET_assert (NULL != input_rfn); | 2015 | GNUNET_assert(NULL != input_rfn); |
2012 | 2016 | ||
2013 | iter = GNUNET_CONTAINER_multihashmap_iterator_create (input_rfn->rfn_elements); | 2017 | iter = GNUNET_CONTAINER_multihashmap_iterator_create(input_rfn->rfn_elements); |
2014 | 2018 | ||
2015 | apply_diff_to_rfn (input_diff, output_rfn, task->key.leader, session->num_peers); | 2019 | apply_diff_to_rfn(input_diff, output_rfn, task->key.leader, session->num_peers); |
2016 | 2020 | ||
2017 | while (GNUNET_YES == | 2021 | while (GNUNET_YES == |
2018 | GNUNET_CONTAINER_multihashmap_iterator_next (iter, | 2022 | GNUNET_CONTAINER_multihashmap_iterator_next(iter, |
2019 | NULL, | 2023 | NULL, |
2020 | (const void **) &ri)) | 2024 | (const void **)&ri)) |
2021 | { | 2025 | { |
2022 | uint16_t majority_num; | 2026 | uint16_t majority_num; |
2023 | enum ReferendumVote majority_vote; | 2027 | enum ReferendumVote majority_vote; |
2024 | 2028 | ||
2025 | // XXX: we need contested votes and non-contested votes here | 2029 | // XXX: we need contested votes and non-contested votes here |
2026 | rfn_majority (input_rfn, ri, &majority_num, &majority_vote); | 2030 | rfn_majority(input_rfn, ri, &majority_num, &majority_vote); |
2027 | 2031 | ||
2028 | if (majority_num <= session->num_peers / 3) | 2032 | if (majority_num <= session->num_peers / 3) |
2029 | majority_vote = VOTE_REMOVE; | 2033 | majority_vote = VOTE_REMOVE; |
2030 | 2034 | ||
2031 | switch (majority_vote) | 2035 | switch (majority_vote) |
2032 | { | 2036 | { |
2033 | case VOTE_STAY: | 2037 | case VOTE_STAY: |
2034 | break; | 2038 | break; |
2035 | case VOTE_ADD: | 2039 | |
2036 | rfn_vote (output_rfn, task->key.leader, VOTE_ADD, ri->element); | 2040 | case VOTE_ADD: |
2037 | break; | 2041 | rfn_vote(output_rfn, task->key.leader, VOTE_ADD, ri->element); |
2038 | case VOTE_REMOVE: | 2042 | break; |
2039 | rfn_vote (output_rfn, task->key.leader, VOTE_REMOVE, ri->element); | 2043 | |
2040 | break; | 2044 | case VOTE_REMOVE: |
2041 | default: | 2045 | rfn_vote(output_rfn, task->key.leader, VOTE_REMOVE, ri->element); |
2042 | GNUNET_assert (0); | 2046 | break; |
2043 | break; | 2047 | |
2048 | default: | ||
2049 | GNUNET_assert(0); | ||
2050 | break; | ||
2051 | } | ||
2044 | } | 2052 | } |
2045 | } | 2053 | GNUNET_CONTAINER_multihashmap_iterator_destroy(iter); |
2046 | GNUNET_CONTAINER_multihashmap_iterator_destroy (iter); | ||
2047 | 2054 | ||
2048 | { | 2055 | { |
2049 | uint16_t noncontested; | 2056 | uint16_t noncontested; |
2050 | noncontested = rfn_noncontested (input_rfn); | 2057 | noncontested = rfn_noncontested(input_rfn); |
2051 | if (noncontested < (session->num_peers / 3) * 2) | 2058 | if (noncontested < (session->num_peers / 3) * 2) |
2052 | { | 2059 | { |
2053 | gradecast_confidence = GNUNET_MIN(1, gradecast_confidence); | 2060 | gradecast_confidence = GNUNET_MIN(1, gradecast_confidence); |
2054 | } | 2061 | } |
2055 | if (noncontested < (session->num_peers / 3) + 1) | 2062 | if (noncontested < (session->num_peers / 3) + 1) |
2056 | { | 2063 | { |
2057 | gradecast_confidence = 0; | 2064 | gradecast_confidence = 0; |
2058 | } | 2065 | } |
2059 | } | 2066 | } |
2060 | 2067 | ||
2061 | if (gradecast_confidence >= 1) | 2068 | if (gradecast_confidence >= 1) |
2062 | rfn_commit (output_rfn, task->key.leader); | 2069 | rfn_commit(output_rfn, task->key.leader); |
2063 | 2070 | ||
2064 | if (gradecast_confidence <= 1) | 2071 | if (gradecast_confidence <= 1) |
2065 | session->peers_blacklisted[task->key.leader] = GNUNET_YES; | 2072 | session->peers_blacklisted[task->key.leader] = GNUNET_YES; |
2066 | 2073 | ||
2067 | finish_task (task); | 2074 | finish_task(task); |
2068 | } | 2075 | } |
2069 | 2076 | ||
2070 | 2077 | ||
2071 | static void | 2078 | static void |
2072 | task_start_reconcile (struct TaskEntry *task) | 2079 | task_start_reconcile(struct TaskEntry *task) |
2073 | { | 2080 | { |
2074 | struct SetEntry *input; | 2081 | struct SetEntry *input; |
2075 | struct SetOpCls *setop = &task->cls.setop; | 2082 | struct SetOpCls *setop = &task->cls.setop; |
2076 | struct ConsensusSession *session = task->step->session; | 2083 | struct ConsensusSession *session = task->step->session; |
2077 | 2084 | ||
2078 | input = lookup_set (session, &setop->input_set); | 2085 | input = lookup_set(session, &setop->input_set); |
2079 | GNUNET_assert (NULL != input); | 2086 | GNUNET_assert(NULL != input); |
2080 | GNUNET_assert (NULL != input->h); | 2087 | GNUNET_assert(NULL != input->h); |
2081 | 2088 | ||
2082 | /* We create the outputs for the operation here | 2089 | /* We create the outputs for the operation here |
2083 | (rather than in the set operation callback) | 2090 | (rather than in the set operation callback) |
@@ -2085,113 +2092,113 @@ task_start_reconcile (struct TaskEntry *task) | |||
2085 | if the other peer doesn't talk to us */ | 2092 | if the other peer doesn't talk to us */ |
2086 | 2093 | ||
2087 | if (SET_KIND_NONE != setop->output_set.set_kind) | 2094 | if (SET_KIND_NONE != setop->output_set.set_kind) |
2088 | { | ||
2089 | /* If we don't have an existing output set, | ||
2090 | we clone the input set. */ | ||
2091 | if (NULL == lookup_set (session, &setop->output_set)) | ||
2092 | { | 2095 | { |
2093 | create_set_copy_for_task (task, &setop->input_set, &setop->output_set); | 2096 | /* If we don't have an existing output set, |
2094 | return; | 2097 | we clone the input set. */ |
2098 | if (NULL == lookup_set(session, &setop->output_set)) | ||
2099 | { | ||
2100 | create_set_copy_for_task(task, &setop->input_set, &setop->output_set); | ||
2101 | return; | ||
2102 | } | ||
2095 | } | 2103 | } |
2096 | } | ||
2097 | 2104 | ||
2098 | if (RFN_KIND_NONE != setop->output_rfn.rfn_kind) | 2105 | if (RFN_KIND_NONE != setop->output_rfn.rfn_kind) |
2099 | { | ||
2100 | if (NULL == lookup_rfn (session, &setop->output_rfn)) | ||
2101 | { | 2106 | { |
2102 | struct ReferendumEntry *rfn; | 2107 | if (NULL == lookup_rfn(session, &setop->output_rfn)) |
2108 | { | ||
2109 | struct ReferendumEntry *rfn; | ||
2103 | 2110 | ||
2104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2111 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2105 | "P%u: output rfn <%s> missing, creating.\n", | 2112 | "P%u: output rfn <%s> missing, creating.\n", |
2106 | session->local_peer_idx, | 2113 | session->local_peer_idx, |
2107 | debug_str_rfn_key (&setop->output_rfn)); | 2114 | debug_str_rfn_key(&setop->output_rfn)); |
2108 | 2115 | ||
2109 | rfn = rfn_create (session->num_peers); | 2116 | rfn = rfn_create(session->num_peers); |
2110 | rfn->key = setop->output_rfn; | 2117 | rfn->key = setop->output_rfn; |
2111 | put_rfn (session, rfn); | 2118 | put_rfn(session, rfn); |
2119 | } | ||
2112 | } | 2120 | } |
2113 | } | ||
2114 | 2121 | ||
2115 | if (DIFF_KIND_NONE != setop->output_diff.diff_kind) | 2122 | if (DIFF_KIND_NONE != setop->output_diff.diff_kind) |
2116 | { | ||
2117 | if (NULL == lookup_diff (session, &setop->output_diff)) | ||
2118 | { | 2123 | { |
2119 | struct DiffEntry *diff; | 2124 | if (NULL == lookup_diff(session, &setop->output_diff)) |
2125 | { | ||
2126 | struct DiffEntry *diff; | ||
2120 | 2127 | ||
2121 | diff = diff_create (); | 2128 | diff = diff_create(); |
2122 | diff->key = setop->output_diff; | 2129 | diff->key = setop->output_diff; |
2123 | put_diff (session, diff); | 2130 | put_diff(session, diff); |
2131 | } | ||
2124 | } | 2132 | } |
2125 | } | ||
2126 | 2133 | ||
2127 | if ( (task->key.peer1 == session->local_peer_idx) && (task->key.peer2 == session->local_peer_idx) ) | 2134 | if ((task->key.peer1 == session->local_peer_idx) && (task->key.peer2 == session->local_peer_idx)) |
2128 | { | 2135 | { |
2129 | /* XXX: mark the corresponding rfn as commited if necessary */ | 2136 | /* XXX: mark the corresponding rfn as commited if necessary */ |
2130 | finish_task (task); | 2137 | finish_task(task); |
2131 | return; | 2138 | return; |
2132 | } | 2139 | } |
2133 | 2140 | ||
2134 | if (task->key.peer1 == session->local_peer_idx) | 2141 | if (task->key.peer1 == session->local_peer_idx) |
2135 | { | 2142 | { |
2136 | struct GNUNET_CONSENSUS_RoundContextMessage rcm; | 2143 | struct GNUNET_CONSENSUS_RoundContextMessage rcm; |
2137 | 2144 | ||
2138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2145 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2139 | "P%u: Looking up set {%s} to run remote union\n", | 2146 | "P%u: Looking up set {%s} to run remote union\n", |
2140 | session->local_peer_idx, | 2147 | session->local_peer_idx, |
2141 | debug_str_set_key (&setop->input_set)); | 2148 | debug_str_set_key(&setop->input_set)); |
2142 | 2149 | ||
2143 | rcm.header.type = htons (GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT); | 2150 | rcm.header.type = htons(GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT); |
2144 | rcm.header.size = htons (sizeof (struct GNUNET_CONSENSUS_RoundContextMessage)); | 2151 | rcm.header.size = htons(sizeof(struct GNUNET_CONSENSUS_RoundContextMessage)); |
2145 | 2152 | ||
2146 | rcm.kind = htons (task->key.kind); | 2153 | rcm.kind = htons(task->key.kind); |
2147 | rcm.peer1 = htons (task->key.peer1); | 2154 | rcm.peer1 = htons(task->key.peer1); |
2148 | rcm.peer2 = htons (task->key.peer2); | 2155 | rcm.peer2 = htons(task->key.peer2); |
2149 | rcm.leader = htons (task->key.leader); | 2156 | rcm.leader = htons(task->key.leader); |
2150 | rcm.repetition = htons (task->key.repetition); | 2157 | rcm.repetition = htons(task->key.repetition); |
2151 | rcm.is_contested = htons (0); | 2158 | rcm.is_contested = htons(0); |
2152 | 2159 | ||
2153 | GNUNET_assert (NULL == setop->op); | 2160 | GNUNET_assert(NULL == setop->op); |
2154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: initiating set op with P%u, our set is %s\n", | 2161 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "P%u: initiating set op with P%u, our set is %s\n", |
2155 | session->local_peer_idx, task->key.peer2, debug_str_set_key (&setop->input_set)); | 2162 | session->local_peer_idx, task->key.peer2, debug_str_set_key(&setop->input_set)); |
2156 | 2163 | ||
2157 | struct GNUNET_SET_Option opts[] = { | 2164 | struct GNUNET_SET_Option opts[] = { |
2158 | { GNUNET_SET_OPTION_BYZANTINE, { .num = session->lower_bound } }, | 2165 | { GNUNET_SET_OPTION_BYZANTINE, { .num = session->lower_bound } }, |
2159 | { GNUNET_SET_OPTION_END }, | 2166 | { GNUNET_SET_OPTION_END }, |
2160 | }; | 2167 | }; |
2161 | 2168 | ||
2162 | // XXX: maybe this should be done while | 2169 | // XXX: maybe this should be done while |
2163 | // setting up tasks alreays? | 2170 | // setting up tasks alreays? |
2164 | setop->op = GNUNET_SET_prepare (&session->peers[task->key.peer2], | 2171 | setop->op = GNUNET_SET_prepare(&session->peers[task->key.peer2], |
2165 | &session->global_id, | 2172 | &session->global_id, |
2166 | &rcm.header, | 2173 | &rcm.header, |
2167 | GNUNET_SET_RESULT_SYMMETRIC, | 2174 | GNUNET_SET_RESULT_SYMMETRIC, |
2168 | opts, | 2175 | opts, |
2169 | set_result_cb, | 2176 | set_result_cb, |
2170 | task); | 2177 | task); |
2171 | 2178 | ||
2172 | commit_set (session, task); | 2179 | commit_set(session, task); |
2173 | } | 2180 | } |
2174 | else if (task->key.peer2 == session->local_peer_idx) | 2181 | else if (task->key.peer2 == session->local_peer_idx) |
2175 | { | ||
2176 | /* Wait for the other peer to contact us */ | ||
2177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: waiting set op with P%u\n", | ||
2178 | session->local_peer_idx, task->key.peer1); | ||
2179 | |||
2180 | if (NULL != setop->op) | ||
2181 | { | 2182 | { |
2182 | commit_set (session, task); | 2183 | /* Wait for the other peer to contact us */ |
2184 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "P%u: waiting set op with P%u\n", | ||
2185 | session->local_peer_idx, task->key.peer1); | ||
2186 | |||
2187 | if (NULL != setop->op) | ||
2188 | { | ||
2189 | commit_set(session, task); | ||
2190 | } | ||
2183 | } | 2191 | } |
2184 | } | ||
2185 | else | 2192 | else |
2186 | { | 2193 | { |
2187 | /* We made an error while constructing the task graph. */ | 2194 | /* We made an error while constructing the task graph. */ |
2188 | GNUNET_assert (0); | 2195 | GNUNET_assert(0); |
2189 | } | 2196 | } |
2190 | } | 2197 | } |
2191 | 2198 | ||
2192 | 2199 | ||
2193 | static void | 2200 | static void |
2194 | task_start_eval_echo (struct TaskEntry *task) | 2201 | task_start_eval_echo(struct TaskEntry *task) |
2195 | { | 2202 | { |
2196 | struct GNUNET_CONTAINER_MultiHashMapIterator *iter; | 2203 | struct GNUNET_CONTAINER_MultiHashMapIterator *iter; |
2197 | struct ReferendumEntry *input_rfn; | 2204 | struct ReferendumEntry *input_rfn; |
@@ -2205,123 +2212,126 @@ task_start_eval_echo (struct TaskEntry *task) | |||
2205 | 2212 | ||
2206 | sk_in = (struct SetKey) { SET_KIND_LEADER_PROPOSAL, task->key.repetition, task->key.leader }; | 2213 | sk_in = (struct SetKey) { SET_KIND_LEADER_PROPOSAL, task->key.repetition, task->key.leader }; |
2207 | sk_out = (struct SetKey) { SET_KIND_ECHO_RESULT, task->key.repetition, task->key.leader }; | 2214 | sk_out = (struct SetKey) { SET_KIND_ECHO_RESULT, task->key.repetition, task->key.leader }; |
2208 | output_set = lookup_set (session, &sk_out); | 2215 | output_set = lookup_set(session, &sk_out); |
2209 | if (NULL == output_set) | 2216 | if (NULL == output_set) |
2210 | { | 2217 | { |
2211 | create_set_copy_for_task (task, &sk_in, &sk_out); | 2218 | create_set_copy_for_task(task, &sk_in, &sk_out); |
2212 | return; | 2219 | return; |
2213 | } | 2220 | } |
2214 | 2221 | ||
2215 | 2222 | ||
2216 | { | 2223 | { |
2217 | // FIXME: should be marked as a shallow copy, so | 2224 | // FIXME: should be marked as a shallow copy, so |
2218 | // we can destroy everything correctly | 2225 | // we can destroy everything correctly |
2219 | struct SetEntry *last_set = GNUNET_new (struct SetEntry); | 2226 | struct SetEntry *last_set = GNUNET_new(struct SetEntry); |
2220 | last_set->h = output_set->h; | 2227 | last_set->h = output_set->h; |
2221 | last_set->key = (struct SetKey) { SET_KIND_LAST_GRADECAST }; | 2228 | last_set->key = (struct SetKey) { SET_KIND_LAST_GRADECAST }; |
2222 | put_set (session, last_set); | 2229 | put_set(session, last_set); |
2223 | } | 2230 | } |
2224 | 2231 | ||
2225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2232 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2226 | "Evaluating referendum in Task {%s}\n", | 2233 | "Evaluating referendum in Task {%s}\n", |
2227 | debug_str_task_key (&task->key)); | 2234 | debug_str_task_key(&task->key)); |
2228 | 2235 | ||
2229 | progress_cls = GNUNET_new (struct SetMutationProgressCls); | 2236 | progress_cls = GNUNET_new(struct SetMutationProgressCls); |
2230 | progress_cls->task = task; | 2237 | progress_cls->task = task; |
2231 | 2238 | ||
2232 | rk_in = (struct RfnKey) { RFN_KIND_ECHO, task->key.repetition, task->key.leader }; | 2239 | rk_in = (struct RfnKey) { RFN_KIND_ECHO, task->key.repetition, task->key.leader }; |
2233 | input_rfn = lookup_rfn (session, &rk_in); | 2240 | input_rfn = lookup_rfn(session, &rk_in); |
2234 | 2241 | ||
2235 | GNUNET_assert (NULL != input_rfn); | 2242 | GNUNET_assert(NULL != input_rfn); |
2236 | 2243 | ||
2237 | iter = GNUNET_CONTAINER_multihashmap_iterator_create (input_rfn->rfn_elements); | 2244 | iter = GNUNET_CONTAINER_multihashmap_iterator_create(input_rfn->rfn_elements); |
2238 | GNUNET_assert (NULL != iter); | 2245 | GNUNET_assert(NULL != iter); |
2239 | 2246 | ||
2240 | while (GNUNET_YES == | 2247 | while (GNUNET_YES == |
2241 | GNUNET_CONTAINER_multihashmap_iterator_next (iter, | 2248 | GNUNET_CONTAINER_multihashmap_iterator_next(iter, |
2242 | NULL, | 2249 | NULL, |
2243 | (const void **) &ri)) | 2250 | (const void **)&ri)) |
2244 | { | 2251 | { |
2245 | enum ReferendumVote majority_vote; | 2252 | enum ReferendumVote majority_vote; |
2246 | uint16_t majority_num; | 2253 | uint16_t majority_num; |
2247 | 2254 | ||
2248 | rfn_majority (input_rfn, ri, &majority_num, &majority_vote); | 2255 | rfn_majority(input_rfn, ri, &majority_num, &majority_vote); |
2249 | 2256 | ||
2250 | if (majority_num < session->num_peers / 3) | 2257 | if (majority_num < session->num_peers / 3) |
2251 | { | 2258 | { |
2252 | /* It is not the case that all nonfaulty peers | 2259 | /* It is not the case that all nonfaulty peers |
2253 | echoed the same value. Since we're doing a set reconciliation, we | 2260 | echoed the same value. Since we're doing a set reconciliation, we |
2254 | can't simply send "nothing" for the value. Thus we mark our 'confirm' | 2261 | can't simply send "nothing" for the value. Thus we mark our 'confirm' |
2255 | reconciliation as contested. Other peers might not know that the | 2262 | reconciliation as contested. Other peers might not know that the |
2256 | leader is faulty, thus we still re-distribute in the confirmation | 2263 | leader is faulty, thus we still re-distribute in the confirmation |
2257 | round. */ | 2264 | round. */ |
2258 | output_set->is_contested = GNUNET_YES; | 2265 | output_set->is_contested = GNUNET_YES; |
2259 | } | 2266 | } |
2260 | 2267 | ||
2261 | switch (majority_vote) | 2268 | switch (majority_vote) |
2262 | { | 2269 | { |
2263 | case VOTE_ADD: | 2270 | case VOTE_ADD: |
2264 | progress_cls->num_pending++; | 2271 | progress_cls->num_pending++; |
2265 | GNUNET_assert (GNUNET_OK == | 2272 | GNUNET_assert(GNUNET_OK == |
2266 | GNUNET_SET_add_element (output_set->h, | 2273 | GNUNET_SET_add_element(output_set->h, |
2267 | ri->element, | 2274 | ri->element, |
2268 | set_mutation_done, | 2275 | set_mutation_done, |
2269 | progress_cls)); | 2276 | progress_cls)); |
2270 | break; | 2277 | break; |
2271 | case VOTE_REMOVE: | 2278 | |
2272 | progress_cls->num_pending++; | 2279 | case VOTE_REMOVE: |
2273 | GNUNET_assert (GNUNET_OK == | 2280 | progress_cls->num_pending++; |
2274 | GNUNET_SET_remove_element (output_set->h, | 2281 | GNUNET_assert(GNUNET_OK == |
2282 | GNUNET_SET_remove_element(output_set->h, | ||
2275 | ri->element, | 2283 | ri->element, |
2276 | set_mutation_done, | 2284 | set_mutation_done, |
2277 | progress_cls)); | 2285 | progress_cls)); |
2278 | break; | 2286 | break; |
2279 | case VOTE_STAY: | 2287 | |
2280 | /* Nothing to do. */ | 2288 | case VOTE_STAY: |
2281 | break; | 2289 | /* Nothing to do. */ |
2282 | default: | 2290 | break; |
2283 | /* not reached */ | 2291 | |
2284 | GNUNET_assert (0); | 2292 | default: |
2293 | /* not reached */ | ||
2294 | GNUNET_assert(0); | ||
2295 | } | ||
2285 | } | 2296 | } |
2286 | } | ||
2287 | 2297 | ||
2288 | GNUNET_CONTAINER_multihashmap_iterator_destroy (iter); | 2298 | GNUNET_CONTAINER_multihashmap_iterator_destroy(iter); |
2289 | 2299 | ||
2290 | if (0 == progress_cls->num_pending) | 2300 | if (0 == progress_cls->num_pending) |
2291 | { | 2301 | { |
2292 | // call closure right now, no pending ops | 2302 | // call closure right now, no pending ops |
2293 | GNUNET_free (progress_cls); | 2303 | GNUNET_free(progress_cls); |
2294 | finish_task (task); | 2304 | finish_task(task); |
2295 | } | 2305 | } |
2296 | } | 2306 | } |
2297 | 2307 | ||
2298 | 2308 | ||
2299 | static void | 2309 | static void |
2300 | task_start_finish (struct TaskEntry *task) | 2310 | task_start_finish(struct TaskEntry *task) |
2301 | { | 2311 | { |
2302 | struct SetEntry *final_set; | 2312 | struct SetEntry *final_set; |
2303 | struct ConsensusSession *session = task->step->session; | 2313 | struct ConsensusSession *session = task->step->session; |
2304 | 2314 | ||
2305 | final_set = lookup_set (session, &task->cls.finish.input_set); | 2315 | final_set = lookup_set(session, &task->cls.finish.input_set); |
2306 | 2316 | ||
2307 | GNUNET_assert (NULL != final_set); | 2317 | GNUNET_assert(NULL != final_set); |
2308 | 2318 | ||
2309 | 2319 | ||
2310 | GNUNET_SET_iterate (final_set->h, | 2320 | GNUNET_SET_iterate(final_set->h, |
2311 | send_to_client_iter, | 2321 | send_to_client_iter, |
2312 | task); | 2322 | task); |
2313 | } | 2323 | } |
2314 | 2324 | ||
2315 | static void | 2325 | static void |
2316 | start_task (struct ConsensusSession *session, struct TaskEntry *task) | 2326 | start_task(struct ConsensusSession *session, struct TaskEntry *task) |
2317 | { | 2327 | { |
2318 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: starting task {%s}\n", session->local_peer_idx, debug_str_task_key (&task->key)); | 2328 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "P%u: starting task {%s}\n", session->local_peer_idx, debug_str_task_key(&task->key)); |
2319 | 2329 | ||
2320 | GNUNET_assert (GNUNET_NO == task->is_started); | 2330 | GNUNET_assert(GNUNET_NO == task->is_started); |
2321 | GNUNET_assert (GNUNET_NO == task->is_finished); | 2331 | GNUNET_assert(GNUNET_NO == task->is_finished); |
2322 | GNUNET_assert (NULL != task->start); | 2332 | GNUNET_assert(NULL != task->start); |
2323 | 2333 | ||
2324 | task->start (task); | 2334 | task->start(task); |
2325 | 2335 | ||
2326 | task->is_started = GNUNET_YES; | 2336 | task->is_started = GNUNET_YES; |
2327 | } | 2337 | } |
@@ -2334,40 +2344,40 @@ start_task (struct ConsensusSession *session, struct TaskEntry *task) | |||
2334 | * more dependencies. | 2344 | * more dependencies. |
2335 | */ | 2345 | */ |
2336 | static void | 2346 | static void |
2337 | run_ready_steps (struct ConsensusSession *session) | 2347 | run_ready_steps(struct ConsensusSession *session) |
2338 | { | 2348 | { |
2339 | struct Step *step; | 2349 | struct Step *step; |
2340 | 2350 | ||
2341 | step = session->steps_head; | 2351 | step = session->steps_head; |
2342 | 2352 | ||
2343 | while (NULL != step) | 2353 | while (NULL != step) |
2344 | { | ||
2345 | if ( (GNUNET_NO == step->is_running) && (0 == step->pending_prereq) && (GNUNET_NO == step->is_finished) ) | ||
2346 | { | 2354 | { |
2347 | size_t i; | 2355 | if ((GNUNET_NO == step->is_running) && (0 == step->pending_prereq) && (GNUNET_NO == step->is_finished)) |
2356 | { | ||
2357 | size_t i; | ||
2348 | 2358 | ||
2349 | GNUNET_assert (0 == step->finished_tasks); | 2359 | GNUNET_assert(0 == step->finished_tasks); |
2350 | 2360 | ||
2351 | #ifdef GNUNET_EXTRA_LOGGING | 2361 | #ifdef GNUNET_EXTRA_LOGGING |
2352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: Running step `%s' of round %d with %d tasks and %d subordinates\n", | 2362 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "P%u: Running step `%s' of round %d with %d tasks and %d subordinates\n", |
2353 | session->local_peer_idx, | 2363 | session->local_peer_idx, |
2354 | step->debug_name, | 2364 | step->debug_name, |
2355 | step->round, step->tasks_len, step->subordinates_len); | 2365 | step->round, step->tasks_len, step->subordinates_len); |
2356 | #endif | 2366 | #endif |
2357 | 2367 | ||
2358 | step->is_running = GNUNET_YES; | 2368 | step->is_running = GNUNET_YES; |
2359 | for (i = 0; i < step->tasks_len; i++) | 2369 | for (i = 0; i < step->tasks_len; i++) |
2360 | start_task (session, step->tasks[i]); | 2370 | start_task(session, step->tasks[i]); |
2361 | 2371 | ||
2362 | /* Sometimes there is no task to trigger finishing the step, so we have to do it here. */ | 2372 | /* Sometimes there is no task to trigger finishing the step, so we have to do it here. */ |
2363 | if ( (step->finished_tasks == step->tasks_len) && (GNUNET_NO == step->is_finished)) | 2373 | if ((step->finished_tasks == step->tasks_len) && (GNUNET_NO == step->is_finished)) |
2364 | finish_step (step); | 2374 | finish_step(step); |
2365 | 2375 | ||
2366 | /* Running the next ready steps will be triggered by task completion */ | 2376 | /* Running the next ready steps will be triggered by task completion */ |
2367 | return; | 2377 | return; |
2378 | } | ||
2379 | step = step->next; | ||
2368 | } | 2380 | } |
2369 | step = step->next; | ||
2370 | } | ||
2371 | 2381 | ||
2372 | return; | 2382 | return; |
2373 | } | 2383 | } |
@@ -2375,22 +2385,22 @@ run_ready_steps (struct ConsensusSession *session) | |||
2375 | 2385 | ||
2376 | 2386 | ||
2377 | static void | 2387 | static void |
2378 | finish_task (struct TaskEntry *task) | 2388 | finish_task(struct TaskEntry *task) |
2379 | { | 2389 | { |
2380 | GNUNET_assert (GNUNET_NO == task->is_finished); | 2390 | GNUNET_assert(GNUNET_NO == task->is_finished); |
2381 | task->is_finished = GNUNET_YES; | 2391 | task->is_finished = GNUNET_YES; |
2382 | 2392 | ||
2383 | task->step->finished_tasks++; | 2393 | task->step->finished_tasks++; |
2384 | 2394 | ||
2385 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2395 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2386 | "P%u: Finishing Task {%s} (now %u/%u tasks finished in step)\n", | 2396 | "P%u: Finishing Task {%s} (now %u/%u tasks finished in step)\n", |
2387 | task->step->session->local_peer_idx, | 2397 | task->step->session->local_peer_idx, |
2388 | debug_str_task_key (&task->key), | 2398 | debug_str_task_key(&task->key), |
2389 | (unsigned int) task->step->finished_tasks, | 2399 | (unsigned int)task->step->finished_tasks, |
2390 | (unsigned int) task->step->tasks_len); | 2400 | (unsigned int)task->step->tasks_len); |
2391 | 2401 | ||
2392 | if (task->step->finished_tasks == task->step->tasks_len) | 2402 | if (task->step->finished_tasks == task->step->tasks_len) |
2393 | finish_step (task->step); | 2403 | finish_step(task->step); |
2394 | } | 2404 | } |
2395 | 2405 | ||
2396 | 2406 | ||
@@ -2402,11 +2412,12 @@ finish_task (struct TaskEntry *task) | |||
2402 | * @return index of peer, -1 if peer is not in session | 2412 | * @return index of peer, -1 if peer is not in session |
2403 | */ | 2413 | */ |
2404 | static int | 2414 | static int |
2405 | get_peer_idx (const struct GNUNET_PeerIdentity *peer, const struct ConsensusSession *session) | 2415 | get_peer_idx(const struct GNUNET_PeerIdentity *peer, const struct ConsensusSession *session) |
2406 | { | 2416 | { |
2407 | int i; | 2417 | int i; |
2418 | |||
2408 | for (i = 0; i < session->num_peers; i++) | 2419 | for (i = 0; i < session->num_peers; i++) |
2409 | if (0 == GNUNET_memcmp (peer, &session->peers[i])) | 2420 | if (0 == GNUNET_memcmp(peer, &session->peers[i])) |
2410 | return i; | 2421 | return i; |
2411 | return -1; | 2422 | return -1; |
2412 | } | 2423 | } |
@@ -2422,21 +2433,21 @@ get_peer_idx (const struct GNUNET_PeerIdentity *peer, const struct ConsensusSess | |||
2422 | * @param local_session_id local id of the consensus session | 2433 | * @param local_session_id local id of the consensus session |
2423 | */ | 2434 | */ |
2424 | static void | 2435 | static void |
2425 | compute_global_id (struct ConsensusSession *session, | 2436 | compute_global_id(struct ConsensusSession *session, |
2426 | const struct GNUNET_HashCode *local_session_id) | 2437 | const struct GNUNET_HashCode *local_session_id) |
2427 | { | 2438 | { |
2428 | const char *salt = "gnunet-service-consensus/session_id"; | 2439 | const char *salt = "gnunet-service-consensus/session_id"; |
2429 | 2440 | ||
2430 | GNUNET_assert (GNUNET_YES == | 2441 | GNUNET_assert(GNUNET_YES == |
2431 | GNUNET_CRYPTO_kdf (&session->global_id, | 2442 | GNUNET_CRYPTO_kdf(&session->global_id, |
2432 | sizeof (struct GNUNET_HashCode), | 2443 | sizeof(struct GNUNET_HashCode), |
2433 | salt, | 2444 | salt, |
2434 | strlen (salt), | 2445 | strlen(salt), |
2435 | session->peers, | 2446 | session->peers, |
2436 | session->num_peers * sizeof (struct GNUNET_PeerIdentity), | 2447 | session->num_peers * sizeof(struct GNUNET_PeerIdentity), |
2437 | local_session_id, | 2448 | local_session_id, |
2438 | sizeof (struct GNUNET_HashCode), | 2449 | sizeof(struct GNUNET_HashCode), |
2439 | NULL)); | 2450 | NULL)); |
2440 | } | 2451 | } |
2441 | 2452 | ||
2442 | 2453 | ||
@@ -2448,9 +2459,9 @@ compute_global_id (struct ConsensusSession *session, | |||
2448 | * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. | 2459 | * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. |
2449 | */ | 2460 | */ |
2450 | static int | 2461 | static int |
2451 | peer_id_cmp (const void *h1, const void *h2) | 2462 | peer_id_cmp(const void *h1, const void *h2) |
2452 | { | 2463 | { |
2453 | return memcmp (h1, h2, sizeof (struct GNUNET_PeerIdentity)); | 2464 | return memcmp(h1, h2, sizeof(struct GNUNET_PeerIdentity)); |
2454 | } | 2465 | } |
2455 | 2466 | ||
2456 | 2467 | ||
@@ -2462,56 +2473,56 @@ peer_id_cmp (const void *h1, const void *h2) | |||
2462 | * @param join_msg join message with the list of peers participating at the end | 2473 | * @param join_msg join message with the list of peers participating at the end |
2463 | */ | 2474 | */ |
2464 | static void | 2475 | static void |
2465 | initialize_session_peer_list (struct ConsensusSession *session, | 2476 | initialize_session_peer_list(struct ConsensusSession *session, |
2466 | const struct GNUNET_CONSENSUS_JoinMessage *join_msg) | 2477 | const struct GNUNET_CONSENSUS_JoinMessage *join_msg) |
2467 | { | 2478 | { |
2468 | const struct GNUNET_PeerIdentity *msg_peers | 2479 | const struct GNUNET_PeerIdentity *msg_peers |
2469 | = (const struct GNUNET_PeerIdentity *) &join_msg[1]; | 2480 | = (const struct GNUNET_PeerIdentity *)&join_msg[1]; |
2470 | int local_peer_in_list; | 2481 | int local_peer_in_list; |
2471 | 2482 | ||
2472 | session->num_peers = ntohl (join_msg->num_peers); | 2483 | session->num_peers = ntohl(join_msg->num_peers); |
2473 | 2484 | ||
2474 | /* Peers in the join message, may or may not include the local peer, | 2485 | /* Peers in the join message, may or may not include the local peer, |
2475 | Add it if it is missing. */ | 2486 | Add it if it is missing. */ |
2476 | local_peer_in_list = GNUNET_NO; | 2487 | local_peer_in_list = GNUNET_NO; |
2477 | for (unsigned int i = 0; i < session->num_peers; i++) | 2488 | for (unsigned int i = 0; i < session->num_peers; i++) |
2478 | { | ||
2479 | if (0 == GNUNET_memcmp (&msg_peers[i], | ||
2480 | &my_peer)) | ||
2481 | { | 2489 | { |
2482 | local_peer_in_list = GNUNET_YES; | 2490 | if (0 == GNUNET_memcmp(&msg_peers[i], |
2483 | break; | 2491 | &my_peer)) |
2492 | { | ||
2493 | local_peer_in_list = GNUNET_YES; | ||
2494 | break; | ||
2495 | } | ||
2484 | } | 2496 | } |
2485 | } | ||
2486 | if (GNUNET_NO == local_peer_in_list) | 2497 | if (GNUNET_NO == local_peer_in_list) |
2487 | session->num_peers++; | 2498 | session->num_peers++; |
2488 | 2499 | ||
2489 | session->peers = GNUNET_new_array (session->num_peers, | 2500 | session->peers = GNUNET_new_array(session->num_peers, |
2490 | struct GNUNET_PeerIdentity); | 2501 | struct GNUNET_PeerIdentity); |
2491 | if (GNUNET_NO == local_peer_in_list) | 2502 | if (GNUNET_NO == local_peer_in_list) |
2492 | session->peers[session->num_peers - 1] = my_peer; | 2503 | session->peers[session->num_peers - 1] = my_peer; |
2493 | 2504 | ||
2494 | GNUNET_memcpy (session->peers, | 2505 | GNUNET_memcpy(session->peers, |
2495 | msg_peers, | 2506 | msg_peers, |
2496 | ntohl (join_msg->num_peers) * sizeof (struct GNUNET_PeerIdentity)); | 2507 | ntohl(join_msg->num_peers) * sizeof(struct GNUNET_PeerIdentity)); |
2497 | qsort (session->peers, | 2508 | qsort(session->peers, |
2498 | session->num_peers, | 2509 | session->num_peers, |
2499 | sizeof (struct GNUNET_PeerIdentity), | 2510 | sizeof(struct GNUNET_PeerIdentity), |
2500 | &peer_id_cmp); | 2511 | &peer_id_cmp); |
2501 | } | 2512 | } |
2502 | 2513 | ||
2503 | 2514 | ||
2504 | static struct TaskEntry * | 2515 | static struct TaskEntry * |
2505 | lookup_task (struct ConsensusSession *session, | 2516 | lookup_task(struct ConsensusSession *session, |
2506 | struct TaskKey *key) | 2517 | struct TaskKey *key) |
2507 | { | 2518 | { |
2508 | struct GNUNET_HashCode hash; | 2519 | struct GNUNET_HashCode hash; |
2509 | 2520 | ||
2510 | 2521 | ||
2511 | GNUNET_CRYPTO_hash (key, sizeof (struct TaskKey), &hash); | 2522 | GNUNET_CRYPTO_hash(key, sizeof(struct TaskKey), &hash); |
2512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up task hash %s\n", | 2523 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Looking up task hash %s\n", |
2513 | GNUNET_h2s (&hash)); | 2524 | GNUNET_h2s(&hash)); |
2514 | return GNUNET_CONTAINER_multihashmap_get (session->taskmap, &hash); | 2525 | return GNUNET_CONTAINER_multihashmap_get(session->taskmap, &hash); |
2515 | } | 2526 | } |
2516 | 2527 | ||
2517 | 2528 | ||
@@ -2531,10 +2542,10 @@ lookup_task (struct ConsensusSession *session, | |||
2531 | * Also necessary to specify the timeout. | 2542 | * Also necessary to specify the timeout. |
2532 | */ | 2543 | */ |
2533 | static void | 2544 | static void |
2534 | set_listen_cb (void *cls, | 2545 | set_listen_cb(void *cls, |
2535 | const struct GNUNET_PeerIdentity *other_peer, | 2546 | const struct GNUNET_PeerIdentity *other_peer, |
2536 | const struct GNUNET_MessageHeader *context_msg, | 2547 | const struct GNUNET_MessageHeader *context_msg, |
2537 | struct GNUNET_SET_Request *request) | 2548 | struct GNUNET_SET_Request *request) |
2538 | { | 2549 | { |
2539 | struct ConsensusSession *session = cls; | 2550 | struct ConsensusSession *session = cls; |
2540 | struct TaskKey tk; | 2551 | struct TaskKey tk; |
@@ -2542,122 +2553,122 @@ set_listen_cb (void *cls, | |||
2542 | struct GNUNET_CONSENSUS_RoundContextMessage *cm; | 2553 | struct GNUNET_CONSENSUS_RoundContextMessage *cm; |
2543 | 2554 | ||
2544 | if (NULL == context_msg) | 2555 | if (NULL == context_msg) |
2545 | { | 2556 | { |
2546 | GNUNET_break_op (0); | 2557 | GNUNET_break_op(0); |
2547 | return; | 2558 | return; |
2548 | } | 2559 | } |
2549 | 2560 | ||
2550 | if (GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT != ntohs (context_msg->type)) | 2561 | if (GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT != ntohs(context_msg->type)) |
2551 | { | 2562 | { |
2552 | GNUNET_break_op (0); | 2563 | GNUNET_break_op(0); |
2553 | return; | 2564 | return; |
2554 | } | 2565 | } |
2555 | 2566 | ||
2556 | if (sizeof (struct GNUNET_CONSENSUS_RoundContextMessage) != ntohs (context_msg->size)) | 2567 | if (sizeof(struct GNUNET_CONSENSUS_RoundContextMessage) != ntohs(context_msg->size)) |
2557 | { | 2568 | { |
2558 | GNUNET_break_op (0); | 2569 | GNUNET_break_op(0); |
2559 | return; | 2570 | return; |
2560 | } | 2571 | } |
2561 | 2572 | ||
2562 | cm = (struct GNUNET_CONSENSUS_RoundContextMessage *) context_msg; | 2573 | cm = (struct GNUNET_CONSENSUS_RoundContextMessage *)context_msg; |
2563 | 2574 | ||
2564 | tk = ((struct TaskKey) { | 2575 | tk = ((struct TaskKey) { |
2565 | .kind = ntohs (cm->kind), | 2576 | .kind = ntohs(cm->kind), |
2566 | .peer1 = ntohs (cm->peer1), | 2577 | .peer1 = ntohs(cm->peer1), |
2567 | .peer2 = ntohs (cm->peer2), | 2578 | .peer2 = ntohs(cm->peer2), |
2568 | .repetition = ntohs (cm->repetition), | 2579 | .repetition = ntohs(cm->repetition), |
2569 | .leader = ntohs (cm->leader), | 2580 | .leader = ntohs(cm->leader), |
2570 | }); | 2581 | }); |
2571 | 2582 | ||
2572 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: got req for task %s\n", | 2583 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "P%u: got req for task %s\n", |
2573 | session->local_peer_idx, debug_str_task_key (&tk)); | 2584 | session->local_peer_idx, debug_str_task_key(&tk)); |
2574 | 2585 | ||
2575 | task = lookup_task (session, &tk); | 2586 | task = lookup_task(session, &tk); |
2576 | 2587 | ||
2577 | if (NULL == task) | 2588 | if (NULL == task) |
2578 | { | 2589 | { |
2579 | GNUNET_break_op (0); | 2590 | GNUNET_break_op(0); |
2580 | return; | 2591 | return; |
2581 | } | 2592 | } |
2582 | 2593 | ||
2583 | if (GNUNET_YES == task->is_finished) | 2594 | if (GNUNET_YES == task->is_finished) |
2584 | { | 2595 | { |
2585 | GNUNET_break_op (0); | 2596 | GNUNET_break_op(0); |
2586 | return; | 2597 | return; |
2587 | } | 2598 | } |
2588 | 2599 | ||
2589 | if (task->key.peer2 != session->local_peer_idx) | 2600 | if (task->key.peer2 != session->local_peer_idx) |
2590 | { | 2601 | { |
2591 | /* We're being asked, so we must be thne 2nd peer. */ | 2602 | /* We're being asked, so we must be thne 2nd peer. */ |
2592 | GNUNET_break_op (0); | 2603 | GNUNET_break_op(0); |
2593 | return; | 2604 | return; |
2594 | } | 2605 | } |
2595 | 2606 | ||
2596 | GNUNET_assert (! ((task->key.peer1 == session->local_peer_idx) && | 2607 | GNUNET_assert(!((task->key.peer1 == session->local_peer_idx) && |
2597 | (task->key.peer2 == session->local_peer_idx))); | 2608 | (task->key.peer2 == session->local_peer_idx))); |
2598 | 2609 | ||
2599 | struct GNUNET_SET_Option opts[] = { | 2610 | struct GNUNET_SET_Option opts[] = { |
2600 | { GNUNET_SET_OPTION_BYZANTINE, { .num = session->lower_bound } }, | 2611 | { GNUNET_SET_OPTION_BYZANTINE, { .num = session->lower_bound } }, |
2601 | { GNUNET_SET_OPTION_END }, | 2612 | { GNUNET_SET_OPTION_END }, |
2602 | }; | 2613 | }; |
2603 | 2614 | ||
2604 | task->cls.setop.op = GNUNET_SET_accept (request, | 2615 | task->cls.setop.op = GNUNET_SET_accept(request, |
2605 | GNUNET_SET_RESULT_SYMMETRIC, | 2616 | GNUNET_SET_RESULT_SYMMETRIC, |
2606 | opts, | 2617 | opts, |
2607 | set_result_cb, | 2618 | set_result_cb, |
2608 | task); | 2619 | task); |
2609 | 2620 | ||
2610 | /* If the task hasn't been started yet, | 2621 | /* If the task hasn't been started yet, |
2611 | we wait for that until we commit. */ | 2622 | we wait for that until we commit. */ |
2612 | 2623 | ||
2613 | if (GNUNET_YES == task->is_started) | 2624 | if (GNUNET_YES == task->is_started) |
2614 | { | 2625 | { |
2615 | commit_set (session, task); | 2626 | commit_set(session, task); |
2616 | } | 2627 | } |
2617 | } | 2628 | } |
2618 | 2629 | ||
2619 | 2630 | ||
2620 | 2631 | ||
2621 | static void | 2632 | static void |
2622 | put_task (struct GNUNET_CONTAINER_MultiHashMap *taskmap, | 2633 | put_task(struct GNUNET_CONTAINER_MultiHashMap *taskmap, |
2623 | struct TaskEntry *t) | 2634 | struct TaskEntry *t) |
2624 | { | 2635 | { |
2625 | struct GNUNET_HashCode round_hash; | 2636 | struct GNUNET_HashCode round_hash; |
2626 | struct Step *s; | 2637 | struct Step *s; |
2627 | 2638 | ||
2628 | GNUNET_assert (NULL != t->step); | 2639 | GNUNET_assert(NULL != t->step); |
2629 | 2640 | ||
2630 | t = GNUNET_memdup (t, sizeof (struct TaskEntry)); | 2641 | t = GNUNET_memdup(t, sizeof(struct TaskEntry)); |
2631 | 2642 | ||
2632 | s = t->step; | 2643 | s = t->step; |
2633 | 2644 | ||
2634 | if (s->tasks_len == s->tasks_cap) | 2645 | if (s->tasks_len == s->tasks_cap) |
2635 | { | 2646 | { |
2636 | unsigned int target_size = 3 * (s->tasks_cap + 1) / 2; | 2647 | unsigned int target_size = 3 * (s->tasks_cap + 1) / 2; |
2637 | GNUNET_array_grow (s->tasks, | 2648 | GNUNET_array_grow(s->tasks, |
2638 | s->tasks_cap, | 2649 | s->tasks_cap, |
2639 | target_size); | 2650 | target_size); |
2640 | } | 2651 | } |
2641 | 2652 | ||
2642 | #ifdef GNUNET_EXTRA_LOGGING | 2653 | #ifdef GNUNET_EXTRA_LOGGING |
2643 | GNUNET_assert (NULL != s->debug_name); | 2654 | GNUNET_assert(NULL != s->debug_name); |
2644 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting task <%s> into step `%s'\n", | 2655 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Putting task <%s> into step `%s'\n", |
2645 | debug_str_task_key (&t->key), | 2656 | debug_str_task_key(&t->key), |
2646 | s->debug_name); | 2657 | s->debug_name); |
2647 | #endif | 2658 | #endif |
2648 | 2659 | ||
2649 | s->tasks[s->tasks_len] = t; | 2660 | s->tasks[s->tasks_len] = t; |
2650 | s->tasks_len++; | 2661 | s->tasks_len++; |
2651 | 2662 | ||
2652 | GNUNET_CRYPTO_hash (&t->key, sizeof (struct TaskKey), &round_hash); | 2663 | GNUNET_CRYPTO_hash(&t->key, sizeof(struct TaskKey), &round_hash); |
2653 | GNUNET_assert (GNUNET_OK == | 2664 | GNUNET_assert(GNUNET_OK == |
2654 | GNUNET_CONTAINER_multihashmap_put (taskmap, &round_hash, t, | 2665 | GNUNET_CONTAINER_multihashmap_put(taskmap, &round_hash, t, |
2655 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 2666 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
2656 | } | 2667 | } |
2657 | 2668 | ||
2658 | 2669 | ||
2659 | static void | 2670 | static void |
2660 | install_step_timeouts (struct ConsensusSession *session) | 2671 | install_step_timeouts(struct ConsensusSession *session) |
2661 | { | 2672 | { |
2662 | /* Given the fully constructed task graph | 2673 | /* Given the fully constructed task graph |
2663 | with rounds for tasks, we can give the tasks timeouts. */ | 2674 | with rounds for tasks, we can give the tasks timeouts. */ |
@@ -2673,37 +2684,37 @@ install_step_timeouts (struct ConsensusSession *session) | |||
2673 | * Arrange two peers in some canonical order. | 2684 | * Arrange two peers in some canonical order. |
2674 | */ | 2685 | */ |
2675 | static void | 2686 | static void |
2676 | arrange_peers (uint16_t *p1, uint16_t *p2, uint16_t n) | 2687 | arrange_peers(uint16_t *p1, uint16_t *p2, uint16_t n) |
2677 | { | 2688 | { |
2678 | uint16_t a; | 2689 | uint16_t a; |
2679 | uint16_t b; | 2690 | uint16_t b; |
2680 | 2691 | ||
2681 | GNUNET_assert (*p1 < n); | 2692 | GNUNET_assert(*p1 < n); |
2682 | GNUNET_assert (*p2 < n); | 2693 | GNUNET_assert(*p2 < n); |
2683 | 2694 | ||
2684 | if (*p1 < *p2) | 2695 | if (*p1 < *p2) |
2685 | { | 2696 | { |
2686 | a = *p1; | 2697 | a = *p1; |
2687 | b = *p2; | 2698 | b = *p2; |
2688 | } | 2699 | } |
2689 | else | 2700 | else |
2690 | { | 2701 | { |
2691 | a = *p2; | 2702 | a = *p2; |
2692 | b = *p1; | 2703 | b = *p1; |
2693 | } | 2704 | } |
2694 | 2705 | ||
2695 | /* For uniformly random *p1, *p2, | 2706 | /* For uniformly random *p1, *p2, |
2696 | this condition is true with 50% chance */ | 2707 | this condition is true with 50% chance */ |
2697 | if (((b - a) + n) % n <= n / 2) | 2708 | if (((b - a) + n) % n <= n / 2) |
2698 | { | 2709 | { |
2699 | *p1 = a; | 2710 | *p1 = a; |
2700 | *p2 = b; | 2711 | *p2 = b; |
2701 | } | 2712 | } |
2702 | else | 2713 | else |
2703 | { | 2714 | { |
2704 | *p1 = b; | 2715 | *p1 = b; |
2705 | *p2 = a; | 2716 | *p2 = a; |
2706 | } | 2717 | } |
2707 | } | 2718 | } |
2708 | 2719 | ||
2709 | 2720 | ||
@@ -2711,36 +2722,36 @@ arrange_peers (uint16_t *p1, uint16_t *p2, uint16_t n) | |||
2711 | * Record @a dep as a dependency of @a step. | 2722 | * Record @a dep as a dependency of @a step. |
2712 | */ | 2723 | */ |
2713 | static void | 2724 | static void |
2714 | step_depend_on (struct Step *step, struct Step *dep) | 2725 | step_depend_on(struct Step *step, struct Step *dep) |
2715 | { | 2726 | { |
2716 | /* We're not checking for cyclic dependencies, | 2727 | /* We're not checking for cyclic dependencies, |
2717 | but this is a cheap sanity check. */ | 2728 | but this is a cheap sanity check. */ |
2718 | GNUNET_assert (step != dep); | 2729 | GNUNET_assert(step != dep); |
2719 | GNUNET_assert (NULL != step); | 2730 | GNUNET_assert(NULL != step); |
2720 | GNUNET_assert (NULL != dep); | 2731 | GNUNET_assert(NULL != dep); |
2721 | GNUNET_assert (dep->round <= step->round); | 2732 | GNUNET_assert(dep->round <= step->round); |
2722 | 2733 | ||
2723 | #ifdef GNUNET_EXTRA_LOGGING | 2734 | #ifdef GNUNET_EXTRA_LOGGING |
2724 | /* Make sure we have complete debugging information. | 2735 | /* Make sure we have complete debugging information. |
2725 | Also checks that we don't screw up too badly | 2736 | Also checks that we don't screw up too badly |
2726 | constructing the task graph. */ | 2737 | constructing the task graph. */ |
2727 | GNUNET_assert (NULL != step->debug_name); | 2738 | GNUNET_assert(NULL != step->debug_name); |
2728 | GNUNET_assert (NULL != dep->debug_name); | 2739 | GNUNET_assert(NULL != dep->debug_name); |
2729 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2740 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2730 | "Making step `%s' depend on `%s'\n", | 2741 | "Making step `%s' depend on `%s'\n", |
2731 | step->debug_name, | 2742 | step->debug_name, |
2732 | dep->debug_name); | 2743 | dep->debug_name); |
2733 | #endif | 2744 | #endif |
2734 | 2745 | ||
2735 | if (dep->subordinates_cap == dep->subordinates_len) | 2746 | if (dep->subordinates_cap == dep->subordinates_len) |
2736 | { | 2747 | { |
2737 | unsigned int target_size = 3 * (dep->subordinates_cap + 1) / 2; | 2748 | unsigned int target_size = 3 * (dep->subordinates_cap + 1) / 2; |
2738 | GNUNET_array_grow (dep->subordinates, | 2749 | GNUNET_array_grow(dep->subordinates, |
2739 | dep->subordinates_cap, | 2750 | dep->subordinates_cap, |
2740 | target_size); | 2751 | target_size); |
2741 | } | 2752 | } |
2742 | 2753 | ||
2743 | GNUNET_assert (dep->subordinates_len <= dep->subordinates_cap); | 2754 | GNUNET_assert(dep->subordinates_len <= dep->subordinates_cap); |
2744 | 2755 | ||
2745 | dep->subordinates[dep->subordinates_len] = step; | 2756 | dep->subordinates[dep->subordinates_len] = step; |
2746 | dep->subordinates_len++; | 2757 | dep->subordinates_len++; |
@@ -2750,16 +2761,17 @@ step_depend_on (struct Step *step, struct Step *dep) | |||
2750 | 2761 | ||
2751 | 2762 | ||
2752 | static struct Step * | 2763 | static struct Step * |
2753 | create_step (struct ConsensusSession *session, int round, int early_finishable) | 2764 | create_step(struct ConsensusSession *session, int round, int early_finishable) |
2754 | { | 2765 | { |
2755 | struct Step *step; | 2766 | struct Step *step; |
2756 | step = GNUNET_new (struct Step); | 2767 | |
2768 | step = GNUNET_new(struct Step); | ||
2757 | step->session = session; | 2769 | step->session = session; |
2758 | step->round = round; | 2770 | step->round = round; |
2759 | step->early_finishable = early_finishable; | 2771 | step->early_finishable = early_finishable; |
2760 | GNUNET_CONTAINER_DLL_insert_tail (session->steps_head, | 2772 | GNUNET_CONTAINER_DLL_insert_tail(session->steps_head, |
2761 | session->steps_tail, | 2773 | session->steps_tail, |
2762 | step); | 2774 | step); |
2763 | return step; | 2775 | return step; |
2764 | } | 2776 | } |
2765 | 2777 | ||
@@ -2769,11 +2781,11 @@ create_step (struct ConsensusSession *session, int round, int early_finishable) | |||
2769 | * gradecast. | 2781 | * gradecast. |
2770 | */ | 2782 | */ |
2771 | static void | 2783 | static void |
2772 | construct_task_graph_gradecast (struct ConsensusSession *session, | 2784 | construct_task_graph_gradecast(struct ConsensusSession *session, |
2773 | uint16_t rep, | 2785 | uint16_t rep, |
2774 | uint16_t lead, | 2786 | uint16_t lead, |
2775 | struct Step *step_before, | 2787 | struct Step *step_before, |
2776 | struct Step *step_after) | 2788 | struct Step *step_after) |
2777 | { | 2789 | { |
2778 | uint16_t n = session->num_peers; | 2790 | uint16_t n = session->num_peers; |
2779 | uint16_t me = session->local_peer_idx; | 2791 | uint16_t me = session->local_peer_idx; |
@@ -2795,155 +2807,155 @@ construct_task_graph_gradecast (struct ConsensusSession *session, | |||
2795 | 2807 | ||
2796 | /* gcast step 1: leader disseminates */ | 2808 | /* gcast step 1: leader disseminates */ |
2797 | 2809 | ||
2798 | step = create_step (session, round, GNUNET_YES); | 2810 | step = create_step(session, round, GNUNET_YES); |
2799 | 2811 | ||
2800 | #ifdef GNUNET_EXTRA_LOGGING | 2812 | #ifdef GNUNET_EXTRA_LOGGING |
2801 | GNUNET_asprintf (&step->debug_name, "disseminate leader %u rep %u", lead, rep); | 2813 | GNUNET_asprintf(&step->debug_name, "disseminate leader %u rep %u", lead, rep); |
2802 | #endif | 2814 | #endif |
2803 | step_depend_on (step, step_before); | 2815 | step_depend_on(step, step_before); |
2804 | 2816 | ||
2805 | if (lead == me) | 2817 | if (lead == me) |
2806 | { | ||
2807 | for (k = 0; k < n; k++) | ||
2808 | { | 2818 | { |
2809 | if (k == me) | 2819 | for (k = 0; k < n; k++) |
2810 | continue; | 2820 | { |
2811 | p1 = me; | 2821 | if (k == me) |
2812 | p2 = k; | 2822 | continue; |
2813 | arrange_peers (&p1, &p2, n); | 2823 | p1 = me; |
2814 | task = ((struct TaskEntry) { | 2824 | p2 = k; |
2825 | arrange_peers(&p1, &p2, n); | ||
2826 | task = ((struct TaskEntry) { | ||
2815 | .step = step, | 2827 | .step = step, |
2816 | .start = task_start_reconcile, | 2828 | .start = task_start_reconcile, |
2817 | .cancel = task_cancel_reconcile, | 2829 | .cancel = task_cancel_reconcile, |
2818 | .key = (struct TaskKey) { PHASE_KIND_GRADECAST_LEADER, p1, p2, rep, me }, | 2830 | .key = (struct TaskKey) { PHASE_KIND_GRADECAST_LEADER, p1, p2, rep, me }, |
2819 | }); | 2831 | }); |
2820 | task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, rep }; | 2832 | task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, rep }; |
2821 | put_task (session->taskmap, &task); | 2833 | put_task(session->taskmap, &task); |
2822 | } | 2834 | } |
2823 | /* We run this task to make sure that the leader | 2835 | /* We run this task to make sure that the leader |
2824 | has the stored the SET_KIND_LEADER set of himself, | 2836 | has the stored the SET_KIND_LEADER set of himself, |
2825 | so it can participate in the rest of the gradecast | 2837 | so it can participate in the rest of the gradecast |
2826 | without the code having to handle any special cases. */ | 2838 | without the code having to handle any special cases. */ |
2827 | task = ((struct TaskEntry) { | 2839 | task = ((struct TaskEntry) { |
2828 | .step = step, | 2840 | .step = step, |
2829 | .key = (struct TaskKey) { PHASE_KIND_GRADECAST_LEADER, me, me, rep, me }, | 2841 | .key = (struct TaskKey) { PHASE_KIND_GRADECAST_LEADER, me, me, rep, me }, |
2830 | .start = task_start_reconcile, | 2842 | .start = task_start_reconcile, |
2831 | .cancel = task_cancel_reconcile, | 2843 | .cancel = task_cancel_reconcile, |
2832 | }); | 2844 | }); |
2833 | task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, rep }; | 2845 | task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, rep }; |
2834 | task.cls.setop.output_set = (struct SetKey) { SET_KIND_LEADER_PROPOSAL, rep, me }; | 2846 | task.cls.setop.output_set = (struct SetKey) { SET_KIND_LEADER_PROPOSAL, rep, me }; |
2835 | task.cls.setop.output_diff = (struct DiffKey) { DIFF_KIND_LEADER_PROPOSAL, rep, me }; | 2847 | task.cls.setop.output_diff = (struct DiffKey) { DIFF_KIND_LEADER_PROPOSAL, rep, me }; |
2836 | put_task (session->taskmap, &task); | 2848 | put_task(session->taskmap, &task); |
2837 | } | 2849 | } |
2838 | else | 2850 | else |
2839 | { | 2851 | { |
2840 | p1 = me; | 2852 | p1 = me; |
2841 | p2 = lead; | 2853 | p2 = lead; |
2842 | arrange_peers (&p1, &p2, n); | 2854 | arrange_peers(&p1, &p2, n); |
2843 | task = ((struct TaskEntry) { | 2855 | task = ((struct TaskEntry) { |
2844 | .step = step, | 2856 | .step = step, |
2845 | .key = (struct TaskKey) { PHASE_KIND_GRADECAST_LEADER, p1, p2, rep, lead }, | 2857 | .key = (struct TaskKey) { PHASE_KIND_GRADECAST_LEADER, p1, p2, rep, lead }, |
2846 | .start = task_start_reconcile, | 2858 | .start = task_start_reconcile, |
2847 | .cancel = task_cancel_reconcile, | 2859 | .cancel = task_cancel_reconcile, |
2848 | }); | 2860 | }); |
2849 | task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, rep }; | 2861 | task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, rep }; |
2850 | task.cls.setop.output_set = (struct SetKey) { SET_KIND_LEADER_PROPOSAL, rep, lead }; | 2862 | task.cls.setop.output_set = (struct SetKey) { SET_KIND_LEADER_PROPOSAL, rep, lead }; |
2851 | task.cls.setop.output_diff = (struct DiffKey) { DIFF_KIND_LEADER_PROPOSAL, rep, lead }; | 2863 | task.cls.setop.output_diff = (struct DiffKey) { DIFF_KIND_LEADER_PROPOSAL, rep, lead }; |
2852 | put_task (session->taskmap, &task); | 2864 | put_task(session->taskmap, &task); |
2853 | } | 2865 | } |
2854 | 2866 | ||
2855 | /* gcast phase 2: echo */ | 2867 | /* gcast phase 2: echo */ |
2856 | prev_step = step; | 2868 | prev_step = step; |
2857 | round += 1; | 2869 | round += 1; |
2858 | step = create_step (session, round, GNUNET_YES); | 2870 | step = create_step(session, round, GNUNET_YES); |
2859 | #ifdef GNUNET_EXTRA_LOGGING | 2871 | #ifdef GNUNET_EXTRA_LOGGING |
2860 | GNUNET_asprintf (&step->debug_name, "echo leader %u rep %u", lead, rep); | 2872 | GNUNET_asprintf(&step->debug_name, "echo leader %u rep %u", lead, rep); |
2861 | #endif | 2873 | #endif |
2862 | step_depend_on (step, prev_step); | 2874 | step_depend_on(step, prev_step); |
2863 | 2875 | ||
2864 | for (k = 0; k < n; k++) | 2876 | for (k = 0; k < n; k++) |
2865 | { | 2877 | { |
2866 | p1 = k; | 2878 | p1 = k; |
2867 | p2 = me; | 2879 | p2 = me; |
2868 | arrange_peers (&p1, &p2, n); | 2880 | arrange_peers(&p1, &p2, n); |
2869 | task = ((struct TaskEntry) { | 2881 | task = ((struct TaskEntry) { |
2870 | .step = step, | 2882 | .step = step, |
2871 | .key = (struct TaskKey) { PHASE_KIND_GRADECAST_ECHO, p1, p2, rep, lead }, | 2883 | .key = (struct TaskKey) { PHASE_KIND_GRADECAST_ECHO, p1, p2, rep, lead }, |
2872 | .start = task_start_reconcile, | 2884 | .start = task_start_reconcile, |
2873 | .cancel = task_cancel_reconcile, | 2885 | .cancel = task_cancel_reconcile, |
2874 | }); | 2886 | }); |
2875 | task.cls.setop.input_set = (struct SetKey) { SET_KIND_LEADER_PROPOSAL, rep, lead }; | 2887 | task.cls.setop.input_set = (struct SetKey) { SET_KIND_LEADER_PROPOSAL, rep, lead }; |
2876 | task.cls.setop.output_rfn = (struct RfnKey) { RFN_KIND_ECHO, rep, lead }; | 2888 | task.cls.setop.output_rfn = (struct RfnKey) { RFN_KIND_ECHO, rep, lead }; |
2877 | put_task (session->taskmap, &task); | 2889 | put_task(session->taskmap, &task); |
2878 | } | 2890 | } |
2879 | 2891 | ||
2880 | prev_step = step; | 2892 | prev_step = step; |
2881 | /* Same round, since step only has local tasks */ | 2893 | /* Same round, since step only has local tasks */ |
2882 | step = create_step (session, round, GNUNET_YES); | 2894 | step = create_step(session, round, GNUNET_YES); |
2883 | #ifdef GNUNET_EXTRA_LOGGING | 2895 | #ifdef GNUNET_EXTRA_LOGGING |
2884 | GNUNET_asprintf (&step->debug_name, "echo grade leader %u rep %u", lead, rep); | 2896 | GNUNET_asprintf(&step->debug_name, "echo grade leader %u rep %u", lead, rep); |
2885 | #endif | 2897 | #endif |
2886 | step_depend_on (step, prev_step); | 2898 | step_depend_on(step, prev_step); |
2887 | 2899 | ||
2888 | arrange_peers (&p1, &p2, n); | 2900 | arrange_peers(&p1, &p2, n); |
2889 | task = ((struct TaskEntry) { | 2901 | task = ((struct TaskEntry) { |
2890 | .key = (struct TaskKey) { PHASE_KIND_GRADECAST_ECHO_GRADE, -1, -1, rep, lead }, | 2902 | .key = (struct TaskKey) { PHASE_KIND_GRADECAST_ECHO_GRADE, -1, -1, rep, lead }, |
2891 | .step = step, | 2903 | .step = step, |
2892 | .start = task_start_eval_echo | 2904 | .start = task_start_eval_echo |
2893 | }); | 2905 | }); |
2894 | put_task (session->taskmap, &task); | 2906 | put_task(session->taskmap, &task); |
2895 | 2907 | ||
2896 | prev_step = step; | 2908 | prev_step = step; |
2897 | round += 1; | 2909 | round += 1; |
2898 | step = create_step (session, round, GNUNET_YES); | 2910 | step = create_step(session, round, GNUNET_YES); |
2899 | #ifdef GNUNET_EXTRA_LOGGING | 2911 | #ifdef GNUNET_EXTRA_LOGGING |
2900 | GNUNET_asprintf (&step->debug_name, "confirm leader %u rep %u", lead, rep); | 2912 | GNUNET_asprintf(&step->debug_name, "confirm leader %u rep %u", lead, rep); |
2901 | #endif | 2913 | #endif |
2902 | step_depend_on (step, prev_step); | 2914 | step_depend_on(step, prev_step); |
2903 | 2915 | ||
2904 | /* gcast phase 3: confirmation and grading */ | 2916 | /* gcast phase 3: confirmation and grading */ |
2905 | for (k = 0; k < n; k++) | 2917 | for (k = 0; k < n; k++) |
2906 | { | 2918 | { |
2907 | p1 = k; | 2919 | p1 = k; |
2908 | p2 = me; | 2920 | p2 = me; |
2909 | arrange_peers (&p1, &p2, n); | 2921 | arrange_peers(&p1, &p2, n); |
2910 | task = ((struct TaskEntry) { | 2922 | task = ((struct TaskEntry) { |
2911 | .step = step, | 2923 | .step = step, |
2912 | .start = task_start_reconcile, | 2924 | .start = task_start_reconcile, |
2913 | .cancel = task_cancel_reconcile, | 2925 | .cancel = task_cancel_reconcile, |
2914 | .key = (struct TaskKey) { PHASE_KIND_GRADECAST_CONFIRM, p1, p2, rep, lead}, | 2926 | .key = (struct TaskKey) { PHASE_KIND_GRADECAST_CONFIRM, p1, p2, rep, lead }, |
2915 | }); | 2927 | }); |
2916 | task.cls.setop.input_set = (struct SetKey) { SET_KIND_ECHO_RESULT, rep, lead }; | 2928 | task.cls.setop.input_set = (struct SetKey) { SET_KIND_ECHO_RESULT, rep, lead }; |
2917 | task.cls.setop.output_rfn = (struct RfnKey) { RFN_KIND_CONFIRM, rep, lead }; | 2929 | task.cls.setop.output_rfn = (struct RfnKey) { RFN_KIND_CONFIRM, rep, lead }; |
2918 | /* If there was at least one element in the echo round that was | 2930 | /* If there was at least one element in the echo round that was |
2919 | contested (i.e. it had no n-t majority), then we let the other peers | 2931 | contested (i.e. it had no n-t majority), then we let the other peers |
2920 | know, and other peers let us know. The contested flag for each peer is | 2932 | know, and other peers let us know. The contested flag for each peer is |
2921 | stored in the rfn. */ | 2933 | stored in the rfn. */ |
2922 | task.cls.setop.transceive_contested = GNUNET_YES; | 2934 | task.cls.setop.transceive_contested = GNUNET_YES; |
2923 | put_task (session->taskmap, &task); | 2935 | put_task(session->taskmap, &task); |
2924 | } | 2936 | } |
2925 | 2937 | ||
2926 | prev_step = step; | 2938 | prev_step = step; |
2927 | /* Same round, since step only has local tasks */ | 2939 | /* Same round, since step only has local tasks */ |
2928 | step = create_step (session, round, GNUNET_YES); | 2940 | step = create_step(session, round, GNUNET_YES); |
2929 | #ifdef GNUNET_EXTRA_LOGGING | 2941 | #ifdef GNUNET_EXTRA_LOGGING |
2930 | GNUNET_asprintf (&step->debug_name, "confirm grade leader %u rep %u", lead, rep); | 2942 | GNUNET_asprintf(&step->debug_name, "confirm grade leader %u rep %u", lead, rep); |
2931 | #endif | 2943 | #endif |
2932 | step_depend_on (step, prev_step); | 2944 | step_depend_on(step, prev_step); |
2933 | 2945 | ||
2934 | task = ((struct TaskEntry) { | 2946 | task = ((struct TaskEntry) { |
2935 | .step = step, | 2947 | .step = step, |
2936 | .key = (struct TaskKey) { PHASE_KIND_GRADECAST_CONFIRM_GRADE, -1, -1, rep, lead }, | 2948 | .key = (struct TaskKey) { PHASE_KIND_GRADECAST_CONFIRM_GRADE, -1, -1, rep, lead }, |
2937 | .start = task_start_grade, | 2949 | .start = task_start_grade, |
2938 | }); | 2950 | }); |
2939 | put_task (session->taskmap, &task); | 2951 | put_task(session->taskmap, &task); |
2940 | 2952 | ||
2941 | step_depend_on (step_after, step); | 2953 | step_depend_on(step_after, step); |
2942 | } | 2954 | } |
2943 | 2955 | ||
2944 | 2956 | ||
2945 | static void | 2957 | static void |
2946 | construct_task_graph (struct ConsensusSession *session) | 2958 | construct_task_graph(struct ConsensusSession *session) |
2947 | { | 2959 | { |
2948 | uint16_t n = session->num_peers; | 2960 | uint16_t n = session->num_peers; |
2949 | uint16_t t = n / 3; | 2961 | uint16_t t = n / 3; |
@@ -2973,60 +2985,60 @@ construct_task_graph (struct ConsensusSession *session) | |||
2973 | 2985 | ||
2974 | /* all-to-all step */ | 2986 | /* all-to-all step */ |
2975 | 2987 | ||
2976 | step = create_step (session, round, GNUNET_NO); | 2988 | step = create_step(session, round, GNUNET_NO); |
2977 | 2989 | ||
2978 | #ifdef GNUNET_EXTRA_LOGGING | 2990 | #ifdef GNUNET_EXTRA_LOGGING |
2979 | step->debug_name = GNUNET_strdup ("all to all"); | 2991 | step->debug_name = GNUNET_strdup("all to all"); |
2980 | #endif | 2992 | #endif |
2981 | 2993 | ||
2982 | for (i = 0; i < n; i++) | 2994 | for (i = 0; i < n; i++) |
2983 | { | 2995 | { |
2984 | uint16_t p1; | 2996 | uint16_t p1; |
2985 | uint16_t p2; | 2997 | uint16_t p2; |
2986 | 2998 | ||
2987 | p1 = me; | 2999 | p1 = me; |
2988 | p2 = i; | 3000 | p2 = i; |
2989 | arrange_peers (&p1, &p2, n); | 3001 | arrange_peers(&p1, &p2, n); |
2990 | task = ((struct TaskEntry) { | 3002 | task = ((struct TaskEntry) { |
2991 | .key = (struct TaskKey) { PHASE_KIND_ALL_TO_ALL, p1, p2, -1, -1 }, | 3003 | .key = (struct TaskKey) { PHASE_KIND_ALL_TO_ALL, p1, p2, -1, -1 }, |
2992 | .step = step, | 3004 | .step = step, |
2993 | .start = task_start_reconcile, | 3005 | .start = task_start_reconcile, |
2994 | .cancel = task_cancel_reconcile, | 3006 | .cancel = task_cancel_reconcile, |
2995 | }); | 3007 | }); |
2996 | task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, 0 }; | 3008 | task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, 0 }; |
2997 | task.cls.setop.output_set = task.cls.setop.input_set; | 3009 | task.cls.setop.output_set = task.cls.setop.input_set; |
2998 | task.cls.setop.do_not_remove = GNUNET_YES; | 3010 | task.cls.setop.do_not_remove = GNUNET_YES; |
2999 | put_task (session->taskmap, &task); | 3011 | put_task(session->taskmap, &task); |
3000 | } | 3012 | } |
3001 | 3013 | ||
3002 | round += 1; | 3014 | round += 1; |
3003 | prev_step = step; | 3015 | prev_step = step; |
3004 | step = create_step (session, round, GNUNET_NO);; | 3016 | step = create_step(session, round, GNUNET_NO);; |
3005 | #ifdef GNUNET_EXTRA_LOGGING | 3017 | #ifdef GNUNET_EXTRA_LOGGING |
3006 | step->debug_name = GNUNET_strdup ("all to all 2"); | 3018 | step->debug_name = GNUNET_strdup("all to all 2"); |
3007 | #endif | 3019 | #endif |
3008 | step_depend_on (step, prev_step); | 3020 | step_depend_on(step, prev_step); |
3009 | 3021 | ||
3010 | 3022 | ||
3011 | for (i = 0; i < n; i++) | 3023 | for (i = 0; i < n; i++) |
3012 | { | 3024 | { |
3013 | uint16_t p1; | 3025 | uint16_t p1; |
3014 | uint16_t p2; | 3026 | uint16_t p2; |
3015 | 3027 | ||
3016 | p1 = me; | 3028 | p1 = me; |
3017 | p2 = i; | 3029 | p2 = i; |
3018 | arrange_peers (&p1, &p2, n); | 3030 | arrange_peers(&p1, &p2, n); |
3019 | task = ((struct TaskEntry) { | 3031 | task = ((struct TaskEntry) { |
3020 | .key = (struct TaskKey) { PHASE_KIND_ALL_TO_ALL_2, p1, p2, -1, -1 }, | 3032 | .key = (struct TaskKey) { PHASE_KIND_ALL_TO_ALL_2, p1, p2, -1, -1 }, |
3021 | .step = step, | 3033 | .step = step, |
3022 | .start = task_start_reconcile, | 3034 | .start = task_start_reconcile, |
3023 | .cancel = task_cancel_reconcile, | 3035 | .cancel = task_cancel_reconcile, |
3024 | }); | 3036 | }); |
3025 | task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, 0 }; | 3037 | task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, 0 }; |
3026 | task.cls.setop.output_set = task.cls.setop.input_set; | 3038 | task.cls.setop.output_set = task.cls.setop.input_set; |
3027 | task.cls.setop.do_not_remove = GNUNET_YES; | 3039 | task.cls.setop.do_not_remove = GNUNET_YES; |
3028 | put_task (session->taskmap, &task); | 3040 | put_task(session->taskmap, &task); |
3029 | } | 3041 | } |
3030 | 3042 | ||
3031 | round += 1; | 3043 | round += 1; |
3032 | 3044 | ||
@@ -3039,47 +3051,47 @@ construct_task_graph (struct ConsensusSession *session) | |||
3039 | 3051 | ||
3040 | /* sequential repetitions of the gradecasts */ | 3052 | /* sequential repetitions of the gradecasts */ |
3041 | for (i = 0; i < t + 1; i++) | 3053 | for (i = 0; i < t + 1; i++) |
3042 | { | 3054 | { |
3043 | struct Step *step_rep_start; | 3055 | struct Step *step_rep_start; |
3044 | struct Step *step_rep_end; | 3056 | struct Step *step_rep_end; |
3045 | 3057 | ||
3046 | /* Every repetition is in a separate round. */ | 3058 | /* Every repetition is in a separate round. */ |
3047 | step_rep_start = create_step (session, round, GNUNET_YES); | 3059 | step_rep_start = create_step(session, round, GNUNET_YES); |
3048 | #ifdef GNUNET_EXTRA_LOGGING | 3060 | #ifdef GNUNET_EXTRA_LOGGING |
3049 | GNUNET_asprintf (&step_rep_start->debug_name, "gradecast start rep %u", i); | 3061 | GNUNET_asprintf(&step_rep_start->debug_name, "gradecast start rep %u", i); |
3050 | #endif | 3062 | #endif |
3051 | 3063 | ||
3052 | step_depend_on (step_rep_start, prev_step); | 3064 | step_depend_on(step_rep_start, prev_step); |
3053 | 3065 | ||
3054 | /* gradecast has three rounds */ | 3066 | /* gradecast has three rounds */ |
3055 | round += 3; | 3067 | round += 3; |
3056 | step_rep_end = create_step (session, round, GNUNET_YES); | 3068 | step_rep_end = create_step(session, round, GNUNET_YES); |
3057 | #ifdef GNUNET_EXTRA_LOGGING | 3069 | #ifdef GNUNET_EXTRA_LOGGING |
3058 | GNUNET_asprintf (&step_rep_end->debug_name, "gradecast end rep %u", i); | 3070 | GNUNET_asprintf(&step_rep_end->debug_name, "gradecast end rep %u", i); |
3059 | #endif | 3071 | #endif |
3060 | 3072 | ||
3061 | /* parallel gradecasts */ | 3073 | /* parallel gradecasts */ |
3062 | for (lead = 0; lead < n; lead++) | 3074 | for (lead = 0; lead < n; lead++) |
3063 | construct_task_graph_gradecast (session, i, lead, step_rep_start, step_rep_end); | 3075 | construct_task_graph_gradecast(session, i, lead, step_rep_start, step_rep_end); |
3064 | 3076 | ||
3065 | task = ((struct TaskEntry) { | 3077 | task = ((struct TaskEntry) { |
3066 | .step = step_rep_end, | 3078 | .step = step_rep_end, |
3067 | .key = (struct TaskKey) { PHASE_KIND_APPLY_REP, -1, -1, i, -1}, | 3079 | .key = (struct TaskKey) { PHASE_KIND_APPLY_REP, -1, -1, i, -1 }, |
3068 | .start = task_start_apply_round, | 3080 | .start = task_start_apply_round, |
3069 | }); | 3081 | }); |
3070 | put_task (session->taskmap, &task); | 3082 | put_task(session->taskmap, &task); |
3071 | 3083 | ||
3072 | prev_step = step_rep_end; | 3084 | prev_step = step_rep_end; |
3073 | } | 3085 | } |
3074 | 3086 | ||
3075 | /* There is no next gradecast round, thus the final | 3087 | /* There is no next gradecast round, thus the final |
3076 | start step is the overall end step of the gradecasts */ | 3088 | start step is the overall end step of the gradecasts */ |
3077 | round += 1; | 3089 | round += 1; |
3078 | step = create_step (session, round, GNUNET_NO); | 3090 | step = create_step(session, round, GNUNET_NO); |
3079 | #ifdef GNUNET_EXTRA_LOGGING | 3091 | #ifdef GNUNET_EXTRA_LOGGING |
3080 | GNUNET_asprintf (&step->debug_name, "finish"); | 3092 | GNUNET_asprintf(&step->debug_name, "finish"); |
3081 | #endif | 3093 | #endif |
3082 | step_depend_on (step, prev_step); | 3094 | step_depend_on(step, prev_step); |
3083 | 3095 | ||
3084 | task = ((struct TaskEntry) { | 3096 | task = ((struct TaskEntry) { |
3085 | .step = step, | 3097 | .step = step, |
@@ -3088,7 +3100,7 @@ construct_task_graph (struct ConsensusSession *session) | |||
3088 | }); | 3100 | }); |
3089 | task.cls.finish.input_set = (struct SetKey) { SET_KIND_LAST_GRADECAST }; | 3101 | task.cls.finish.input_set = (struct SetKey) { SET_KIND_LAST_GRADECAST }; |
3090 | 3102 | ||
3091 | put_task (session->taskmap, &task); | 3103 | put_task(session->taskmap, &task); |
3092 | } | 3104 | } |
3093 | 3105 | ||
3094 | 3106 | ||
@@ -3101,17 +3113,17 @@ construct_task_graph (struct ConsensusSession *session) | |||
3101 | * @return #GNUNET_OK if @a m is well-formed | 3113 | * @return #GNUNET_OK if @a m is well-formed |
3102 | */ | 3114 | */ |
3103 | static int | 3115 | static int |
3104 | check_client_join (void *cls, | 3116 | check_client_join(void *cls, |
3105 | const struct GNUNET_CONSENSUS_JoinMessage *m) | 3117 | const struct GNUNET_CONSENSUS_JoinMessage *m) |
3106 | { | 3118 | { |
3107 | uint32_t listed_peers = ntohl (m->num_peers); | 3119 | uint32_t listed_peers = ntohl(m->num_peers); |
3108 | 3120 | ||
3109 | if ( (ntohs (m->header.size) - sizeof (*m)) != | 3121 | if ((ntohs(m->header.size) - sizeof(*m)) != |
3110 | listed_peers * sizeof (struct GNUNET_PeerIdentity)) | 3122 | listed_peers * sizeof(struct GNUNET_PeerIdentity)) |
3111 | { | 3123 | { |
3112 | GNUNET_break (0); | 3124 | GNUNET_break(0); |
3113 | return GNUNET_SYSERR; | 3125 | return GNUNET_SYSERR; |
3114 | } | 3126 | } |
3115 | return GNUNET_OK; | 3127 | return GNUNET_OK; |
3116 | } | 3128 | } |
3117 | 3129 | ||
@@ -3123,16 +3135,16 @@ check_client_join (void *cls, | |||
3123 | * @param m message sent by the client | 3135 | * @param m message sent by the client |
3124 | */ | 3136 | */ |
3125 | static void | 3137 | static void |
3126 | handle_client_join (void *cls, | 3138 | handle_client_join(void *cls, |
3127 | const struct GNUNET_CONSENSUS_JoinMessage *m) | 3139 | const struct GNUNET_CONSENSUS_JoinMessage *m) |
3128 | { | 3140 | { |
3129 | struct ConsensusSession *session = cls; | 3141 | struct ConsensusSession *session = cls; |
3130 | struct ConsensusSession *other_session; | 3142 | struct ConsensusSession *other_session; |
3131 | 3143 | ||
3132 | initialize_session_peer_list (session, | 3144 | initialize_session_peer_list(session, |
3133 | m); | 3145 | m); |
3134 | compute_global_id (session, | 3146 | compute_global_id(session, |
3135 | &m->session_id); | 3147 | &m->session_id); |
3136 | 3148 | ||
3137 | /* Check if some local client already owns the session. | 3149 | /* Check if some local client already owns the session. |
3138 | It is only legal to have a session with an existing global id | 3150 | It is only legal to have a session with an existing global id |
@@ -3140,75 +3152,75 @@ handle_client_join (void *cls, | |||
3140 | for (other_session = sessions_head; | 3152 | for (other_session = sessions_head; |
3141 | NULL != other_session; | 3153 | NULL != other_session; |
3142 | other_session = other_session->next) | 3154 | other_session = other_session->next) |
3143 | { | 3155 | { |
3144 | if ( (other_session != session) && | 3156 | if ((other_session != session) && |
3145 | (0 == GNUNET_CRYPTO_hash_cmp (&session->global_id, | 3157 | (0 == GNUNET_CRYPTO_hash_cmp(&session->global_id, |
3146 | &other_session->global_id)) ) | 3158 | &other_session->global_id))) |
3147 | break; | 3159 | break; |
3148 | } | 3160 | } |
3149 | 3161 | ||
3150 | session->conclude_deadline | 3162 | session->conclude_deadline |
3151 | = GNUNET_TIME_absolute_ntoh (m->deadline); | 3163 | = GNUNET_TIME_absolute_ntoh(m->deadline); |
3152 | session->conclude_start | 3164 | session->conclude_start |
3153 | = GNUNET_TIME_absolute_ntoh (m->start); | 3165 | = GNUNET_TIME_absolute_ntoh(m->start); |
3154 | session->local_peer_idx = get_peer_idx (&my_peer, | 3166 | session->local_peer_idx = get_peer_idx(&my_peer, |
3155 | session); | 3167 | session); |
3156 | GNUNET_assert (-1 != session->local_peer_idx); | 3168 | GNUNET_assert(-1 != session->local_peer_idx); |
3157 | 3169 | ||
3158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3170 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3159 | "Joining consensus session %s containing %u peers as %u with timeout %s\n", | 3171 | "Joining consensus session %s containing %u peers as %u with timeout %s\n", |
3160 | GNUNET_h2s (&m->session_id), | 3172 | GNUNET_h2s(&m->session_id), |
3161 | session->num_peers, | 3173 | session->num_peers, |
3162 | session->local_peer_idx, | 3174 | session->local_peer_idx, |
3163 | GNUNET_STRINGS_relative_time_to_string | 3175 | GNUNET_STRINGS_relative_time_to_string |
3164 | (GNUNET_TIME_absolute_get_difference (session->conclude_start, | 3176 | (GNUNET_TIME_absolute_get_difference(session->conclude_start, |
3165 | session->conclude_deadline), | 3177 | session->conclude_deadline), |
3166 | GNUNET_YES)); | 3178 | GNUNET_YES)); |
3167 | 3179 | ||
3168 | session->set_listener | 3180 | session->set_listener |
3169 | = GNUNET_SET_listen (cfg, | 3181 | = GNUNET_SET_listen(cfg, |
3170 | GNUNET_SET_OPERATION_UNION, | 3182 | GNUNET_SET_OPERATION_UNION, |
3171 | &session->global_id, | 3183 | &session->global_id, |
3172 | &set_listen_cb, | 3184 | &set_listen_cb, |
3173 | session); | 3185 | session); |
3174 | 3186 | ||
3175 | session->setmap = GNUNET_CONTAINER_multihashmap_create (1, | 3187 | session->setmap = GNUNET_CONTAINER_multihashmap_create(1, |
3188 | GNUNET_NO); | ||
3189 | session->taskmap = GNUNET_CONTAINER_multihashmap_create(1, | ||
3176 | GNUNET_NO); | 3190 | GNUNET_NO); |
3177 | session->taskmap = GNUNET_CONTAINER_multihashmap_create (1, | 3191 | session->diffmap = GNUNET_CONTAINER_multihashmap_create(1, |
3178 | GNUNET_NO); | ||
3179 | session->diffmap = GNUNET_CONTAINER_multihashmap_create (1, | ||
3180 | GNUNET_NO); | ||
3181 | session->rfnmap = GNUNET_CONTAINER_multihashmap_create (1, | ||
3182 | GNUNET_NO); | 3192 | GNUNET_NO); |
3193 | session->rfnmap = GNUNET_CONTAINER_multihashmap_create(1, | ||
3194 | GNUNET_NO); | ||
3183 | 3195 | ||
3184 | { | 3196 | { |
3185 | struct SetEntry *client_set; | 3197 | struct SetEntry *client_set; |
3186 | 3198 | ||
3187 | client_set = GNUNET_new (struct SetEntry); | 3199 | client_set = GNUNET_new(struct SetEntry); |
3188 | client_set->h = GNUNET_SET_create (cfg, | 3200 | client_set->h = GNUNET_SET_create(cfg, |
3189 | GNUNET_SET_OPERATION_UNION); | 3201 | GNUNET_SET_OPERATION_UNION); |
3190 | struct SetHandle *sh = GNUNET_new (struct SetHandle); | 3202 | struct SetHandle *sh = GNUNET_new(struct SetHandle); |
3191 | sh->h = client_set->h; | 3203 | sh->h = client_set->h; |
3192 | GNUNET_CONTAINER_DLL_insert (session->set_handles_head, | 3204 | GNUNET_CONTAINER_DLL_insert(session->set_handles_head, |
3193 | session->set_handles_tail, | 3205 | session->set_handles_tail, |
3194 | sh); | 3206 | sh); |
3195 | client_set->key = ((struct SetKey) { SET_KIND_CURRENT, 0, 0 }); | 3207 | client_set->key = ((struct SetKey) { SET_KIND_CURRENT, 0, 0 }); |
3196 | put_set (session, | 3208 | put_set(session, |
3197 | client_set); | 3209 | client_set); |
3198 | } | 3210 | } |
3199 | 3211 | ||
3200 | session->peers_blacklisted = GNUNET_new_array (session->num_peers, | 3212 | session->peers_blacklisted = GNUNET_new_array(session->num_peers, |
3201 | int); | 3213 | int); |
3202 | 3214 | ||
3203 | /* Just construct the task graph, | 3215 | /* Just construct the task graph, |
3204 | but don't run anything until the client calls conclude. */ | 3216 | but don't run anything until the client calls conclude. */ |
3205 | construct_task_graph (session); | 3217 | construct_task_graph(session); |
3206 | GNUNET_SERVICE_client_continue (session->client); | 3218 | GNUNET_SERVICE_client_continue(session->client); |
3207 | } | 3219 | } |
3208 | 3220 | ||
3209 | 3221 | ||
3210 | static void | 3222 | static void |
3211 | client_insert_done (void *cls) | 3223 | client_insert_done(void *cls) |
3212 | { | 3224 | { |
3213 | // FIXME: implement | 3225 | // FIXME: implement |
3214 | } | 3226 | } |
@@ -3222,8 +3234,8 @@ client_insert_done (void *cls) | |||
3222 | * @return #GNUNET_OK (always well-formed) | 3234 | * @return #GNUNET_OK (always well-formed) |
3223 | */ | 3235 | */ |
3224 | static int | 3236 | static int |
3225 | check_client_insert (void *cls, | 3237 | check_client_insert(void *cls, |
3226 | const struct GNUNET_CONSENSUS_ElementMessage *msg) | 3238 | const struct GNUNET_CONSENSUS_ElementMessage *msg) |
3227 | { | 3239 | { |
3228 | return GNUNET_OK; | 3240 | return GNUNET_OK; |
3229 | } | 3241 | } |
@@ -3236,8 +3248,8 @@ check_client_insert (void *cls, | |||
3236 | * @param msg message sent by the client | 3248 | * @param msg message sent by the client |
3237 | */ | 3249 | */ |
3238 | static void | 3250 | static void |
3239 | handle_client_insert (void *cls, | 3251 | handle_client_insert(void *cls, |
3240 | const struct GNUNET_CONSENSUS_ElementMessage *msg) | 3252 | const struct GNUNET_CONSENSUS_ElementMessage *msg) |
3241 | { | 3253 | { |
3242 | struct ConsensusSession *session = cls; | 3254 | struct ConsensusSession *session = cls; |
3243 | ssize_t element_size; | 3255 | ssize_t element_size; |
@@ -3245,20 +3257,20 @@ handle_client_insert (void *cls, | |||
3245 | struct ConsensusElement *ce; | 3257 | struct ConsensusElement *ce; |
3246 | 3258 | ||
3247 | if (GNUNET_YES == session->conclude_started) | 3259 | if (GNUNET_YES == session->conclude_started) |
3248 | { | 3260 | { |
3249 | GNUNET_break (0); | 3261 | GNUNET_break(0); |
3250 | GNUNET_SERVICE_client_drop (session->client); | 3262 | GNUNET_SERVICE_client_drop(session->client); |
3251 | return; | 3263 | return; |
3252 | } | 3264 | } |
3253 | 3265 | ||
3254 | element_size = ntohs (msg->header.size) - sizeof (struct GNUNET_CONSENSUS_ElementMessage); | 3266 | element_size = ntohs(msg->header.size) - sizeof(struct GNUNET_CONSENSUS_ElementMessage); |
3255 | ce = GNUNET_malloc (sizeof (struct ConsensusElement) + element_size); | 3267 | ce = GNUNET_malloc(sizeof(struct ConsensusElement) + element_size); |
3256 | GNUNET_memcpy (&ce[1], &msg[1], element_size); | 3268 | GNUNET_memcpy(&ce[1], &msg[1], element_size); |
3257 | ce->payload_type = msg->element_type; | 3269 | ce->payload_type = msg->element_type; |
3258 | 3270 | ||
3259 | struct GNUNET_SET_Element element = { | 3271 | struct GNUNET_SET_Element element = { |
3260 | .element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT, | 3272 | .element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT, |
3261 | .size = sizeof (struct ConsensusElement) + element_size, | 3273 | .size = sizeof(struct ConsensusElement) + element_size, |
3262 | .data = ce, | 3274 | .data = ce, |
3263 | }; | 3275 | }; |
3264 | 3276 | ||
@@ -3266,28 +3278,28 @@ handle_client_insert (void *cls, | |||
3266 | struct SetKey key = { SET_KIND_CURRENT, 0, 0 }; | 3278 | struct SetKey key = { SET_KIND_CURRENT, 0, 0 }; |
3267 | struct SetEntry *entry; | 3279 | struct SetEntry *entry; |
3268 | 3280 | ||
3269 | entry = lookup_set (session, | 3281 | entry = lookup_set(session, |
3270 | &key); | 3282 | &key); |
3271 | GNUNET_assert (NULL != entry); | 3283 | GNUNET_assert(NULL != entry); |
3272 | initial_set = entry->h; | 3284 | initial_set = entry->h; |
3273 | } | 3285 | } |
3274 | 3286 | ||
3275 | session->num_client_insert_pending++; | 3287 | session->num_client_insert_pending++; |
3276 | GNUNET_SET_add_element (initial_set, | 3288 | GNUNET_SET_add_element(initial_set, |
3277 | &element, | 3289 | &element, |
3278 | &client_insert_done, | 3290 | &client_insert_done, |
3279 | session); | 3291 | session); |
3280 | 3292 | ||
3281 | #ifdef GNUNET_EXTRA_LOGGING | 3293 | #ifdef GNUNET_EXTRA_LOGGING |
3282 | { | 3294 | { |
3283 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3295 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3284 | "P%u: element %s added\n", | 3296 | "P%u: element %s added\n", |
3285 | session->local_peer_idx, | 3297 | session->local_peer_idx, |
3286 | debug_str_element (&element)); | 3298 | debug_str_element(&element)); |
3287 | } | 3299 | } |
3288 | #endif | 3300 | #endif |
3289 | GNUNET_free (ce); | 3301 | GNUNET_free(ce); |
3290 | GNUNET_SERVICE_client_continue (session->client); | 3302 | GNUNET_SERVICE_client_continue(session->client); |
3291 | } | 3303 | } |
3292 | 3304 | ||
3293 | 3305 | ||
@@ -3298,24 +3310,24 @@ handle_client_insert (void *cls, | |||
3298 | * @param message message sent by the client | 3310 | * @param message message sent by the client |
3299 | */ | 3311 | */ |
3300 | static void | 3312 | static void |
3301 | handle_client_conclude (void *cls, | 3313 | handle_client_conclude(void *cls, |
3302 | const struct GNUNET_MessageHeader *message) | 3314 | const struct GNUNET_MessageHeader *message) |
3303 | { | 3315 | { |
3304 | struct ConsensusSession *session = cls; | 3316 | struct ConsensusSession *session = cls; |
3305 | 3317 | ||
3306 | if (GNUNET_YES == session->conclude_started) | 3318 | if (GNUNET_YES == session->conclude_started) |
3307 | { | 3319 | { |
3308 | /* conclude started twice */ | 3320 | /* conclude started twice */ |
3309 | GNUNET_break (0); | 3321 | GNUNET_break(0); |
3310 | GNUNET_SERVICE_client_drop (session->client); | 3322 | GNUNET_SERVICE_client_drop(session->client); |
3311 | return; | 3323 | return; |
3312 | } | 3324 | } |
3313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3325 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3314 | "conclude requested\n"); | 3326 | "conclude requested\n"); |
3315 | session->conclude_started = GNUNET_YES; | 3327 | session->conclude_started = GNUNET_YES; |
3316 | install_step_timeouts (session); | 3328 | install_step_timeouts(session); |
3317 | run_ready_steps (session); | 3329 | run_ready_steps(session); |
3318 | GNUNET_SERVICE_client_continue (session->client); | 3330 | GNUNET_SERVICE_client_continue(session->client); |
3319 | } | 3331 | } |
3320 | 3332 | ||
3321 | 3333 | ||
@@ -3325,12 +3337,12 @@ handle_client_conclude (void *cls, | |||
3325 | * @param cls closure | 3337 | * @param cls closure |
3326 | */ | 3338 | */ |
3327 | static void | 3339 | static void |
3328 | shutdown_task (void *cls) | 3340 | shutdown_task(void *cls) |
3329 | { | 3341 | { |
3330 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 3342 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
3331 | "shutting down\n"); | 3343 | "shutting down\n"); |
3332 | GNUNET_STATISTICS_destroy (statistics, | 3344 | GNUNET_STATISTICS_destroy(statistics, |
3333 | GNUNET_NO); | 3345 | GNUNET_NO); |
3334 | statistics = NULL; | 3346 | statistics = NULL; |
3335 | } | 3347 | } |
3336 | 3348 | ||
@@ -3343,24 +3355,24 @@ shutdown_task (void *cls) | |||
3343 | * @param service the initialized service | 3355 | * @param service the initialized service |
3344 | */ | 3356 | */ |
3345 | static void | 3357 | static void |
3346 | run (void *cls, | 3358 | run(void *cls, |
3347 | const struct GNUNET_CONFIGURATION_Handle *c, | 3359 | const struct GNUNET_CONFIGURATION_Handle *c, |
3348 | struct GNUNET_SERVICE_Handle *service) | 3360 | struct GNUNET_SERVICE_Handle *service) |
3349 | { | 3361 | { |
3350 | cfg = c; | 3362 | cfg = c; |
3351 | if (GNUNET_OK != | 3363 | if (GNUNET_OK != |
3352 | GNUNET_CRYPTO_get_peer_identity (cfg, | 3364 | GNUNET_CRYPTO_get_peer_identity(cfg, |
3353 | &my_peer)) | 3365 | &my_peer)) |
3354 | { | 3366 | { |
3355 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3367 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3356 | "Could not retrieve host identity\n"); | 3368 | "Could not retrieve host identity\n"); |
3357 | GNUNET_SCHEDULER_shutdown (); | 3369 | GNUNET_SCHEDULER_shutdown(); |
3358 | return; | 3370 | return; |
3359 | } | 3371 | } |
3360 | statistics = GNUNET_STATISTICS_create ("consensus", | 3372 | statistics = GNUNET_STATISTICS_create("consensus", |
3361 | cfg); | 3373 | cfg); |
3362 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 3374 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, |
3363 | NULL); | 3375 | NULL); |
3364 | } | 3376 | } |
3365 | 3377 | ||
3366 | 3378 | ||
@@ -3373,17 +3385,17 @@ run (void *cls, | |||
3373 | * @return @a c | 3385 | * @return @a c |
3374 | */ | 3386 | */ |
3375 | static void * | 3387 | static void * |
3376 | client_connect_cb (void *cls, | 3388 | client_connect_cb(void *cls, |
3377 | struct GNUNET_SERVICE_Client *c, | 3389 | struct GNUNET_SERVICE_Client *c, |
3378 | struct GNUNET_MQ_Handle *mq) | 3390 | struct GNUNET_MQ_Handle *mq) |
3379 | { | 3391 | { |
3380 | struct ConsensusSession *session = GNUNET_new (struct ConsensusSession); | 3392 | struct ConsensusSession *session = GNUNET_new(struct ConsensusSession); |
3381 | 3393 | ||
3382 | session->client = c; | 3394 | session->client = c; |
3383 | session->client_mq = mq; | 3395 | session->client_mq = mq; |
3384 | GNUNET_CONTAINER_DLL_insert (sessions_head, | 3396 | GNUNET_CONTAINER_DLL_insert(sessions_head, |
3385 | sessions_tail, | 3397 | sessions_tail, |
3386 | session); | 3398 | session); |
3387 | return session; | 3399 | return session; |
3388 | } | 3400 | } |
3389 | 3401 | ||
@@ -3396,29 +3408,29 @@ client_connect_cb (void *cls, | |||
3396 | * @param internal_cls should be equal to @a c | 3408 | * @param internal_cls should be equal to @a c |
3397 | */ | 3409 | */ |
3398 | static void | 3410 | static void |
3399 | client_disconnect_cb (void *cls, | 3411 | client_disconnect_cb(void *cls, |
3400 | struct GNUNET_SERVICE_Client *c, | 3412 | struct GNUNET_SERVICE_Client *c, |
3401 | void *internal_cls) | 3413 | void *internal_cls) |
3402 | { | 3414 | { |
3403 | struct ConsensusSession *session = internal_cls; | 3415 | struct ConsensusSession *session = internal_cls; |
3404 | 3416 | ||
3405 | if (NULL != session->set_listener) | 3417 | if (NULL != session->set_listener) |
3406 | { | 3418 | { |
3407 | GNUNET_SET_listen_cancel (session->set_listener); | 3419 | GNUNET_SET_listen_cancel(session->set_listener); |
3408 | session->set_listener = NULL; | 3420 | session->set_listener = NULL; |
3409 | } | 3421 | } |
3410 | GNUNET_CONTAINER_DLL_remove (sessions_head, | 3422 | GNUNET_CONTAINER_DLL_remove(sessions_head, |
3411 | sessions_tail, | 3423 | sessions_tail, |
3412 | session); | 3424 | session); |
3413 | 3425 | ||
3414 | while (session->set_handles_head) | 3426 | while (session->set_handles_head) |
3415 | { | 3427 | { |
3416 | struct SetHandle *sh = session->set_handles_head; | 3428 | struct SetHandle *sh = session->set_handles_head; |
3417 | session->set_handles_head = sh->next; | 3429 | session->set_handles_head = sh->next; |
3418 | GNUNET_SET_destroy (sh->h); | 3430 | GNUNET_SET_destroy(sh->h); |
3419 | GNUNET_free (sh); | 3431 | GNUNET_free(sh); |
3420 | } | 3432 | } |
3421 | GNUNET_free (session); | 3433 | GNUNET_free(session); |
3422 | } | 3434 | } |
3423 | 3435 | ||
3424 | 3436 | ||
@@ -3426,24 +3438,24 @@ client_disconnect_cb (void *cls, | |||
3426 | * Define "main" method using service macro. | 3438 | * Define "main" method using service macro. |
3427 | */ | 3439 | */ |
3428 | GNUNET_SERVICE_MAIN | 3440 | GNUNET_SERVICE_MAIN |
3429 | ("consensus", | 3441 | ("consensus", |
3430 | GNUNET_SERVICE_OPTION_NONE, | 3442 | GNUNET_SERVICE_OPTION_NONE, |
3431 | &run, | 3443 | &run, |
3432 | &client_connect_cb, | 3444 | &client_connect_cb, |
3433 | &client_disconnect_cb, | 3445 | &client_disconnect_cb, |
3434 | NULL, | 3446 | NULL, |
3435 | GNUNET_MQ_hd_fixed_size (client_conclude, | 3447 | GNUNET_MQ_hd_fixed_size(client_conclude, |
3436 | GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE, | 3448 | GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE, |
3437 | struct GNUNET_MessageHeader, | 3449 | struct GNUNET_MessageHeader, |
3438 | NULL), | 3450 | NULL), |
3439 | GNUNET_MQ_hd_var_size (client_insert, | 3451 | GNUNET_MQ_hd_var_size(client_insert, |
3440 | GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_INSERT, | 3452 | GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_INSERT, |
3441 | struct GNUNET_CONSENSUS_ElementMessage, | 3453 | struct GNUNET_CONSENSUS_ElementMessage, |
3442 | NULL), | 3454 | NULL), |
3443 | GNUNET_MQ_hd_var_size (client_join, | 3455 | GNUNET_MQ_hd_var_size(client_join, |
3444 | GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN, | 3456 | GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN, |
3445 | struct GNUNET_CONSENSUS_JoinMessage, | 3457 | struct GNUNET_CONSENSUS_JoinMessage, |
3446 | NULL), | 3458 | NULL), |
3447 | GNUNET_MQ_handler_end ()); | 3459 | GNUNET_MQ_handler_end()); |
3448 | 3460 | ||
3449 | /* end of gnunet-service-consensus.c */ | 3461 | /* end of gnunet-service-consensus.c */ |