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 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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_consensus_service.h
23 * @brief multi-peer set reconciliation
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"
42 #include "gnunet_set_service.h"
46 * Called when a new element was received from another peer, or an error occured.
47 * May deliver duplicate values.
48 * Elements given to a consensus operation by the local peer are NOT given
52 * @param element new element, NULL on error
54 typedef void (*GNUNET_CONSENSUS_ElementCallback) (void *cls,
55 const struct GNUNET_SET_Element *element);
60 * Opaque handle for the consensus service.
62 struct GNUNET_CONSENSUS_Handle;
66 * Create a consensus session. The set being reconciled is initially
71 * @param peers array of peers participating in this consensus session
72 * Inclusion of the local peer is optional.
73 * @param session_id session identifier
74 * Allows a group of peers to have more than consensus session.
75 * @param new_element_cb callback, called when a new element is added to the set by
76 * another peer. Also called when an error occurs.
77 * @param new_element_cls closure for new_element
78 * @return handle to use, NULL on error
80 struct GNUNET_CONSENSUS_Handle *
81 GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
82 unsigned int num_peers,
83 const struct GNUNET_PeerIdentity *peers,
84 const struct GNUNET_HashCode *session_id,
85 GNUNET_CONSENSUS_ElementCallback new_element_cb,
86 void *new_element_cls);
90 * Called when an insertion (transmission to consensus service, which
91 * does not imply fully consensus on this element with all other
92 * peers) was successful. May not call GNUNET_CONSENSUS_destroy();
93 * schedule a task to call GNUNET_CONSENSUS_destroy() instead (if
97 * @param success #GNUNET_OK on success, #GNUNET_SYSERR if
98 * the insertion and thus the consensus failed for good
100 typedef void (*GNUNET_CONSENSUS_InsertDoneCallback) (void *cls,
105 * Insert an element in the set being reconsiled. Only transmit changes to
106 * other peers if GNUNET_CONSENSUS_begin() has been called.
107 * Must not be called after GNUNET_CONSENSUS_conclude().
108 * May not call GNUNET_CONSENSUS_destroy(); schedule a task to call
109 * GNUNET_CONSENSUS_destroy() instead (if needed).
111 * @param consensus handle for the consensus session
112 * @param element the element to be inserted
113 * @param idc function called when we are done with this element and it
114 * is thus allowed to call GNUNET_CONSENSUS_insert() again
115 * @param idc_cls closure for @a idc
118 GNUNET_CONSENSUS_insert (struct GNUNET_CONSENSUS_Handle *consensus,
119 const struct GNUNET_SET_Element *element,
120 GNUNET_CONSENSUS_InsertDoneCallback idc,
126 * Called when a conclusion was successful.
130 typedef void (*GNUNET_CONSENSUS_ConcludeCallback) (void *cls);
134 * We are finished inserting new elements into the consensus;
135 * try to conclude the consensus within a given time window.
137 * @param consensus consensus session
138 * @param deadline deadline after which the conculde callback
140 * @param conclude called when the conclusion was successful
141 * @param conclude_cls closure for the conclude callback
144 GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus,
145 struct GNUNET_TIME_Absolute deadline,
146 GNUNET_CONSENSUS_ConcludeCallback conclude,
151 * Destroy a consensus handle (free all state associated with
152 * it, no longer call any of the callbacks).
154 * @param consensus handle to destroy
157 GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus);
160 #if 0 /* keep Emacsens' auto-indent happy */