curl_lib: fix building with gnurl/curl.h
[oweals/gnunet.git] / src / include / gnunet_consensus_service.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2012 GNUnet e.V.
4
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.
9
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.
14
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.
19  */
20
21 /**
22  * @author Florian Dold
23  *
24  * @file
25  * Multi-peer set reconciliation
26  *
27  * @defgroup consensus  Consensus service
28  * Multi-peer set reconciliation
29  * @{
30  */
31
32 #ifndef GNUNET_CONSENSUS_SERVICE_H
33 #define GNUNET_CONSENSUS_SERVICE_H
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #if 0                           /* keep Emacsens' auto-indent happy */
39 }
40 #endif
41 #endif
42
43 #include "platform.h"
44 #include "gnunet_common.h"
45 #include "gnunet_time_lib.h"
46 #include "gnunet_configuration_lib.h"
47 #include "gnunet_set_service.h"
48
49
50 /**
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.
54  */
55 #define GNUNET_CONSENSUS_ELEMENT_TYPE_USER_MAX 0xFFF0
56
57
58 /**
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
62  * to this callback.
63  *
64  * @param cls closure
65  * @param element new element, NULL on error
66  */
67 typedef void (*GNUNET_CONSENSUS_ElementCallback) (void *cls,
68                                                   const struct GNUNET_SET_Element *element);
69
70
71
72 /**
73  * Opaque handle for the consensus service.
74  */
75 struct GNUNET_CONSENSUS_Handle;
76
77
78 /**
79  * Create a consensus session.  The set being reconciled is initially
80  * empty.
81  *
82  * @param cfg
83  * @param num_peers
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
89  *              the start time.
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
95  */
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);
105
106
107 /**
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
112  * needed).
113  *
114  * @param cls
115  * @param success #GNUNET_OK on success, #GNUNET_SYSERR if
116  *        the insertion and thus the consensus failed for good
117  */
118 typedef void (*GNUNET_CONSENSUS_InsertDoneCallback) (void *cls,
119                                                      int success);
120
121
122 /**
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).
128  *
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
134  */
135 void
136 GNUNET_CONSENSUS_insert (struct GNUNET_CONSENSUS_Handle *consensus,
137                          const struct GNUNET_SET_Element *element,
138                          GNUNET_CONSENSUS_InsertDoneCallback idc,
139                          void *idc_cls);
140
141
142
143 /**
144  * Called when a conclusion was successful.
145  *
146  * @param cls
147  */
148 typedef void (*GNUNET_CONSENSUS_ConcludeCallback) (void *cls);
149
150
151 /**
152  * We are finished inserting new elements into the consensus;
153  * try to conclude the consensus within a given time window.
154  *
155  * @param consensus consensus session
156  * @param conclude called when the conclusion was successful
157  * @param conclude_cls closure for the conclude callback
158  */
159 void
160 GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus,
161                            GNUNET_CONSENSUS_ConcludeCallback conclude,
162                            void *conclude_cls);
163
164
165 /**
166  * Destroy a consensus handle (free all state associated with
167  * it, no longer call any of the callbacks).
168  *
169  * @param consensus handle to destroy
170  */
171 void
172 GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus);
173
174
175 #if 0                           /* keep Emacsens' auto-indent happy */
176 {
177 #endif
178 #ifdef __cplusplus
179 }
180 #endif
181
182 #endif
183
184 /** @} */  /* end of group */