aboutsummaryrefslogtreecommitdiff
path: root/src/consensus/consensus_api.c
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2012-11-26 17:12:24 +0000
committerFlorian Dold <florian.dold@gmail.com>2012-11-26 17:12:24 +0000
commit691d973ea5dc7e297f598c7261fc2704b381972f (patch)
tree21c9ea084b305a59f402b17efd5415300c8e8ac1 /src/consensus/consensus_api.c
parent3c4db5aeee2a22aa38ee8049c3dbbd7fa989bf45 (diff)
downloadgnunet-691d973ea5dc7e297f598c7261fc2704b381972f.tar.gz
gnunet-691d973ea5dc7e297f598c7261fc2704b381972f.zip
fixed doxygen
Diffstat (limited to 'src/consensus/consensus_api.c')
-rw-r--r--src/consensus/consensus_api.c82
1 files changed, 63 insertions, 19 deletions
diff --git a/src/consensus/consensus_api.c b/src/consensus/consensus_api.c
index 0d7e6c8e4..b1de10edd 100644
--- a/src/consensus/consensus_api.c
+++ b/src/consensus/consensus_api.c
@@ -151,8 +151,6 @@ static void
151message_handler (void *cls, const struct GNUNET_MessageHeader *msg) 151message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
152{ 152{
153 struct GNUNET_CONSENSUS_Handle *consensus = cls; 153 struct GNUNET_CONSENSUS_Handle *consensus = cls;
154 GNUNET_CONSENSUS_InsertDoneCallback idc;
155 void *idc_cls;
156 154
157 if (msg == NULL) 155 if (msg == NULL)
158 { 156 {
@@ -171,13 +169,6 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
171 169
172 switch (ntohs(msg->type)) 170 switch (ntohs(msg->type))
173 { 171 {
174 case GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_INSERT_ACK:
175 idc = consensus->idc;
176 consensus->idc = NULL;
177 idc_cls = consensus->idc_cls;
178 consensus->idc_cls = NULL;
179 idc(idc_cls, GNUNET_YES);
180 break;
181 case GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT: 172 case GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT:
182 handle_new_element(consensus, (struct GNUNET_CONSENSUS_ElementMessage *) msg); 173 handle_new_element(consensus, (struct GNUNET_CONSENSUS_ElementMessage *) msg);
183 break; 174 break;
@@ -210,7 +201,9 @@ transmit_insert (void *cls, size_t size, void *buf)
210{ 201{
211 struct GNUNET_CONSENSUS_ElementMessage *msg; 202 struct GNUNET_CONSENSUS_ElementMessage *msg;
212 struct GNUNET_CONSENSUS_Handle *consensus; 203 struct GNUNET_CONSENSUS_Handle *consensus;
204 GNUNET_CONSENSUS_InsertDoneCallback idc;
213 int msize; 205 int msize;
206 void *idc_cls;
214 207
215 GNUNET_assert (NULL != buf); 208 GNUNET_assert (NULL != buf);
216 209
@@ -220,7 +213,6 @@ transmit_insert (void *cls, size_t size, void *buf)
220 213
221 consensus->th = NULL; 214 consensus->th = NULL;
222 215
223
224 msg = buf; 216 msg = buf;
225 217
226 msize = sizeof (struct GNUNET_CONSENSUS_ElementMessage) + 218 msize = sizeof (struct GNUNET_CONSENSUS_ElementMessage) +
@@ -232,6 +224,13 @@ transmit_insert (void *cls, size_t size, void *buf)
232 consensus->insert_element->data, 224 consensus->insert_element->data,
233 consensus->insert_element->size); 225 consensus->insert_element->size);
234 226
227
228 idc = consensus->idc;
229 consensus->idc = NULL;
230 idc_cls = consensus->idc_cls;
231 consensus->idc_cls = NULL;
232 idc(idc_cls, GNUNET_YES);
233
235 return msize; 234 return msize;
236} 235}
237 236
@@ -328,6 +327,38 @@ transmit_conclude (void *cls, size_t size, void *buf)
328} 327}
329 328
330 329
330/**
331 * Function called to notify a client about the connection
332 * begin ready to queue more data. "buf" will be
333 * NULL and "size" zero if the connection was closed for
334 * writing in the meantime.
335 *
336 * @param cls the consensus handle
337 * @param size number of bytes available in buf
338 * @param buf where the callee should write the message
339 * @return number of bytes written to buf
340 */
341static size_t
342transmit_begin (void *cls, size_t size, void *buf)
343{
344 struct GNUNET_MessageHeader *msg;
345 struct GNUNET_CONSENSUS_Handle *consensus;
346 int msize;
347
348 GNUNET_assert (NULL != buf);
349
350 consensus = cls;
351 consensus->th = NULL;
352
353 msg = buf;
354
355 msize = sizeof (struct GNUNET_MessageHeader);
356
357 msg->type = htons (GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_BEGIN);
358 msg->size = htons (msize);
359
360 return msize;
361}
331 362
332 363
333/** 364/**
@@ -339,9 +370,7 @@ transmit_conclude (void *cls, size_t size, void *buf)
339 * Inclusion of the local peer is optional. 370 * Inclusion of the local peer is optional.
340 * @param session_id session identifier 371 * @param session_id session identifier
341 * Allows a group of peers to have more than consensus session. 372 * Allows a group of peers to have more than consensus session.
342 * @param num_initial_elements number of entries in the 'initial_elements' array 373 * @param new_element_cb callback, called when a new element is added to the set by
343 * @param initial_elements our elements for the consensus (each of 'element_size'
344 * @param new_element callback, called when a new element is added to the set by
345 * another peer 374 * another peer
346 * @param new_element_cls closure for new_element 375 * @param new_element_cls closure for new_element
347 * @return handle to use, NULL on error 376 * @return handle to use, NULL on error
@@ -351,11 +380,7 @@ GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
351 unsigned int num_peers, 380 unsigned int num_peers,
352 const struct GNUNET_PeerIdentity *peers, 381 const struct GNUNET_PeerIdentity *peers,
353 const struct GNUNET_HashCode *session_id, 382 const struct GNUNET_HashCode *session_id,
354 /* 383 GNUNET_CONSENSUS_NewElementCallback new_element_cb,
355 unsigned int num_initial_elements,
356 const struct GNUNET_CONSENSUS_Element **initial_elements,
357 */
358 GNUNET_CONSENSUS_NewElementCallback new_element,
359 void *new_element_cls) 384 void *new_element_cls)
360{ 385{
361 struct GNUNET_CONSENSUS_Handle *consensus; 386 struct GNUNET_CONSENSUS_Handle *consensus;
@@ -364,7 +389,7 @@ GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
364 389
365 consensus = GNUNET_malloc (sizeof (struct GNUNET_CONSENSUS_Handle)); 390 consensus = GNUNET_malloc (sizeof (struct GNUNET_CONSENSUS_Handle));
366 consensus->cfg = cfg; 391 consensus->cfg = cfg;
367 consensus->new_element_cb = new_element; 392 consensus->new_element_cb = new_element_cb;
368 consensus->new_element_cls = new_element_cls; 393 consensus->new_element_cls = new_element_cls;
369 consensus->num_peers = num_peers; 394 consensus->num_peers = num_peers;
370 consensus->session_id = *session_id; 395 consensus->session_id = *session_id;
@@ -448,6 +473,25 @@ GNUNET_CONSENSUS_insert (struct GNUNET_CONSENSUS_Handle *consensus,
448 473
449 474
450/** 475/**
476 * Begin reconciling elements with other peers.
477 *
478 * @param consensus handle for the consensus session
479 */
480void
481GNUNET_CONSENSUS_begin (struct GNUNET_CONSENSUS_Handle *consensus)
482{
483 GNUNET_assert (NULL == consensus->idc);
484 GNUNET_assert (NULL == consensus->insert_element);
485
486 consensus->th =
487 GNUNET_CLIENT_notify_transmit_ready (consensus->client,
488 sizeof (struct GNUNET_MessageHeader),
489 GNUNET_TIME_UNIT_FOREVER_REL,
490 GNUNET_NO, &transmit_begin, consensus);
491}
492
493
494/**
451 * We are finished inserting new elements into the consensus; 495 * We are finished inserting new elements into the consensus;
452 * try to conclude the consensus within a given time window. 496 * try to conclude the consensus within a given time window.
453 * 497 *