aboutsummaryrefslogtreecommitdiff
path: root/src/set/set_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/set/set_api.c')
-rw-r--r--src/set/set_api.c923
1 files changed, 461 insertions, 462 deletions
diff --git a/src/set/set_api.c b/src/set/set_api.c
index 3b92cd26c..7db5abcbd 100644
--- a/src/set/set_api.c
+++ b/src/set/set_api.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file set/set_api.c 21 * @file set/set_api.c
22 * @brief api for the set service 22 * @brief api for the set service
@@ -30,10 +30,9 @@
30#include "set.h" 30#include "set.h"
31 31
32 32
33#define LOG(kind,...) GNUNET_log_from (kind, "set-api",__VA_ARGS__) 33#define LOG(kind, ...) GNUNET_log_from(kind, "set-api", __VA_ARGS__)
34 34
35struct SetCopyRequest 35struct SetCopyRequest {
36{
37 struct SetCopyRequest *next; 36 struct SetCopyRequest *next;
38 37
39 struct SetCopyRequest *prev; 38 struct SetCopyRequest *prev;
@@ -46,8 +45,7 @@ struct SetCopyRequest
46/** 45/**
47 * Opaque handle to a set. 46 * Opaque handle to a set.
48 */ 47 */
49struct GNUNET_SET_Handle 48struct GNUNET_SET_Handle {
50{
51 /** 49 /**
52 * Message queue for @e client. 50 * Message queue for @e client.
53 */ 51 */
@@ -112,8 +110,7 @@ struct GNUNET_SET_Handle
112/** 110/**
113 * Handle for a set operation request from another peer. 111 * Handle for a set operation request from another peer.
114 */ 112 */
115struct GNUNET_SET_Request 113struct GNUNET_SET_Request {
116{
117 /** 114 /**
118 * Id of the request, used to identify the request when 115 * Id of the request, used to identify the request when
119 * accepting/rejecting it. 116 * accepting/rejecting it.
@@ -132,8 +129,7 @@ struct GNUNET_SET_Request
132 * Handle to an operation. Only known to the service after committing 129 * Handle to an operation. Only known to the service after committing
133 * the handle with a set. 130 * the handle with a set.
134 */ 131 */
135struct GNUNET_SET_OperationHandle 132struct GNUNET_SET_OperationHandle {
136{
137 /** 133 /**
138 * Function to be called when we have a result, 134 * Function to be called when we have a result,
139 * or an error. 135 * or an error.
@@ -183,9 +179,7 @@ struct GNUNET_SET_OperationHandle
183/** 179/**
184 * Opaque handle to a listen operation. 180 * Opaque handle to a listen operation.
185 */ 181 */
186struct GNUNET_SET_ListenHandle 182struct GNUNET_SET_ListenHandle {
187{
188
189 /** 183 /**
190 * Message queue for the client. 184 * Message queue for the client.
191 */ 185 */
@@ -233,9 +227,9 @@ struct GNUNET_SET_ListenHandle
233 227
234/* mutual recursion with handle_copy_lazy */ 228/* mutual recursion with handle_copy_lazy */
235static struct GNUNET_SET_Handle * 229static struct GNUNET_SET_Handle *
236create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg, 230create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg,
237 enum GNUNET_SET_OperationType op, 231 enum GNUNET_SET_OperationType op,
238 const uint32_t *cookie); 232 const uint32_t *cookie);
239 233
240 234
241/** 235/**
@@ -246,8 +240,8 @@ create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg,
246 * @param msg the message 240 * @param msg the message
247 */ 241 */
248static void 242static void
249handle_copy_lazy (void *cls, 243handle_copy_lazy(void *cls,
250 const struct GNUNET_SET_CopyLazyResponseMessage *msg) 244 const struct GNUNET_SET_CopyLazyResponseMessage *msg)
251{ 245{
252 struct GNUNET_SET_Handle *set = cls; 246 struct GNUNET_SET_Handle *set = cls;
253 struct SetCopyRequest *req; 247 struct SetCopyRequest *req;
@@ -255,24 +249,24 @@ handle_copy_lazy (void *cls,
255 249
256 req = set->copy_req_head; 250 req = set->copy_req_head;
257 if (NULL == req) 251 if (NULL == req)
258 { 252 {
259 /* Service sent us unsolicited lazy copy response */ 253 /* Service sent us unsolicited lazy copy response */
260 GNUNET_break (0); 254 GNUNET_break(0);
261 return; 255 return;
262 } 256 }
263 257
264 LOG (GNUNET_ERROR_TYPE_DEBUG, 258 LOG(GNUNET_ERROR_TYPE_DEBUG,
265 "Handling response to lazy copy\n"); 259 "Handling response to lazy copy\n");
266 GNUNET_CONTAINER_DLL_remove (set->copy_req_head, 260 GNUNET_CONTAINER_DLL_remove(set->copy_req_head,
267 set->copy_req_tail, 261 set->copy_req_tail,
268 req); 262 req);
269 // We pass none as operation here, since it doesn't matter when 263 // We pass none as operation here, since it doesn't matter when
270 // cloning. 264 // cloning.
271 new_set = create_internal (set->cfg, 265 new_set = create_internal(set->cfg,
272 GNUNET_SET_OPERATION_NONE, 266 GNUNET_SET_OPERATION_NONE,
273 &msg->cookie); 267 &msg->cookie);
274 req->cb (req->cls, new_set); 268 req->cb(req->cls, new_set);
275 GNUNET_free (req); 269 GNUNET_free(req);
276} 270}
277 271
278 272
@@ -284,8 +278,8 @@ handle_copy_lazy (void *cls,
284 * @return #GNUNET_OK if message is well-formed 278 * @return #GNUNET_OK if message is well-formed
285 */ 279 */
286static int 280static int
287check_iter_element (void *cls, 281check_iter_element(void *cls,
288 const struct GNUNET_SET_IterResponseMessage *msg) 282 const struct GNUNET_SET_IterResponseMessage *msg)
289{ 283{
290 /* minimum size was already checked, everything else is OK! */ 284 /* minimum size was already checked, everything else is OK! */
291 return GNUNET_OK; 285 return GNUNET_OK;
@@ -300,8 +294,8 @@ check_iter_element (void *cls,
300 * @param mh the message 294 * @param mh the message
301 */ 295 */
302static void 296static void
303handle_iter_element (void *cls, 297handle_iter_element(void *cls,
304 const struct GNUNET_SET_IterResponseMessage *msg) 298 const struct GNUNET_SET_IterResponseMessage *msg)
305{ 299{
306 struct GNUNET_SET_Handle *set = cls; 300 struct GNUNET_SET_Handle *set = cls;
307 GNUNET_SET_ElementIterator iter = set->iterator; 301 GNUNET_SET_ElementIterator iter = set->iterator;
@@ -310,26 +304,26 @@ handle_iter_element (void *cls,
310 struct GNUNET_MQ_Envelope *ev; 304 struct GNUNET_MQ_Envelope *ev;
311 uint16_t msize; 305 uint16_t msize;
312 306
313 LOG (GNUNET_ERROR_TYPE_DEBUG, 307 LOG(GNUNET_ERROR_TYPE_DEBUG,
314 "Received element in set iteration\n"); 308 "Received element in set iteration\n");
315 msize = ntohs (msg->header.size); 309 msize = ntohs(msg->header.size);
316 if (set->iteration_id != ntohs (msg->iteration_id)) 310 if (set->iteration_id != ntohs(msg->iteration_id))
317 { 311 {
318 /* element from a previous iteration, skip! */ 312 /* element from a previous iteration, skip! */
319 iter = NULL; 313 iter = NULL;
320 } 314 }
321 if (NULL != iter) 315 if (NULL != iter)
322 { 316 {
323 element.size = msize - sizeof (struct GNUNET_SET_IterResponseMessage); 317 element.size = msize - sizeof(struct GNUNET_SET_IterResponseMessage);
324 element.element_type = ntohs (msg->element_type); 318 element.element_type = ntohs(msg->element_type);
325 element.data = &msg[1]; 319 element.data = &msg[1];
326 iter (set->iterator_cls, 320 iter(set->iterator_cls,
327 &element); 321 &element);
328 } 322 }
329 ev = GNUNET_MQ_msg (ack_msg, 323 ev = GNUNET_MQ_msg(ack_msg,
330 GNUNET_MESSAGE_TYPE_SET_ITER_ACK); 324 GNUNET_MESSAGE_TYPE_SET_ITER_ACK);
331 ack_msg->send_more = htonl ((NULL != iter)); 325 ack_msg->send_more = htonl((NULL != iter));
332 GNUNET_MQ_send (set->mq, ev); 326 GNUNET_MQ_send(set->mq, ev);
333} 327}
334 328
335 329
@@ -341,31 +335,31 @@ handle_iter_element (void *cls,
341 * @param mh the message 335 * @param mh the message
342 */ 336 */
343static void 337static void
344handle_iter_done (void *cls, 338handle_iter_done(void *cls,
345 const struct GNUNET_MessageHeader *mh) 339 const struct GNUNET_MessageHeader *mh)
346{ 340{
347 struct GNUNET_SET_Handle *set = cls; 341 struct GNUNET_SET_Handle *set = cls;
348 GNUNET_SET_ElementIterator iter = set->iterator; 342 GNUNET_SET_ElementIterator iter = set->iterator;
349 343
350 if (NULL == iter) 344 if (NULL == iter)
351 { 345 {
352 /* FIXME: if this is true, could cancel+start a fresh one 346 /* FIXME: if this is true, could cancel+start a fresh one
353 cause elements to go to the wrong iteration? */ 347 cause elements to go to the wrong iteration? */
354 LOG (GNUNET_ERROR_TYPE_INFO, 348 LOG(GNUNET_ERROR_TYPE_INFO,
355 "Service completed set iteration that was already cancelled\n"); 349 "Service completed set iteration that was already cancelled\n");
356 return; 350 return;
357 } 351 }
358 LOG (GNUNET_ERROR_TYPE_DEBUG, 352 LOG(GNUNET_ERROR_TYPE_DEBUG,
359 "Set iteration completed\n"); 353 "Set iteration completed\n");
360 set->destroy_requested = GNUNET_SYSERR; 354 set->destroy_requested = GNUNET_SYSERR;
361 set->iterator = NULL; 355 set->iterator = NULL;
362 set->iteration_id++; 356 set->iteration_id++;
363 iter (set->iterator_cls, 357 iter(set->iterator_cls,
364 NULL); 358 NULL);
365 if (GNUNET_SYSERR == set->destroy_requested) 359 if (GNUNET_SYSERR == set->destroy_requested)
366 set->destroy_requested = GNUNET_NO; 360 set->destroy_requested = GNUNET_NO;
367 if (GNUNET_YES == set->destroy_requested) 361 if (GNUNET_YES == set->destroy_requested)
368 GNUNET_SET_destroy (set); 362 GNUNET_SET_destroy(set);
369} 363}
370 364
371 365
@@ -377,8 +371,8 @@ handle_iter_done (void *cls,
377 * @return #GNUNET_OK if message is well-formed 371 * @return #GNUNET_OK if message is well-formed
378 */ 372 */
379static int 373static int
380check_result (void *cls, 374check_result(void *cls,
381 const struct GNUNET_SET_ResultMessage *msg) 375 const struct GNUNET_SET_ResultMessage *msg)
382{ 376{
383 /* minimum size was already checked, everything else is OK! */ 377 /* minimum size was already checked, everything else is OK! */
384 return GNUNET_OK; 378 return GNUNET_OK;
@@ -392,8 +386,8 @@ check_result (void *cls,
392 * @param mh the message 386 * @param mh the message
393 */ 387 */
394static void 388static void
395handle_result (void *cls, 389handle_result(void *cls,
396 const struct GNUNET_SET_ResultMessage *msg) 390 const struct GNUNET_SET_ResultMessage *msg)
397{ 391{
398 struct GNUNET_SET_Handle *set = cls; 392 struct GNUNET_SET_Handle *set = cls;
399 struct GNUNET_SET_OperationHandle *oh; 393 struct GNUNET_SET_OperationHandle *oh;
@@ -401,78 +395,80 @@ handle_result (void *cls,
401 enum GNUNET_SET_Status result_status; 395 enum GNUNET_SET_Status result_status;
402 int destroy_set; 396 int destroy_set;
403 397
404 GNUNET_assert (NULL != set->mq); 398 GNUNET_assert(NULL != set->mq);
405 result_status = (enum GNUNET_SET_Status) ntohs (msg->result_status); 399 result_status = (enum GNUNET_SET_Status)ntohs(msg->result_status);
406 LOG (GNUNET_ERROR_TYPE_DEBUG, 400 LOG(GNUNET_ERROR_TYPE_DEBUG,
407 "Got result message with status %d\n", 401 "Got result message with status %d\n",
408 result_status); 402 result_status);
409 403
410 oh = GNUNET_MQ_assoc_get (set->mq, 404 oh = GNUNET_MQ_assoc_get(set->mq,
411 ntohl (msg->request_id)); 405 ntohl(msg->request_id));
412 if (NULL == oh) 406 if (NULL == oh)
413 { 407 {
414 /* 'oh' can be NULL if we canceled the operation, but the service 408 /* 'oh' can be NULL if we canceled the operation, but the service
415 did not get the cancel message yet. */ 409 did not get the cancel message yet. */
416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 410 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
417 "Ignoring result from canceled operation\n"); 411 "Ignoring result from canceled operation\n");
418 return; 412 return;
419 } 413 }
420 414
421 switch (result_status) 415 switch (result_status)
422 { 416 {
423 case GNUNET_SET_STATUS_OK: 417 case GNUNET_SET_STATUS_OK:
424 case GNUNET_SET_STATUS_ADD_LOCAL: 418 case GNUNET_SET_STATUS_ADD_LOCAL:
425 case GNUNET_SET_STATUS_ADD_REMOTE: 419 case GNUNET_SET_STATUS_ADD_REMOTE:
426 goto do_element; 420 goto do_element;
421
427 case GNUNET_SET_STATUS_FAILURE: 422 case GNUNET_SET_STATUS_FAILURE:
428 case GNUNET_SET_STATUS_DONE: 423 case GNUNET_SET_STATUS_DONE:
429 goto do_final; 424 goto do_final;
425
430 case GNUNET_SET_STATUS_HALF_DONE: 426 case GNUNET_SET_STATUS_HALF_DONE:
431 /* not used anymore */ 427 /* not used anymore */
432 GNUNET_assert (0); 428 GNUNET_assert(0);
433 } 429 }
434 430
435do_final: 431do_final:
436 LOG (GNUNET_ERROR_TYPE_DEBUG, 432 LOG(GNUNET_ERROR_TYPE_DEBUG,
437 "Treating result as final status\n"); 433 "Treating result as final status\n");
438 GNUNET_MQ_assoc_remove (set->mq, 434 GNUNET_MQ_assoc_remove(set->mq,
439 ntohl (msg->request_id)); 435 ntohl(msg->request_id));
440 GNUNET_CONTAINER_DLL_remove (set->ops_head, 436 GNUNET_CONTAINER_DLL_remove(set->ops_head,
441 set->ops_tail, 437 set->ops_tail,
442 oh); 438 oh);
443 /* Need to do this calculation _before_ the result callback, 439 /* Need to do this calculation _before_ the result callback,
444 as IF the application still has a valid set handle, it 440 as IF the application still has a valid set handle, it
445 may trigger destruction of the set during the callback. */ 441 may trigger destruction of the set during the callback. */
446 destroy_set = (GNUNET_YES == set->destroy_requested) && 442 destroy_set = (GNUNET_YES == set->destroy_requested) &&
447 (NULL == set->ops_head); 443 (NULL == set->ops_head);
448 if (NULL != oh->result_cb) 444 if (NULL != oh->result_cb)
449 { 445 {
450 oh->result_cb (oh->result_cls, 446 oh->result_cb(oh->result_cls,
451 NULL, 447 NULL,
452 GNUNET_ntohll (msg->current_size), 448 GNUNET_ntohll(msg->current_size),
453 result_status); 449 result_status);
454 } 450 }
455 else 451 else
456 { 452 {
457 LOG (GNUNET_ERROR_TYPE_DEBUG, 453 LOG(GNUNET_ERROR_TYPE_DEBUG,
458 "No callback for final status\n"); 454 "No callback for final status\n");
459 } 455 }
460 if (destroy_set) 456 if (destroy_set)
461 GNUNET_SET_destroy (set); 457 GNUNET_SET_destroy(set);
462 GNUNET_free (oh); 458 GNUNET_free(oh);
463 return; 459 return;
464 460
465do_element: 461do_element:
466 LOG (GNUNET_ERROR_TYPE_DEBUG, 462 LOG(GNUNET_ERROR_TYPE_DEBUG,
467 "Treating result as element\n"); 463 "Treating result as element\n");
468 e.data = &msg[1]; 464 e.data = &msg[1];
469 e.size = ntohs (msg->header.size) - sizeof (struct GNUNET_SET_ResultMessage); 465 e.size = ntohs(msg->header.size) - sizeof(struct GNUNET_SET_ResultMessage);
470 e.element_type = ntohs (msg->element_type); 466 e.element_type = ntohs(msg->element_type);
471 if (NULL != oh->result_cb) 467 if (NULL != oh->result_cb)
472 oh->result_cb (oh->result_cls, 468 oh->result_cb(oh->result_cls,
473 &e, 469 &e,
474 GNUNET_ntohll (msg->current_size), 470 GNUNET_ntohll(msg->current_size),
475 result_status); 471 result_status);
476} 472}
477 473
478 474
@@ -482,25 +478,25 @@ do_element:
482 * @param oh set operation to destroy 478 * @param oh set operation to destroy
483 */ 479 */
484static void 480static void
485set_operation_destroy (struct GNUNET_SET_OperationHandle *oh) 481set_operation_destroy(struct GNUNET_SET_OperationHandle *oh)
486{ 482{
487 struct GNUNET_SET_Handle *set = oh->set; 483 struct GNUNET_SET_Handle *set = oh->set;
488 struct GNUNET_SET_OperationHandle *h_assoc; 484 struct GNUNET_SET_OperationHandle *h_assoc;
489 485
490 if (NULL != oh->conclude_mqm) 486 if (NULL != oh->conclude_mqm)
491 GNUNET_MQ_discard (oh->conclude_mqm); 487 GNUNET_MQ_discard(oh->conclude_mqm);
492 /* is the operation already commited? */ 488 /* is the operation already commited? */
493 if (NULL != set) 489 if (NULL != set)
494 { 490 {
495 GNUNET_CONTAINER_DLL_remove (set->ops_head, 491 GNUNET_CONTAINER_DLL_remove(set->ops_head,
496 set->ops_tail, 492 set->ops_tail,
497 oh); 493 oh);
498 h_assoc = GNUNET_MQ_assoc_remove (set->mq, 494 h_assoc = GNUNET_MQ_assoc_remove(set->mq,
499 oh->request_id); 495 oh->request_id);
500 GNUNET_assert ( (NULL == h_assoc) || 496 GNUNET_assert((NULL == h_assoc) ||
501 (h_assoc == oh) ); 497 (h_assoc == oh));
502 } 498 }
503 GNUNET_free (oh); 499 GNUNET_free(oh);
504} 500}
505 501
506 502
@@ -512,29 +508,29 @@ set_operation_destroy (struct GNUNET_SET_OperationHandle *oh)
512 * @param oh set operation to cancel 508 * @param oh set operation to cancel
513 */ 509 */
514void 510void
515GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh) 511GNUNET_SET_operation_cancel(struct GNUNET_SET_OperationHandle *oh)
516{ 512{
517 struct GNUNET_SET_Handle *set = oh->set; 513 struct GNUNET_SET_Handle *set = oh->set;
518 struct GNUNET_SET_CancelMessage *m; 514 struct GNUNET_SET_CancelMessage *m;
519 struct GNUNET_MQ_Envelope *mqm; 515 struct GNUNET_MQ_Envelope *mqm;
520 516
521 LOG (GNUNET_ERROR_TYPE_DEBUG, 517 LOG(GNUNET_ERROR_TYPE_DEBUG,
522 "Cancelling SET operation\n"); 518 "Cancelling SET operation\n");
523 if (NULL != set) 519 if (NULL != set)
524 { 520 {
525 mqm = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_SET_CANCEL); 521 mqm = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_SET_CANCEL);
526 m->request_id = htonl (oh->request_id); 522 m->request_id = htonl(oh->request_id);
527 GNUNET_MQ_send (set->mq, mqm); 523 GNUNET_MQ_send(set->mq, mqm);
528 } 524 }
529 set_operation_destroy (oh); 525 set_operation_destroy(oh);
530 if ( (NULL != set) && 526 if ((NULL != set) &&
531 (GNUNET_YES == set->destroy_requested) && 527 (GNUNET_YES == set->destroy_requested) &&
532 (NULL == set->ops_head) ) 528 (NULL == set->ops_head))
533 { 529 {
534 LOG (GNUNET_ERROR_TYPE_DEBUG, 530 LOG(GNUNET_ERROR_TYPE_DEBUG,
535 "Destroying set after operation cancel\n"); 531 "Destroying set after operation cancel\n");
536 GNUNET_SET_destroy (set); 532 GNUNET_SET_destroy(set);
537 } 533 }
538} 534}
539 535
540 536
@@ -546,31 +542,31 @@ GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh)
546 * @param error error code 542 * @param error error code
547 */ 543 */
548static void 544static void
549handle_client_set_error (void *cls, 545handle_client_set_error(void *cls,
550 enum GNUNET_MQ_Error error) 546 enum GNUNET_MQ_Error error)
551{ 547{
552 struct GNUNET_SET_Handle *set = cls; 548 struct GNUNET_SET_Handle *set = cls;
553 GNUNET_SET_ElementIterator iter = set->iterator; 549 GNUNET_SET_ElementIterator iter = set->iterator;
554 550
555 LOG (GNUNET_ERROR_TYPE_ERROR, 551 LOG(GNUNET_ERROR_TYPE_ERROR,
556 "Handling client set error %d\n", 552 "Handling client set error %d\n",
557 error); 553 error);
558 while (NULL != set->ops_head) 554 while (NULL != set->ops_head)
559 { 555 {
560 if ( (NULL != set->ops_head->result_cb) && 556 if ((NULL != set->ops_head->result_cb) &&
561 (GNUNET_NO == set->destroy_requested) ) 557 (GNUNET_NO == set->destroy_requested))
562 set->ops_head->result_cb (set->ops_head->result_cls, 558 set->ops_head->result_cb(set->ops_head->result_cls,
563 NULL, 559 NULL,
564 0, 560 0,
565 GNUNET_SET_STATUS_FAILURE); 561 GNUNET_SET_STATUS_FAILURE);
566 set_operation_destroy (set->ops_head); 562 set_operation_destroy(set->ops_head);
567 } 563 }
568 set->iterator = NULL; 564 set->iterator = NULL;
569 set->iteration_id++; 565 set->iteration_id++;
570 set->invalid = GNUNET_YES; 566 set->invalid = GNUNET_YES;
571 if (NULL != iter) 567 if (NULL != iter)
572 iter (set->iterator_cls, 568 iter(set->iterator_cls,
573 NULL); 569 NULL);
574} 570}
575 571
576 572
@@ -578,65 +574,65 @@ handle_client_set_error (void *cls,
578 * FIXME. 574 * FIXME.
579 */ 575 */
580static struct GNUNET_SET_Handle * 576static struct GNUNET_SET_Handle *
581create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg, 577create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg,
582 enum GNUNET_SET_OperationType op, 578 enum GNUNET_SET_OperationType op,
583 const uint32_t *cookie) 579 const uint32_t *cookie)
584{ 580{
585 struct GNUNET_SET_Handle *set = GNUNET_new (struct GNUNET_SET_Handle); 581 struct GNUNET_SET_Handle *set = GNUNET_new(struct GNUNET_SET_Handle);
586 struct GNUNET_MQ_MessageHandler mq_handlers[] = { 582 struct GNUNET_MQ_MessageHandler mq_handlers[] = {
587 GNUNET_MQ_hd_var_size (result, 583 GNUNET_MQ_hd_var_size(result,
588 GNUNET_MESSAGE_TYPE_SET_RESULT, 584 GNUNET_MESSAGE_TYPE_SET_RESULT,
589 struct GNUNET_SET_ResultMessage, 585 struct GNUNET_SET_ResultMessage,
590 set), 586 set),
591 GNUNET_MQ_hd_var_size (iter_element, 587 GNUNET_MQ_hd_var_size(iter_element,
592 GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT, 588 GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT,
593 struct GNUNET_SET_IterResponseMessage, 589 struct GNUNET_SET_IterResponseMessage,
594 set), 590 set),
595 GNUNET_MQ_hd_fixed_size (iter_done, 591 GNUNET_MQ_hd_fixed_size(iter_done,
596 GNUNET_MESSAGE_TYPE_SET_ITER_DONE, 592 GNUNET_MESSAGE_TYPE_SET_ITER_DONE,
597 struct GNUNET_MessageHeader, 593 struct GNUNET_MessageHeader,
598 set), 594 set),
599 GNUNET_MQ_hd_fixed_size (copy_lazy, 595 GNUNET_MQ_hd_fixed_size(copy_lazy,
600 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE, 596 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE,
601 struct GNUNET_SET_CopyLazyResponseMessage, 597 struct GNUNET_SET_CopyLazyResponseMessage,
602 set), 598 set),
603 GNUNET_MQ_handler_end () 599 GNUNET_MQ_handler_end()
604 }; 600 };
605 struct GNUNET_MQ_Envelope *mqm; 601 struct GNUNET_MQ_Envelope *mqm;
606 struct GNUNET_SET_CreateMessage *create_msg; 602 struct GNUNET_SET_CreateMessage *create_msg;
607 struct GNUNET_SET_CopyLazyConnectMessage *copy_msg; 603 struct GNUNET_SET_CopyLazyConnectMessage *copy_msg;
608 604
609 set->cfg = cfg; 605 set->cfg = cfg;
610 set->mq = GNUNET_CLIENT_connect (cfg, 606 set->mq = GNUNET_CLIENT_connect(cfg,
611 "set", 607 "set",
612 mq_handlers, 608 mq_handlers,
613 &handle_client_set_error, 609 &handle_client_set_error,
614 set); 610 set);
615 if (NULL == set->mq) 611 if (NULL == set->mq)
616 { 612 {
617 GNUNET_free (set); 613 GNUNET_free(set);
618 return NULL; 614 return NULL;
619 } 615 }
620 if (NULL == cookie) 616 if (NULL == cookie)
621 { 617 {
622 LOG (GNUNET_ERROR_TYPE_DEBUG, 618 LOG(GNUNET_ERROR_TYPE_DEBUG,
623 "Creating new set (operation %u)\n", 619 "Creating new set (operation %u)\n",
624 op); 620 op);
625 mqm = GNUNET_MQ_msg (create_msg, 621 mqm = GNUNET_MQ_msg(create_msg,
626 GNUNET_MESSAGE_TYPE_SET_CREATE); 622 GNUNET_MESSAGE_TYPE_SET_CREATE);
627 create_msg->operation = htonl (op); 623 create_msg->operation = htonl(op);
628 } 624 }
629 else 625 else
630 { 626 {
631 LOG (GNUNET_ERROR_TYPE_DEBUG, 627 LOG(GNUNET_ERROR_TYPE_DEBUG,
632 "Creating new set (lazy copy)\n", 628 "Creating new set (lazy copy)\n",
633 op); 629 op);
634 mqm = GNUNET_MQ_msg (copy_msg, 630 mqm = GNUNET_MQ_msg(copy_msg,
635 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT); 631 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT);
636 copy_msg->cookie = *cookie; 632 copy_msg->cookie = *cookie;
637 } 633 }
638 GNUNET_MQ_send (set->mq, 634 GNUNET_MQ_send(set->mq,
639 mqm); 635 mqm);
640 return set; 636 return set;
641} 637}
642 638
@@ -653,18 +649,18 @@ create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg,
653 * @return a handle to the set 649 * @return a handle to the set
654 */ 650 */
655struct GNUNET_SET_Handle * 651struct GNUNET_SET_Handle *
656GNUNET_SET_create (const struct GNUNET_CONFIGURATION_Handle *cfg, 652GNUNET_SET_create(const struct GNUNET_CONFIGURATION_Handle *cfg,
657 enum GNUNET_SET_OperationType op) 653 enum GNUNET_SET_OperationType op)
658{ 654{
659 struct GNUNET_SET_Handle *set; 655 struct GNUNET_SET_Handle *set;
660 656
661 set = create_internal (cfg, 657 set = create_internal(cfg,
662 op, 658 op,
663 NULL); 659 NULL);
664 LOG (GNUNET_ERROR_TYPE_DEBUG, 660 LOG(GNUNET_ERROR_TYPE_DEBUG,
665 "Creating set %p for operation %d\n", 661 "Creating set %p for operation %d\n",
666 set, 662 set,
667 op); 663 op);
668 return set; 664 return set;
669} 665}
670 666
@@ -683,35 +679,35 @@ GNUNET_SET_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
683 * set is invalid (e.g. the set service crashed) 679 * set is invalid (e.g. the set service crashed)
684 */ 680 */
685int 681int
686GNUNET_SET_add_element (struct GNUNET_SET_Handle *set, 682GNUNET_SET_add_element(struct GNUNET_SET_Handle *set,
687 const struct GNUNET_SET_Element *element, 683 const struct GNUNET_SET_Element *element,
688 GNUNET_SET_Continuation cont, 684 GNUNET_SET_Continuation cont,
689 void *cont_cls) 685 void *cont_cls)
690{ 686{
691 struct GNUNET_MQ_Envelope *mqm; 687 struct GNUNET_MQ_Envelope *mqm;
692 struct GNUNET_SET_ElementMessage *msg; 688 struct GNUNET_SET_ElementMessage *msg;
693 689
694 LOG (GNUNET_ERROR_TYPE_DEBUG, 690 LOG(GNUNET_ERROR_TYPE_DEBUG,
695 "adding element of type %u to set %p\n", 691 "adding element of type %u to set %p\n",
696 (unsigned int) element->element_type, 692 (unsigned int)element->element_type,
697 set); 693 set);
698 GNUNET_assert (NULL != set); 694 GNUNET_assert(NULL != set);
699 if (GNUNET_YES == set->invalid) 695 if (GNUNET_YES == set->invalid)
700 { 696 {
701 if (NULL != cont) 697 if (NULL != cont)
702 cont (cont_cls); 698 cont(cont_cls);
703 return GNUNET_SYSERR; 699 return GNUNET_SYSERR;
704 } 700 }
705 mqm = GNUNET_MQ_msg_extra (msg, 701 mqm = GNUNET_MQ_msg_extra(msg,
706 element->size, 702 element->size,
707 GNUNET_MESSAGE_TYPE_SET_ADD); 703 GNUNET_MESSAGE_TYPE_SET_ADD);
708 msg->element_type = htons (element->element_type); 704 msg->element_type = htons(element->element_type);
709 GNUNET_memcpy (&msg[1], 705 GNUNET_memcpy(&msg[1],
710 element->data, 706 element->data,
711 element->size); 707 element->size);
712 GNUNET_MQ_notify_sent (mqm, 708 GNUNET_MQ_notify_sent(mqm,
713 cont, cont_cls); 709 cont, cont_cls);
714 GNUNET_MQ_send (set->mq, mqm); 710 GNUNET_MQ_send(set->mq, mqm);
715 return GNUNET_OK; 711 return GNUNET_OK;
716} 712}
717 713
@@ -730,33 +726,33 @@ GNUNET_SET_add_element (struct GNUNET_SET_Handle *set,
730 * set is invalid (e.g. the set service crashed) 726 * set is invalid (e.g. the set service crashed)
731 */ 727 */
732int 728int
733GNUNET_SET_remove_element (struct GNUNET_SET_Handle *set, 729GNUNET_SET_remove_element(struct GNUNET_SET_Handle *set,
734 const struct GNUNET_SET_Element *element, 730 const struct GNUNET_SET_Element *element,
735 GNUNET_SET_Continuation cont, 731 GNUNET_SET_Continuation cont,
736 void *cont_cls) 732 void *cont_cls)
737{ 733{
738 struct GNUNET_MQ_Envelope *mqm; 734 struct GNUNET_MQ_Envelope *mqm;
739 struct GNUNET_SET_ElementMessage *msg; 735 struct GNUNET_SET_ElementMessage *msg;
740 736
741 LOG (GNUNET_ERROR_TYPE_DEBUG, 737 LOG(GNUNET_ERROR_TYPE_DEBUG,
742 "Removing element from set %p\n", 738 "Removing element from set %p\n",
743 set); 739 set);
744 if (GNUNET_YES == set->invalid) 740 if (GNUNET_YES == set->invalid)
745 { 741 {
746 if (NULL != cont) 742 if (NULL != cont)
747 cont (cont_cls); 743 cont(cont_cls);
748 return GNUNET_SYSERR; 744 return GNUNET_SYSERR;
749 } 745 }
750 mqm = GNUNET_MQ_msg_extra (msg, 746 mqm = GNUNET_MQ_msg_extra(msg,
751 element->size, 747 element->size,
752 GNUNET_MESSAGE_TYPE_SET_REMOVE); 748 GNUNET_MESSAGE_TYPE_SET_REMOVE);
753 msg->element_type = htons (element->element_type); 749 msg->element_type = htons(element->element_type);
754 GNUNET_memcpy (&msg[1], 750 GNUNET_memcpy(&msg[1],
755 element->data, 751 element->data,
756 element->size); 752 element->size);
757 GNUNET_MQ_notify_sent (mqm, 753 GNUNET_MQ_notify_sent(mqm,
758 cont, cont_cls); 754 cont, cont_cls);
759 GNUNET_MQ_send (set->mq, mqm); 755 GNUNET_MQ_send(set->mq, mqm);
760 return GNUNET_OK; 756 return GNUNET_OK;
761} 757}
762 758
@@ -768,29 +764,29 @@ GNUNET_SET_remove_element (struct GNUNET_SET_Handle *set,
768 * @param set set handle to destroy 764 * @param set set handle to destroy
769 */ 765 */
770void 766void
771GNUNET_SET_destroy (struct GNUNET_SET_Handle *set) 767GNUNET_SET_destroy(struct GNUNET_SET_Handle *set)
772{ 768{
773 /* destroying set while iterator is active is currently 769 /* destroying set while iterator is active is currently
774 not supported; we should expand the API to allow 770 not supported; we should expand the API to allow
775 clients to explicitly cancel the iteration! */ 771 clients to explicitly cancel the iteration! */
776 GNUNET_assert (NULL != set); 772 GNUNET_assert(NULL != set);
777 if ( (NULL != set->ops_head) || 773 if ((NULL != set->ops_head) ||
778 (NULL != set->iterator) || 774 (NULL != set->iterator) ||
779 (GNUNET_SYSERR == set->destroy_requested) ) 775 (GNUNET_SYSERR == set->destroy_requested))
780 { 776 {
781 LOG (GNUNET_ERROR_TYPE_DEBUG, 777 LOG(GNUNET_ERROR_TYPE_DEBUG,
782 "Set operations are pending, delaying set destruction\n"); 778 "Set operations are pending, delaying set destruction\n");
783 set->destroy_requested = GNUNET_YES; 779 set->destroy_requested = GNUNET_YES;
784 return; 780 return;
785 } 781 }
786 LOG (GNUNET_ERROR_TYPE_DEBUG, 782 LOG(GNUNET_ERROR_TYPE_DEBUG,
787 "Really destroying set\n"); 783 "Really destroying set\n");
788 if (NULL != set->mq) 784 if (NULL != set->mq)
789 { 785 {
790 GNUNET_MQ_destroy (set->mq); 786 GNUNET_MQ_destroy(set->mq);
791 set->mq = NULL; 787 set->mq = NULL;
792 } 788 }
793 GNUNET_free (set); 789 GNUNET_free(set);
794} 790}
795 791
796 792
@@ -809,50 +805,53 @@ GNUNET_SET_destroy (struct GNUNET_SET_Handle *set)
809 * @return a handle to cancel the operation 805 * @return a handle to cancel the operation
810 */ 806 */
811struct GNUNET_SET_OperationHandle * 807struct GNUNET_SET_OperationHandle *
812GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer, 808GNUNET_SET_prepare(const struct GNUNET_PeerIdentity *other_peer,
813 const struct GNUNET_HashCode *app_id, 809 const struct GNUNET_HashCode *app_id,
814 const struct GNUNET_MessageHeader *context_msg, 810 const struct GNUNET_MessageHeader *context_msg,
815 enum GNUNET_SET_ResultMode result_mode, 811 enum GNUNET_SET_ResultMode result_mode,
816 struct GNUNET_SET_Option options[], 812 struct GNUNET_SET_Option options[],
817 GNUNET_SET_ResultIterator result_cb, 813 GNUNET_SET_ResultIterator result_cb,
818 void *result_cls) 814 void *result_cls)
819{ 815{
820 struct GNUNET_MQ_Envelope *mqm; 816 struct GNUNET_MQ_Envelope *mqm;
821 struct GNUNET_SET_OperationHandle *oh; 817 struct GNUNET_SET_OperationHandle *oh;
822 struct GNUNET_SET_EvaluateMessage *msg; 818 struct GNUNET_SET_EvaluateMessage *msg;
823 struct GNUNET_SET_Option *opt; 819 struct GNUNET_SET_Option *opt;
824 820
825 LOG (GNUNET_ERROR_TYPE_DEBUG, 821 LOG(GNUNET_ERROR_TYPE_DEBUG,
826 "Client prepares set operation (%d)\n", 822 "Client prepares set operation (%d)\n",
827 result_mode); 823 result_mode);
828 oh = GNUNET_new (struct GNUNET_SET_OperationHandle); 824 oh = GNUNET_new(struct GNUNET_SET_OperationHandle);
829 oh->result_cb = result_cb; 825 oh->result_cb = result_cb;
830 oh->result_cls = result_cls; 826 oh->result_cls = result_cls;
831 mqm = GNUNET_MQ_msg_nested_mh (msg, 827 mqm = GNUNET_MQ_msg_nested_mh(msg,
832 GNUNET_MESSAGE_TYPE_SET_EVALUATE, 828 GNUNET_MESSAGE_TYPE_SET_EVALUATE,
833 context_msg); 829 context_msg);
834 msg->app_id = *app_id; 830 msg->app_id = *app_id;
835 msg->result_mode = htonl (result_mode); 831 msg->result_mode = htonl(result_mode);
836 msg->target_peer = *other_peer; 832 msg->target_peer = *other_peer;
837 for (opt = options; opt->type != 0; opt++) 833 for (opt = options; opt->type != 0; opt++)
838 {
839 switch (opt->type)
840 { 834 {
841 case GNUNET_SET_OPTION_BYZANTINE: 835 switch (opt->type)
842 msg->byzantine = GNUNET_YES; 836 {
843 msg->byzantine_lower_bound = opt->v.num; 837 case GNUNET_SET_OPTION_BYZANTINE:
844 break; 838 msg->byzantine = GNUNET_YES;
845 case GNUNET_SET_OPTION_FORCE_FULL: 839 msg->byzantine_lower_bound = opt->v.num;
846 msg->force_full = GNUNET_YES; 840 break;
847 break; 841
848 case GNUNET_SET_OPTION_FORCE_DELTA: 842 case GNUNET_SET_OPTION_FORCE_FULL:
849 msg->force_delta = GNUNET_YES; 843 msg->force_full = GNUNET_YES;
850 break; 844 break;
851 default: 845
852 LOG (GNUNET_ERROR_TYPE_ERROR, 846 case GNUNET_SET_OPTION_FORCE_DELTA:
853 "Option with type %d not recognized\n", (int) opt->type); 847 msg->force_delta = GNUNET_YES;
848 break;
849
850 default:
851 LOG(GNUNET_ERROR_TYPE_ERROR,
852 "Option with type %d not recognized\n", (int)opt->type);
853 }
854 } 854 }
855 }
856 oh->conclude_mqm = mqm; 855 oh->conclude_mqm = mqm;
857 oh->request_id_addr = &msg->request_id; 856 oh->request_id_addr = &msg->request_id;
858 857
@@ -866,7 +865,7 @@ GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer,
866 * @param cls the `struct GNUNET_SET_ListenHandle *` to connect 865 * @param cls the `struct GNUNET_SET_ListenHandle *` to connect
867 */ 866 */
868static void 867static void
869listen_connect (void *cls); 868listen_connect(void *cls);
870 869
871 870
872/** 871/**
@@ -877,20 +876,20 @@ listen_connect (void *cls);
877 * @return #GNUNET_OK if the message is well-formed 876 * @return #GNUNET_OK if the message is well-formed
878 */ 877 */
879static int 878static int
880check_request (void *cls, 879check_request(void *cls,
881 const struct GNUNET_SET_RequestMessage *msg) 880 const struct GNUNET_SET_RequestMessage *msg)
882{ 881{
883 const struct GNUNET_MessageHeader *context_msg; 882 const struct GNUNET_MessageHeader *context_msg;
884 883
885 if (ntohs (msg->header.size) == sizeof (*msg)) 884 if (ntohs(msg->header.size) == sizeof(*msg))
886 return GNUNET_OK; /* no context message is OK */ 885 return GNUNET_OK; /* no context message is OK */
887 context_msg = GNUNET_MQ_extract_nested_mh (msg); 886 context_msg = GNUNET_MQ_extract_nested_mh(msg);
888 if (NULL == context_msg) 887 if (NULL == context_msg)
889 { 888 {
890 /* malformed context message is NOT ok */ 889 /* malformed context message is NOT ok */
891 GNUNET_break_op (0); 890 GNUNET_break_op(0);
892 return GNUNET_SYSERR; 891 return GNUNET_SYSERR;
893 } 892 }
894 return GNUNET_OK; 893 return GNUNET_OK;
895} 894}
896 895
@@ -902,8 +901,8 @@ check_request (void *cls,
902 * @param msg the message 901 * @param msg the message
903 */ 902 */
904static void 903static void
905handle_request (void *cls, 904handle_request(void *cls,
906 const struct GNUNET_SET_RequestMessage *msg) 905 const struct GNUNET_SET_RequestMessage *msg)
907{ 906{
908 struct GNUNET_SET_ListenHandle *lh = cls; 907 struct GNUNET_SET_ListenHandle *lh = cls;
909 struct GNUNET_SET_Request req; 908 struct GNUNET_SET_Request req;
@@ -911,28 +910,28 @@ handle_request (void *cls,
911 struct GNUNET_MQ_Envelope *mqm; 910 struct GNUNET_MQ_Envelope *mqm;
912 struct GNUNET_SET_RejectMessage *rmsg; 911 struct GNUNET_SET_RejectMessage *rmsg;
913 912
914 LOG (GNUNET_ERROR_TYPE_DEBUG, 913 LOG(GNUNET_ERROR_TYPE_DEBUG,
915 "Processing incoming operation request with id %u\n", 914 "Processing incoming operation request with id %u\n",
916 ntohl (msg->accept_id)); 915 ntohl(msg->accept_id));
917 /* we got another valid request => reset the backoff */ 916 /* we got another valid request => reset the backoff */
918 lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; 917 lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
919 req.accept_id = ntohl (msg->accept_id); 918 req.accept_id = ntohl(msg->accept_id);
920 req.accepted = GNUNET_NO; 919 req.accepted = GNUNET_NO;
921 context_msg = GNUNET_MQ_extract_nested_mh (msg); 920 context_msg = GNUNET_MQ_extract_nested_mh(msg);
922 /* calling #GNUNET_SET_accept() in the listen cb will set req->accepted */ 921 /* calling #GNUNET_SET_accept() in the listen cb will set req->accepted */
923 lh->listen_cb (lh->listen_cls, 922 lh->listen_cb(lh->listen_cls,
924 &msg->peer_id, 923 &msg->peer_id,
925 context_msg, 924 context_msg,
926 &req); 925 &req);
927 if (GNUNET_YES == req.accepted) 926 if (GNUNET_YES == req.accepted)
928 return; /* the accept-case is handled in #GNUNET_SET_accept() */ 927 return; /* the accept-case is handled in #GNUNET_SET_accept() */
929 LOG (GNUNET_ERROR_TYPE_DEBUG, 928 LOG(GNUNET_ERROR_TYPE_DEBUG,
930 "Rejected request %u\n", 929 "Rejected request %u\n",
931 ntohl (msg->accept_id)); 930 ntohl(msg->accept_id));
932 mqm = GNUNET_MQ_msg (rmsg, 931 mqm = GNUNET_MQ_msg(rmsg,
933 GNUNET_MESSAGE_TYPE_SET_REJECT); 932 GNUNET_MESSAGE_TYPE_SET_REJECT);
934 rmsg->accept_reject_id = msg->accept_id; 933 rmsg->accept_reject_id = msg->accept_id;
935 GNUNET_MQ_send (lh->mq, mqm); 934 GNUNET_MQ_send(lh->mq, mqm);
936} 935}
937 936
938 937
@@ -944,20 +943,20 @@ handle_request (void *cls,
944 * @param error reason for the disconnect 943 * @param error reason for the disconnect
945 */ 944 */
946static void 945static void
947handle_client_listener_error (void *cls, 946handle_client_listener_error(void *cls,
948 enum GNUNET_MQ_Error error) 947 enum GNUNET_MQ_Error error)
949{ 948{
950 struct GNUNET_SET_ListenHandle *lh = cls; 949 struct GNUNET_SET_ListenHandle *lh = cls;
951 950
952 LOG (GNUNET_ERROR_TYPE_DEBUG, 951 LOG(GNUNET_ERROR_TYPE_DEBUG,
953 "Listener broke down (%d), re-connecting\n", 952 "Listener broke down (%d), re-connecting\n",
954 (int) error); 953 (int)error);
955 GNUNET_MQ_destroy (lh->mq); 954 GNUNET_MQ_destroy(lh->mq);
956 lh->mq = NULL; 955 lh->mq = NULL;
957 lh->reconnect_task = GNUNET_SCHEDULER_add_delayed (lh->reconnect_backoff, 956 lh->reconnect_task = GNUNET_SCHEDULER_add_delayed(lh->reconnect_backoff,
958 &listen_connect, 957 &listen_connect,
959 lh); 958 lh);
960 lh->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (lh->reconnect_backoff); 959 lh->reconnect_backoff = GNUNET_TIME_STD_BACKOFF(lh->reconnect_backoff);
961} 960}
962 961
963 962
@@ -967,33 +966,33 @@ handle_client_listener_error (void *cls,
967 * @param cls the `struct GNUNET_SET_ListenHandle *` to connect 966 * @param cls the `struct GNUNET_SET_ListenHandle *` to connect
968 */ 967 */
969static void 968static void
970listen_connect (void *cls) 969listen_connect(void *cls)
971{ 970{
972 struct GNUNET_SET_ListenHandle *lh = cls; 971 struct GNUNET_SET_ListenHandle *lh = cls;
973 struct GNUNET_MQ_MessageHandler mq_handlers[] = { 972 struct GNUNET_MQ_MessageHandler mq_handlers[] = {
974 GNUNET_MQ_hd_var_size (request, 973 GNUNET_MQ_hd_var_size(request,
975 GNUNET_MESSAGE_TYPE_SET_REQUEST, 974 GNUNET_MESSAGE_TYPE_SET_REQUEST,
976 struct GNUNET_SET_RequestMessage, 975 struct GNUNET_SET_RequestMessage,
977 lh), 976 lh),
978 GNUNET_MQ_handler_end () 977 GNUNET_MQ_handler_end()
979 }; 978 };
980 struct GNUNET_MQ_Envelope *mqm; 979 struct GNUNET_MQ_Envelope *mqm;
981 struct GNUNET_SET_ListenMessage *msg; 980 struct GNUNET_SET_ListenMessage *msg;
982 981
983 lh->reconnect_task = NULL; 982 lh->reconnect_task = NULL;
984 GNUNET_assert (NULL == lh->mq); 983 GNUNET_assert(NULL == lh->mq);
985 lh->mq = GNUNET_CLIENT_connect (lh->cfg, 984 lh->mq = GNUNET_CLIENT_connect(lh->cfg,
986 "set", 985 "set",
987 mq_handlers, 986 mq_handlers,
988 &handle_client_listener_error, 987 &handle_client_listener_error,
989 lh); 988 lh);
990 if (NULL == lh->mq) 989 if (NULL == lh->mq)
991 return; 990 return;
992 mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_LISTEN); 991 mqm = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_SET_LISTEN);
993 msg->operation = htonl (lh->operation); 992 msg->operation = htonl(lh->operation);
994 msg->app_id = lh->app_id; 993 msg->app_id = lh->app_id;
995 GNUNET_MQ_send (lh->mq, 994 GNUNET_MQ_send(lh->mq,
996 mqm); 995 mqm);
997} 996}
998 997
999 998
@@ -1010,30 +1009,30 @@ listen_connect (void *cls)
1010 * @return a handle that can be used to cancel the listen operation 1009 * @return a handle that can be used to cancel the listen operation
1011 */ 1010 */
1012struct GNUNET_SET_ListenHandle * 1011struct GNUNET_SET_ListenHandle *
1013GNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg, 1012GNUNET_SET_listen(const struct GNUNET_CONFIGURATION_Handle *cfg,
1014 enum GNUNET_SET_OperationType operation, 1013 enum GNUNET_SET_OperationType operation,
1015 const struct GNUNET_HashCode *app_id, 1014 const struct GNUNET_HashCode *app_id,
1016 GNUNET_SET_ListenCallback listen_cb, 1015 GNUNET_SET_ListenCallback listen_cb,
1017 void *listen_cls) 1016 void *listen_cls)
1018{ 1017{
1019 struct GNUNET_SET_ListenHandle *lh; 1018 struct GNUNET_SET_ListenHandle *lh;
1020 1019
1021 LOG (GNUNET_ERROR_TYPE_DEBUG, 1020 LOG(GNUNET_ERROR_TYPE_DEBUG,
1022 "Starting listener for app %s\n", 1021 "Starting listener for app %s\n",
1023 GNUNET_h2s (app_id)); 1022 GNUNET_h2s(app_id));
1024 lh = GNUNET_new (struct GNUNET_SET_ListenHandle); 1023 lh = GNUNET_new(struct GNUNET_SET_ListenHandle);
1025 lh->listen_cb = listen_cb; 1024 lh->listen_cb = listen_cb;
1026 lh->listen_cls = listen_cls; 1025 lh->listen_cls = listen_cls;
1027 lh->cfg = cfg; 1026 lh->cfg = cfg;
1028 lh->operation = operation; 1027 lh->operation = operation;
1029 lh->app_id = *app_id; 1028 lh->app_id = *app_id;
1030 lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; 1029 lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
1031 listen_connect (lh); 1030 listen_connect(lh);
1032 if (NULL == lh->mq) 1031 if (NULL == lh->mq)
1033 { 1032 {
1034 GNUNET_free (lh); 1033 GNUNET_free(lh);
1035 return NULL; 1034 return NULL;
1036 } 1035 }
1037 return lh; 1036 return lh;
1038} 1037}
1039 1038
@@ -1044,22 +1043,22 @@ GNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg,
1044 * @param lh handle for the listen operation 1043 * @param lh handle for the listen operation
1045 */ 1044 */
1046void 1045void
1047GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh) 1046GNUNET_SET_listen_cancel(struct GNUNET_SET_ListenHandle *lh)
1048{ 1047{
1049 LOG (GNUNET_ERROR_TYPE_DEBUG, 1048 LOG(GNUNET_ERROR_TYPE_DEBUG,
1050 "Canceling listener %s\n", 1049 "Canceling listener %s\n",
1051 GNUNET_h2s (&lh->app_id)); 1050 GNUNET_h2s(&lh->app_id));
1052 if (NULL != lh->mq) 1051 if (NULL != lh->mq)
1053 { 1052 {
1054 GNUNET_MQ_destroy (lh->mq); 1053 GNUNET_MQ_destroy(lh->mq);
1055 lh->mq = NULL; 1054 lh->mq = NULL;
1056 } 1055 }
1057 if (NULL != lh->reconnect_task) 1056 if (NULL != lh->reconnect_task)
1058 { 1057 {
1059 GNUNET_SCHEDULER_cancel (lh->reconnect_task); 1058 GNUNET_SCHEDULER_cancel(lh->reconnect_task);
1060 lh->reconnect_task = NULL; 1059 lh->reconnect_task = NULL;
1061 } 1060 }
1062 GNUNET_free (lh); 1061 GNUNET_free(lh);
1063} 1062}
1064 1063
1065 1064
@@ -1078,27 +1077,27 @@ GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh)
1078 * @return a handle to cancel the operation 1077 * @return a handle to cancel the operation
1079 */ 1078 */
1080struct GNUNET_SET_OperationHandle * 1079struct GNUNET_SET_OperationHandle *
1081GNUNET_SET_accept (struct GNUNET_SET_Request *request, 1080GNUNET_SET_accept(struct GNUNET_SET_Request *request,
1082 enum GNUNET_SET_ResultMode result_mode, 1081 enum GNUNET_SET_ResultMode result_mode,
1083 struct GNUNET_SET_Option options[], 1082 struct GNUNET_SET_Option options[],
1084 GNUNET_SET_ResultIterator result_cb, 1083 GNUNET_SET_ResultIterator result_cb,
1085 void *result_cls) 1084 void *result_cls)
1086{ 1085{
1087 struct GNUNET_MQ_Envelope *mqm; 1086 struct GNUNET_MQ_Envelope *mqm;
1088 struct GNUNET_SET_OperationHandle *oh; 1087 struct GNUNET_SET_OperationHandle *oh;
1089 struct GNUNET_SET_AcceptMessage *msg; 1088 struct GNUNET_SET_AcceptMessage *msg;
1090 1089
1091 GNUNET_assert (GNUNET_NO == request->accepted); 1090 GNUNET_assert(GNUNET_NO == request->accepted);
1092 LOG (GNUNET_ERROR_TYPE_DEBUG, 1091 LOG(GNUNET_ERROR_TYPE_DEBUG,
1093 "Client accepts set operation (%d) with id %u\n", 1092 "Client accepts set operation (%d) with id %u\n",
1094 result_mode, 1093 result_mode,
1095 request->accept_id); 1094 request->accept_id);
1096 request->accepted = GNUNET_YES; 1095 request->accepted = GNUNET_YES;
1097 mqm = GNUNET_MQ_msg (msg, 1096 mqm = GNUNET_MQ_msg(msg,
1098 GNUNET_MESSAGE_TYPE_SET_ACCEPT); 1097 GNUNET_MESSAGE_TYPE_SET_ACCEPT);
1099 msg->accept_reject_id = htonl (request->accept_id); 1098 msg->accept_reject_id = htonl(request->accept_id);
1100 msg->result_mode = htonl (result_mode); 1099 msg->result_mode = htonl(result_mode);
1101 oh = GNUNET_new (struct GNUNET_SET_OperationHandle); 1100 oh = GNUNET_new(struct GNUNET_SET_OperationHandle);
1102 oh->result_cb = result_cb; 1101 oh->result_cb = result_cb;
1103 oh->result_cls = result_cls; 1102 oh->result_cls = result_cls;
1104 oh->conclude_mqm = mqm; 1103 oh->conclude_mqm = mqm;
@@ -1121,31 +1120,31 @@ GNUNET_SET_accept (struct GNUNET_SET_Request *request,
1121 * set is invalid (e.g. the set service crashed) 1120 * set is invalid (e.g. the set service crashed)
1122 */ 1121 */
1123int 1122int
1124GNUNET_SET_commit (struct GNUNET_SET_OperationHandle *oh, 1123GNUNET_SET_commit(struct GNUNET_SET_OperationHandle *oh,
1125 struct GNUNET_SET_Handle *set) 1124 struct GNUNET_SET_Handle *set)
1126{ 1125{
1127 if (NULL != oh->set) 1126 if (NULL != oh->set)
1128 { 1127 {
1129 /* Some other set was already committed for this 1128 /* Some other set was already committed for this
1130 * operation, there is a logic bug in the client of this API */ 1129 * operation, there is a logic bug in the client of this API */
1131 GNUNET_break (0); 1130 GNUNET_break(0);
1132 return GNUNET_OK; 1131 return GNUNET_OK;
1133 } 1132 }
1134 GNUNET_assert (NULL != set); 1133 GNUNET_assert(NULL != set);
1135 if (GNUNET_YES == set->invalid) 1134 if (GNUNET_YES == set->invalid)
1136 return GNUNET_SYSERR; 1135 return GNUNET_SYSERR;
1137 LOG (GNUNET_ERROR_TYPE_DEBUG, 1136 LOG(GNUNET_ERROR_TYPE_DEBUG,
1138 "Client commits to SET\n"); 1137 "Client commits to SET\n");
1139 GNUNET_assert (NULL != oh->conclude_mqm); 1138 GNUNET_assert(NULL != oh->conclude_mqm);
1140 oh->set = set; 1139 oh->set = set;
1141 GNUNET_CONTAINER_DLL_insert (set->ops_head, 1140 GNUNET_CONTAINER_DLL_insert(set->ops_head,
1142 set->ops_tail, 1141 set->ops_tail,
1143 oh); 1142 oh);
1144 oh->request_id = GNUNET_MQ_assoc_add (set->mq, 1143 oh->request_id = GNUNET_MQ_assoc_add(set->mq,
1145 oh); 1144 oh);
1146 *oh->request_id_addr = htonl (oh->request_id); 1145 *oh->request_id_addr = htonl(oh->request_id);
1147 GNUNET_MQ_send (set->mq, 1146 GNUNET_MQ_send(set->mq,
1148 oh->conclude_mqm); 1147 oh->conclude_mqm);
1149 oh->conclude_mqm = NULL; 1148 oh->conclude_mqm = NULL;
1150 oh->request_id_addr = NULL; 1149 oh->request_id_addr = NULL;
1151 return GNUNET_OK; 1150 return GNUNET_OK;
@@ -1165,46 +1164,46 @@ GNUNET_SET_commit (struct GNUNET_SET_OperationHandle *oh,
1165 * #GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected) 1164 * #GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected)
1166 */ 1165 */
1167int 1166int
1168GNUNET_SET_iterate (struct GNUNET_SET_Handle *set, 1167GNUNET_SET_iterate(struct GNUNET_SET_Handle *set,
1169 GNUNET_SET_ElementIterator iter, 1168 GNUNET_SET_ElementIterator iter,
1170 void *iter_cls) 1169 void *iter_cls)
1171{ 1170{
1172 struct GNUNET_MQ_Envelope *ev; 1171 struct GNUNET_MQ_Envelope *ev;
1173 1172
1174 GNUNET_assert (NULL != iter); 1173 GNUNET_assert(NULL != iter);
1175 if (GNUNET_YES == set->invalid) 1174 if (GNUNET_YES == set->invalid)
1176 return GNUNET_SYSERR; 1175 return GNUNET_SYSERR;
1177 if (NULL != set->iterator) 1176 if (NULL != set->iterator)
1178 return GNUNET_NO; 1177 return GNUNET_NO;
1179 LOG (GNUNET_ERROR_TYPE_DEBUG, 1178 LOG(GNUNET_ERROR_TYPE_DEBUG,
1180 "Iterating over set\n"); 1179 "Iterating over set\n");
1181 set->iterator = iter; 1180 set->iterator = iter;
1182 set->iterator_cls = iter_cls; 1181 set->iterator_cls = iter_cls;
1183 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST); 1182 ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST);
1184 GNUNET_MQ_send (set->mq, ev); 1183 GNUNET_MQ_send(set->mq, ev);
1185 return GNUNET_YES; 1184 return GNUNET_YES;
1186} 1185}
1187 1186
1188 1187
1189void 1188void
1190GNUNET_SET_copy_lazy (struct GNUNET_SET_Handle *set, 1189GNUNET_SET_copy_lazy(struct GNUNET_SET_Handle *set,
1191 GNUNET_SET_CopyReadyCallback cb, 1190 GNUNET_SET_CopyReadyCallback cb,
1192 void *cls) 1191 void *cls)
1193{ 1192{
1194 struct GNUNET_MQ_Envelope *ev; 1193 struct GNUNET_MQ_Envelope *ev;
1195 struct SetCopyRequest *req; 1194 struct SetCopyRequest *req;
1196 1195
1197 LOG (GNUNET_ERROR_TYPE_DEBUG, 1196 LOG(GNUNET_ERROR_TYPE_DEBUG,
1198 "Creating lazy copy of set\n"); 1197 "Creating lazy copy of set\n");
1199 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE); 1198 ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE);
1200 GNUNET_MQ_send (set->mq, ev); 1199 GNUNET_MQ_send(set->mq, ev);
1201 1200
1202 req = GNUNET_new (struct SetCopyRequest); 1201 req = GNUNET_new(struct SetCopyRequest);
1203 req->cb = cb; 1202 req->cb = cb;
1204 req->cls = cls; 1203 req->cls = cls;
1205 GNUNET_CONTAINER_DLL_insert (set->copy_req_head, 1204 GNUNET_CONTAINER_DLL_insert(set->copy_req_head,
1206 set->copy_req_tail, 1205 set->copy_req_tail,
1207 req); 1206 req);
1208} 1207}
1209 1208
1210 1209
@@ -1216,17 +1215,17 @@ GNUNET_SET_copy_lazy (struct GNUNET_SET_Handle *set,
1216 * @return the copied element 1215 * @return the copied element
1217 */ 1216 */
1218struct GNUNET_SET_Element * 1217struct GNUNET_SET_Element *
1219GNUNET_SET_element_dup (const struct GNUNET_SET_Element *element) 1218GNUNET_SET_element_dup(const struct GNUNET_SET_Element *element)
1220{ 1219{
1221 struct GNUNET_SET_Element *copy; 1220 struct GNUNET_SET_Element *copy;
1222 1221
1223 copy = GNUNET_malloc (element->size + sizeof (struct GNUNET_SET_Element)); 1222 copy = GNUNET_malloc(element->size + sizeof(struct GNUNET_SET_Element));
1224 copy->size = element->size; 1223 copy->size = element->size;
1225 copy->element_type = element->element_type; 1224 copy->element_type = element->element_type;
1226 copy->data = &copy[1]; 1225 copy->data = &copy[1];
1227 GNUNET_memcpy (&copy[1], 1226 GNUNET_memcpy(&copy[1],
1228 element->data, 1227 element->data,
1229 copy->size); 1228 copy->size);
1230 return copy; 1229 return copy;
1231} 1230}
1232 1231
@@ -1239,17 +1238,17 @@ GNUNET_SET_element_dup (const struct GNUNET_SET_Element *element)
1239 * should be stored 1238 * should be stored
1240 */ 1239 */
1241void 1240void
1242GNUNET_SET_element_hash (const struct GNUNET_SET_Element *element, 1241GNUNET_SET_element_hash(const struct GNUNET_SET_Element *element,
1243 struct GNUNET_HashCode *ret_hash) 1242 struct GNUNET_HashCode *ret_hash)
1244{ 1243{
1245 struct GNUNET_HashContext *ctx = GNUNET_CRYPTO_hash_context_start (); 1244 struct GNUNET_HashContext *ctx = GNUNET_CRYPTO_hash_context_start();
1246 1245
1247 /* It's not guaranteed that the element data is always after the element header, 1246 /* It's not guaranteed that the element data is always after the element header,
1248 so we need to hash the chunks separately. */ 1247 so we need to hash the chunks separately. */
1249 GNUNET_CRYPTO_hash_context_read (ctx, &element->size, sizeof (uint16_t)); 1248 GNUNET_CRYPTO_hash_context_read(ctx, &element->size, sizeof(uint16_t));
1250 GNUNET_CRYPTO_hash_context_read (ctx, &element->element_type, sizeof (uint16_t)); 1249 GNUNET_CRYPTO_hash_context_read(ctx, &element->element_type, sizeof(uint16_t));
1251 GNUNET_CRYPTO_hash_context_read (ctx, element->data, element->size); 1250 GNUNET_CRYPTO_hash_context_read(ctx, element->data, element->size);
1252 GNUNET_CRYPTO_hash_context_finish (ctx, ret_hash); 1251 GNUNET_CRYPTO_hash_context_finish(ctx, ret_hash);
1253} 1252}
1254 1253
1255/* end of set_api.c */ 1254/* end of set_api.c */