SET service: accurate results for symmetric mode
[oweals/gnunet.git] / src / include / gnunet_consensus_service.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2012 Christian Grothoff (and other contributing authors)
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  * @file include/gnunet_consensus_service.h
23  * @brief multi-peer set reconciliation
24  * @author Florian Dold
25  */
26
27 #ifndef GNUNET_CONSENSUS_SERVICE_H
28 #define GNUNET_CONSENSUS_SERVICE_H
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 #include "platform.h"
39 #include "gnunet_common.h"
40 #include "gnunet_time_lib.h"
41 #include "gnunet_configuration_lib.h"
42 #include "gnunet_set_service.h"
43
44
45 /**
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
49  * to this callback.
50  *
51  * @param cls closure
52  * @param element new element, NULL on error
53  */
54 typedef void (*GNUNET_CONSENSUS_ElementCallback) (void *cls,
55                                                   const struct GNUNET_SET_Element *element);
56
57
58
59 /**
60  * Opaque handle for the consensus service.
61  */
62 struct GNUNET_CONSENSUS_Handle;
63
64
65 /**
66  * Create a consensus session.  The set being reconciled is initially
67  * empty.
68  *
69  * @param cfg
70  * @param num_peers
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 start start time of the consensus, conclude should be called before
76  *              the start time.
77  * @param deadline time when the consensus should have concluded
78  * @param new_element_cb callback, called when a new element is added to the set by
79  *                    another peer. Also called when an error occurs.
80  * @param new_element_cls closure for new_element
81  * @return handle to use, NULL on error
82  */
83 struct GNUNET_CONSENSUS_Handle *
84 GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
85                          unsigned int num_peers,
86                          const struct GNUNET_PeerIdentity *peers,
87                          const struct GNUNET_HashCode *session_id,
88                          struct GNUNET_TIME_Absolute start,
89                          struct GNUNET_TIME_Absolute deadline,
90                          GNUNET_CONSENSUS_ElementCallback new_element_cb,
91                          void *new_element_cls);
92
93
94 /**
95  * Called when an insertion (transmission to consensus service, which
96  * does not imply fully consensus on this element with all other
97  * peers) was successful.  May not call GNUNET_CONSENSUS_destroy();
98  * schedule a task to call GNUNET_CONSENSUS_destroy() instead (if
99  * needed).
100  *
101  * @param cls
102  * @param success #GNUNET_OK on success, #GNUNET_SYSERR if
103  *        the insertion and thus the consensus failed for good
104  */
105 typedef void (*GNUNET_CONSENSUS_InsertDoneCallback) (void *cls,
106                                                      int success);
107
108
109 /**
110  * Insert an element in the set being reconsiled.  Only transmit changes to
111  * other peers if GNUNET_CONSENSUS_begin() has been called.
112  * Must not be called after GNUNET_CONSENSUS_conclude().
113  * May not call GNUNET_CONSENSUS_destroy(); schedule a task to call
114  * GNUNET_CONSENSUS_destroy() instead (if needed).
115  *
116  * @param consensus handle for the consensus session
117  * @param element the element to be inserted
118  * @param idc function called when we are done with this element and it
119  *            is thus allowed to call GNUNET_CONSENSUS_insert() again
120  * @param idc_cls closure for @a idc
121  */
122 void
123 GNUNET_CONSENSUS_insert (struct GNUNET_CONSENSUS_Handle *consensus,
124                          const struct GNUNET_SET_Element *element,
125                          GNUNET_CONSENSUS_InsertDoneCallback idc,
126                          void *idc_cls);
127
128
129
130 /**
131  * Called when a conclusion was successful.
132  *
133  * @param cls
134  */
135 typedef void (*GNUNET_CONSENSUS_ConcludeCallback) (void *cls);
136
137
138 /**
139  * We are finished inserting new elements into the consensus;
140  * try to conclude the consensus within a given time window.
141  *
142  * @param consensus consensus session
143  * @param conclude called when the conclusion was successful
144  * @param conclude_cls closure for the conclude callback
145  */
146 void
147 GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus,
148                            GNUNET_CONSENSUS_ConcludeCallback conclude,
149                            void *conclude_cls);
150
151
152 /**
153  * Destroy a consensus handle (free all state associated with
154  * it, no longer call any of the callbacks).
155  *
156  * @param consensus handle to destroy
157  */
158 void
159 GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus);
160
161
162 #if 0                           /* keep Emacsens' auto-indent happy */
163 {
164 #endif
165 #ifdef __cplusplus
166 }
167 #endif
168
169 #endif