2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_consensus_service.h
24 * @author Florian Dold
27 #ifndef GNUNET_CONSENSUS_SERVICE_H
28 #define GNUNET_CONSENSUS_SERVICE_H
33 #if 0 /* keep Emacsens' auto-indent happy */
39 #include "gnunet_common.h"
40 #include "gnunet_time_lib.h"
44 * Called when a new element was received from another peer; elements
45 * given to a consensus operation by the local peer are NOT given
49 * @param element_size will match the size given to GNUNET_CONSENSUS_create
52 typedef void (*GNUNET_CONSENSUS_NewElementCallback) (void *cls,
58 * Called when a conclusion was successful.
61 * @param num_peers_in_consensus
62 * @param peers_in_consensus
64 typedef void (*GNUNET_CONSENSUS_ConcludeCallback) (void *cls,
65 unsigned int num_peers_in_consensus,
66 cnost struct GNUNET_PeerIdentity *peers_in_consensus);
70 * Opaque handle for the consensus service.
72 struct GNUNET_CONSENSUS_Handle;
76 * Create a consensus session.
80 * @param peers array of peers participating in this consensus session
81 * @param session_id session identifier
82 * Allows a group of peers to have more than consensus session.
83 * @param element_size size of the elements in the reconciled set in bytes
84 * @param new_element callback, called when a new element is added to the set by
86 * @param cls closure for new_element
88 * @return handle to use
90 struct GNUNET_CONSENSUS_Handle *
91 GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
92 unsigned int num_peers,
93 const struct GNUNET_PeerIdentity *peers,
94 const struct GNUNET_HashCode *session_id,
96 const void **initial_elements,
97 GNUNET_CONSENSUS_NewElementCallback new_element,
98 void *new_element_cls);
103 * Insert an element in the set being reconsiled. Must not be called after
104 * "GNUNET_CONSENSUS_conclude".
106 * @param consensus handle for the consensus session
107 * @param element_size must match element size from GNUNET_CONSENSUS_create
108 * @param element the element to be inserted
111 GNUNET_CONSENSUS_insert (struct GNUNET_CONSENSUS_Handle *consensus,
113 const void *element);
117 * We are finished inserting new elements into the consensus;
118 * try to conclude the consensus within a given time window.
120 * @param consensus consensus session
121 * @param timeout timeout after which the conculde callback
123 * @param conclude called when the conclusion was successful
124 * @param conclude_cls closure for the conclude callback
127 GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus,
128 struct GNUNET_TIME_Relative timeout,
129 GNUNET_CONSENSUS_ConcludeCallback conclude,
134 * Destroy a consensus handle (free all state associated with
135 * it, no longer call any of the callbacks).
137 * @param consensus handle to destroy
140 GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus);
143 #if 0 /* keep Emacsens' auto-indent happy */