GNUnet  0.11.x
setu_api.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2012-2016, 2020 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  */
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 #include "gnunet_protocols.h"
30 #include "gnunet_setu_service.h"
31 #include "setu.h"
32 
33 
34 #define LOG(kind, ...) GNUNET_log_from (kind, "set-api", __VA_ARGS__)
35 
40 {
45 
50 
55 
62 
66  int invalid;
67 
68 };
69 
70 
75 {
80  uint32_t accept_id;
81 
86  int accepted;
87 };
88 
89 
95 {
101 
105  void *result_cls;
106 
112 
118 
123  uint32_t *request_id_addr;
124 
129 
134 
138  uint32_t request_id;
139 };
140 
141 
146 {
151 
158 
164 
168  void *listen_cls;
169 
173  struct GNUNET_HashCode app_id;
174 
179 
184 
185 };
186 
187 
195 static int
196 check_result (void *cls,
197  const struct GNUNET_SETU_ResultMessage *msg)
198 {
199  /* minimum size was already checked, everything else is OK! */
200  return GNUNET_OK;
201 }
202 
203 
210 static void
211 handle_result (void *cls,
212  const struct GNUNET_SETU_ResultMessage *msg)
213 {
214  struct GNUNET_SETU_Handle *set = cls;
216  struct GNUNET_SETU_Element e;
217  enum GNUNET_SETU_Status result_status;
218  int destroy_set;
219 
220  GNUNET_assert (NULL != set->mq);
221  result_status = (enum GNUNET_SETU_Status) ntohs (msg->result_status);
223  "Got result message with status %d\n",
224  result_status);
225  oh = GNUNET_MQ_assoc_get (set->mq,
226  ntohl (msg->request_id));
227  if (NULL == oh)
228  {
229  /* 'oh' can be NULL if we canceled the operation, but the service
230  did not get the cancel message yet. */
232  "Ignoring result from canceled operation\n");
233  return;
234  }
235 
236  switch (result_status)
237  {
240  e.data = &msg[1];
241  e.size = ntohs (msg->header.size)
242  - sizeof(struct GNUNET_SETU_ResultMessage);
243  e.element_type = ntohs (msg->element_type);
244  if (NULL != oh->result_cb)
245  oh->result_cb (oh->result_cls,
246  &e,
247  GNUNET_ntohll (msg->current_size),
248  result_status);
249  return;
253  "Treating result as final status\n");
255  ntohl (msg->request_id));
257  set->ops_tail,
258  oh);
259  /* Need to do this calculation _before_ the result callback,
260  as IF the application still has a valid set handle, it
261  may trigger destruction of the set during the callback. */
262  destroy_set = (GNUNET_YES == set->destroy_requested) &&
263  (NULL == set->ops_head);
264  if (NULL != oh->result_cb)
265  {
266  oh->result_cb (oh->result_cls,
267  NULL,
268  GNUNET_ntohll (msg->current_size),
269  result_status);
270  }
271  else
272  {
274  "No callback for final status\n");
275  }
276  if (destroy_set)
277  GNUNET_SETU_destroy (set);
278  GNUNET_free (oh);
279  return;
280  }
281 }
282 
283 
289 static void
291 {
292  struct GNUNET_SETU_Handle *set = oh->set;
293  struct GNUNET_SETU_OperationHandle *h_assoc;
294 
295  if (NULL != oh->conclude_mqm)
296  GNUNET_MQ_discard (oh->conclude_mqm);
297  /* is the operation already committed? */
298  if (NULL != set)
299  {
301  set->ops_tail,
302  oh);
303  h_assoc = GNUNET_MQ_assoc_remove (set->mq,
304  oh->request_id);
305  GNUNET_assert ((NULL == h_assoc) ||
306  (h_assoc == oh));
307  }
308  GNUNET_free (oh);
309 }
310 
311 
319 void
321 {
322  struct GNUNET_SETU_Handle *set = oh->set;
324  struct GNUNET_MQ_Envelope *mqm;
325 
327  "Cancelling SET operation\n");
328  if (NULL != set)
329  {
331  m->request_id = htonl (oh->request_id);
332  GNUNET_MQ_send (set->mq, mqm);
333  }
335  if ((NULL != set) &&
336  (GNUNET_YES == set->destroy_requested) &&
337  (NULL == set->ops_head))
338  {
340  "Destroying set after operation cancel\n");
341  GNUNET_SETU_destroy (set);
342  }
343 }
344 
345 
353 static void
355  enum GNUNET_MQ_Error error)
356 {
357  struct GNUNET_SETU_Handle *set = cls;
358 
360  "Handling client set error %d\n",
361  error);
362  while (NULL != set->ops_head)
363  {
364  if ((NULL != set->ops_head->result_cb) &&
365  (GNUNET_NO == set->destroy_requested))
366  set->ops_head->result_cb (set->ops_head->result_cls,
367  NULL,
368  0,
371  }
372  set->invalid = GNUNET_YES;
373 }
374 
375 
383 struct GNUNET_SETU_Handle *
385 {
386  struct GNUNET_SETU_Handle *set = GNUNET_new (struct GNUNET_SETU_Handle);
387  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
391  set),
393  };
394  struct GNUNET_MQ_Envelope *mqm;
395  struct GNUNET_SETU_CreateMessage *create_msg;
396 
397  set->mq = GNUNET_CLIENT_connect (cfg,
398  "setu",
399  mq_handlers,
401  set);
402  if (NULL == set->mq)
403  {
404  GNUNET_free (set);
405  return NULL;
406  }
407  mqm = GNUNET_MQ_msg (create_msg,
409  GNUNET_MQ_send (set->mq,
410  mqm);
411  return set;
412 }
413 
414 
428 int
430  const struct GNUNET_SETU_Element *element,
432  void *cb_cls)
433 {
434  struct GNUNET_MQ_Envelope *mqm;
436 
438  "adding element of type %u to set %p\n",
439  (unsigned int) element->element_type,
440  set);
441  GNUNET_assert (NULL != set);
442  if (GNUNET_YES == set->invalid)
443  {
444  if (NULL != cb)
445  cb (cb_cls);
446  return GNUNET_SYSERR;
447  }
448  mqm = GNUNET_MQ_msg_extra (msg,
449  element->size,
451  msg->element_type = htons (element->element_type);
452  GNUNET_memcpy (&msg[1],
453  element->data,
454  element->size);
456  cb,
457  cb_cls);
458  GNUNET_MQ_send (set->mq,
459  mqm);
460  return GNUNET_OK;
461 }
462 
463 
470 void
472 {
473  /* destroying set while iterator is active is currently
474  not supported; we should expand the API to allow
475  clients to explicitly cancel the iteration! */
476  GNUNET_assert (NULL != set);
477  if ((NULL != set->ops_head) ||
479  {
481  "Set operations are pending, delaying set destruction\n");
483  return;
484  }
486  "Really destroying set\n");
487  if (NULL != set->mq)
488  {
489  GNUNET_MQ_destroy (set->mq);
490  set->mq = NULL;
491  }
492  GNUNET_free (set);
493 }
494 
495 
509 GNUNET_SETU_prepare (const struct GNUNET_PeerIdentity *other_peer,
510  const struct GNUNET_HashCode *app_id,
511  const struct GNUNET_MessageHeader *context_msg,
512  const struct GNUNET_SETU_Option options[],
514  void *result_cls)
515 {
516  struct GNUNET_MQ_Envelope *mqm;
519 
521  "Client prepares set union operation\n");
523  oh->result_cb = result_cb;
524  oh->result_cls = result_cls;
527  context_msg);
528  msg->app_id = *app_id;
529  msg->target_peer = *other_peer;
530 
531  /* Set default values */
532  msg->byzantine_upper_bond = UINT64_MAX;
533  msg->bandwidth_latency_tradeoff = 0;
534  msg->ibf_bucket_number_factor = 2;
535  msg->ibf_number_of_buckets_per_element = 3;
536 
537 
538  for (const struct GNUNET_SETU_Option *opt = options; opt->type != 0; opt++)
539  {
540  switch (opt->type)
541  {
543  msg->byzantine = GNUNET_YES;
544  msg->byzantine_lower_bound = htonl (opt->v.num);
545  break;
547  msg->byzantine_upper_bond = htonl (opt->v.num);
548  break;
550  msg->bandwidth_latency_tradeoff = htonl (opt->v.num);
551  break;
553  msg->ibf_bucket_number_factor = htonl (opt->v.num);
554  break;
556  msg->ibf_number_of_buckets_per_element = htonl (opt->v.num);
557  break;
559  msg->force_full = GNUNET_YES;
560  break;
562  msg->force_delta = GNUNET_YES;
563  break;
565  msg->symmetric = GNUNET_YES;
566  break;
567  default:
569  "Option with type %d not recognized\n",
570  (int) opt->type);
571  }
572  }
573  oh->conclude_mqm = mqm;
574  oh->request_id_addr = &msg->request_id;
575  return oh;
576 }
577 
578 
584 static void
585 listen_connect (void *cls);
586 
587 
595 static int
596 check_request (void *cls,
597  const struct GNUNET_SETU_RequestMessage *msg)
598 {
599  const struct GNUNET_MessageHeader *context_msg;
600 
601  if (ntohs (msg->header.size) == sizeof(*msg))
602  return GNUNET_OK; /* no context message is OK */
603  context_msg = GNUNET_MQ_extract_nested_mh (msg);
604  if (NULL == context_msg)
605  {
606  /* malformed context message is NOT ok */
607  GNUNET_break_op (0);
608  return GNUNET_SYSERR;
609  }
610  return GNUNET_OK;
611 }
612 
613 
620 static void
621 handle_request (void *cls,
622  const struct GNUNET_SETU_RequestMessage *msg)
623 {
624  struct GNUNET_SETU_ListenHandle *lh = cls;
625  struct GNUNET_SETU_Request req;
626  const struct GNUNET_MessageHeader *context_msg;
627  struct GNUNET_MQ_Envelope *mqm;
628  struct GNUNET_SETU_RejectMessage *rmsg;
629 
631  "Processing incoming operation request with id %u\n",
632  ntohl (msg->accept_id));
633  /* we got another valid request => reset the backoff */
635  req.accept_id = ntohl (msg->accept_id);
636  req.accepted = GNUNET_NO;
637  context_msg = GNUNET_MQ_extract_nested_mh (msg);
638  /* calling #GNUNET_SETU_accept() in the listen cb will set req->accepted */
639  lh->listen_cb (lh->listen_cls,
640  &msg->peer_id,
641  context_msg,
642  &req);
643  if (GNUNET_YES == req.accepted)
644  return; /* the accept-case is handled in #GNUNET_SETU_accept() */
646  "Rejected request %u\n",
647  ntohl (msg->accept_id));
648  mqm = GNUNET_MQ_msg (rmsg,
650  rmsg->accept_reject_id = msg->accept_id;
651  GNUNET_MQ_send (lh->mq,
652  mqm);
653 }
654 
655 
663 static void
665  enum GNUNET_MQ_Error error)
666 {
667  struct GNUNET_SETU_ListenHandle *lh = cls;
668 
670  "Listener broke down (%d), re-connecting\n",
671  (int) error);
672  GNUNET_MQ_destroy (lh->mq);
673  lh->mq = NULL;
676  lh);
678 }
679 
680 
686 static void
687 listen_connect (void *cls)
688 {
689  struct GNUNET_SETU_ListenHandle *lh = cls;
690  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
694  lh),
696  };
697  struct GNUNET_MQ_Envelope *mqm;
699 
700  lh->reconnect_task = NULL;
701  GNUNET_assert (NULL == lh->mq);
702  lh->mq = GNUNET_CLIENT_connect (lh->cfg,
703  "setu",
704  mq_handlers,
706  lh);
707  if (NULL == lh->mq)
708  return;
709  mqm = GNUNET_MQ_msg (msg,
711  msg->app_id = lh->app_id;
712  GNUNET_MQ_send (lh->mq,
713  mqm);
714 }
715 
716 
730  const struct GNUNET_HashCode *app_id,
732  void *listen_cls)
733 {
734  struct GNUNET_SETU_ListenHandle *lh;
735 
737  "Starting listener for app %s\n",
738  GNUNET_h2s (app_id));
739  lh = GNUNET_new (struct GNUNET_SETU_ListenHandle);
740  lh->listen_cb = listen_cb;
741  lh->listen_cls = listen_cls;
742  lh->cfg = cfg;
743  lh->app_id = *app_id;
745  listen_connect (lh);
746  if (NULL == lh->mq)
747  {
748  GNUNET_free (lh);
749  return NULL;
750  }
751  return lh;
752 }
753 
754 
760 void
762 {
764  "Canceling listener %s\n",
765  GNUNET_h2s (&lh->app_id));
766  if (NULL != lh->mq)
767  {
768  GNUNET_MQ_destroy (lh->mq);
769  lh->mq = NULL;
770  }
771  if (NULL != lh->reconnect_task)
772  {
774  lh->reconnect_task = NULL;
775  }
776  GNUNET_free (lh);
777 }
778 
779 
796  const struct GNUNET_SETU_Option options[],
798  void *result_cls)
799 {
800  struct GNUNET_MQ_Envelope *mqm;
803 
804  GNUNET_assert (GNUNET_NO == request->accepted);
806  "Client accepts set union operation with id %u\n",
807  request->accept_id);
808  request->accepted = GNUNET_YES;
809  mqm = GNUNET_MQ_msg (msg,
811  msg->accept_reject_id = htonl (request->accept_id);
812 
813  /* Set default values */
814  msg->byzantine_upper_bond = UINT64_MAX;
815  msg->bandwidth_latency_tradeoff = 0;
816  msg->ibf_bucket_number_factor = 2;
817  msg->ibf_number_of_buckets_per_element = 3;
818 
819  for (const struct GNUNET_SETU_Option *opt = options; opt->type != 0; opt++)
820  {
821  switch (opt->type)
822  {
824  msg->byzantine = GNUNET_YES;
825  msg->byzantine_lower_bound = htonl (opt->v.num);
826  break;
828  msg->byzantine_upper_bond = htonl (opt->v.num);
829  break;
831  msg->bandwidth_latency_tradeoff = htonl (opt->v.num);
832  break;
834  msg->ibf_bucket_number_factor = htonl (opt->v.num);
835  break;
837  msg->ibf_number_of_buckets_per_element = htonl (opt->v.num);
838  break;
840  msg->force_full = GNUNET_YES;
841  break;
843  msg->force_delta = GNUNET_YES;
844  break;
846  msg->symmetric = GNUNET_YES;
847  break;
848  default:
850  "Option with type %d not recognized\n",
851  (int) opt->type);
852  }
853  }
855  oh->result_cb = result_cb;
856  oh->result_cls = result_cls;
857  oh->conclude_mqm = mqm;
858  oh->request_id_addr = &msg->request_id;
859  return oh;
860 }
861 
862 
876 int
878  struct GNUNET_SETU_Handle *set)
879 {
880  if (NULL != oh->set)
881  {
882  /* Some other set was already committed for this
883  * operation, there is a logic bug in the client of this API */
884  GNUNET_break (0);
885  return GNUNET_OK;
886  }
887  GNUNET_assert (NULL != set);
888  if (GNUNET_YES == set->invalid)
889  return GNUNET_SYSERR;
891  "Client commits to SET\n");
892  GNUNET_assert (NULL != oh->conclude_mqm);
893  oh->set = set;
895  set->ops_tail,
896  oh);
897  oh->request_id = GNUNET_MQ_assoc_add (set->mq,
898  oh);
899  *oh->request_id_addr = htonl (oh->request_id);
900  GNUNET_MQ_send (set->mq,
901  oh->conclude_mqm);
902  oh->conclude_mqm = NULL;
903  oh->request_id_addr = NULL;
904  return GNUNET_OK;
905 }
906 
907 
915 void
917  struct GNUNET_HashCode *ret_hash)
918 {
920 
921  /* It's not guaranteed that the element data is always after the element header,
922  so we need to hash the chunks separately. */
924  &element->size,
925  sizeof(uint16_t));
927  &element->element_type,
928  sizeof(uint16_t));
930  element->data,
931  element->size);
933  ret_hash);
934 }
935 
936 
937 /* end of setu_api.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
static struct Experiment * e
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
static struct GNUNET_TRANSPORT_OfferHelloHandle * oh
Active HELLO offering to transport service.
static int result
Global testing status.
static struct GNUNET_HashCode app_id
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
#define GNUNET_log(kind,...)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_NO
Definition: gnunet_common.h:94
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
Definition: crypto_hash.c:321
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:340
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
Definition: crypto_hash.c:364
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:1064
#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_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
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#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:355
#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:323
#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:52
#define GNUNET_MQ_msg_nested_mh(mvar, type, mh)
Allocate a GNUNET_MQ_Envelope, and append a payload message after the given message struct.
void * GNUNET_MQ_assoc_remove(struct GNUNET_MQ_Handle *mq, uint32_t request_id)
Remove the association for a request_id.
Definition: mq.c:765
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#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:787
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:721
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:749
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
#define GNUNET_MQ_extract_nested_mh(var)
Return a pointer to the message at the end of the given message.
#define GNUNET_MESSAGE_TYPE_SETU_REQUEST
Notify the client of an incoming request from a remote peer.
#define GNUNET_MESSAGE_TYPE_SETU_REJECT
Reject a set request.
#define GNUNET_MESSAGE_TYPE_SETU_RESULT
Handle result message from operation.
#define GNUNET_MESSAGE_TYPE_SETU_CREATE
Create a new local set.
#define GNUNET_MESSAGE_TYPE_SETU_ADD
Add element to set.
#define GNUNET_MESSAGE_TYPE_SETU_ACCEPT
Accept an incoming set request.
#define GNUNET_MESSAGE_TYPE_SETU_CANCEL
Cancel a set operation.
#define GNUNET_MESSAGE_TYPE_SETU_LISTEN
Listen for operation requests.
#define GNUNET_MESSAGE_TYPE_SETU_EVALUATE
Evaluate a set operation.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
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:1269
void GNUNET_SETU_element_hash(const struct GNUNET_SETU_Element *element, struct GNUNET_HashCode *ret_hash)
Hash a set element.
Definition: setu_api.c:916
struct GNUNET_SETU_Handle * GNUNET_SETU_create(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create an empty set, supporting the specified operation.
Definition: setu_api.c:384
void GNUNET_SETU_operation_cancel(struct GNUNET_SETU_OperationHandle *oh)
Cancel the given set operation.
Definition: setu_api.c:320
struct GNUNET_SETU_ListenHandle * GNUNET_SETU_listen(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_HashCode *app_id, GNUNET_SETU_ListenCallback listen_cb, void *listen_cls)
Wait for set operation requests for the given application id.
Definition: setu_api.c:729
struct GNUNET_SETU_OperationHandle * GNUNET_SETU_prepare(const struct GNUNET_PeerIdentity *other_peer, const struct GNUNET_HashCode *app_id, const struct GNUNET_MessageHeader *context_msg, const struct GNUNET_SETU_Option options[], GNUNET_SETU_ResultIterator result_cb, void *result_cls)
Prepare a set operation to be evaluated with another peer.
Definition: setu_api.c:509
void(* GNUNET_SETU_ListenCallback)(void *cls, const struct GNUNET_PeerIdentity *other_peer, const struct GNUNET_MessageHeader *context_msg, struct GNUNET_SETU_Request *request)
Called when another peer wants to do a set operation with the local peer.
void GNUNET_SETU_destroy(struct GNUNET_SETU_Handle *set)
Destroy the set handle if no operations are left, mark the set for destruction otherwise.
Definition: setu_api.c:471
struct GNUNET_SETU_OperationHandle * GNUNET_SETU_accept(struct GNUNET_SETU_Request *request, const struct GNUNET_SETU_Option options[], GNUNET_SETU_ResultIterator result_cb, void *result_cls)
Accept a request we got via GNUNET_SETU_listen.
Definition: setu_api.c:795
int GNUNET_SETU_commit(struct GNUNET_SETU_OperationHandle *oh, struct GNUNET_SETU_Handle *set)
Commit a set to be used with a set operation.
Definition: setu_api.c:877
void(* GNUNET_SETU_ResultIterator)(void *cls, const struct GNUNET_SETU_Element *element, uint64_t current_size, enum GNUNET_SETU_Status status)
Callback for set union operation results.
GNUNET_SETU_Status
Status for the result callback.
void GNUNET_SETU_listen_cancel(struct GNUNET_SETU_ListenHandle *lh)
Cancel the given listen operation.
Definition: setu_api.c:761
int GNUNET_SETU_add_element(struct GNUNET_SETU_Handle *set, const struct GNUNET_SETU_Element *element, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Add an element to the given set.
Definition: setu_api.c:429
@ GNUNET_SETU_OPTION_FORCE_DELTA
Only use optimized set operations, even though for this particular set operation they might be much s...
@ GNUNET_SETU_OPTION_CUSTOM_IBF_BUCKETS_PER_ELEMENT
This setting determines to how many IBF buckets an single elements is mapped to.
@ GNUNET_SETU_OPTION_CUSTOM_BANDWIDTH_LATENCY_TRADEOFF
Bandwidth latency tradeoff determines how much bytes a single RTT is worth, which is a performance se...
@ GNUNET_SETU_OPTION_CUSTOM_IBF_BUCKET_NUMBER_FACTOR
The factor determines the number of buckets an IBF has which is multiplied by the estimated setsize d...
@ GNUNET_SETU_OPTION_CUSTOM_BYZANTINE_UPPER_BOUND
Byzantine upper bound.
@ GNUNET_SETU_OPTION_SYMMETRIC
Notify client also if we are sending a value to the other peer.
@ GNUNET_SETU_OPTION_BYZANTINE
Fail set operations when the other peer shows weird behavior that might by a Byzantine fault.
@ GNUNET_SETU_OPTION_FORCE_FULL
Do not use the optimized set operation, but send full sets.
@ GNUNET_SETU_STATUS_DONE
Success, all elements have been sent (and received).
@ GNUNET_SETU_STATUS_ADD_REMOTE
Element should be added to the result set of the remote peer, i.e.
@ GNUNET_SETU_STATUS_FAILURE
The other peer refused to do the operation with us, or something went wrong.
@ GNUNET_SETU_STATUS_ADD_LOCAL
Element should be added to the result set of the local peer, i.e.
#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...
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: setu_api.c:664
static int check_result(void *cls, const struct GNUNET_SETU_ResultMessage *msg)
Check that the given msg is well-formed.
Definition: setu_api.c:196
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: setu_api.c:354
static void listen_connect(void *cls)
Connect to the set service in order to listen for requests.
Definition: setu_api.c:687
static void set_operation_destroy(struct GNUNET_SETU_OperationHandle *oh)
Destroy the given set operation.
Definition: setu_api.c:290
static void handle_result(void *cls, const struct GNUNET_SETU_ResultMessage *msg)
Handle result message for a set operation.
Definition: setu_api.c:211
static void handle_request(void *cls, const struct GNUNET_SETU_RequestMessage *msg)
Handle request message for a listen operation.
Definition: setu_api.c:621
#define LOG(kind,...)
Definition: setu_api.c:34
static int check_request(void *cls, const struct GNUNET_SETU_RequestMessage *msg)
Check validity of request message for a listen operation.
Definition: setu_api.c:596
A 512-bit hashcode.
Handle to a message queue.
Definition: mq.c:86
Message handler for a specific message type.
Header for all communications.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition: scheduler.c:135
Message sent by a listening client to the service to accept performing the operation with the other p...
Definition: setu.h:79
Sent to the service by the client in order to cancel a set operation.
Definition: setu.h:350
Message sent by the client to the service to ask starting a new set to perform operations with.
Definition: setu.h:41
Message sent by client to the service to add an element to the set.
Definition: setu.h:326
Element stored in a set.
uint16_t element_type
Application-specific element type.
uint16_t size
Number of bytes in the buffer pointed to by data.
const void * data
Actual data of the element.
Message sent by client to service to initiate a set operation as a client (not as listener).
Definition: setu.h:203
Opaque handle to a set.
Definition: setu_api.c:40
struct GNUNET_SETU_OperationHandle * ops_tail
Linked list of operations on the set.
Definition: setu_api.c:54
int destroy_requested
Should the set be destroyed once all operations are gone? GNUNET_SYSERR if GNUNET_SETU_destroy() must...
Definition: setu_api.c:61
int invalid
Has the set become invalid (e.g.
Definition: setu_api.c:66
struct GNUNET_SETU_OperationHandle * ops_head
Linked list of operations on the set.
Definition: setu_api.c:49
struct GNUNET_MQ_Handle * mq
Message queue for client.
Definition: setu_api.c:44
Opaque handle to a listen operation.
Definition: setu_api.c:146
struct GNUNET_HashCode app_id
Application ID we listen for.
Definition: setu_api.c:173
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: setu_api.c:150
GNUNET_SETU_ListenCallback listen_cb
Function to call on a new incoming request, or on error.
Definition: setu_api.c:163
void * listen_cls
Closure for listen_cb.
Definition: setu_api.c:168
struct GNUNET_TIME_Relative reconnect_backoff
Time to wait until we try to reconnect on failure.
Definition: setu_api.c:178
struct GNUNET_SCHEDULER_Task * reconnect_task
Task for reconnecting when the listener fails.
Definition: setu_api.c:183
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration handle for the listener, stored here to be able to reconnect transparently on connectio...
Definition: setu_api.c:157
Message sent by the client to the service to start listening for incoming requests to perform a certa...
Definition: setu.h:56
Handle to an operation.
Definition: setu_api.c:95
void * result_cls
Closure for result_cb.
Definition: setu_api.c:105
GNUNET_SETU_ResultIterator result_cb
Function to be called when we have a result, or an error.
Definition: setu_api.c:100
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: setu_api.c:123
struct GNUNET_SETU_Handle * set
Local set used for the operation, NULL if no set has been provided by conclude yet.
Definition: setu_api.c:111
uint32_t request_id
Request ID to identify the operation within the set.
Definition: setu_api.c:138
struct GNUNET_MQ_Envelope * conclude_mqm
Message sent to the server on calling conclude, NULL if conclude has been called.
Definition: setu_api.c:117
struct GNUNET_SETU_OperationHandle * prev
Handles are kept in a linked list.
Definition: setu_api.c:128
struct GNUNET_SETU_OperationHandle * next
Handles are kept in a linked list.
Definition: setu_api.c:133
Option for set operations.
Message sent by a listening client to the service to reject performing the operation with the other p...
Definition: setu.h:158
uint32_t accept_reject_id
ID of the incoming request we want to reject.
Definition: setu.h:167
A request for an operation with another client.
Definition: setu.h:175
Handle for a set operation request from another peer.
Definition: setu_api.c:75
int accepted
Has the request been accepted already? GNUNET_YES/GNUNET_NO.
Definition: setu_api.c:86
uint32_t accept_id
Id of the request, used to identify the request when accepting/rejecting it.
Definition: setu_api.c:80
Message sent by the service to the client to indicate an element that is removed (set intersection) o...
Definition: setu.h:290
uint16_t result_status
Was the evaluation successful? Contains an enum GNUNET_SETU_Status in NBO.
Definition: setu.h:310
Time for relative time used by GNUnet, in microseconds.