2 This file is part of GNUnet
3 Copyright (C) 2012 GNUnet e.V.
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 3, 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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @author Florian Dold
25 * Multi-peer set reconciliation
27 * @defgroup consensus Consensus service
28 * Multi-peer set reconciliation
32 #ifndef GNUNET_CONSENSUS_SERVICE_H
33 #define GNUNET_CONSENSUS_SERVICE_H
38 #if 0 /* keep Emacsens' auto-indent happy */
44 #include "gnunet_common.h"
45 #include "gnunet_time_lib.h"
46 #include "gnunet_configuration_lib.h"
47 #include "gnunet_set_service.h"
51 * Elements inserted into the consensus set by the client
52 * may not be larger than this constant, since types in
53 * the upper range are used by CONSENSUS internally.
55 #define GNUNET_CONSENSUS_ELEMENT_TYPE_USER_MAX 0xFFF0
59 * Called when a new element was received from another peer, or an error occured.
60 * May deliver duplicate values.
61 * Elements given to a consensus operation by the local peer are NOT given
65 * @param element new element, NULL on error
67 typedef void (*GNUNET_CONSENSUS_ElementCallback) (void *cls,
68 const struct GNUNET_SET_Element *element);
73 * Opaque handle for the consensus service.
75 struct GNUNET_CONSENSUS_Handle;
79 * Create a consensus session. The set being reconciled is initially
84 * @param peers array of peers participating in this consensus session
85 * Inclusion of the local peer is optional.
86 * @param session_id session identifier
87 * Allows a group of peers to have more than consensus session.
88 * @param start start time of the consensus, conclude should be called before
90 * @param deadline time when the consensus should have concluded
91 * @param new_element_cb callback, called when a new element is added to the set by
92 * another peer. Also called when an error occurs.
93 * @param new_element_cls closure for new_element
94 * @return handle to use, NULL on error
96 struct GNUNET_CONSENSUS_Handle *
97 GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
98 unsigned int num_peers,
99 const struct GNUNET_PeerIdentity *peers,
100 const struct GNUNET_HashCode *session_id,
101 struct GNUNET_TIME_Absolute start,
102 struct GNUNET_TIME_Absolute deadline,
103 GNUNET_CONSENSUS_ElementCallback new_element_cb,
104 void *new_element_cls);
108 * Called when an insertion (transmission to consensus service, which
109 * does not imply fully consensus on this element with all other
110 * peers) was successful. May not call GNUNET_CONSENSUS_destroy();
111 * schedule a task to call GNUNET_CONSENSUS_destroy() instead (if
115 * @param success #GNUNET_OK on success, #GNUNET_SYSERR if
116 * the insertion and thus the consensus failed for good
118 typedef void (*GNUNET_CONSENSUS_InsertDoneCallback) (void *cls,
123 * Insert an element in the set being reconsiled. Only transmit changes to
124 * other peers if GNUNET_CONSENSUS_begin() has been called.
125 * Must not be called after GNUNET_CONSENSUS_conclude().
126 * May not call GNUNET_CONSENSUS_destroy(); schedule a task to call
127 * GNUNET_CONSENSUS_destroy() instead (if needed).
129 * @param consensus handle for the consensus session
130 * @param element the element to be inserted
131 * @param idc function called when we are done with this element and it
132 * is thus allowed to call GNUNET_CONSENSUS_insert() again
133 * @param idc_cls closure for @a idc
136 GNUNET_CONSENSUS_insert (struct GNUNET_CONSENSUS_Handle *consensus,
137 const struct GNUNET_SET_Element *element,
138 GNUNET_CONSENSUS_InsertDoneCallback idc,
144 * Called when a conclusion was successful.
148 typedef void (*GNUNET_CONSENSUS_ConcludeCallback) (void *cls);
152 * We are finished inserting new elements into the consensus;
153 * try to conclude the consensus within a given time window.
155 * @param consensus consensus session
156 * @param conclude called when the conclusion was successful
157 * @param conclude_cls closure for the conclude callback
160 GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus,
161 GNUNET_CONSENSUS_ConcludeCallback conclude,
166 * Destroy a consensus handle (free all state associated with
167 * it, no longer call any of the callbacks).
169 * @param consensus handle to destroy
172 GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus);
175 #if 0 /* keep Emacsens' auto-indent happy */
184 /** @} */ /* end of group */