GNUnet 0.22.2
set_api.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2016 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_protocols.h"
29#include "gnunet_set_service.h"
30#include "set.h"
31
32
33#define LOG(kind, ...) GNUNET_log_from (kind, "set-api", __VA_ARGS__)
34
36{
38
40
41 void *cls;
42
44};
45
50{
55
60
65
71
76
83
88
93 uint16_t iteration_id;
94
99
104
109};
110
111
116{
121 uint32_t accept_id;
122
128};
129
130
136{
142
147
153
159
165
170
175
179 uint32_t request_id;
180};
181
182
187{
192
199
205
210
215
220
225
230};
231
232
233/* mutual recursion with handle_copy_lazy */
234static struct GNUNET_SET_Handle *
237 const uint32_t *cookie);
238
239
247static void
250{
251 struct GNUNET_SET_Handle *set = cls;
252 struct SetCopyRequest *req;
253 struct GNUNET_SET_Handle *new_set;
254
255 req = set->copy_req_head;
256 if (NULL == req)
257 {
258 /* Service sent us unsolicited lazy copy response */
259 GNUNET_break (0);
260 return;
261 }
262
264 "Handling response to lazy copy\n");
266 set->copy_req_tail,
267 req);
268 // We pass none as operation here, since it doesn't matter when
269 // cloning.
270 new_set = create_internal (set->cfg,
272 &msg->cookie);
273 req->cb (req->cls, new_set);
274 GNUNET_free (req);
275}
276
277
285static int
288{
289 /* minimum size was already checked, everything else is OK! */
290 return GNUNET_OK;
291}
292
293
301static void
304{
305 struct GNUNET_SET_Handle *set = cls;
307 struct GNUNET_SET_Element element;
308 struct GNUNET_SET_IterAckMessage *ack_msg;
309 struct GNUNET_MQ_Envelope *ev;
310 uint16_t msize;
311
313 "Received element in set iteration\n");
314 msize = ntohs (msg->header.size);
315 if (set->iteration_id != ntohs (msg->iteration_id))
316 {
317 /* element from a previous iteration, skip! */
318 iter = NULL;
319 }
320 if (NULL != iter)
321 {
322 element.size = msize - sizeof(struct GNUNET_SET_IterResponseMessage);
323 element.element_type = ntohs (msg->element_type);
324 element.data = &msg[1];
325 iter (set->iterator_cls,
326 &element);
327 }
328 ev = GNUNET_MQ_msg (ack_msg,
330 ack_msg->send_more = htonl ((NULL != iter));
331 GNUNET_MQ_send (set->mq, ev);
332}
333
334
342static void
344 const struct GNUNET_MessageHeader *mh)
345{
346 struct GNUNET_SET_Handle *set = cls;
348
349 if (NULL == iter)
350 {
351 /* FIXME: if this is true, could cancel+start a fresh one
352 cause elements to go to the wrong iteration? */
354 "Service completed set iteration that was already cancelled\n");
355 return;
356 }
358 "Set iteration completed\n");
360 set->iterator = NULL;
361 set->iteration_id++;
362 iter (set->iterator_cls,
363 NULL);
366 if (GNUNET_YES == set->destroy_requested)
367 GNUNET_SET_destroy (set);
368}
369
370
378static int
379check_result (void *cls,
380 const struct GNUNET_SET_ResultMessage *msg)
381{
382 /* minimum size was already checked, everything else is OK! */
383 return GNUNET_OK;
384}
385
386
393static void
394handle_result (void *cls,
395 const struct GNUNET_SET_ResultMessage *msg)
396{
397 struct GNUNET_SET_Handle *set = cls;
399 struct GNUNET_SET_Element e;
400 enum GNUNET_SET_Status result_status;
401 int destroy_set;
402
403 GNUNET_assert (NULL != set->mq);
404 result_status = ntohs (msg->result_status);
406 "Got result message with status %d\n",
407 result_status);
408
409 oh = GNUNET_MQ_assoc_get (set->mq,
410 ntohl (msg->request_id));
411 if (NULL == oh)
412 {
413 /* 'oh' can be NULL if we canceled the operation, but the service
414 did not get the cancel message yet. */
416 "Ignoring result from canceled operation\n");
417 return;
418 }
419
420 switch (result_status)
421 {
425 goto do_element;
426
429 goto do_final;
430
432 /* not used anymore */
433 GNUNET_assert (0);
434 }
435
436do_final:
438 "Treating result as final status\n");
440 ntohl (msg->request_id));
442 set->ops_tail,
443 oh);
444 /* Need to do this calculation _before_ the result callback,
445 as IF the application still has a valid set handle, it
446 may trigger destruction of the set during the callback. */
447 destroy_set = (GNUNET_YES == set->destroy_requested) &&
448 (NULL == set->ops_head);
449 if (NULL != oh->result_cb)
450 {
451 oh->result_cb (oh->result_cls,
452 NULL,
453 GNUNET_ntohll (msg->current_size),
454 result_status);
455 }
456 else
457 {
459 "No callback for final status\n");
460 }
461 if (destroy_set)
462 GNUNET_SET_destroy (set);
463 GNUNET_free (oh);
464 return;
465
466do_element:
468 "Treating result as element\n");
469 e.data = &msg[1];
470 e.size = ntohs (msg->header.size) - sizeof(struct GNUNET_SET_ResultMessage);
471 e.element_type = ntohs (msg->element_type);
472 if (NULL != oh->result_cb)
473 oh->result_cb (oh->result_cls,
474 &e,
475 GNUNET_ntohll (msg->current_size),
477}
478
479
485static void
487{
488 struct GNUNET_SET_Handle *set = oh->set;
489 struct GNUNET_SET_OperationHandle *h_assoc;
490
491 if (NULL != oh->conclude_mqm)
493 /* is the operation already committed? */
494 if (NULL != set)
495 {
497 set->ops_tail,
498 oh);
499 h_assoc = GNUNET_MQ_assoc_remove (set->mq,
500 oh->request_id);
501 GNUNET_assert ((NULL == h_assoc) ||
502 (h_assoc == oh));
503 }
504 GNUNET_free (oh);
505}
506
507
515void
517{
518 struct GNUNET_SET_Handle *set = oh->set;
520 struct GNUNET_MQ_Envelope *mqm;
521
523 "Cancelling SET operation\n");
524 if (NULL != set)
525 {
527 m->request_id = htonl (oh->request_id);
528 GNUNET_MQ_send (set->mq, mqm);
529 }
531 if ((NULL != set) &&
532 (GNUNET_YES == set->destroy_requested) &&
533 (NULL == set->ops_head))
534 {
536 "Destroying set after operation cancel\n");
537 GNUNET_SET_destroy (set);
538 }
539}
540
541
549static void
551 enum GNUNET_MQ_Error error)
552{
553 struct GNUNET_SET_Handle *set = cls;
555
557 "Handling client set error %d\n",
558 error);
559 while (NULL != set->ops_head)
560 {
561 if ((NULL != set->ops_head->result_cb) &&
564 NULL,
565 0,
568 }
569 set->iterator = NULL;
570 set->iteration_id++;
571 set->invalid = GNUNET_YES;
572 if (NULL != iter)
573 iter (set->iterator_cls,
574 NULL);
575}
576
577
581static struct GNUNET_SET_Handle *
584 const uint32_t *cookie)
585{
586 struct GNUNET_SET_Handle *set = GNUNET_new (struct GNUNET_SET_Handle);
587 struct GNUNET_MQ_MessageHandler mq_handlers[] = {
591 set),
592 GNUNET_MQ_hd_var_size (iter_element,
595 set),
596 GNUNET_MQ_hd_fixed_size (iter_done,
599 set),
600 GNUNET_MQ_hd_fixed_size (copy_lazy,
603 set),
605 };
606 struct GNUNET_MQ_Envelope *mqm;
607 struct GNUNET_SET_CreateMessage *create_msg;
608 struct GNUNET_SET_CopyLazyConnectMessage *copy_msg;
609
610 set->cfg = cfg;
612 "set",
613 mq_handlers,
615 set);
616 if (NULL == set->mq)
617 {
618 GNUNET_free (set);
619 return NULL;
620 }
621 if (NULL == cookie)
622 {
624 "Creating new set (operation %u)\n",
625 op);
626 mqm = GNUNET_MQ_msg (create_msg,
628 create_msg->operation = htonl (op);
629 }
630 else
631 {
633 "Creating new set (lazy copy)\n");
634 mqm = GNUNET_MQ_msg (copy_msg,
636 copy_msg->cookie = *cookie;
637 }
638 GNUNET_MQ_send (set->mq,
639 mqm);
640 return set;
641}
642
643
655struct GNUNET_SET_Handle *
658{
659 struct GNUNET_SET_Handle *set;
660
661 set = create_internal (cfg,
662 op,
663 NULL);
665 "Creating set %p for operation %d\n",
666 set,
667 op);
668 return set;
669}
670
671
672int
674 const struct GNUNET_SET_Element *element,
676 void *cont_cls)
677{
678 struct GNUNET_MQ_Envelope *mqm;
680
682 "adding element of type %u to set %p\n",
683 (unsigned int) element->element_type,
684 set);
685 GNUNET_assert (NULL != set);
686 if (GNUNET_YES == set->invalid)
687 {
688 if (NULL != cont)
689 cont (cont_cls);
690 return GNUNET_SYSERR;
691 }
693 element->size,
695 msg->element_type = htons (element->element_type);
696 GNUNET_memcpy (&msg[1],
697 element->data,
698 element->size);
700 cont, cont_cls);
701 GNUNET_MQ_send (set->mq, mqm);
702 return GNUNET_OK;
703}
704
705
706int
708 const struct GNUNET_SET_Element *element,
710 void *cont_cls)
711{
712 struct GNUNET_MQ_Envelope *mqm;
714
716 "Removing element from set %p\n",
717 set);
718 if (GNUNET_YES == set->invalid)
719 {
720 if (NULL != cont)
721 cont (cont_cls);
722 return GNUNET_SYSERR;
723 }
725 element->size,
727 msg->element_type = htons (element->element_type);
728 GNUNET_memcpy (&msg[1],
729 element->data,
730 element->size);
732 cont, cont_cls);
733 GNUNET_MQ_send (set->mq, mqm);
734 return GNUNET_OK;
735}
736
737
744void
746{
747 /* destroying set while iterator is active is currently
748 not supported; we should expand the API to allow
749 clients to explicitly cancel the iteration! */
750 GNUNET_assert (NULL != set);
751 if ((NULL != set->ops_head) ||
752 (NULL != set->iterator) ||
754 {
756 "Set operations are pending, delaying set destruction\n");
758 return;
759 }
761 "Really destroying set\n");
762 if (NULL != set->mq)
763 {
764 GNUNET_MQ_destroy (set->mq);
765 set->mq = NULL;
766 }
767 GNUNET_free (set);
768}
769
770
772GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer,
773 const struct GNUNET_HashCode *app_id,
774 const struct GNUNET_MessageHeader *context_msg,
775 enum GNUNET_SET_ResultMode result_mode,
776 struct GNUNET_SET_Option options[],
778 void *result_cls)
779{
780 struct GNUNET_MQ_Envelope *mqm;
783 struct GNUNET_SET_Option *opt;
784
786 "Client prepares set operation (%d)\n",
787 result_mode);
789 oh->result_cb = result_cb;
790 oh->result_cls = result_cls;
793 context_msg);
794 msg->app_id = *app_id;
795 msg->result_mode = htonl (result_mode);
796 msg->target_peer = *other_peer;
797 for (opt = options; opt->type != 0; opt++)
798 {
799 switch (opt->type)
800 {
802 msg->byzantine = GNUNET_YES;
803 msg->byzantine_lower_bound = opt->v.num;
804 break;
805
807 msg->force_full = GNUNET_YES;
808 break;
809
811 msg->force_delta = GNUNET_YES;
812 break;
813
814 default:
816 "Option with type %d not recognized\n", (int) opt->type);
817 }
818 }
819 oh->conclude_mqm = mqm;
820 oh->request_id_addr = &msg->request_id;
821
822 return oh;
823}
824
825
831static void
832listen_connect (void *cls);
833
834
842static int
843check_request (void *cls,
844 const struct GNUNET_SET_RequestMessage *msg)
845{
846 const struct GNUNET_MessageHeader *context_msg;
847
848 if (ntohs (msg->header.size) == sizeof(*msg))
849 return GNUNET_OK; /* no context message is OK */
850 context_msg = GNUNET_MQ_extract_nested_mh (msg);
851 if (NULL == context_msg)
852 {
853 /* malformed context message is NOT ok */
854 GNUNET_break_op (0);
855 return GNUNET_SYSERR;
856 }
857 return GNUNET_OK;
858}
859
860
867static void
868handle_request (void *cls,
869 const struct GNUNET_SET_RequestMessage *msg)
870{
871 struct GNUNET_SET_ListenHandle *lh = cls;
872 struct GNUNET_SET_Request req;
873 const struct GNUNET_MessageHeader *context_msg;
874 struct GNUNET_MQ_Envelope *mqm;
875 struct GNUNET_SET_RejectMessage *rmsg;
876
878 "Processing incoming operation request with id %u\n",
879 ntohl (msg->accept_id));
880 /* we got another valid request => reset the backoff */
882 req.accept_id = ntohl (msg->accept_id);
883 req.accepted = GNUNET_NO;
884 context_msg = GNUNET_MQ_extract_nested_mh (msg);
885 /* calling #GNUNET_SET_accept() in the listen cb will set req->accepted */
886 lh->listen_cb (lh->listen_cls,
887 &msg->peer_id,
888 context_msg,
889 &req);
890 if (GNUNET_YES == req.accepted)
891 return; /* the accept-case is handled in #GNUNET_SET_accept() */
893 "Rejected request %u\n",
894 ntohl (msg->accept_id));
895 mqm = GNUNET_MQ_msg (rmsg,
897 rmsg->accept_reject_id = msg->accept_id;
898 GNUNET_MQ_send (lh->mq, mqm);
899}
900
901
909static void
911 enum GNUNET_MQ_Error error)
912{
913 struct GNUNET_SET_ListenHandle *lh = cls;
914
916 "Listener broke down (%d), re-connecting\n",
917 (int) error);
918 GNUNET_MQ_destroy (lh->mq);
919 lh->mq = NULL;
922 lh);
924}
925
926
932static void
933listen_connect (void *cls)
934{
935 struct GNUNET_SET_ListenHandle *lh = cls;
936 struct GNUNET_MQ_MessageHandler mq_handlers[] = {
940 lh),
942 };
943 struct GNUNET_MQ_Envelope *mqm;
945
946 lh->reconnect_task = NULL;
947 GNUNET_assert (NULL == lh->mq);
948 lh->mq = GNUNET_CLIENT_connect (lh->cfg,
949 "set",
950 mq_handlers,
952 lh);
953 if (NULL == lh->mq)
954 return;
956 msg->operation = htonl (lh->operation);
957 msg->app_id = lh->app_id;
958 GNUNET_MQ_send (lh->mq,
959 mqm);
960}
961
962
978 const struct GNUNET_HashCode *app_id,
980 void *listen_cls)
981{
982 struct GNUNET_SET_ListenHandle *lh;
983
985 "Starting listener for app %s\n",
988 lh->listen_cb = listen_cb;
990 lh->cfg = cfg;
991 lh->operation = operation;
992 lh->app_id = *app_id;
994 listen_connect (lh);
995 if (NULL == lh->mq)
996 {
997 GNUNET_free (lh);
998 return NULL;
999 }
1000 return lh;
1001}
1002
1003
1009void
1011{
1013 "Canceling listener %s\n",
1014 GNUNET_h2s (&lh->app_id));
1015 if (NULL != lh->mq)
1016 {
1017 GNUNET_MQ_destroy (lh->mq);
1018 lh->mq = NULL;
1019 }
1020 if (NULL != lh->reconnect_task)
1021 {
1023 lh->reconnect_task = NULL;
1024 }
1025 GNUNET_free (lh);
1026}
1027
1028
1031 enum GNUNET_SET_ResultMode result_mode,
1032 struct GNUNET_SET_Option options[],
1034 void *result_cls)
1035{
1036 struct GNUNET_MQ_Envelope *mqm;
1037 struct GNUNET_SET_OperationHandle *oh;
1039
1040 GNUNET_assert (GNUNET_NO == request->accepted);
1042 "Client accepts set operation (%d) with id %u\n",
1044 request->accept_id);
1045 request->accepted = GNUNET_YES;
1046 mqm = GNUNET_MQ_msg (msg,
1048 msg->accept_reject_id = htonl (request->accept_id);
1049 msg->result_mode = htonl (result_mode);
1051 oh->result_cb = result_cb;
1052 oh->result_cls = result_cls;
1053 oh->conclude_mqm = mqm;
1054 oh->request_id_addr = &msg->request_id;
1055 return oh;
1056}
1057
1058
1072int
1074 struct GNUNET_SET_Handle *set)
1075{
1076 if (NULL != oh->set)
1077 {
1078 /* Some other set was already committed for this
1079 * operation, there is a logic bug in the client of this API */
1080 GNUNET_break (0);
1081 return GNUNET_OK;
1082 }
1083 GNUNET_assert (NULL != set);
1084 if (GNUNET_YES == set->invalid)
1085 return GNUNET_SYSERR;
1087 "Client commits to SET\n");
1088 GNUNET_assert (NULL != oh->conclude_mqm);
1089 oh->set = set;
1091 set->ops_tail,
1092 oh);
1093 oh->request_id = GNUNET_MQ_assoc_add (set->mq,
1094 oh);
1095 *oh->request_id_addr = htonl (oh->request_id);
1096 GNUNET_MQ_send (set->mq,
1097 oh->conclude_mqm);
1098 oh->conclude_mqm = NULL;
1099 oh->request_id_addr = NULL;
1100 return GNUNET_OK;
1101}
1102
1103
1116int
1119 void *iter_cls)
1120{
1121 struct GNUNET_MQ_Envelope *ev;
1122
1123 GNUNET_assert (NULL != iter);
1124 if (GNUNET_YES == set->invalid)
1125 return GNUNET_SYSERR;
1126 if (NULL != set->iterator)
1127 return GNUNET_NO;
1129 "Iterating over set\n");
1130 set->iterator = iter;
1131 set->iterator_cls = iter_cls;
1133 GNUNET_MQ_send (set->mq, ev);
1134 return GNUNET_YES;
1135}
1136
1137
1138void
1141 void *cls)
1142{
1143 struct GNUNET_MQ_Envelope *ev;
1144 struct SetCopyRequest *req;
1145
1147 "Creating lazy copy of set\n");
1149 GNUNET_MQ_send (set->mq, ev);
1150
1151 req = GNUNET_new (struct SetCopyRequest);
1152 req->cb = cb;
1153 req->cls = cls;
1155 set->copy_req_tail,
1156 req);
1157}
1158
1159
1167struct GNUNET_SET_Element *
1169{
1170 struct GNUNET_SET_Element *copy;
1171
1172 copy = GNUNET_malloc (element->size + sizeof(struct GNUNET_SET_Element));
1173 copy->size = element->size;
1174 copy->element_type = element->element_type;
1175 copy->data = &copy[1];
1176 GNUNET_memcpy (&copy[1],
1177 element->data,
1178 copy->size);
1179 return copy;
1180}
1181
1182
1183void
1185 struct GNUNET_HashCode *ret_hash)
1186{
1188
1189 /* It's not guaranteed that the element data is always after the element header,
1190 so we need to hash the chunks separately. */
1191 GNUNET_CRYPTO_hash_context_read (ctx, &element->size, sizeof(uint16_t));
1193 sizeof(uint16_t));
1194 GNUNET_CRYPTO_hash_context_read (ctx, element->data, element->size);
1196}
1197
1198
1199/* end of set_api.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:143
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:103
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
static struct GNUNET_FS_Handle * ctx
static int result
Global testing status.
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:40
Constants for network protocols.
Two-peer set operations.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1060
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_log(kind,...)
void GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc, const void *buf, size_t size)
Add data to be hashed.
Definition: crypto_hash.c:363
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:54
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
Definition: crypto_hash.c:387
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
Definition: crypto_hash.c:347
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:285
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:61
#define GNUNET_MQ_msg_nested_mh(mvar, type, mh)
Allocate a GNUNET_MQ_Envelope, and append a payload message after the given message struct.
#define GNUNET_MQ_msg_header(type)
Allocate a GNUNET_MQ_Envelope, where the message only consists of a header.
Definition: gnunet_mq_lib.h:85
void * GNUNET_MQ_assoc_get(struct GNUNET_MQ_Handle *mq, uint32_t request_id)
Get the data associated with a request_id in a queue.
Definition: mq.c:621
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:76
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
Definition: mq.c:655
uint32_t GNUNET_MQ_assoc_add(struct GNUNET_MQ_Handle *mq, void *assoc_data)
Associate the assoc_data in mq with a unique request id.
Definition: mq.c:592
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void * GNUNET_MQ_assoc_remove(struct GNUNET_MQ_Handle *mq, uint32_t request_id)
Remove the association for a request_id.
Definition: mq.c:639
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700
#define GNUNET_MQ_extract_nested_mh(var)
Return a pointer to the message at the end of the given message.
#define GNUNET_MESSAGE_TYPE_SET_EVALUATE
Evaluate a set operation.
#define GNUNET_MESSAGE_TYPE_SET_CANCEL
Cancel a set operation.
#define GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE
Give the client an ID for connecting to the set's copy.
#define GNUNET_MESSAGE_TYPE_SET_ADD
Add element to set.
#define GNUNET_MESSAGE_TYPE_SET_REQUEST
Notify the client of a request from a remote peer.
#define GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE
Ask the set service to prepare a copy of a set.
#define GNUNET_MESSAGE_TYPE_SET_REJECT
Reject a set request.
#define GNUNET_MESSAGE_TYPE_SET_LISTEN
Listen for operation requests.
#define GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT
Element result for the iterating client.
#define GNUNET_MESSAGE_TYPE_SET_ACCEPT
Accept a set request.
#define GNUNET_MESSAGE_TYPE_SET_RESULT
Create an empty set.
#define GNUNET_MESSAGE_TYPE_SET_REMOVE
Remove element from set.
#define GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST
Start iteration over set elements.
#define GNUNET_MESSAGE_TYPE_SET_ITER_ACK
Acknowledge result from iteration.
#define GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT
Sent by the client to the server to connect to an existing, lazily copied set.
#define GNUNET_MESSAGE_TYPE_SET_ITER_DONE
Iteration end marker for the client.
#define GNUNET_MESSAGE_TYPE_SET_CREATE
Create a new local set.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1277
GNUNET_SET_Status
Status for the result callback.
void GNUNET_SET_destroy(struct GNUNET_SET_Handle *set)
Destroy the set handle if no operations are left, mark the set for destruction otherwise.
Definition: set_api.c:745
void GNUNET_SET_copy_lazy(struct GNUNET_SET_Handle *set, GNUNET_SET_CopyReadyCallback cb, void *cls)
Definition: set_api.c:1139
struct GNUNET_SET_Element * GNUNET_SET_element_dup(const struct GNUNET_SET_Element *element)
Create a copy of an element.
Definition: set_api.c:1168
void GNUNET_SET_listen_cancel(struct GNUNET_SET_ListenHandle *lh)
Cancel the given listen operation.
Definition: set_api.c:1010
int GNUNET_SET_remove_element(struct GNUNET_SET_Handle *set, const struct GNUNET_SET_Element *element, GNUNET_SET_Continuation cont, void *cont_cls)
Remove an element to the given set.
Definition: set_api.c:707
void(* GNUNET_SET_Continuation)(void *cls)
Continuation used for some of the set operations.
int GNUNET_SET_iterate(struct GNUNET_SET_Handle *set, GNUNET_SET_ElementIterator iter, void *iter_cls)
Iterate over all elements in the given set.
Definition: set_api.c:1117
void(* GNUNET_SET_ResultIterator)(void *cls, const struct GNUNET_SET_Element *element, uint64_t current_size, enum GNUNET_SET_Status status)
Callback for set operation results.
void GNUNET_SET_operation_cancel(struct GNUNET_SET_OperationHandle *oh)
Cancel the given set operation.
Definition: set_api.c:516
void(* GNUNET_SET_ListenCallback)(void *cls, const struct GNUNET_PeerIdentity *other_peer, const struct GNUNET_MessageHeader *context_msg, struct GNUNET_SET_Request *request)
Called when another peer wants to do a set operation with the local peer.
GNUNET_SET_ResultMode
The way results are given to the client.
int(* GNUNET_SET_ElementIterator)(void *cls, const struct GNUNET_SET_Element *element)
Iterator for set elements.
void(* GNUNET_SET_CopyReadyCallback)(void *cls, struct GNUNET_SET_Handle *copy)
GNUNET_SET_OperationType
The operation that a set set supports.
struct GNUNET_SET_Handle * GNUNET_SET_create(const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_SET_OperationType op)
Create an empty set, supporting the specified operation.
Definition: set_api.c:656
int GNUNET_SET_commit(struct GNUNET_SET_OperationHandle *oh, struct GNUNET_SET_Handle *set)
Commit a set to be used with a set operation.
Definition: set_api.c:1073
struct GNUNET_SET_ListenHandle * GNUNET_SET_listen(const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_SET_OperationType operation, const struct GNUNET_HashCode *app_id, GNUNET_SET_ListenCallback listen_cb, void *listen_cls)
Wait for set operation requests for the given application id.
Definition: set_api.c:976
struct GNUNET_SET_OperationHandle * GNUNET_SET_prepare(const struct GNUNET_PeerIdentity *other_peer, const struct GNUNET_HashCode *app_id, const struct GNUNET_MessageHeader *context_msg, enum GNUNET_SET_ResultMode result_mode, struct GNUNET_SET_Option options[], GNUNET_SET_ResultIterator result_cb, void *result_cls)
Prepare a set operation to be evaluated with another peer.
Definition: set_api.c:772
struct GNUNET_SET_OperationHandle * GNUNET_SET_accept(struct GNUNET_SET_Request *request, enum GNUNET_SET_ResultMode result_mode, struct GNUNET_SET_Option options[], GNUNET_SET_ResultIterator result_cb, void *result_cls)
Accept a request we got via GNUNET_SET_listen().
Definition: set_api.c:1030
int GNUNET_SET_add_element(struct GNUNET_SET_Handle *set, const struct GNUNET_SET_Element *element, GNUNET_SET_Continuation cont, void *cont_cls)
Add an element to the given set.
Definition: set_api.c:673
void GNUNET_SET_element_hash(const struct GNUNET_SET_Element *element, struct GNUNET_HashCode *ret_hash)
Hash a set element.
Definition: set_api.c:1184
@ GNUNET_SET_STATUS_OK
Everything went ok, we are transmitting an element of the result (in set, or to be removed from set,...
@ GNUNET_SET_STATUS_FAILURE
The other peer refused to to the operation with us, or something went wrong.
@ GNUNET_SET_STATUS_ADD_REMOTE
Element should be added to the result set of the remote peer, i.e.
@ GNUNET_SET_STATUS_HALF_DONE
Success, all elements have been returned (but the other peer might still be receiving some from us,...
@ GNUNET_SET_STATUS_DONE
Success, all elements have been sent (and received).
@ GNUNET_SET_STATUS_ADD_LOCAL
Element should be added to the result set of the local peer, i.e.
@ GNUNET_SET_OPTION_FORCE_DELTA
Only use optimized set operations, even though for this particular set operation they might be much s...
@ GNUNET_SET_OPTION_BYZANTINE
Fail set operations when the other peer shows weird behavior that might by a Byzantine fault.
@ GNUNET_SET_OPTION_FORCE_FULL
Do not use the optimized set operation, but send full sets.
@ GNUNET_SET_OPERATION_NONE
A purely local set that does not support any operation.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
messages used for the set api
static int check_iter_element(void *cls, const struct GNUNET_SET_IterResponseMessage *msg)
Check that the given msg is well-formed.
Definition: set_api.c:286
static void handle_iter_done(void *cls, const struct GNUNET_MessageHeader *mh)
Handle message signalling conclusion of iteration over the set.
Definition: set_api.c:343
static void handle_copy_lazy(void *cls, const struct GNUNET_SET_CopyLazyResponseMessage *msg)
Handle element for iteration over the set.
Definition: set_api.c:248
static void handle_request(void *cls, const struct GNUNET_SET_RequestMessage *msg)
Handle request message for a listen operation.
Definition: set_api.c:868
static void handle_client_listener_error(void *cls, enum GNUNET_MQ_Error error)
Our connection with the set service encountered an error, re-initialize with exponential back-off.
Definition: set_api.c:910
static void handle_result(void *cls, const struct GNUNET_SET_ResultMessage *msg)
Handle result message for a set operation.
Definition: set_api.c:394
static void set_operation_destroy(struct GNUNET_SET_OperationHandle *oh)
Destroy the given set operation.
Definition: set_api.c:486
static struct GNUNET_SET_Handle * create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_SET_OperationType op, const uint32_t *cookie)
FIXME.
Definition: set_api.c:582
static int check_result(void *cls, const struct GNUNET_SET_ResultMessage *msg)
Check that the given msg is well-formed.
Definition: set_api.c:379
static void handle_client_set_error(void *cls, enum GNUNET_MQ_Error error)
We encountered an error communicating with the set service while performing a set operation.
Definition: set_api.c:550
static void listen_connect(void *cls)
Connect to the set service in order to listen for requests.
Definition: set_api.c:933
static int check_request(void *cls, const struct GNUNET_SET_RequestMessage *msg)
Check validity of request message for a listen operation.
Definition: set_api.c:843
static void handle_iter_element(void *cls, const struct GNUNET_SET_IterResponseMessage *msg)
Handle element for iteration over the set.
Definition: set_api.c:302
#define LOG(kind,...)
Definition: set_api.c:33
A 512-bit hashcode.
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
Header for all communications.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition: scheduler.c:136
Message sent by a listening client to the service to accept performing the operation with the other p...
Definition: set.h:83
uint32_t result_mode
How should results be sent to us? See enum GNUNET_SET_ResultMode.
Definition: set.h:103
Sent to the service by the client in order to cancel a set operation.
Definition: set.h:307
Client connects to a lazily copied set.
Definition: set.h:385
uint32_t cookie
Temporary name for the copied set.
Definition: set.h:394
Server responds to a lazy copy request.
Definition: set.h:368
Message sent by the client to the service to ask starting a new set to perform operations with.
Definition: set.h:41
uint32_t operation
Operation type, values of enum GNUNET_SET_OperationType
Definition: set.h:50
Message sent by client to the service to add or remove an element to/from the set.
Definition: set.h:281
Element stored in a set.
uint16_t size
Number of bytes in the buffer pointed to by data.
const void * data
Actual data of the element.
uint16_t element_type
Application-specific element type.
Message sent by client to service to initiate a set operation as a client (not as listener).
Definition: set.h:181
Opaque handle to a set.
Definition: set_api.c:50
uint16_t iteration_id
Both client and service count the number of iterators created so far to match replies with iterators.
Definition: set_api.c:93
struct GNUNET_SET_OperationHandle * ops_head
Linked list of operations on the set.
Definition: set_api.c:59
int invalid
Has the set become invalid (e.g.
Definition: set_api.c:87
struct GNUNET_SET_OperationHandle * ops_tail
Linked list of operations on the set.
Definition: set_api.c:64
int destroy_requested
Should the set be destroyed once all operations are gone? GNUNET_SYSERR if GNUNET_SET_destroy() must ...
Definition: set_api.c:82
struct GNUNET_MQ_Handle * mq
Message queue for client.
Definition: set_api.c:54
GNUNET_SET_ElementIterator iterator
Callback for the current iteration over the set, NULL if no iterator is active.
Definition: set_api.c:70
struct SetCopyRequest * copy_req_head
Doubly linked list of copy requests.
Definition: set_api.c:103
void * iterator_cls
Closure for iterator.
Definition: set_api.c:75
struct SetCopyRequest * copy_req_tail
Doubly linked list of copy requests.
Definition: set_api.c:108
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration, needed when creating (lazy) copies.
Definition: set_api.c:98
Client acknowledges receiving element in iteration.
Definition: set.h:351
uint32_t send_more
Non-zero if the service should continue sending elements.
Definition: set.h:360
Set element transmitted by service to client in response to a set iteration request.
Definition: set.h:325
Opaque handle to a listen operation.
Definition: set_api.c:187
struct GNUNET_TIME_Relative reconnect_backoff
Time to wait until we try to reconnect on failure.
Definition: set_api.c:219
void * listen_cls
Closure for listen_cb.
Definition: set_api.c:209
struct GNUNET_SCHEDULER_Task * reconnect_task
Task for reconnecting when the listener fails.
Definition: set_api.c:224
struct GNUNET_HashCode app_id
Application ID we listen for.
Definition: set_api.c:214
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration handle for the listener, stored here to be able to reconnect transparently on connectio...
Definition: set_api.c:198
enum GNUNET_SET_OperationType operation
Operation we listen for.
Definition: set_api.c:229
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: set_api.c:191
GNUNET_SET_ListenCallback listen_cb
Function to call on a new incoming request, or on error.
Definition: set_api.c:204
Message sent by the client to the service to start listening for incoming requests to perform a certa...
Definition: set.h:60
Handle to an operation.
Definition: set_api.c:136
struct GNUNET_SET_Handle * set
Local set used for the operation, NULL if no set has been provided by conclude yet.
Definition: set_api.c:152
GNUNET_SET_ResultIterator result_cb
Function to be called when we have a result, or an error.
Definition: set_api.c:141
uint32_t * request_id_addr
Address of the request if in the conclude message, used to patch the request id into the message when...
Definition: set_api.c:164
void * result_cls
Closure for result_cb.
Definition: set_api.c:146
struct GNUNET_SET_OperationHandle * prev
Handles are kept in a linked list.
Definition: set_api.c:169
uint32_t request_id
Request ID to identify the operation within the set.
Definition: set_api.c:179
struct GNUNET_MQ_Envelope * conclude_mqm
Message sent to the server on calling conclude, NULL if conclude has been called.
Definition: set_api.c:158
struct GNUNET_SET_OperationHandle * next
Handles are kept in a linked list.
Definition: set_api.c:174
Option for set operations.
union GNUNET_SET_Option::@30 v
Value for the option, only used with some options.
enum GNUNET_SET_OptionType type
Type of the option.
Message sent by a listening client to the service to reject performing the operation with the other p...
Definition: set.h:136
uint32_t accept_reject_id
ID of the incoming request we want to reject.
Definition: set.h:145
A request for an operation with another client.
Definition: set.h:153
Handle for a set operation request from another peer.
Definition: set_api.c:116
int accepted
Has the request been accepted already? GNUNET_YES/GNUNET_NO.
Definition: set_api.c:127
uint32_t accept_id
Id of the request, used to identify the request when accepting/rejecting it.
Definition: set_api.c:121
Message sent by the service to the client to indicate an element that is removed (set intersection) o...
Definition: set.h:245
uint16_t result_status
Was the evaluation successful? Contains an enum GNUNET_SET_Status in NBO.
Definition: set.h:265
Time for relative time used by GNUnet, in microseconds.
struct SetCopyRequest * prev
Definition: set_api.c:39
struct SetCopyRequest * next
Definition: set_api.c:37
void * cls
Definition: set_api.c:41
GNUNET_SET_CopyReadyCallback cb
Definition: set_api.c:43