27#include "gnunet_dht_block_types.h"
571 default:
return "(unknown)";
587 default:
return "(unknown)";
603 default:
return "(unknown)";
621 default:
return "(unknown)";
626#ifdef GNUNET_EXTRA_LOGGING
641debug_str_task_key (
const struct TaskKey *tk)
643 static char buf[256];
645 snprintf (buf,
sizeof(buf),
646 "TaskKey kind=%s, p1=%d, p2=%d, l=%d, rep=%d",
655debug_str_diff_key (
const struct DiffKey *dk)
657 static char buf[256];
659 snprintf (buf,
sizeof(buf),
660 "DiffKey kind=%s, k1=%d, k2=%d",
668debug_str_set_key (
const struct SetKey *sk)
670 static char buf[256];
672 snprintf (buf,
sizeof(buf),
673 "SetKey kind=%s, k1=%d, k2=%d",
682debug_str_rfn_key (
const struct RfnKey *rk)
684 static char buf[256];
686 snprintf (buf,
sizeof(buf),
687 "RfnKey kind=%s, k1=%d, k2=%d",
731 "P%d: sending element %s to client\n",
733 debug_str_element (element));
748 "P%d: finished iterating elements for client\n",
766 "P%u: looking up set {%s}\n",
768 debug_str_set_key (
key));
786 "P%u: looking up diff {%s}\n",
788 debug_str_diff_key (
key));
805 "P%u: looking up rfn {%s}\n",
807 debug_str_rfn_key (
key));
828 "diff_insert with element size %u\n",
832 "hashing element\n");
858 uint16_t commit_peer)
868 uint16_t contested_peer)
882 for (uint16_t i = 0; i < rfn->
num_peers; i++)
893 uint16_t voting_peer,
939 uint64_t a = *(uint64_t *) pa;
940 uint64_t b = *(uint64_t *) pb;
962 uint64_t current_size,
970 unsigned int other_idx;
977 "P%u: got element of type %u, status %u\n",
983 consensus_element = element->
data;
990 "P%u: got set result for {%s}, status %u\n",
992 debug_str_task_key (&task->
key),
1038 if ((NULL != consensus_element) && (0 != consensus_element->
marker))
1041 "P%u: got some marker\n",
1054 "P%u: got size marker\n",
1074 "P%u: lower bound %llu\n",
1091 "Adding element in Task {%s}\n",
1092 debug_str_task_key (&task->
key));
1093 if (NULL != output_set)
1100#ifdef GNUNET_EXTRA_LOGGING
1102 "P%u: adding element %s into set {%s} of task {%s}\n",
1104 debug_str_element (element),
1106 debug_str_task_key (&task->
key));
1109 if (NULL != output_diff)
1112#ifdef GNUNET_EXTRA_LOGGING
1114 "P%u: adding element %s into diff {%s} of task {%s}\n",
1116 debug_str_element (element),
1118 debug_str_task_key (&task->
key));
1121 if (NULL != output_rfn)
1124#ifdef GNUNET_EXTRA_LOGGING
1126 "P%u: adding element %s into rfn {%s} of task {%s}\n",
1128 debug_str_element (element),
1130 debug_str_task_key (&task->
key));
1143 "Removing element in Task {%s}\n",
1144 debug_str_task_key (&task->
key));
1145 if (NULL != output_set)
1152#ifdef GNUNET_EXTRA_LOGGING
1154 "P%u: removing element %s from set {%s} of task {%s}\n",
1156 debug_str_element (element),
1158 debug_str_task_key (&task->
key));
1161 if (NULL != output_diff)
1164#ifdef GNUNET_EXTRA_LOGGING
1166 "P%u: removing element %s from diff {%s} of task {%s}\n",
1168 debug_str_element (element),
1170 debug_str_task_key (&task->
key));
1173 if (NULL != output_rfn)
1176#ifdef GNUNET_EXTRA_LOGGING
1178 "P%u: removing element %s from rfn {%s} of task {%s}\n",
1180 debug_str_element (element),
1182 debug_str_task_key (&task->
key));
1191 "P%u: Finishing setop in Task {%s} (%u/%u)\n",
1193 debug_str_task_key (&task->
key),
1196 if (NULL != output_rfn)
1235 EVILNESS_SUB_REPLACEMENT,
1236 EVILNESS_SUB_NO_REPLACEMENT,
1241 enum EvilnessType
type;
1242 enum EvilnessSubType subtype;
1248parse_evilness_cram_subtype (
const char *evil_subtype_str,
1249 struct Evilness *evil)
1251 if (0 == strcmp (
"replace", evil_subtype_str))
1253 evil->subtype = EVILNESS_SUB_REPLACEMENT;
1255 else if (0 == strcmp (
"noreplace", evil_subtype_str))
1257 evil->subtype = EVILNESS_SUB_NO_REPLACEMENT;
1262 "Malformed field '%s' in EVIL_SPEC (unknown subtype), behaving like a good peer.\n",
1275 char *evil_type_str = NULL;
1276 char *evil_subtype_str = NULL;
1285 "P%u: no evilness\n",
1287 evil->type = EVILNESS_NONE;
1291 "P%u: got evilness spec\n",
1294 for (field = strtok (evil_spec,
"/");
1296 field = strtok (NULL,
"/"))
1298 unsigned int peer_num;
1299 unsigned int evil_num;
1302 evil_type_str = NULL;
1303 evil_subtype_str = NULL;
1305 ret = sscanf (field,
"%u;%m[a-z-];%m[a-z-];%u", &peer_num, &evil_type_str,
1306 &evil_subtype_str, &evil_num);
1311 "Malformed field '%s' in EVIL_SPEC (expected 4 components got %d), behaving like a good peer.\n",
1322 if (0 == strcmp (
"slack", evil_type_str))
1324 evil->type = EVILNESS_SLACK;
1326 if (0 == strcmp (
"slack-a2a", evil_type_str))
1328 evil->type = EVILNESS_SLACK_A2A;
1330 else if (0 == strcmp (
"cram-all", evil_type_str))
1332 evil->type = EVILNESS_CRAM_ALL;
1333 evil->num = evil_num;
1334 if (
GNUNET_OK != parse_evilness_cram_subtype (evil_subtype_str, evil))
1337 else if (0 == strcmp (
"cram-lead", evil_type_str))
1339 evil->type = EVILNESS_CRAM_LEAD;
1340 evil->num = evil_num;
1341 if (
GNUNET_OK != parse_evilness_cram_subtype (evil_subtype_str, evil))
1344 else if (0 == strcmp (
"cram-echo", evil_type_str))
1346 evil->type = EVILNESS_CRAM_ECHO;
1347 evil->num = evil_num;
1348 if (
GNUNET_OK != parse_evilness_cram_subtype (evil_subtype_str, evil))
1354 "Malformed field '%s' in EVIL_SPEC (unknown type), behaving like a good peer.\n",
1361 free (evil_type_str);
1362 evil_type_str = NULL;
1363 evil_subtype_str = NULL;
1366 evil->type = EVILNESS_NONE;
1371 if (NULL != evil_type_str)
1372 free (evil_type_str);
1373 if (NULL != evil_subtype_str)
1374 free (evil_subtype_str);
1419 element.
data = &cse;
1427 struct Evilness evil;
1429 get_evilness (session, &evil);
1430 if (EVILNESS_NONE != evil.type)
1440 case EVILNESS_CRAM_ALL:
1441 case EVILNESS_CRAM_LEAD:
1442 case EVILNESS_CRAM_ECHO:
1452 if ((EVILNESS_CRAM_LEAD == evil.type) &&
1465 for (
unsigned int i = 0; i < evil.num; i++)
1476 if (EVILNESS_SUB_REPLACEMENT == evil.subtype)
1482 else if (EVILNESS_SUB_NO_REPLACEMENT == evil.subtype)
1492#ifdef GNUNET_EXTRA_LOGGING
1494 "P%u: evil peer: cramming element %s into set {%s} of task {%s}\n",
1496 debug_str_element (&element),
1498 debug_str_task_key (&task->
key));
1502 "# stuffed elements",
1508 case EVILNESS_SLACK:
1510 "P%u: evil peer: slacking\n",
1514 case EVILNESS_SLACK_A2A:
1579 debug_str_set_key (&set->
key));
1617 uint16_t voting_peer,
1628 (
const void **) &di))
1671 (
const void **) &di))
1683 (
const void **) &di))
1733 uint16_t *ret_majority,
1736 uint16_t votes_yes = 0;
1737 uint16_t num_commited = 0;
1740 "Computing rfn majority for element %s of rfn {%s}\n",
1741 debug_str_element (ri->
element),
1742 debug_str_rfn_key (&rfn->
key));
1744 for (uint16_t i = 0; i < rfn->
num_peers; i++)
1754 if (votes_yes > (num_commited) / 2)
1757 *ret_majority = votes_yes;
1762 *ret_majority = num_commited - votes_yes;
1792 set->
key = dst_set_key;
1805 struct SetKey *src_set_key,
1806 struct SetKey *dst_set_key)
1812 "Copying set {%s} to {%s} for task {%s}\n",
1813 debug_str_set_key (src_set_key),
1815 debug_str_task_key (&
task->
key));
1846 if (0 ==
pc->num_pending)
1867#ifdef GNUNET_EXTRA_LOGGING
1869 "Finishing step `%s' early.\n",
1877#ifdef GNUNET_EXTRA_LOGGING
1879 "Decreased pending_prereq to %u for step `%s'.\n",
1898#ifdef GNUNET_EXTRA_LOGGING
1900 "All tasks of step `%s' with %u subordinates finished.\n",
1909#ifdef GNUNET_EXTRA_LOGGING
1911 "Decreased pending_prereq to %u for step `%s'.\n",
1942 uint16_t worst_majority = UINT16_MAX;
1949 if (NULL == set_out)
1961 progress_cls->
task = task;
1968 (
const void **) &ri))
1970 uint16_t majority_num;
1973 rfn_majority (rfn_in, ri, &majority_num, &majority_vote);
1975 if (worst_majority > majority_num)
1976 worst_majority = majority_num;
1978 switch (majority_vote)
1988 "P%u: apply round: adding element %s with %u-majority.\n",
1990 debug_str_element (ri->
element), majority_num);
2001 "P%u: apply round: deleting element %s with %u-majority.\n",
2003 debug_str_element (ri->
element), majority_num);
2008 "P%u: apply round: keeping element %s with %u-majority.\n",
2010 debug_str_element (ri->
element), majority_num);
2028 uint16_t thresh = (session->
num_peers / 3) * 2;
2030 if (worst_majority >= thresh)
2037 "P%u: Stopping early (after one more superround)\n",
2043 "P%u: finishing steps due to early finish\n",
2072 "P%u: NOT finishing early (majority not good enough)\n",
2091 unsigned int gradecast_confidence = 2;
2095 if (NULL == output_rfn)
2098 output_rfn->
key = rfn_key;
2099 put_rfn (session, output_rfn);
2121 (
const void **) &ri))
2123 uint16_t majority_num;
2127 rfn_majority (input_rfn, ri, &majority_num, &majority_vote);
2129 if (majority_num <= session->
num_peers / 3)
2132 switch (majority_vote)
2153 uint16_t noncontested;
2155 if (noncontested < (session->
num_peers / 3) * 2)
2157 gradecast_confidence =
GNUNET_MIN (1, gradecast_confidence);
2159 if (noncontested < (session->
num_peers / 3) + 1)
2161 gradecast_confidence = 0;
2165 if (gradecast_confidence >= 1)
2168 if (gradecast_confidence <= 1)
2211 "P%u: output rfn <%s> missing, creating.\n",
2246 "P%u: Looking up set {%s} to run remote union\n",
2260 "P%u: initiating set op with P%u, our set is %s\n",
2290 if (NULL != setop->
op)
2321 if (NULL == output_set)
2334 last_set->
h = output_set->
h;
2340 "Evaluating referendum in Task {%s}\n",
2341 debug_str_task_key (&task->
key));
2344 progress_cls->
task = task;
2356 (
const void **) &ri))
2359 uint16_t majority_num;
2361 rfn_majority (input_rfn, ri, &majority_num, &majority_vote);
2363 if (majority_num < session->
num_peers / 3)
2374 switch (majority_vote)
2435 "P%u: starting task {%s}\n",
2437 debug_str_task_key (&task->
key));
2457 while (NULL != step)
2464#ifdef GNUNET_EXTRA_LOGGING
2466 "P%u: Running step `%s' of round %d with %d tasks and %d subordinates\n",
2473 for (
size_t i = 0; i < step->
tasks_len; i++)
2498 "P%u: Finishing Task {%s} (now %u/%u tasks finished in step)\n",
2500 debug_str_task_key (&task->
key),
2540 const char *
salt =
"gnunet-service-consensus/session_id";
2585 int local_peer_in_list;
2592 for (
unsigned int i = 0; i < session->
num_peers; i++)
2612 qsort (session->
peers,
2629 "Looking up task hash %s\n",
2662 if (NULL == context_msg)
2685 .kind = ntohs (cm->
kind),
2686 .peer1 = ntohs (cm->
peer1),
2687 .peer2 = ntohs (cm->
peer2),
2689 .leader = ntohs (cm->
leader),
2753 unsigned int target_size = 3 * (s->
tasks_cap + 1) / 2;
2759#ifdef GNUNET_EXTRA_LOGGING
2762 debug_str_task_key (&
t->key),
2819 if (((b - a) + n) % n <= n / 2)
2846#ifdef GNUNET_EXTRA_LOGGING
2853 "Making step `%s' depend on `%s'\n",
2900 struct Step *step_before,
2901 struct Step *step_after)
2910 struct Step *prev_step;
2919#ifdef GNUNET_EXTRA_LOGGING
2921 "disseminate leader %u rep %u",
2930 for (
unsigned int k = 0; k < n; k++)
2990#ifdef GNUNET_EXTRA_LOGGING
2992 "echo leader %u rep %u",
2999 for (
unsigned int k = 0; k < n; k++)
3019#ifdef GNUNET_EXTRA_LOGGING
3036#ifdef GNUNET_EXTRA_LOGGING
3042 for (
unsigned int k = 0; k < n; k++)
3068#ifdef GNUNET_EXTRA_LOGGING
3097 struct Step *prev_step;
3098 unsigned int round = 0;
3112#ifdef GNUNET_EXTRA_LOGGING
3116 for (
unsigned int i = 0; i < n; i++)
3139#ifdef GNUNET_EXTRA_LOGGING
3145 for (
unsigned int i = 0; i < n; i++)
3174 for (
unsigned int i = 0; i <
t + 1; i++)
3176 struct Step *step_rep_start;
3177 struct Step *step_rep_end;
3181#ifdef GNUNET_EXTRA_LOGGING
3190#ifdef GNUNET_EXTRA_LOGGING
3195 for (lead = 0; lead < n; lead++)
3200 .step = step_rep_end,
3206 prev_step = step_rep_end;
3213#ifdef GNUNET_EXTRA_LOGGING
3240 uint32_t listed_peers = ntohl (
m->num_peers);
3242 if ((ntohs (
m->header.size) -
sizeof(*
m)) !=
3274 NULL != other_session;
3275 other_session = other_session->
next)
3277 if ( (other_session != session) &&
3292 "Joining consensus session %s containing %u peers as %u with timeout %s\n",
3324 sh->h = client_set->
h;
3369 ssize_t element_size;
3379 element_size = ntohs (
msg->header.
size) -
sizeof(*msg);
3393 initial_set = entry->
h;
3409#ifdef GNUNET_EXTRA_LOGGING
3411 "P%u: element %s added\n",
3413 debug_str_element (&element));
3441 "conclude requested\n");
3483 "Could not retrieve host identity\n");
struct GNUNET_MQ_Handle * mq
struct GNUNET_MessageHeader * msg
p2p message definitions for consensus
@ CONSENSUS_MARKER_CONTESTED
static mp_limb_t d[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
static int ret
Final status code.
static unsigned int phase
Processing stage that we are in.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static void cleanup(void *cls)
Disconnect and shutdown.
static struct GNUNET_IDENTITY_Handle * sh
Handle to IDENTITY service.
static struct GNUNET_IDENTITY_EgoLookup * el
Handle to identity lookup.
static uint32_t type
Type string converted to DNS type value.
static int status
The program status; 0 for success.
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
static struct GNUNET_CRYPTO_PowSalt salt
Salt for PoW calculations.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
static void rfn_contest(struct ReferendumEntry *rfn, uint16_t contested_peer)
static void rfn_vote(struct ReferendumEntry *rfn, uint16_t voting_peer, enum ReferendumVote vote, const struct GNUNET_SET_Element *element)
static void handle_client_join(void *cls, const struct GNUNET_CONSENSUS_JoinMessage *m)
Called when a client wants to join a consensus session.
static int get_peer_idx(const struct GNUNET_PeerIdentity *peer, const struct ConsensusSession *session)
Search peer in the list of peers in session.
static void task_start_grade(struct TaskEntry *task)
static struct ConsensusSession * sessions_head
Linked list of sessions this peer participates in.
static uint16_t task_other_peer(struct TaskEntry *task)
static void handle_client_insert(void *cls, const struct GNUNET_CONSENSUS_ElementMessage *msg)
Called when a client performs an insert operation.
static struct SetEntry * lookup_set(struct ConsensusSession *session, const struct SetKey *key)
static void apply_diff_to_rfn(struct DiffEntry *diff, struct ReferendumEntry *rfn, uint16_t voting_peer, uint16_t num_peers)
static struct Step * create_step(struct ConsensusSession *session, int round, int early_finishable)
static void arrange_peers(uint16_t *p1, uint16_t *p2, uint16_t n)
static void start_task(struct ConsensusSession *session, struct TaskEntry *task)
static void initialize_session_peer_list(struct ConsensusSession *session, const struct GNUNET_CONSENSUS_JoinMessage *join_msg)
Create the sorted list of peers for the session, add the local peer if not in the join message.
@ DIFF_KIND_LEADER_PROPOSAL
@ DIFF_KIND_LEADER_CONSENSUS
@ DIFF_KIND_GRADECAST_RESULT
static void compute_global_id(struct ConsensusSession *session, const struct GNUNET_HashCode *local_session_id)
Compute a global, (hopefully) unique consensus session id, from the local id of the consensus session...
static void set_listen_cb(void *cls, const struct GNUNET_PeerIdentity *other_peer, const struct GNUNET_MessageHeader *context_msg, struct GNUNET_SET_Request *request)
Called when another peer wants to do a set operation with the local peer.
@ PHASE_KIND_GRADECAST_CONFIRM
@ PHASE_KIND_GRADECAST_ECHO
@ PHASE_KIND_ALL_TO_ALL_2
@ PHASE_KIND_APPLY_REP
Apply a repetition of the all-to-all gradecast to the current set.
@ PHASE_KIND_GRADECAST_LEADER
@ PHASE_KIND_GRADECAST_ECHO_GRADE
@ PHASE_KIND_GRADECAST_CONFIRM_GRADE
static struct DiffEntry * lookup_diff(struct ConsensusSession *session, const struct DiffKey *key)
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration of the consensus service.
static void finish_step(struct Step *step)
static int peer_id_cmp(const void *h1, const void *h2)
Compare two peer identities (for qsort()).
static void put_rfn(struct ConsensusSession *session, struct ReferendumEntry *rfn)
static void put_diff(struct ConsensusSession *session, struct DiffEntry *diff)
static void shutdown_task(void *cls)
Called to clean up, after a shutdown has been requested.
static void try_finish_step_early(struct Step *step)
static void put_set(struct ConsensusSession *session, struct SetEntry *set)
struct GNUNET_STATISTICS_Handle * statistics
Statistics handle.
static void task_cancel_reconcile(struct TaskEntry *task)
static const char * setname(uint16_t kind)
static void construct_task_graph(struct ConsensusSession *session)
@ VOTE_ADD
Vote that an element should be added.
@ VOTE_REMOVE
Vote that an element should be removed.
@ VOTE_STAY
Vote that nothing should change.
static void diff_insert(struct DiffEntry *diff, int weight, const struct GNUNET_SET_Element *element)
static void put_task(struct GNUNET_CONTAINER_MultiHashMap *taskmap, struct TaskEntry *t)
static void finish_task(struct TaskEntry *task)
static void construct_task_graph_gradecast(struct ConsensusSession *session, uint16_t rep, uint16_t lead, struct Step *step_before, struct Step *step_after)
Construct the task graph for a single gradecast.
static int check_client_join(void *cls, const struct GNUNET_CONSENSUS_JoinMessage *m)
Check join message.
@ RFN_KIND_GRADECAST_RESULT
static void task_start_finish(struct TaskEntry *task)
static void rfn_majority(const struct ReferendumEntry *rfn, const struct RfnElementInfo *ri, uint16_t *ret_majority, enum ReferendumVote *ret_vote)
For a given majority, count what the outcome is (add/remove/keep), and give the number of peers that ...
static void run_ready_steps(struct ConsensusSession *session)
static const char * phasename(uint16_t phase)
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
Start processing consensus requests.
static struct ConsensusSession * sessions_tail
Linked list of sessions this peer participates in.
static void task_start_reconcile(struct TaskEntry *task)
static void step_depend_on(struct Step *step, struct Step *dep)
Record dep as a dependency of step.
static void install_step_timeouts(struct ConsensusSession *session)
static struct ReferendumEntry * lookup_rfn(struct ConsensusSession *session, const struct RfnKey *key)
GNUNET_SERVICE_MAIN(GNUNET_OS_project_data_gnunet(), "consensus", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_fixed_size(client_conclude, GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_hd_var_size(client_insert, GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_INSERT, struct GNUNET_CONSENSUS_ElementMessage, NULL), GNUNET_MQ_hd_var_size(client_join, GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN, struct GNUNET_CONSENSUS_JoinMessage, NULL), GNUNET_MQ_handler_end())
Define "main" method using service macro.
static struct TaskEntry * lookup_task(const struct ConsensusSession *session, const struct TaskKey *key)
static void set_copy_cb(void *cls, struct GNUNET_SET_Handle *copy)
static void create_set_copy_for_task(struct TaskEntry *task, struct SetKey *src_set_key, struct SetKey *dst_set_key)
Call the start function of the given task again after we created a copy of the given set.
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq)
Callback called when a client connects to the service.
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls)
Callback called when a client disconnected from the service.
static uint16_t rfn_noncontested(struct ReferendumEntry *rfn)
static void set_result_cb(void *cls, const struct GNUNET_SET_Element *element, uint64_t current_size, enum GNUNET_SET_Status status)
Callback for set operation results.
@ SET_KIND_LEADER_PROPOSAL
@ SET_KIND_LAST_GRADECAST
Last result set from a gradecast.
static int cmp_uint64_t(const void *pa, const void *pb)
static const char * rfnname(uint16_t kind)
static void commit_set(struct ConsensusSession *session, struct TaskEntry *task)
Commit the appropriate set for a task.
static struct ReferendumEntry * rfn_create(uint16_t size)
static const char * diffname(uint16_t kind)
static struct DiffEntry * diff_create(void)
static void rfn_commit(struct ReferendumEntry *rfn, uint16_t commit_peer)
static void task_start_apply_round(struct TaskEntry *task)
Apply the result from one round of gradecasts (i.e.
static int check_client_insert(void *cls, const struct GNUNET_CONSENSUS_ElementMessage *msg)
Called when a client performs an insert operation.
@ EARLY_STOPPING_ONE_MORE
static int send_to_client_iter(void *cls, const struct GNUNET_SET_Element *element)
Send the final result set of the consensus to the client, element by element.
static struct GNUNET_PeerIdentity my_peer
Peer that runs this service.
void(* TaskFunc)(struct TaskEntry *task)
static void set_mutation_done(void *cls)
static void task_start_eval_echo(struct TaskEntry *task)
static void handle_client_conclude(void *cls, const struct GNUNET_MessageHeader *message)
Called when a client performs the conclude operation.
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
static struct GNUNET_SCHEDULER_Task * t
Main task.
static unsigned int num_peers
Number of peers.
Constants for network protocols.
API to create, modify and access statistics.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_get_peer_identity(const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_PeerIdentity *dst)
Retrieve the identity of the host's peer.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
void GNUNET_CRYPTO_hash_create_random(enum GNUNET_CRYPTO_Quality mode, struct GNUNET_HashCode *result)
Create a random hash code.
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_iterator_next(struct GNUNET_CONTAINER_MultiHashMapIterator *iter, struct GNUNET_HashCode *key, const void **value)
Retrieve the next element from the hash map at the iterator's position.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
void GNUNET_CONTAINER_multihashmap_iterator_destroy(struct GNUNET_CONTAINER_MultiHashMapIterator *iter)
Destroy a multihashmap iterator.
struct GNUNET_CONTAINER_MultiHashMapIterator * GNUNET_CONTAINER_multihashmap_iterator_create(const struct GNUNET_CONTAINER_MultiHashMap *map)
Create an iterator for a multihashmap.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE
If a value with the given key exists, replace it.
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_PACKED
gcc-ism to get packed structs.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg_header(type)
Allocate a GNUNET_MQ_Envelope, where the message only consists of a header.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
#define GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN
Join a consensus session.
#define GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE_DONE
Sent by service to client in order to signal a completed consensus conclusion.
#define GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT
Sent by service when a new element is added.
#define GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_INSERT
Insert an element.
#define GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE
Sent by client to service in order to start the consensus conclusion.
#define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT
Provide context for a consensus round.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
@ GNUNET_SERVICE_OPTION_NONE
Use defaults.
GNUNET_SET_Status
Status for the result callback.
void GNUNET_SET_destroy(struct GNUNET_SET_Handle *set)
Destroy the set handle if no operations are left, mark the set for destruction otherwise.
void GNUNET_SET_copy_lazy(struct GNUNET_SET_Handle *set, GNUNET_SET_CopyReadyCallback cb, void *cls)
struct GNUNET_SET_Element * GNUNET_SET_element_dup(const struct GNUNET_SET_Element *element)
Create a copy of an element.
void GNUNET_SET_listen_cancel(struct GNUNET_SET_ListenHandle *lh)
Cancel the given listen operation.
int GNUNET_SET_remove_element(struct GNUNET_SET_Handle *set, const struct GNUNET_SET_Element *element, GNUNET_SET_Continuation cont, void *cont_cls)
Remove an element to the given set.
int GNUNET_SET_iterate(struct GNUNET_SET_Handle *set, GNUNET_SET_ElementIterator iter, void *iter_cls)
Iterate over all elements in the given set.
void GNUNET_SET_operation_cancel(struct GNUNET_SET_OperationHandle *oh)
Cancel the given set operation.
struct GNUNET_SET_Handle * GNUNET_SET_create(const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_SET_OperationType op)
Create an empty set, supporting the specified operation.
int GNUNET_SET_commit(struct GNUNET_SET_OperationHandle *oh, struct GNUNET_SET_Handle *set)
Commit a set to be used with a set operation.
struct GNUNET_SET_ListenHandle * GNUNET_SET_listen(const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_SET_OperationType operation, const struct GNUNET_HashCode *app_id, GNUNET_SET_ListenCallback listen_cb, void *listen_cls)
Wait for set operation requests for the given application id.
struct GNUNET_SET_OperationHandle * GNUNET_SET_prepare(const struct GNUNET_PeerIdentity *other_peer, const struct GNUNET_HashCode *app_id, const struct GNUNET_MessageHeader *context_msg, enum GNUNET_SET_ResultMode result_mode, struct GNUNET_SET_Option options[], GNUNET_SET_ResultIterator result_cb, void *result_cls)
Prepare a set operation to be evaluated with another peer.
struct GNUNET_SET_OperationHandle * GNUNET_SET_accept(struct GNUNET_SET_Request *request, enum GNUNET_SET_ResultMode result_mode, struct GNUNET_SET_Option options[], GNUNET_SET_ResultIterator result_cb, void *result_cls)
Accept a request we got via GNUNET_SET_listen().
int GNUNET_SET_add_element(struct GNUNET_SET_Handle *set, const struct GNUNET_SET_Element *element, GNUNET_SET_Continuation cont, void *cont_cls)
Add an element to the given set.
void GNUNET_SET_element_hash(const struct GNUNET_SET_Element *element, struct GNUNET_HashCode *ret_hash)
Hash a set element.
@ GNUNET_SET_STATUS_FAILURE
The other peer refused to to the operation with us, or something went wrong.
@ GNUNET_SET_STATUS_ADD_REMOTE
Element should be added to the result set of the remote peer, i.e.
@ GNUNET_SET_STATUS_DONE
Success, all elements have been sent (and received).
@ GNUNET_SET_STATUS_ADD_LOCAL
Element should be added to the result set of the local peer, i.e.
@ GNUNET_SET_OPTION_END
List terminator.
@ GNUNET_SET_OPTION_BYZANTINE
Fail set operations when the other peer shows weird behavior that might by a Byzantine fault.
@ GNUNET_SET_RESULT_SYMMETRIC
Client gets notified of the required changes for both the local and the remote set.
@ GNUNET_SET_OPERATION_UNION
Set union, return all elements that are in at least one of the sets.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
static unsigned int size
Size of the "table".
@ GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT
Block type for consensus elements.
Consensus element, either marker or payload.
uint16_t payload_type
Payload element_type, only valid if this is not a marker element.
uint8_t marker
Is this a marker element?
A consensus session consists of one local client and the remote authorities.
struct GNUNET_HashCode global_id
Global consensus identification, computed from the session id and participating authorities.
struct GNUNET_TIME_Absolute conclude_start
Time when the conclusion of the consensus should begin.
struct GNUNET_CONTAINER_MultiHashMap * diffmap
struct SetHandle * set_handles_tail
struct GNUNET_CONTAINER_MultiHashMap * rfnmap
unsigned int local_peer_idx
Index of the local peer in the peers array.
unsigned int num_peers
Number of other peers in the consensus.
struct ConsensusSession * prev
Consensus sessions are kept in a DLL.
struct GNUNET_PeerIdentity * peers
struct GNUNET_TIME_Absolute conclude_deadline
Timeout for all rounds together, single rounds will schedule a timeout task with a fraction of the co...
struct GNUNET_MQ_Handle * client_mq
Queued messages to the client.
uint64_t first_size
Our set size from the first round.
struct GNUNET_SERVICE_Client * client
Client that inhabits the session.
struct GNUNET_SET_ListenHandle * set_listener
Listener for requests from other peers.
struct ConsensusSession * next
Consensus sessions are kept in a DLL.
int * peers_blacklisted
Array of peers with length 'num_peers'.
unsigned int num_client_insert_pending
uint64_t * first_sizes_received
uint64_t lower_bound
Bounded Eppstein lower bound.
struct SetHandle * set_handles_head
int early_stopping
State of our early stopping scheme.
struct GNUNET_CONTAINER_MultiHashMap * setmap
struct GNUNET_CONTAINER_MultiHashMap * taskmap
struct ConsensusElement ce
struct GNUNET_HashCode rand
struct ConsensusElement ce
int weight
Positive weight for 'add', negative weights for 'remove'.
const struct GNUNET_SET_Element * element
struct GNUNET_CONTAINER_MultiHashMap * changes
Sent by the client to the service, when the client wants the service to join a consensus session.
uint32_t num_peers
Number of peers (at the end of this message) that want to participate in the consensus.
Sent as context message for set reconciliation.
int16_t repetition
Repetition of the gradecast phase.
int16_t peer1
Number of the first peer in canonical order.
int16_t leader
Leader in the gradecast phase.
int16_t peer2
Number of the second peer in canonical order.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT.
uint16_t kind
A value from 'enum PhaseKind'.
uint16_t is_contested
Non-zero if this set reconciliation had elements removed because they were contested.
Cursor into a multihashmap.
Internal representation of the hash map.
Handle to a message queue.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Handle to a client that is connected to a service.
uint16_t size
Number of bytes in the buffer pointed to by data.
const void * data
Actual data of the element.
uint16_t element_type
Application-specific element type.
Opaque handle to a listen operation.
Option for set operations.
Handle for a set operation request from another peer.
Time for absolute times used by GNUnet, in microseconds.
int * peer_commited
Stores, for every peer in the session, whether the peer finished the whole referendum.
struct GNUNET_CONTAINER_MultiHashMap * rfn_elements
int * peer_contested
Contestation state of the peer.
enum ReferendumVote proposal
Proposal for this element, can only be VOTE_ADD or VOTE_REMOVE.
int * votes
GNUNET_YES if the peer votes for the proposal.
const struct GNUNET_SET_Element * element
struct SetKey dst_set_key
int is_contested
GNUNET_YES if the set resulted from applying a referendum with contested elements.
struct GNUNET_SET_Handle * h
struct GNUNET_SET_Handle * h
int k1
Repetition counter.
struct TaskEntry * task
Task to finish once all changes are through.
struct DiffKey output_diff
struct GNUNET_SET_OperationHandle * op
unsigned int subordinates_cap
unsigned int round
Synchrony round of the task.
int early_finishable
When we're doing an early finish, how should this step be treated? If GNUNET_YES, the step will be ma...
struct GNUNET_SCHEDULER_Task * timeout_task
Task that will run this step despite any pending prerequisites.
size_t pending_prereq
Counter for the prerequisites of this step.
char * debug_name
Human-readable name for the task, used for debugging.
struct Step * next
All steps of one session are in a linked list for easier deallocation.
struct ConsensusSession * session
struct TaskEntry ** tasks
Tasks that this step is composed of.
struct Step ** subordinates
unsigned int finished_tasks
struct Step * prev
All steps of one session are in a linked list for easier deallocation.
unsigned int subordinates_len
Tuple of integers that together identify a task uniquely.
uint16_t kind
A value from 'enum PhaseKind'.
int16_t peer1
Number of the first peer in canonical order.
int16_t peer2
Number of the second peer in canonical order.
int16_t repetition
Repetition of the gradecast phase.
int16_t leader
Leader in the gradecast phase.
Closure for both start_task and cancel_task.