summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2020-08-31 09:24:07 +0200
committert3sserakt <t3ss@posteo.de>2020-08-31 09:30:46 +0200
commit4887fa044a7792d367b0cf9d48b3d6d3b0adfd17 (patch)
tree97f19bff30d18d52b61cc84483059f64fa225c9d
parent72cb328c689aacf5a20a0107e5762c1749ea2886 (diff)
parent38e90f057952ed81492d6ee3db0bc87cef9e4207 (diff)
Merge branch 'master' of ssh://gnunet.org/gnunet
-rw-r--r--src/consensus/consensus_protocol.h1
-rw-r--r--src/consensus/gnunet-service-consensus.c552
-rw-r--r--src/consensus/plugin_block_consensus.c13
-rw-r--r--src/include/gnunet_crypto_lib.h2
-rw-r--r--src/util/crypto_hash.c2
5 files changed, 295 insertions, 275 deletions
diff --git a/src/consensus/consensus_protocol.h b/src/consensus/consensus_protocol.h
index a40162fb8..0afd56b27 100644
--- a/src/consensus/consensus_protocol.h
+++ b/src/consensus/consensus_protocol.h
@@ -124,6 +124,7 @@ struct ConsensusSizeElement
uint8_t sender_index;
};
+
struct ConsensusStuffedElement
{
struct ConsensusElement ce;
diff --git a/src/consensus/gnunet-service-consensus.c b/src/consensus/gnunet-service-consensus.c
index 13fa0d0e7..371b7f67f 100644
--- a/src/consensus/gnunet-service-consensus.c
+++ b/src/consensus/gnunet-service-consensus.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet
- Copyright (C) 2012, 2013, 2017 GNUnet e.V.
+ Copyright (C) 2012, 2013, 2017, 2020 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -17,13 +17,11 @@
SPDX-License-Identifier: AGPL3.0-or-later
*/
-
/**
* @file consensus/gnunet-service-consensus.c
* @brief multi-peer set reconciliation
* @author Florian Dold <flo@dold.me>
*/
-
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_block_lib.h"
@@ -62,11 +60,57 @@ enum EarlyStoppingPhase
};
+enum PhaseKind
+{
+ PHASE_KIND_ALL_TO_ALL,
+ PHASE_KIND_ALL_TO_ALL_2,
+ PHASE_KIND_GRADECAST_LEADER,
+ PHASE_KIND_GRADECAST_ECHO,
+ PHASE_KIND_GRADECAST_ECHO_GRADE,
+ PHASE_KIND_GRADECAST_CONFIRM,
+ PHASE_KIND_GRADECAST_CONFIRM_GRADE,
+ /**
+ * Apply a repetition of the all-to-all
+ * gradecast to the current set.
+ */
+ PHASE_KIND_APPLY_REP,
+ PHASE_KIND_FINISH,
+};
+
+
+enum SetKind
+{
+ SET_KIND_NONE = 0,
+ SET_KIND_CURRENT,
+ /**
+ * Last result set from a gradecast
+ */
+ SET_KIND_LAST_GRADECAST,
+ SET_KIND_LEADER_PROPOSAL,
+ SET_KIND_ECHO_RESULT,
+};
+
+enum DiffKind
+{
+ DIFF_KIND_NONE = 0,
+ DIFF_KIND_LEADER_PROPOSAL,
+ DIFF_KIND_LEADER_CONSENSUS,
+ DIFF_KIND_GRADECAST_RESULT,
+};
+
+enum RfnKind
+{
+ RFN_KIND_NONE = 0,
+ RFN_KIND_ECHO,
+ RFN_KIND_CONFIRM,
+ RFN_KIND_GRADECAST_RESULT
+};
+
+
GNUNET_NETWORK_STRUCT_BEGIN
/**
- * Tuple of integers that together
- * identify a task uniquely.
+ * Tuple of integers that together identify a task uniquely.
*/
struct TaskKey
{
@@ -102,8 +146,14 @@ struct TaskKey
struct SetKey
{
- int set_kind GNUNET_PACKED;
+ enum SetKind set_kind GNUNET_PACKED;
+ /**
+ * Repetition counter.
+ */
int k1 GNUNET_PACKED;
+ /**
+ * Leader (or 0).
+ */
int k2 GNUNET_PACKED;
};
@@ -112,9 +162,9 @@ struct SetEntry
{
struct SetKey key;
struct GNUNET_SET_Handle *h;
+
/**
- * GNUNET_YES if the set resulted
- * from applying a referendum with contested
+ * #GNUNET_YES if the set resulted from applying a referendum with contested
* elements.
*/
int is_contested;
@@ -123,14 +173,16 @@ struct SetEntry
struct DiffKey
{
- int diff_kind GNUNET_PACKED;
+ enum DiffKind diff_kind GNUNET_PACKED;
+
int k1 GNUNET_PACKED;
+
int k2 GNUNET_PACKED;
};
struct RfnKey
{
- int rfn_kind GNUNET_PACKED;
+ enum RfnKind rfn_kind GNUNET_PACKED;
int k1 GNUNET_PACKED;
int k2 GNUNET_PACKED;
};
@@ -138,52 +190,6 @@ struct RfnKey
GNUNET_NETWORK_STRUCT_END
-enum PhaseKind
-{
- PHASE_KIND_ALL_TO_ALL,
- PHASE_KIND_ALL_TO_ALL_2,
- PHASE_KIND_GRADECAST_LEADER,
- PHASE_KIND_GRADECAST_ECHO,
- PHASE_KIND_GRADECAST_ECHO_GRADE,
- PHASE_KIND_GRADECAST_CONFIRM,
- PHASE_KIND_GRADECAST_CONFIRM_GRADE,
- /**
- * Apply a repetition of the all-to-all
- * gradecast to the current set.
- */
- PHASE_KIND_APPLY_REP,
- PHASE_KIND_FINISH,
-};
-
-
-enum SetKind
-{
- SET_KIND_NONE = 0,
- SET_KIND_CURRENT,
- /**
- * Last result set from a gradecast
- */
- SET_KIND_LAST_GRADECAST,
- SET_KIND_LEADER_PROPOSAL,
- SET_KIND_ECHO_RESULT,
-};
-
-enum DiffKind
-{
- DIFF_KIND_NONE = 0,
- DIFF_KIND_LEADER_PROPOSAL,
- DIFF_KIND_LEADER_CONSENSUS,
- DIFF_KIND_GRADECAST_RESULT,
-};
-
-enum RfnKind
-{
- RFN_KIND_NONE = 0,
- RFN_KIND_ECHO,
- RFN_KIND_CONFIRM,
- RFN_KIND_GRADECAST_RESULT
-};
-
struct SetOpCls
{
@@ -216,9 +222,13 @@ union TaskFuncCls
struct FinishCls finish;
};
+
struct TaskEntry;
-typedef void (*TaskFunc) (struct TaskEntry *task);
+
+typedef void
+(*TaskFunc) (struct TaskEntry *task);
+
/*
* Node in the consensus task graph.
@@ -277,14 +287,12 @@ struct Step
unsigned int subordinates_cap;
/**
- * Counter for the prerequisites of
- * this step.
+ * Counter for the prerequisites of this step.
*/
size_t pending_prereq;
- /*
- * Task that will run this step despite
- * any pending prerequisites.
+ /**
+ * Task that will run this step despite any pending prerequisites.
*/
struct GNUNET_SCHEDULER_Task *timeout_task;
@@ -292,28 +300,23 @@ struct Step
unsigned int is_finished;
- /*
- * Synchrony round of the task.
- * Determines the deadline for the task.
+ /**
+ * Synchrony round of the task. Determines the deadline for the task.
*/
unsigned int round;
/**
- * Human-readable name for
- * the task, used for debugging.
+ * Human-readable name for the task, used for debugging.
*/
char *debug_name;
/**
- * When we're doing an early finish, how should this step be
- * treated?
- * If GNUNET_YES, the step will be marked as finished
- * without actually running its tasks.
- * Otherwise, the step will still be run even after
- * an early finish.
+ * When we're doing an early finish, how should this step be treated? If
+ * #GNUNET_YES, the step will be marked as finished without actually running
+ * its tasks. Otherwise, the step will still be run even after an early
+ * finish.
*
- * Note that a task may never be finished early if
- * it is already running.
+ * Note that a task may never be finished early if it is already running.
*/
int early_finishable;
};
@@ -323,14 +326,13 @@ struct RfnElementInfo
{
const struct GNUNET_SET_Element *element;
- /*
- * GNUNET_YES if the peer votes for the proposal.
+ /**
+ * #GNUNET_YES if the peer votes for the proposal.
*/
int *votes;
/**
- * Proposal for this element,
- * can only be VOTE_ADD or VOTE_REMOVE.
+ * Proposal for this element, can only be #VOTE_ADD or #VOTE_REMOVE.
*/
enum ReferendumVote proposal;
};
@@ -638,7 +640,7 @@ debug_str_element (const struct GNUNET_SET_Element *el)
static const char *
-debug_str_task_key (struct TaskKey *tk)
+debug_str_task_key (const struct TaskKey *tk)
{
static char buf[256];
@@ -652,7 +654,7 @@ debug_str_task_key (struct TaskKey *tk)
static const char *
-debug_str_diff_key (struct DiffKey *dk)
+debug_str_diff_key (const struct DiffKey *dk)
{
static char buf[256];
@@ -671,8 +673,9 @@ debug_str_set_key (const struct SetKey *sk)
snprintf (buf, sizeof(buf),
"SetKey kind=%s, k1=%d, k2=%d",
- setname (sk->set_kind), sk->k1, sk->k2);
-
+ setname (sk->set_kind),
+ sk->k1,
+ sk->k2);
return buf;
}
@@ -684,8 +687,9 @@ debug_str_rfn_key (const struct RfnKey *rk)
snprintf (buf, sizeof(buf),
"RfnKey kind=%s, k1=%d, k2=%d",
- rfnname (rk->rfn_kind), rk->k1, rk->k2);
-
+ rfnname (rk->rfn_kind),
+ rk->k1,
+ rk->k2);
return buf;
}
@@ -730,13 +734,15 @@ send_to_client_iter (void *cls,
session->local_peer_idx,
debug_str_element (element));
- ev = GNUNET_MQ_msg_extra (m, element->size - sizeof(struct
- ConsensusElement),
+ ev = GNUNET_MQ_msg_extra (m,
+ element->size - sizeof(struct ConsensusElement),
GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT);
m->element_type = ce->payload_type;
- GNUNET_memcpy (&m[1], &ce[1], element->size - sizeof(struct
- ConsensusElement));
- GNUNET_MQ_send (session->client_mq, ev);
+ GNUNET_memcpy (&m[1],
+ &ce[1],
+ element->size - sizeof(struct ConsensusElement));
+ GNUNET_MQ_send (session->client_mq,
+ ev);
}
else
{
@@ -745,14 +751,16 @@ send_to_client_iter (void *cls,
session->local_peer_idx);
ev = GNUNET_MQ_msg_header (
GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE_DONE);
- GNUNET_MQ_send (session->client_mq, ev);
+ GNUNET_MQ_send (session->client_mq,
+ ev);
}
return GNUNET_YES;
}
static struct SetEntry *
-lookup_set (struct ConsensusSession *session, struct SetKey *key)
+lookup_set (struct ConsensusSession *session,
+ const struct SetKey *key)
{
struct GNUNET_HashCode hash;
@@ -762,13 +770,17 @@ lookup_set (struct ConsensusSession *session, struct SetKey *key)
debug_str_set_key (key));
GNUNET_assert (SET_KIND_NONE != key->set_kind);
- GNUNET_CRYPTO_hash (key, sizeof(struct SetKey), &hash);
- return GNUNET_CONTAINER_multihashmap_get (session->setmap, &hash);
+ GNUNET_CRYPTO_hash (key,
+ sizeof(struct SetKey),
+ &hash);
+ return GNUNET_CONTAINER_multihashmap_get (session->setmap,
+ &hash);
}
static struct DiffEntry *
-lookup_diff (struct ConsensusSession *session, struct DiffKey *key)
+lookup_diff (struct ConsensusSession *session,
+ const struct DiffKey *key)
{
struct GNUNET_HashCode hash;
@@ -776,15 +788,18 @@ lookup_diff (struct ConsensusSession *session, struct DiffKey *key)
"P%u: looking up diff {%s}\n",
session->local_peer_idx,
debug_str_diff_key (key));
-
GNUNET_assert (DIFF_KIND_NONE != key->diff_kind);
- GNUNET_CRYPTO_hash (key, sizeof(struct DiffKey), &hash);
- return GNUNET_CONTAINER_multihashmap_get (session->diffmap, &hash);
+ GNUNET_CRYPTO_hash (key,
+ sizeof(struct DiffKey),
+ &hash);
+ return GNUNET_CONTAINER_multihashmap_get (session->diffmap,
+ &hash);
}
static struct ReferendumEntry *
-lookup_rfn (struct ConsensusSession *session, struct RfnKey *key)
+lookup_rfn (struct ConsensusSession *session,
+ const struct RfnKey *key)
{
struct GNUNET_HashCode hash;
@@ -792,10 +807,12 @@ lookup_rfn (struct ConsensusSession *session, struct RfnKey *key)
"P%u: looking up rfn {%s}\n",
session->local_peer_idx,
debug_str_rfn_key (key));
-
GNUNET_assert (RFN_KIND_NONE != key->rfn_kind);
- GNUNET_CRYPTO_hash (key, sizeof(struct RfnKey), &hash);
- return GNUNET_CONTAINER_multihashmap_get (session->rfnmap, &hash);
+ GNUNET_CRYPTO_hash (key,
+ sizeof(struct RfnKey),
+ &hash);
+ return GNUNET_CONTAINER_multihashmap_get (session->rfnmap,
+ &hash);
}
@@ -829,7 +846,8 @@ diff_insert (struct DiffEntry *diff,
di->element = GNUNET_SET_element_dup (element);
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multihashmap_put (diff->changes,
- &hash, di,
+ &hash,
+ di,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
}
@@ -860,11 +878,10 @@ rfn_contest (struct ReferendumEntry *rfn,
static uint16_t
rfn_noncontested (struct ReferendumEntry *rfn)
{
- uint16_t i;
uint16_t ret;
ret = 0;
- for (i = 0; i < rfn->num_peers; i++)
+ for (uint16_t i = 0; i < rfn->num_peers; i++)
if ((GNUNET_YES == rfn->peer_commited[i]) && (GNUNET_NO ==
rfn->peer_contested[i]))
ret++;
@@ -993,7 +1010,8 @@ set_result_cb (void *cls,
if (SET_KIND_NONE != setop->output_set.set_kind)
{
- output_set = lookup_set (session, &setop->output_set);
+ output_set = lookup_set (session,
+ &setop->output_set);
GNUNET_assert (NULL != output_set);
}
@@ -1226,8 +1244,8 @@ struct Evilness
static int
-parse_evilness_cram_subtype (const char *evil_subtype_str, struct
- Evilness *evil)
+parse_evilness_cram_subtype (const char *evil_subtype_str,
+ struct Evilness *evil)
{
if (0 == strcmp ("replace", evil_subtype_str))
{
@@ -1360,8 +1378,7 @@ cleanup:
/**
- * Commit the appropriate set for a
- * task.
+ * Commit the appropriate set for a task.
*/
static void
commit_set (struct ConsensusSession *session,
@@ -1379,6 +1396,7 @@ commit_set (struct ConsensusSession *session,
{
struct GNUNET_SET_Element element;
struct ConsensusElement ce = { 0 };
+
ce.marker = CONSENSUS_MARKER_CONTESTED;
element.data = &ce;
element.size = sizeof(struct ConsensusElement);
@@ -1405,7 +1423,6 @@ commit_set (struct ConsensusSession *session,
#ifdef EVIL
{
- unsigned int i;
struct Evilness evil;
get_evilness (session, &evil);
@@ -1444,7 +1461,7 @@ commit_set (struct ConsensusSession *session,
GNUNET_SET_commit (setop->op, set->h);
break;
}
- for (i = 0; i < evil.num; i++)
+ for (unsigned int i = 0; i < evil.num; i++)
{
struct GNUNET_SET_Element element;
struct ConsensusStuffedElement se = {
@@ -1504,12 +1521,14 @@ commit_set (struct ConsensusSession *session,
}
else
{
- GNUNET_SET_commit (setop->op, set->h);
+ GNUNET_SET_commit (setop->op,
+ set->h);
}
break;
case EVILNESS_NONE:
- GNUNET_SET_commit (setop->op, set->h);
+ GNUNET_SET_commit (setop->op,
+ set->h);
break;
}
}
@@ -1536,11 +1555,12 @@ put_diff (struct ConsensusSession *session,
{
struct GNUNET_HashCode hash;
- GNUNET_assert (NULL != diff);
-
- GNUNET_CRYPTO_hash (&diff->key, sizeof(struct DiffKey), &hash);
+ GNUNET_CRYPTO_hash (&diff->key,
+ sizeof(struct DiffKey),
+ &hash);
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (session->diffmap, &hash,
+ GNUNET_CONTAINER_multihashmap_put (session->diffmap,
+ &hash,
diff,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
}
@@ -1553,14 +1573,16 @@ put_set (struct ConsensusSession *session,
struct GNUNET_HashCode hash;
GNUNET_assert (NULL != set->h);
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Putting set %s\n",
debug_str_set_key (&set->key));
-
- GNUNET_CRYPTO_hash (&set->key, sizeof(struct SetKey), &hash);
+ GNUNET_CRYPTO_hash (&set->key,
+ sizeof(struct SetKey),
+ &hash);
GNUNET_assert (GNUNET_SYSERR !=
- GNUNET_CONTAINER_multihashmap_put (session->setmap, &hash, set,
+ GNUNET_CONTAINER_multihashmap_put (session->setmap,
+ &hash,
+ set,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
}
@@ -1573,7 +1595,9 @@ put_rfn (struct ConsensusSession *session,
GNUNET_CRYPTO_hash (&rfn->key, sizeof(struct RfnKey), &hash);
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (session->rfnmap, &hash, rfn,
+ GNUNET_CONTAINER_multihashmap_put (session->rfnmap,
+ &hash,
+ rfn,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
}
@@ -1616,18 +1640,20 @@ apply_diff_to_rfn (struct DiffEntry *diff,
}
-struct DiffEntry *
-diff_create ()
+static struct DiffEntry *
+diff_create (void)
{
struct DiffEntry *d = GNUNET_new (struct DiffEntry);
- d->changes = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO);
+ d->changes = GNUNET_CONTAINER_multihashmap_create (8,
+ GNUNET_NO);
return d;
}
-struct DiffEntry *
+#if 0
+static struct DiffEntry *
diff_compose (struct DiffEntry *diff_1,
struct DiffEntry *diff_2)
{
@@ -1638,22 +1664,26 @@ diff_compose (struct DiffEntry *diff_1,
diff_new = diff_create ();
iter = GNUNET_CONTAINER_multihashmap_iterator_create (diff_1->changes);
- while (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next (iter, NULL,
- (const
- void **) &
- di))
+ while (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_iterator_next (iter,
+ NULL,
+ (const void **) &di))
{
- diff_insert (diff_new, di->weight, di->element);
+ diff_insert (diff_new,
+ di->weight,
+ di->element);
}
GNUNET_CONTAINER_multihashmap_iterator_destroy (iter);
iter = GNUNET_CONTAINER_multihashmap_iterator_create (diff_2->changes);
- while (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next (iter, NULL,
- (const
- void **) &
- di))
+ while (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_iterator_next (iter,
+ NULL,
+ (const void **) &di))
{
- diff_insert (diff_new, di->weight, di->element);
+ diff_insert (diff_new,
+ di->weight,
+ di->element);
}
GNUNET_CONTAINER_multihashmap_iterator_destroy (iter);
@@ -1661,6 +1691,9 @@ diff_compose (struct DiffEntry *diff_1,
}
+#endif
+
+
struct ReferendumEntry *
rfn_create (uint16_t size)
{
@@ -1701,14 +1734,13 @@ rfn_majority (const struct ReferendumEntry *rfn,
{
uint16_t votes_yes = 0;
uint16_t num_commited = 0;
- uint16_t i;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Computing rfn majority for element %s of rfn {%s}\n",
debug_str_element (ri->element),
debug_str_rfn_key (&rfn->key));
- for (i = 0; i < rfn->num_peers; i++)
+ for (uint16_t i = 0; i < rfn->num_peers; i++)
{
if (GNUNET_NO == rfn->peer_commited[i])
continue;
@@ -1739,7 +1771,8 @@ struct SetCopyCls
static void
-set_copy_cb (void *cls, struct GNUNET_SET_Handle *copy)
+set_copy_cb (void *cls,
+ struct GNUNET_SET_Handle *copy)
{
struct SetCopyCls *scc = cls;
struct TaskEntry *task = scc->task;
@@ -1821,8 +1854,6 @@ set_mutation_done (void *cls)
static void
try_finish_step_early (struct Step *step)
{
- unsigned int i;
-
if (GNUNET_YES == step->is_running)
return;
if (GNUNET_YES == step->is_finished)
@@ -1838,7 +1869,7 @@ try_finish_step_early (struct Step *step)
step->debug_name);
#endif
- for (i = 0; i < step->subordinates_len; i++)
+ for (unsigned int i = 0; i < step->subordinates_len; i++)
{
GNUNET_assert (step->subordinates[i]->pending_prereq > 0);
step->subordinates[i]->pending_prereq--;
@@ -1859,8 +1890,6 @@ try_finish_step_early (struct Step *step)
static void
finish_step (struct Step *step)
{
- unsigned int i;
-
GNUNET_assert (step->finished_tasks == step->tasks_len);
GNUNET_assert (GNUNET_YES == step->is_running);
GNUNET_assert (GNUNET_NO == step->is_finished);
@@ -1872,7 +1901,7 @@ finish_step (struct Step *step)
step->subordinates_len);
#endif
- for (i = 0; i < step->subordinates_len; i++)
+ for (unsigned int i = 0; i < step->subordinates_len; i++)
{
GNUNET_assert (step->subordinates[i]->pending_prereq > 0);
step->subordinates[i]->pending_prereq--;
@@ -1918,7 +1947,9 @@ task_start_apply_round (struct TaskEntry *task)
set_out = lookup_set (session, &sk_out);
if (NULL == set_out)
{
- create_set_copy_for_task (task, &sk_in, &sk_out);
+ create_set_copy_for_task (task,
+ &sk_in,
+ &sk_out);
return;
}
@@ -2162,7 +2193,9 @@ task_start_reconcile (struct TaskEntry *task)
we clone the input set. */
if (NULL == lookup_set (session, &setop->output_set))
{
- create_set_copy_for_task (task, &setop->input_set, &setop->output_set);
+ create_set_copy_for_task (task,
+ &setop->input_set,
+ &setop->output_set);
return;
}
}
@@ -2212,11 +2245,8 @@ task_start_reconcile (struct TaskEntry *task)
"P%u: Looking up set {%s} to run remote union\n",
session->local_peer_idx,
debug_str_set_key (&setop->input_set));
-
rcm.header.type = htons (GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT);
- rcm.header.size = htons (sizeof(struct
- GNUNET_CONSENSUS_RoundContextMessage));
-
+ rcm.header.size = htons (sizeof(rcm));
rcm.kind = htons (task->key.kind);
rcm.peer1 = htons (task->key.peer1);
rcm.peer2 = htons (task->key.peer2);
@@ -2227,8 +2257,9 @@ task_start_reconcile (struct TaskEntry *task)
GNUNET_assert (NULL == setop->op);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"P%u: initiating set op with P%u, our set is %s\n",
- session->local_peer_idx, task->key.peer2, debug_str_set_key (
- &setop->input_set));
+ session->local_peer_idx,
+ task->key.peer2,
+ debug_str_set_key (&setop->input_set));
struct GNUNET_SET_Option opts[] = {
{ GNUNET_SET_OPTION_BYZANTINE, { .num = session->lower_bound } },
@@ -2286,15 +2317,17 @@ task_start_eval_echo (struct TaskEntry *task)
output_set = lookup_set (session, &sk_out);
if (NULL == output_set)
{
- create_set_copy_for_task (task, &sk_in, &sk_out);
+ create_set_copy_for_task (task,
+ &sk_in,
+ &sk_out);
return;
}
-
{
// FIXME: should be marked as a shallow copy, so
// we can destroy everything correctly
struct SetEntry *last_set = GNUNET_new (struct SetEntry);
+
last_set->h = output_set->h;
last_set->key = (struct SetKey) { SET_KIND_LAST_GRADECAST };
put_set (session, last_set);
@@ -2306,13 +2339,10 @@ task_start_eval_echo (struct TaskEntry *task)
progress_cls = GNUNET_new (struct SetMutationProgressCls);
progress_cls->task = task;
-
rk_in = (struct RfnKey) { RFN_KIND_ECHO, task->key.repetition,
task->key.leader };
input_rfn = lookup_rfn (session, &rk_in);
-
GNUNET_assert (NULL != input_rfn);
-
iter = GNUNET_CONTAINER_multihashmap_iterator_create (
input_rfn->rfn_elements);
GNUNET_assert (NULL != iter);
@@ -2334,7 +2364,8 @@ task_start_eval_echo (struct TaskEntry *task)
can't simply send "nothing" for the value. Thus we mark our 'confirm'
reconciliation as contested. Other peers might not know that the
leader is faulty, thus we still re-distribute in the confirmation
- round. */output_set->is_contested = GNUNET_YES;
+ round. *///
+ output_set->is_contested = GNUNET_YES;
}
switch (majority_vote)
@@ -2384,29 +2415,27 @@ task_start_finish (struct TaskEntry *task)
struct SetEntry *final_set;
struct ConsensusSession *session = task->step->session;
- final_set = lookup_set (session, &task->cls.finish.input_set);
-
+ final_set = lookup_set (session,
+ &task->cls.finish.input_set);
GNUNET_assert (NULL != final_set);
-
-
GNUNET_SET_iterate (final_set->h,
- send_to_client_iter,
+ &send_to_client_iter,
task);
}
static void
-start_task (struct ConsensusSession *session, struct TaskEntry *task)
+start_task (struct ConsensusSession *session,
+ struct TaskEntry *task)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: starting task {%s}\n",
- session->local_peer_idx, debug_str_task_key (&task->key));
-
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "P%u: starting task {%s}\n",
+ session->local_peer_idx,
+ debug_str_task_key (&task->key));
GNUNET_assert (GNUNET_NO == task->is_started);
GNUNET_assert (GNUNET_NO == task->is_finished);
GNUNET_assert (NULL != task->start);
-
task->start (task);
-
task->is_started = GNUNET_YES;
}
@@ -2427,8 +2456,6 @@ run_ready_steps (struct ConsensusSession *session)
if ((GNUNET_NO == step->is_running) && (0 == step->pending_prereq) &&
(GNUNET_NO == step->is_finished))
{
- size_t i;
-
GNUNET_assert (0 == step->finished_tasks);
#ifdef GNUNET_EXTRA_LOGGING
@@ -2440,7 +2467,7 @@ run_ready_steps (struct ConsensusSession *session)
#endif
step->is_running = GNUNET_YES;
- for (i = 0; i < step->tasks_len; i++)
+ for (size_t i = 0; i < step->tasks_len; i++)
start_task (session, step->tasks[i]);
/* Sometimes there is no task to trigger finishing the step, so we have to do it here. */
@@ -2463,9 +2490,7 @@ finish_task (struct TaskEntry *task)
{
GNUNET_assert (GNUNET_NO == task->is_finished);
task->is_finished = GNUNET_YES;
-
task->step->finished_tasks++;
-
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"P%u: Finishing Task {%s} (now %u/%u tasks finished in step)\n",
task->step->session->local_peer_idx,
@@ -2486,12 +2511,10 @@ finish_task (struct TaskEntry *task)
* @return index of peer, -1 if peer is not in session
*/
static int
-get_peer_idx (const struct GNUNET_PeerIdentity *peer, const struct
- ConsensusSession *session)
+get_peer_idx (const struct GNUNET_PeerIdentity *peer,
+ const struct ConsensusSession *session)
{
- int i;
-
- for (i = 0; i < session->num_peers; i++)
+ for (int i = 0; i < session->num_peers; i++)
if (0 == GNUNET_memcmp (peer, &session->peers[i]))
return i;
return -1;
@@ -2528,14 +2551,15 @@ compute_global_id (struct ConsensusSession *session,
/**
- * Compare two peer identities.
+ * Compare two peer identities (for qsort()).
*
* @param h1 some peer identity
* @param h2 some peer identity
* @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.
*/
static int
-peer_id_cmp (const void *h1, const void *h2)
+peer_id_cmp (const void *h1,
+ const void *h2)
{
return memcmp (h1, h2, sizeof(struct GNUNET_PeerIdentity));
}
@@ -2549,9 +2573,9 @@ peer_id_cmp (const void *h1, const void *h2)
* @param join_msg join message with the list of peers participating at the end
*/
static void
-initialize_session_peer_list (struct ConsensusSession *session,
- const struct
- GNUNET_CONSENSUS_JoinMessage *join_msg)
+initialize_session_peer_list (
+ struct ConsensusSession *session,
+ const struct GNUNET_CONSENSUS_JoinMessage *join_msg)
{
const struct GNUNET_PeerIdentity *msg_peers
= (const struct GNUNET_PeerIdentity *) &join_msg[1];
@@ -2578,29 +2602,31 @@ initialize_session_peer_list (struct ConsensusSession *session,
struct GNUNET_PeerIdentity);
if (GNUNET_NO == local_peer_in_list)
session->peers[session->num_peers - 1] = my_peer;
-
GNUNET_memcpy (session->peers,
msg_peers,
- ntohl (join_msg->num_peers) * sizeof(struct
- GNUNET_PeerIdentity));
+ ntohl (join_msg->num_peers)
+ * sizeof(struct GNUNET_PeerIdentity));
qsort (session->peers,
session->num_peers,
- sizeof(struct GNUNET_PeerIdentity),
+ sizeof (struct GNUNET_PeerIdentity),
&peer_id_cmp);
}
static struct TaskEntry *
-lookup_task (struct ConsensusSession *session,
- struct TaskKey *key)
+lookup_task (const struct ConsensusSession *session,
+ const struct TaskKey *key)
{
struct GNUNET_HashCode hash;
-
- GNUNET_CRYPTO_hash (key, sizeof(struct TaskKey), &hash);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up task hash %s\n",
+ GNUNET_CRYPTO_hash (key,
+ sizeof(struct TaskKey),
+ &hash);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Looking up task hash %s\n",
GNUNET_h2s (&hash));
- return GNUNET_CONTAINER_multihashmap_get (session->taskmap, &hash);
+ return GNUNET_CONTAINER_multihashmap_get (session->taskmap,
+ &hash);
}
@@ -2695,7 +2721,7 @@ set_listen_cb (void *cls,
task->cls.setop.op = GNUNET_SET_accept (request,
GNUNET_SET_RESULT_SYMMETRIC,
opts,
- set_result_cb,
+ &set_result_cb,
task);
/* If the task hasn't been started yet,
@@ -2716,11 +2742,8 @@ put_task (struct GNUNET_CONTAINER_MultiHashMap *taskmap,
struct Step *s;
GNUNET_assert (NULL != t->step);
-
t = GNUNET_memdup (t, sizeof(struct TaskEntry));
-
s = t->step;
-
if (s->tasks_len == s->tasks_cap)
{
unsigned int target_size = 3 * (s->tasks_cap + 1) / 2;
@@ -2739,9 +2762,13 @@ put_task (struct GNUNET_CONTAINER_MultiHashMap *taskmap,
s->tasks[s->tasks_len] = t;
s->tasks_len++;
- GNUNET_CRYPTO_hash (&t->key, sizeof(struct TaskKey), &round_hash);
+ GNUNET_CRYPTO_hash (&t->key,
+ sizeof(struct TaskKey),
+ &round_hash);
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (taskmap, &round_hash, t,
+ GNUNET_CONTAINER_multihashmap_put (taskmap,
+ &round_hash,
+ t,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
}
@@ -2762,7 +2789,9 @@ install_step_timeouts (struct ConsensusSession *session)
* Arrange two peers in some canonical order.
*/
static void
-arrange_peers (uint16_t *p1, uint16_t *p2, uint16_t n)
+arrange_peers (uint16_t *p1,
+ uint16_t *p2,
+ uint16_t n)
{
uint16_t a;
uint16_t b;
@@ -2800,7 +2829,8 @@ arrange_peers (uint16_t *p1, uint16_t *p2, uint16_t n)
* Record @a dep as a dependency of @a step.
*/
static void
-step_depend_on (struct Step *step, struct Step *dep)
+step_depend_on (struct Step *step,
+ struct Step *dep)
{
/* We're not checking for cyclic dependencies,
but this is a cheap sanity check. */
@@ -2839,7 +2869,9 @@ step_depend_on (struct Step *step, struct Step *dep)
static struct Step *
-create_step (struct ConsensusSession *session, int round, int early_finishable)
+create_step (struct ConsensusSession *session,
+ int round,
+ int early_finishable)
{
struct Step *step;
@@ -2855,8 +2887,7 @@ create_step (struct ConsensusSession *session, int round, int early_finishable)
/**
- * Construct the task graph for a single
- * gradecast.
+ * Construct the task graph for a single gradecast.
*/
static void
construct_task_graph_gradecast (struct ConsensusSession *session,
@@ -2867,35 +2898,32 @@ construct_task_graph_gradecast (struct ConsensusSession *session,
{
uint16_t n = session->num_peers;
uint16_t me = session->local_peer_idx;
-
uint16_t p1;
uint16_t p2;
-
/* The task we're currently setting up. */
struct TaskEntry task;
-
struct Step *step;
struct Step *prev_step;
-
uint16_t round;
- unsigned int k;
-
round = step_before->round + 1;
/* gcast step 1: leader disseminates */
-
- step = create_step (session, round, GNUNET_YES);
-
+ step = create_step (session,
+ round,
+ GNUNET_YES);
#ifdef GNUNET_EXTRA_LOGGING
- GNUNET_asprintf (&step->debug_name, "disseminate leader %u rep %u", lead,
+ GNUNET_asprintf (&step->debug_name,
+ "disseminate leader %u rep %u",
+ lead,
rep);
#endif
- step_depend_on (step, step_before);
+ step_depend_on (step,
+ step_before);
if (lead == me)
{
- for (k = 0; k < n; k++)
+ for (unsigned int k = 0; k < n; k++)
{
if (k == me)
continue;
@@ -2952,13 +2980,19 @@ construct_task_graph_gradecast (struct ConsensusSession *session,
/* gcast phase 2: echo */
prev_step = step;
round += 1;
- step = create_step (session, round, GNUNET_YES);
+ step = create_step (session,
+ round,
+ GNUNET_YES);
#ifdef GNUNET_EXTRA_LOGGING
- GNUNET_asprintf (&step->debug_name, "echo leader %u rep %u", lead, rep);
+ GNUNET_asprintf (&step->debug_name,
+ "echo leader %u rep %u",
+ lead,
+ rep);
#endif
- step_depend_on (step, prev_step);
+ step_depend_on (step,
+ prev_step);
- for (k = 0; k < n; k++)
+ for (unsigned int k = 0; k < n; k++)
{
p1 = k;
p2 = me;
@@ -3001,7 +3035,7 @@ construct_task_graph_gradecast (struct ConsensusSession *session,
step_depend_on (step, prev_step);
/* gcast phase 3: confirmation and grading */
- for (k = 0; k < n; k++)
+ for (unsigned int k = 0; k < n; k++)
{
p1 = k;
p2 = me;
@@ -3050,22 +3084,15 @@ construct_task_graph (struct ConsensusSession *session)
{
uint16_t n = session->num_peers;
uint16_t t = n / 3;
-
uint16_t me = session->local_peer_idx;
-
/* The task we're currently setting up. */
struct TaskEntry task;
-
/* Current leader */
unsigned int lead;
-
struct Step *step;
struct Step *prev_step;
-
unsigned int round = 0;
- unsigned int i;
-
// XXX: introduce first step,
// where we wait for all insert acks
// from the set service
@@ -3082,7 +3109,7 @@ construct_task_graph (struct ConsensusSession *session)
step->debug_name = GNUNET_strdup ("all to all");
#endif
- for (i = 0; i < n; i++)
+ for (unsigned int i = 0; i < n; i++)
{
uint16_t p1;
uint16_t p2;
@@ -3111,7 +3138,7 @@ construct_task_graph (struct ConsensusSession *session)
step_depend_on (step, prev_step);
- for (i = 0; i < n; i++)
+ for (unsigned int i = 0; i < n; i++)
{
uint16_t p1;
uint16_t p2;
@@ -3140,7 +3167,7 @@ construct_task_graph (struct ConsensusSession *session)
/* Byzantine union */
/* sequential repetitions of the gradecasts */
- for (i = 0; i < t + 1; i++)
+ for (unsigned int i = 0; i < t + 1; i++)
{
struct Step *step_rep_start;
struct Step *step_rep_end;
@@ -3243,9 +3270,9 @@ handle_client_join (void *cls,
NULL != other_session;
other_session = other_session->next)
{
- if ((other_session != session) &&
- (0 == GNUNET_CRYPTO_hash_cmp (&session->global_id,
- &other_session->global_id)))
+ if ( (other_session != session) &&
+ (0 == GNUNET_CRYPTO_hash_cmp (&session->global_id,
+ &other_session->global_id)) )
break;
}
@@ -3262,9 +3289,9 @@ handle_client_join (void *cls,
GNUNET_h2s (&m->session_id),
session->num_peers,
session->local_peer_idx,
- GNUNET_STRINGS_relative_time_to_string
- (GNUNET_TIME_absolute_get_difference (session->conclude_start,
- session->conclude_deadline),
+ GNUNET_STRINGS_relative_time_to_string (
+ GNUNET_TIME_absolute_get_difference (session->conclude_start,
+ session->conclude_deadline),
GNUNET_YES));
session->set_listener
@@ -3309,13 +3336,6 @@ handle_client_join (void *cls,
}
-static void
-client_insert_done (void *cls)
-{
- // FIXME: implement
-}
-
-
/**
* Called when a client performs an insert operation.
*
@@ -3352,19 +3372,13 @@ handle_client_insert (void *cls,
GNUNET_SERVICE_client_drop (session->client);
return;
}
-
- element_size = ntohs (msg->header.size) - sizeof(struct
- GNUNET_CONSENSUS_ElementMessage);
+ element_size = ntohs (msg->header.size) - sizeof(*msg);
ce = GNUNET_malloc (sizeof(struct ConsensusElement) + element_size);
- GNUNET_memcpy (&ce[1], &msg[1], element_size);
+ GNUNET_memcpy (&ce[1],
+ &msg[1],
+ element_size);
ce->payload_type = msg->element_type;
- struct GNUNET_SET_Element element = {
- .element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT,
- .size = sizeof(struct ConsensusElement) + element_size,
- .data = ce,
- };
-
{
struct SetKey key = { SET_KIND_CURRENT, 0, 0 };
struct SetEntry *entry;
@@ -3376,19 +3390,25 @@ handle_client_insert (void *cls,
}
session->num_client_insert_pending++;
- GNUNET_SET_add_element (initial_set,
- &element,
- &client_insert_done,
- session);
-#ifdef GNUNET_EXTRA_LOGGING
{
+ struct GNUNET_SET_Element element = {
+ .element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT,
+ .size = sizeof(struct ConsensusElement) + element_size,
+ .data = ce,
+ };
+
+ GNUNET_SET_add_element (initial_set,
+ &element,
+ NULL,
+ NULL);
+#ifdef GNUNET_EXTRA_LOGGING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"P%u: element %s added\n",
session->local_peer_idx,
debug_str_element (&element));
- }
#endif
+ }
GNUNET_free (ce);
GNUNET_SERVICE_client_continue (session->client);
}
@@ -3513,10 +3533,10 @@ client_disconnect_cb (void *cls,
GNUNET_CONTAINER_DLL_remove (sessions_head,
sessions_tail,
session);
-
while (session->set_handles_head)
{
struct SetHandle *sh = session->set_handles_head;
+
session->set_handles_head = sh->next;
GNUNET_SET_destroy (sh->h);
GNUNET_free (sh);
@@ -3528,8 +3548,8 @@ client_disconnect_cb (void *cls,
/**
* Define "main" method using service macro.
*/
-GNUNET_SERVICE_MAIN
- ("consensus",
+GNUNET_SERVICE_MAIN (
+ "consensus",
GNUNET_SERVICE_OPTION_NONE,
&run,
&client_connect_cb,
diff --git a/src/consensus/plugin_block_consensus.c b/src/consensus/plugin_block_consensus.c
index fb6da5bcd..cdac12ed5 100644
--- a/src/consensus/plugin_block_consensus.c
+++ b/src/consensus/plugin_block_consensus.c
@@ -58,13 +58,12 @@ block_plugin_consensus_evaluate (void *cls,
const void *reply_block,
size_t reply_block_size)
{
- if (reply_block_size < sizeof(struct ConsensusElement))
- return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
-
const struct ConsensusElement *ce = reply_block;
- if ((0 != ce->marker) ||
- (0 == ce->payload_type))
+ if (reply_block_size < sizeof(struct ConsensusElement))
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ if ( (0 != ce->marker) ||
+ (0 == ce->payload_type) )
return GNUNET_BLOCK_EVALUATION_OK_MORE;
return GNUNET_BLOCK_evaluate (ctx,
@@ -75,8 +74,8 @@ block_plugin_consensus_evaluate (void *cls,
xquery,
xquery_size,
&ce[1],
- reply_block_size - sizeof(struct
- ConsensusElement));
+ reply_block_size
+ - sizeof(struct ConsensusElement));
}
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 8c3f4f058..03fb16a43 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -619,7 +619,7 @@ GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode *block,
* @param result where to store the hash code
* @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CRYPTO_hash_from_string2 (const char *enc,
size_t enclen,
struct GNUNET_HashCode *result);
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 0dbe9dbe8..94b6f5099 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -94,7 +94,7 @@ GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode *block,
* @param result where to store the hash code
* @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_CRYPTO_hash_from_string2 (const char *enc,
size_t enclen,
struct GNUNET_HashCode *result)