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"
41 #include "gnunet_configuration_lib.h"
45 * An element of the consensus set.
47 struct GNUNET_CONSENSUS_Element
50 * The actual data of the element.
55 * Size of the element's data.
60 * Application specific element type
67 * Called when a new element was received from another peer, or an error occured.
69 * Elements given to a consensus operation by the local peer are NOT given
73 * @param element new element, NULL on error
75 typedef void (*GNUNET_CONSENSUS_NewElementCallback) (void *cls,
76 struct GNUNET_CONSENSUS_Element *element);
81 * Opaque handle for the consensus service.
83 struct GNUNET_CONSENSUS_Handle;
87 * Create a consensus session.
91 * @param peers array of peers participating in this consensus session
92 * Inclusion of the local peer is optional.
93 * @param session_id session identifier
94 * Allows a group of peers to have more than consensus session.
95 * @param num_initial_elements number of entries in the 'initial_elements' array
96 * @param initial_elements our elements for the consensus (each of 'element_size'
97 * @param new_element callback, called when a new element is added to the set by
99 * @param new_element_cls closure for new_element
100 * @return handle to use, NULL on error
102 struct GNUNET_CONSENSUS_Handle *
103 GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
104 unsigned int num_peers,
105 const struct GNUNET_PeerIdentity *peers,
106 const struct GNUNET_HashCode *session_id,
108 unsigned int num_initial_elements,
109 const struct GNUNET_CONSENSUS_Element **initial_elements,
111 GNUNET_CONSENSUS_NewElementCallback new_element,
112 void *new_element_cls);
116 * Called when an insertion (transmission to consensus service,
117 * which does not imply fully consensus on this element with
118 * all other peers) was successful.
121 * @param success GNUNET_OK on success, GNUNET_SYSERR if
122 * the insertion and thus the consensus failed for good
124 typedef void (*GNUNET_CONSENSUS_InsertDoneCallback) (void *cls,
129 * Insert an element in the set being reconsiled. Must not be called after
130 * "GNUNET_CONSENSUS_conclude".
132 * @param consensus handle for the consensus session
133 * @param element the element to be inserted
134 * @param idc function called when we are done with this element and it
135 * is thus allowed to call GNUNET_CONSENSUS_insert again
136 * @param idc_cls closure for 'idc'
139 GNUNET_CONSENSUS_insert (struct GNUNET_CONSENSUS_Handle *consensus,
140 const struct GNUNET_CONSENSUS_Element *element,
141 GNUNET_CONSENSUS_InsertDoneCallback idc,
146 * Called when a conclusion was successful.
149 * @param num_peers_in_consensus
150 * @param peers_in_consensus
152 typedef void (*GNUNET_CONSENSUS_ConcludeCallback) (void *cls,
153 unsigned int num_peers_in_consensus,
154 const struct GNUNET_PeerIdentity *peers_in_consensus);
158 * We are finished inserting new elements into the consensus;
159 * try to conclude the consensus within a given time window.
161 * @param consensus consensus session
162 * @param timeout timeout after which the conculde callback
164 * @param conclude called when the conclusion was successful
165 * @param conclude_cls closure for the conclude callback
168 GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus,
169 struct GNUNET_TIME_Relative timeout,
170 GNUNET_CONSENSUS_ConcludeCallback conclude,
175 * Destroy a consensus handle (free all state associated with
176 * it, no longer call any of the callbacks).
178 * @param consensus handle to destroy
181 GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus);
184 #if 0 /* keep Emacsens' auto-indent happy */