aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_consensus_service.h
blob: a2bf69021e36ac4af5ee0fa180bc77f47014b212 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
      This file is part of GNUnet
      (C) 2012 Christian Grothoff (and other contributing authors)

      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
      by the Free Software Foundation; either version 2, or (at your
      option) any later version.

      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      Boston, MA 02111-1307, USA.
 */

/**
 * @file include/gnunet_consensus_service.h
 * @brief 
 * @author Florian Dold
 */

#ifndef GNUNET_CONSENSUS_SERVICE_H
#define GNUNET_CONSENSUS_SERVICE_H

#ifdef __cplusplus
extern "C"
{
#if 0                           /* keep Emacsens' auto-indent happy */
}
#endif
#endif

#include "platform.h"
#include "gnunet_common.h"
#include "gnunet_time_lib.h"


/**
 * Called when a new element was received from another peer; elements
 * given to a consensus operation by the local peer are NOT given
 * to this callback.
 *
 * @param cls closure
 * @param element_size will match the size given to GNUNET_CONSENSUS_create
 * @param element
 */
typedef void (*GNUNET_CONSENSUS_NewElementCallback) (void *cls,
						     size_t element_size,
						     const void *element);



/**
 * Opaque handle for the consensus service.
 */
struct GNUNET_CONSENSUS_Handle;


/**
 * Create a consensus session.
 *
 * @param cfg
 * @param num_peers
 * @param peers array of peers participating in this consensus session
 * @param session_id session identifier
 *                   Allows a group of peers to have more than consensus session.
 * @param element_size size of the elements in the reconciled set in bytes
 * @param num_initial_elements number of entries in the 'initial_elements' array
 * @param initial_elements our elements for the consensus (each of 'element_size'
 * @param new_element callback, called when a new element is added to the set by
 *                    another peer
 * @param new_element_cls closure for new_element
 * @return handle to use, NULL on error
 */
struct GNUNET_CONSENSUS_Handle *
GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
			 unsigned int num_peers,
			 const struct GNUNET_PeerIdentity *peers,
                         const struct GNUNET_HashCode *session_id,
                         size_t element_size,
			 unsigned int num_initial_elements,
                         const void **initial_elements,
                         GNUNET_CONSENSUS_NewElementCallback new_element,
                         void *new_element_cls);


/**
 * Called when an insertion (transmission to consensus service,
 * which does not imply fully consensus on this element with
 * all other peers) was successful.
 *
 * @param cls
 * @param success GNUNET_OK on success, GNUNET_SYSERR if 
 *        the insertion and thus the consensus failed for good
 */
typedef void (*GNUNET_CONSENSUS_InsertDoneCallback) (void *cls,
						     int success);


/**
 * Insert an element in the set being reconsiled.  Must not be called after
 * "GNUNET_CONSENSUS_conclude".
 *
 * @param consensus handle for the consensus session
 * @param element_size must match element size from GNUNET_CONSENSUS_create
 * @param element the element to be inserted
 * @param idc function called when we are done with this element and it 
 *            is thus allowed to call GNUNET_CONSENSUS_insert again
 * @param idc_cls closure for 'idc'
 */
void
GNUNET_CONSENSUS_insert (struct GNUNET_CONSENSUS_Handle *consensus,
			 size_t element_size,
			 const void *element,
			 GNUNET_CONSENSUS_InsertDoneCallback idc,
			 void *idc_cls);


/**
 * Called when a conclusion was successful.
 *
 * @param cls
 * @param num_peers_in_consensus
 * @param peers_in_consensus
 */
typedef void (*GNUNET_CONSENSUS_ConcludeCallback) (void *cls, 
						   unsigned int num_peers_in_consensus,
						   const struct GNUNET_PeerIdentity *peers_in_consensus);


/**
 * We are finished inserting new elements into the consensus;
 * try to conclude the consensus within a given time window.
 *
 * @param consensus consensus session
 * @param timeout timeout after which the conculde callback
 *                must be called
 * @param conclude called when the conclusion was successful
 * @param conclude_cls closure for the conclude callback
 */
void
GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus,
			   struct GNUNET_TIME_Relative timeout,
			   GNUNET_CONSENSUS_ConcludeCallback conclude,
			   void *conclude_cls);


/**
 * Destroy a consensus handle (free all state associated with
 * it, no longer call any of the callbacks).
 *
 * @param consensus handle to destroy
 */
void
GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus);


#if 0                           /* keep Emacsens' auto-indent happy */
{
#endif
#ifdef __cplusplus
}
#endif

#endif