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.c126
1 files changed, 103 insertions, 23 deletions
diff --git a/src/set/set_api.c b/src/set/set_api.c
index 7a7267a33..f5c43a9a7 100644
--- a/src/set/set_api.c
+++ b/src/set/set_api.c
@@ -76,6 +76,8 @@ struct GNUNET_SET_Handle
76 76
77 /** 77 /**
78 * Should the set be destroyed once all operations are gone? 78 * Should the set be destroyed once all operations are gone?
79 * #GNUNET_SYSERR if #GNUNET_SET_destroy() must raise this flag,
80 * #GNUNET_YES if #GNUNET_SET_destroy() did raise this flag.
79 */ 81 */
80 int destroy_requested; 82 int destroy_requested;
81 83
@@ -297,9 +299,9 @@ check_iter_element (void *cls,
297 * @param cls the `struct GNUNET_SET_Handle *` 299 * @param cls the `struct GNUNET_SET_Handle *`
298 * @param mh the message 300 * @param mh the message
299 */ 301 */
300 static void 302static void
301 handle_iter_element (void *cls, 303handle_iter_element (void *cls,
302 const struct GNUNET_SET_IterResponseMessage *msg) 304 const struct GNUNET_SET_IterResponseMessage *msg)
303{ 305{
304 struct GNUNET_SET_Handle *set = cls; 306 struct GNUNET_SET_Handle *set = cls;
305 GNUNET_SET_ElementIterator iter = set->iterator; 307 GNUNET_SET_ElementIterator iter = set->iterator;
@@ -308,6 +310,8 @@ check_iter_element (void *cls,
308 struct GNUNET_MQ_Envelope *ev; 310 struct GNUNET_MQ_Envelope *ev;
309 uint16_t msize; 311 uint16_t msize;
310 312
313 LOG (GNUNET_ERROR_TYPE_DEBUG,
314 "Received element in set iteration\n");
311 msize = ntohs (msg->header.size); 315 msize = ntohs (msg->header.size);
312 if (set->iteration_id != ntohs (msg->iteration_id)) 316 if (set->iteration_id != ntohs (msg->iteration_id))
313 { 317 {
@@ -344,11 +348,24 @@ handle_iter_done (void *cls,
344 GNUNET_SET_ElementIterator iter = set->iterator; 348 GNUNET_SET_ElementIterator iter = set->iterator;
345 349
346 if (NULL == iter) 350 if (NULL == iter)
351 {
352 /* FIXME: if this is true, could cancel+start a fresh one
353 cause elements to go to the wrong iteration? */
354 LOG (GNUNET_ERROR_TYPE_INFO,
355 "Service completed set iteration that was already cancelled\n");
347 return; 356 return;
357 }
358 LOG (GNUNET_ERROR_TYPE_DEBUG,
359 "Set iteration completed\n");
360 set->destroy_requested = GNUNET_SYSERR;
348 set->iterator = NULL; 361 set->iterator = NULL;
349 set->iteration_id++; 362 set->iteration_id++;
350 iter (set->iterator_cls, 363 iter (set->iterator_cls,
351 NULL); 364 NULL);
365 if (GNUNET_SYSERR == set->destroy_requested)
366 set->destroy_requested = GNUNET_NO;
367 if (GNUNET_YES == set->destroy_requested)
368 GNUNET_SET_destroy (set);
352} 369}
353 370
354 371
@@ -385,7 +402,7 @@ handle_result (void *cls,
385 int destroy_set; 402 int destroy_set;
386 403
387 GNUNET_assert (NULL != set->mq); 404 GNUNET_assert (NULL != set->mq);
388 result_status = ntohs (msg->result_status); 405 result_status = (enum GNUNET_SET_Status) ntohs (msg->result_status);
389 LOG (GNUNET_ERROR_TYPE_DEBUG, 406 LOG (GNUNET_ERROR_TYPE_DEBUG,
390 "Got result message with status %d\n", 407 "Got result message with status %d\n",
391 result_status); 408 result_status);
@@ -432,6 +449,7 @@ do_final:
432 { 449 {
433 oh->result_cb (oh->result_cls, 450 oh->result_cb (oh->result_cls,
434 NULL, 451 NULL,
452 GNUNET_ntohll (msg->current_size),
435 result_status); 453 result_status);
436 } 454 }
437 else 455 else
@@ -453,6 +471,7 @@ do_element:
453 if (NULL != oh->result_cb) 471 if (NULL != oh->result_cb)
454 oh->result_cb (oh->result_cls, 472 oh->result_cb (oh->result_cls,
455 &e, 473 &e,
474 GNUNET_ntohll (msg->current_size),
456 result_status); 475 result_status);
457} 476}
458 477
@@ -498,6 +517,8 @@ GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh)
498 struct GNUNET_SET_CancelMessage *m; 517 struct GNUNET_SET_CancelMessage *m;
499 struct GNUNET_MQ_Envelope *mqm; 518 struct GNUNET_MQ_Envelope *mqm;
500 519
520 LOG (GNUNET_ERROR_TYPE_DEBUG,
521 "Cancelling SET operation\n");
501 if (NULL != set) 522 if (NULL != set)
502 { 523 {
503 mqm = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_SET_CANCEL); 524 mqm = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_SET_CANCEL);
@@ -530,7 +551,7 @@ handle_client_set_error (void *cls,
530 struct GNUNET_SET_Handle *set = cls; 551 struct GNUNET_SET_Handle *set = cls;
531 GNUNET_SET_ElementIterator iter = set->iterator; 552 GNUNET_SET_ElementIterator iter = set->iterator;
532 553
533 LOG (GNUNET_ERROR_TYPE_DEBUG, 554 LOG (GNUNET_ERROR_TYPE_ERROR,
534 "Handling client set error %d\n", 555 "Handling client set error %d\n",
535 error); 556 error);
536 while (NULL != set->ops_head) 557 while (NULL != set->ops_head)
@@ -538,24 +559,22 @@ handle_client_set_error (void *cls,
538 if (NULL != set->ops_head->result_cb) 559 if (NULL != set->ops_head->result_cb)
539 set->ops_head->result_cb (set->ops_head->result_cls, 560 set->ops_head->result_cb (set->ops_head->result_cls,
540 NULL, 561 NULL,
562 0,
541 GNUNET_SET_STATUS_FAILURE); 563 GNUNET_SET_STATUS_FAILURE);
542 set_operation_destroy (set->ops_head); 564 set_operation_destroy (set->ops_head);
543 } 565 }
544 set->iterator = NULL; 566 set->iterator = NULL;
545 set->iteration_id++; 567 set->iteration_id++;
568 set->invalid = GNUNET_YES;
546 if (NULL != iter) 569 if (NULL != iter)
547 iter (set->iterator_cls, 570 iter (set->iterator_cls,
548 NULL); 571 NULL);
549 set->invalid = GNUNET_YES;
550 if (GNUNET_YES == set->destroy_requested)
551 {
552 LOG (GNUNET_ERROR_TYPE_DEBUG,
553 "Destroying set after operation failure\n");
554 GNUNET_SET_destroy (set);
555 }
556} 572}
557 573
558 574
575/**
576 * FIXME.
577 */
559static struct GNUNET_SET_Handle * 578static struct GNUNET_SET_Handle *
560create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg, 579create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg,
561 enum GNUNET_SET_OperationType op, 580 enum GNUNET_SET_OperationType op,
@@ -614,7 +633,8 @@ create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg,
614 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT); 633 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT);
615 copy_msg->cookie = *cookie; 634 copy_msg->cookie = *cookie;
616 } 635 }
617 GNUNET_MQ_send (set->mq, mqm); 636 GNUNET_MQ_send (set->mq,
637 mqm);
618 return set; 638 return set;
619} 639}
620 640
@@ -634,7 +654,16 @@ struct GNUNET_SET_Handle *
634GNUNET_SET_create (const struct GNUNET_CONFIGURATION_Handle *cfg, 654GNUNET_SET_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
635 enum GNUNET_SET_OperationType op) 655 enum GNUNET_SET_OperationType op)
636{ 656{
637 return create_internal (cfg, op, NULL); 657 struct GNUNET_SET_Handle *set;
658
659 set = create_internal (cfg,
660 op,
661 NULL);
662 LOG (GNUNET_ERROR_TYPE_DEBUG,
663 "Creating set %p for operation %d\n",
664 set,
665 op);
666 return set;
638} 667}
639 668
640 669
@@ -660,13 +689,18 @@ GNUNET_SET_add_element (struct GNUNET_SET_Handle *set,
660 struct GNUNET_MQ_Envelope *mqm; 689 struct GNUNET_MQ_Envelope *mqm;
661 struct GNUNET_SET_ElementMessage *msg; 690 struct GNUNET_SET_ElementMessage *msg;
662 691
692 LOG (GNUNET_ERROR_TYPE_INFO,
693 "adding element of type %u to set %p\n",
694 (unsigned int) element->element_type,
695 set);
663 if (GNUNET_YES == set->invalid) 696 if (GNUNET_YES == set->invalid)
664 { 697 {
665 if (NULL != cont) 698 if (NULL != cont)
666 cont (cont_cls); 699 cont (cont_cls);
667 return GNUNET_SYSERR; 700 return GNUNET_SYSERR;
668 } 701 }
669 mqm = GNUNET_MQ_msg_extra (msg, element->size, 702 mqm = GNUNET_MQ_msg_extra (msg,
703 element->size,
670 GNUNET_MESSAGE_TYPE_SET_ADD); 704 GNUNET_MESSAGE_TYPE_SET_ADD);
671 msg->element_type = htons (element->element_type); 705 msg->element_type = htons (element->element_type);
672 GNUNET_memcpy (&msg[1], 706 GNUNET_memcpy (&msg[1],
@@ -701,6 +735,9 @@ GNUNET_SET_remove_element (struct GNUNET_SET_Handle *set,
701 struct GNUNET_MQ_Envelope *mqm; 735 struct GNUNET_MQ_Envelope *mqm;
702 struct GNUNET_SET_ElementMessage *msg; 736 struct GNUNET_SET_ElementMessage *msg;
703 737
738 LOG (GNUNET_ERROR_TYPE_DEBUG,
739 "Removing element from set %p\n",
740 set);
704 if (GNUNET_YES == set->invalid) 741 if (GNUNET_YES == set->invalid)
705 { 742 {
706 if (NULL != cont) 743 if (NULL != cont)
@@ -733,8 +770,9 @@ GNUNET_SET_destroy (struct GNUNET_SET_Handle *set)
733 /* destroying set while iterator is active is currently 770 /* destroying set while iterator is active is currently
734 not supported; we should expand the API to allow 771 not supported; we should expand the API to allow
735 clients to explicitly cancel the iteration! */ 772 clients to explicitly cancel the iteration! */
736 GNUNET_assert (NULL == set->iterator); 773 if ( (NULL != set->ops_head) ||
737 if (NULL != set->ops_head) 774 (NULL != set->iterator) ||
775 (GNUNET_SYSERR == set->destroy_requested) )
738 { 776 {
739 LOG (GNUNET_ERROR_TYPE_DEBUG, 777 LOG (GNUNET_ERROR_TYPE_DEBUG,
740 "Set operations are pending, delaying set destruction\n"); 778 "Set operations are pending, delaying set destruction\n");
@@ -771,13 +809,18 @@ GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer,
771 const struct GNUNET_HashCode *app_id, 809 const struct GNUNET_HashCode *app_id,
772 const struct GNUNET_MessageHeader *context_msg, 810 const struct GNUNET_MessageHeader *context_msg,
773 enum GNUNET_SET_ResultMode result_mode, 811 enum GNUNET_SET_ResultMode result_mode,
812 struct GNUNET_SET_Option options[],
774 GNUNET_SET_ResultIterator result_cb, 813 GNUNET_SET_ResultIterator result_cb,
775 void *result_cls) 814 void *result_cls)
776{ 815{
777 struct GNUNET_MQ_Envelope *mqm; 816 struct GNUNET_MQ_Envelope *mqm;
778 struct GNUNET_SET_OperationHandle *oh; 817 struct GNUNET_SET_OperationHandle *oh;
779 struct GNUNET_SET_EvaluateMessage *msg; 818 struct GNUNET_SET_EvaluateMessage *msg;
819 struct GNUNET_SET_Option *opt;
780 820
821 LOG (GNUNET_ERROR_TYPE_DEBUG,
822 "Client prepares set operation (%d)\n",
823 result_mode);
781 oh = GNUNET_new (struct GNUNET_SET_OperationHandle); 824 oh = GNUNET_new (struct GNUNET_SET_OperationHandle);
782 oh->result_cb = result_cb; 825 oh->result_cb = result_cb;
783 oh->result_cls = result_cls; 826 oh->result_cls = result_cls;
@@ -787,6 +830,25 @@ GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer,
787 msg->app_id = *app_id; 830 msg->app_id = *app_id;
788 msg->result_mode = htonl (result_mode); 831 msg->result_mode = htonl (result_mode);
789 msg->target_peer = *other_peer; 832 msg->target_peer = *other_peer;
833 for (opt = options; opt->type != 0; opt++)
834 {
835 switch (opt->type)
836 {
837 case GNUNET_SET_OPTION_BYZANTINE:
838 msg->byzantine = GNUNET_YES;
839 msg->byzantine_lower_bound = opt->v.num;
840 break;
841 case GNUNET_SET_OPTION_FORCE_FULL:
842 msg->force_full = GNUNET_YES;
843 break;
844 case GNUNET_SET_OPTION_FORCE_DELTA:
845 msg->force_delta = GNUNET_YES;
846 break;
847 default:
848 LOG (GNUNET_ERROR_TYPE_ERROR,
849 "Option with type %d not recognized\n", (int) opt->type);
850 }
851 }
790 oh->conclude_mqm = mqm; 852 oh->conclude_mqm = mqm;
791 oh->request_id_addr = &msg->request_id; 853 oh->request_id_addr = &msg->request_id;
792 854
@@ -846,7 +908,8 @@ handle_request (void *cls,
846 struct GNUNET_SET_RejectMessage *rmsg; 908 struct GNUNET_SET_RejectMessage *rmsg;
847 909
848 LOG (GNUNET_ERROR_TYPE_DEBUG, 910 LOG (GNUNET_ERROR_TYPE_DEBUG,
849 "Processing incoming operation request\n"); 911 "Processing incoming operation request with id %u\n",
912 ntohl (msg->accept_id));
850 /* we got another valid request => reset the backoff */ 913 /* we got another valid request => reset the backoff */
851 lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; 914 lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
852 req.accept_id = ntohl (msg->accept_id); 915 req.accept_id = ntohl (msg->accept_id);
@@ -860,7 +923,8 @@ handle_request (void *cls,
860 if (GNUNET_YES == req.accepted) 923 if (GNUNET_YES == req.accepted)
861 return; /* the accept-case is handled in #GNUNET_SET_accept() */ 924 return; /* the accept-case is handled in #GNUNET_SET_accept() */
862 LOG (GNUNET_ERROR_TYPE_DEBUG, 925 LOG (GNUNET_ERROR_TYPE_DEBUG,
863 "Rejecting request\n"); 926 "Rejected request %u\n",
927 ntohl (msg->accept_id));
864 mqm = GNUNET_MQ_msg (rmsg, 928 mqm = GNUNET_MQ_msg (rmsg,
865 GNUNET_MESSAGE_TYPE_SET_REJECT); 929 GNUNET_MESSAGE_TYPE_SET_REJECT);
866 rmsg->accept_reject_id = msg->accept_id; 930 rmsg->accept_reject_id = msg->accept_id;
@@ -950,6 +1014,9 @@ GNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg,
950{ 1014{
951 struct GNUNET_SET_ListenHandle *lh; 1015 struct GNUNET_SET_ListenHandle *lh;
952 1016
1017 LOG (GNUNET_ERROR_TYPE_DEBUG,
1018 "Starting listener for app %s\n",
1019 GNUNET_h2s (app_id));
953 lh = GNUNET_new (struct GNUNET_SET_ListenHandle); 1020 lh = GNUNET_new (struct GNUNET_SET_ListenHandle);
954 lh->listen_cb = listen_cb; 1021 lh->listen_cb = listen_cb;
955 lh->listen_cls = listen_cls; 1022 lh->listen_cls = listen_cls;
@@ -976,7 +1043,8 @@ void
976GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh) 1043GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh)
977{ 1044{
978 LOG (GNUNET_ERROR_TYPE_DEBUG, 1045 LOG (GNUNET_ERROR_TYPE_DEBUG,
979 "Canceling listener\n"); 1046 "Canceling listener %s\n",
1047 GNUNET_h2s (&lh->app_id));
980 if (NULL != lh->mq) 1048 if (NULL != lh->mq)
981 { 1049 {
982 GNUNET_MQ_destroy (lh->mq); 1050 GNUNET_MQ_destroy (lh->mq);
@@ -1008,6 +1076,7 @@ GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh)
1008struct GNUNET_SET_OperationHandle * 1076struct GNUNET_SET_OperationHandle *
1009GNUNET_SET_accept (struct GNUNET_SET_Request *request, 1077GNUNET_SET_accept (struct GNUNET_SET_Request *request,
1010 enum GNUNET_SET_ResultMode result_mode, 1078 enum GNUNET_SET_ResultMode result_mode,
1079 struct GNUNET_SET_Option options[],
1011 GNUNET_SET_ResultIterator result_cb, 1080 GNUNET_SET_ResultIterator result_cb,
1012 void *result_cls) 1081 void *result_cls)
1013{ 1082{
@@ -1016,8 +1085,13 @@ GNUNET_SET_accept (struct GNUNET_SET_Request *request,
1016 struct GNUNET_SET_AcceptMessage *msg; 1085 struct GNUNET_SET_AcceptMessage *msg;
1017 1086
1018 GNUNET_assert (GNUNET_NO == request->accepted); 1087 GNUNET_assert (GNUNET_NO == request->accepted);
1088 LOG (GNUNET_ERROR_TYPE_DEBUG,
1089 "Client accepts set operation (%d) with id %u\n",
1090 result_mode,
1091 request->accept_id);
1019 request->accepted = GNUNET_YES; 1092 request->accepted = GNUNET_YES;
1020 mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_ACCEPT); 1093 mqm = GNUNET_MQ_msg (msg,
1094 GNUNET_MESSAGE_TYPE_SET_ACCEPT);
1021 msg->accept_reject_id = htonl (request->accept_id); 1095 msg->accept_reject_id = htonl (request->accept_id);
1022 msg->result_mode = htonl (result_mode); 1096 msg->result_mode = htonl (result_mode);
1023 oh = GNUNET_new (struct GNUNET_SET_OperationHandle); 1097 oh = GNUNET_new (struct GNUNET_SET_OperationHandle);
@@ -1055,14 +1129,18 @@ GNUNET_SET_commit (struct GNUNET_SET_OperationHandle *oh,
1055 } 1129 }
1056 if (GNUNET_YES == set->invalid) 1130 if (GNUNET_YES == set->invalid)
1057 return GNUNET_SYSERR; 1131 return GNUNET_SYSERR;
1132 LOG (GNUNET_ERROR_TYPE_DEBUG,
1133 "Client commits to SET\n");
1058 GNUNET_assert (NULL != oh->conclude_mqm); 1134 GNUNET_assert (NULL != oh->conclude_mqm);
1059 oh->set = set; 1135 oh->set = set;
1060 GNUNET_CONTAINER_DLL_insert (set->ops_head, 1136 GNUNET_CONTAINER_DLL_insert (set->ops_head,
1061 set->ops_tail, 1137 set->ops_tail,
1062 oh); 1138 oh);
1063 oh->request_id = GNUNET_MQ_assoc_add (set->mq, oh); 1139 oh->request_id = GNUNET_MQ_assoc_add (set->mq,
1140 oh);
1064 *oh->request_id_addr = htonl (oh->request_id); 1141 *oh->request_id_addr = htonl (oh->request_id);
1065 GNUNET_MQ_send (set->mq, oh->conclude_mqm); 1142 GNUNET_MQ_send (set->mq,
1143 oh->conclude_mqm);
1066 oh->conclude_mqm = NULL; 1144 oh->conclude_mqm = NULL;
1067 oh->request_id_addr = NULL; 1145 oh->request_id_addr = NULL;
1068 return GNUNET_OK; 1146 return GNUNET_OK;
@@ -1111,6 +1189,8 @@ GNUNET_SET_copy_lazy (struct GNUNET_SET_Handle *set,
1111 struct GNUNET_MQ_Envelope *ev; 1189 struct GNUNET_MQ_Envelope *ev;
1112 struct SetCopyRequest *req; 1190 struct SetCopyRequest *req;
1113 1191
1192 LOG (GNUNET_ERROR_TYPE_DEBUG,
1193 "Creating lazy copy of set\n");
1114 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE); 1194 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE);
1115 GNUNET_MQ_send (set->mq, ev); 1195 GNUNET_MQ_send (set->mq, ev);
1116 1196