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 
111  struct GNUNET_SETU_Handle *set;
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 
174 
178  struct GNUNET_TIME_Relative reconnect_backoff;
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,
248  result_status);
249  return;
253  "Treating result as final status\n");
254  GNUNET_MQ_assoc_remove (set->mq,
255  ntohl (msg->request_id));
256  GNUNET_CONTAINER_DLL_remove (set->ops_head,
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,
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)
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,
370  set_operation_destroy (set->ops_head);
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) ||
478  (GNUNET_SYSERR == set->destroy_requested))
479  {
481  "Set operations are pending, delaying set destruction\n");
482  set->destroy_requested = GNUNET_YES;
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;
525  mqm = GNUNET_MQ_msg_nested_mh (msg,
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;
534  msg->ibf_bucket_number_factor = 2;
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;
816  msg->ibf_bucket_number_factor = 2;
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;
894  GNUNET_CONTAINER_DLL_insert (set->ops_head,
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 */
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void * listen_cls
Closure for listen_cb.
Definition: setu_api.c:168
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: setu_api.c:150
Fail set operations when the other peer shows weird behavior that might by a Byzantine fault...
int invalid
Has the set become invalid (e.g.
Definition: setu_api.c:66
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
Handle for a set operation request from another peer.
Definition: setu_api.c:74
Message sent by the client to the service to start listening for incoming requests to perform a certa...
Definition: setu.h:55
#define GNUNET_MESSAGE_TYPE_SETU_REQUEST
Notify the client of an incoming request from a remote peer.
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
struct GNUNET_SCHEDULER_Task * reconnect_task
Task for reconnecting when the listener fails.
Definition: setu_api.c:183
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
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
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_SETU_RESULT.
Definition: setu.h:294
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
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
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:1063
#define GNUNET_MQ_msg_nested_mh(mvar, type, mh)
Allocate a GNUNET_MQ_Envelope, and append a payload message after the given message struct...
struct GNUNET_HashCode app_id
Application id.
Definition: setu.h:223
const void * data
Actual data of the element.
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 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
int accepted
Has the request been accepted already? GNUNET_YES/GNUNET_NO.
Definition: setu_api.c:86
uint8_t symmetric
Also return set elements we are sending to the remote peer.
Definition: setu.h:246
uint32_t accept_reject_id
ID of the incoming request we want to reject.
Definition: setu.h:167
GNUNET_MQ_Error
Error codes for the queue.
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
#define GNUNET_MQ_extract_nested_mh(var)
Return a pointer to the message at the end of the given message.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint64_t ibf_bucket_number_factor
The factor determines the number of buckets an IBF has which is multiplied by the estimated setsize d...
Definition: setu.h:270
uint64_t byzantine_upper_bond
Upper bound for the set size, used only when byzantine mode is enabled.
Definition: setu.h:258
uint32_t request_id
ID of the request we want to cancel.
Definition: setu.h:359
Option for set operations.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_SETU_REQUEST.
Definition: setu.h:179
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.
struct GNUNET_HashCode app_id
Application ID we listen for.
Definition: setu_api.c:173
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
uint32_t accept_reject_id
ID of the incoming request we want to accept.
Definition: setu.h:88
struct GNUNET_TIME_Relative reconnect_backoff
Time to wait until we try to reconnect on failure.
Definition: setu_api.c:178
void * result_cls
Closure for result_cb.
Definition: setu_api.c:105
uint64_t byzantine_upper_bond
Upper bound for the set size, used only when byzantine mode is enabled.
Definition: setu.h:130
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
Definition: crypto_hash.c:321
static struct GNUNET_HashCode app_id
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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.
uint32_t request_id
id the result belongs to
Definition: setu.h:304
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
uint32_t request_id
Request ID to identify responses.
Definition: setu.h:93
uint8_t byzantine
GNUNET_YES to fail operations where Byzantine faults are suspected
Definition: setu.h:111
struct GNUNET_MQ_Handle * mq
Message queue for client.
Definition: setu_api.c:44
uint16_t element_type
Type of the element attached to the message, if any.
Definition: setu.h:315
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
Message sent by the client to the service to ask starting a new set to perform operations with...
Definition: setu.h:40
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
Opaque handle to a listen operation.
Definition: setu_api.c:145
uint64_t ibf_bucket_number_factor
The factor determines the number of buckets an IBF has which is multiplied by the estimated setsize d...
Definition: setu.h:142
uint8_t force_full
Always send full sets, even if delta operations would be more efficient.
Definition: setu.h:235
uint64_t ibf_number_of_buckets_per_element
This setting determines to how many IBF buckets an single elements is mapped to.
Definition: setu.h:148
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
uint64_t bandwidth_latency_tradeoff
Bandwidth latency tradeoff determines how much bytes a single RTT is worth, which is a performance se...
Definition: setu.h:264
#define LOG(kind,...)
Definition: setu_api.c:34
uint8_t symmetric
GNUNET_YES to also send back set elements we are sending to the remote peer.
Definition: setu.h:117
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
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
uint16_t element_type
Type of the element to add or remove.
Definition: setu.h:335
uint64_t bandwidth_latency_tradeoff
Bandwidth latency tradeoff determines how much bytes a single RTT is worth, which is a performance se...
Definition: setu.h:136
Message sent by client to service to initiate a set operation as a client (not as listener)...
Definition: setu.h:202
#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
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
The other peer refused to do the operation with us, or something went wrong.
struct GNUNET_SETU_OperationHandle * next
Handles are kept in a linked list.
Definition: setu_api.c:133
GNUNET_SETU_Status
Status for the result callback.
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
#define GNUNET_MESSAGE_TYPE_SETU_ACCEPT
Accept an incoming set request.
#define GNUNET_MESSAGE_TYPE_SETU_RESULT
Handle result message from operation.
Opaque handle to a set.
Definition: setu_api.c:39
static struct GNUNET_TRANSPORT_OfferHelloHandle * oh
Active HELLO offering to transport service.
#define GNUNET_MESSAGE_TYPE_SETU_CREATE
Create a new local set.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
Success, all elements have been sent (and received).
uint16_t element_type
Application-specific element type.
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
static void listen_connect(void *cls)
Connect to the set service in order to listen for requests.
Definition: setu_api.c:687
Element should be added to the result set of the local peer, i.e.
uint32_t accept_id
ID of the to identify the request when accepting or rejecting it.
Definition: setu.h:185
#define GNUNET_MESSAGE_TYPE_SETU_CANCEL
Cancel a set operation.
static int result
Global testing status.
uint32_t byzantine_lower_bound
Lower bound for the set size, used only when byzantine mode is enabled.
Definition: setu.h:252
static void handle_request(void *cls, const struct GNUNET_SETU_RequestMessage *msg)
Handle request message for a listen operation.
Definition: setu_api.c:621
uint64_t ibf_number_of_buckets_per_element
This setting determines to how many IBF buckets an single elements is mapped to.
Definition: setu.h:276
A 512-bit hashcode.
uint16_t result_status
Was the evaluation successful? Contains an enum GNUNET_SETU_Status in NBO.
Definition: setu.h:310
Message sent by a listening client to the service to accept performing the operation with the other p...
Definition: setu.h:78
uint8_t force_delta
Always use delta operation instead of sending full sets, even it it&#39;s less efficient.
Definition: setu.h:229
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
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
Message handler for a specific message type.
Handle to an operation.
Definition: setu_api.c:94
GNUNET_SETU_ResultIterator result_cb
Function to be called when we have a result, or an error.
Definition: setu_api.c:100
uint8_t byzantine
GNUNET_YES to fail operations where Byzantine faults are suspected
Definition: setu.h:241
GNUNET_SETU_ListenCallback listen_cb
Function to call on a new incoming request, or on error.
Definition: setu_api.c:163
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:323
enum GNUNET_SETU_OptionType type
Type of the option.
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
struct GNUNET_SETU_OperationHandle * prev
Handles are kept in a linked list.
Definition: setu_api.c:128
#define GNUNET_MESSAGE_TYPE_SETU_ADD
Add element to set.
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
static void set_operation_destroy(struct GNUNET_SETU_OperationHandle *oh)
Destroy the given set operation.
Definition: setu_api.c:290
uint64_t current_size
Current set size.
Definition: setu.h:299
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
Message sent by client to the service to add an element to the set.
Definition: setu.h:325
struct GNUNET_PeerIdentity target_peer
Peer to evaluate the operation with.
Definition: setu.h:218
Notify client also if we are sending a value to the other peer.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
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
A request for an operation with another client.
Definition: setu.h:174
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
uint32_t request_id
Id of our set to evaluate, chosen implicitly by the client when it calls GNUNET_SETU_commit().
Definition: setu.h:213
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
Handle to a message queue.
Definition: mq.c:85
static void handle_result(void *cls, const struct GNUNET_SETU_ResultMessage *msg)
Handle result message for a set operation.
Definition: setu_api.c:211
The identity of the host (wraps the signing key of the peer).
struct GNUNET_PeerIdentity peer_id
Identity of the requesting peer.
Definition: setu.h:190
Do not use the optimized set operation, but send full sets.
uint8_t force_full
Always send full sets, even if delta operations would be more efficient.
Definition: setu.h:105
The factor determines the number of buckets an IBF has which is multiplied by the estimated setsize d...
Only use optimized set operations, even though for this particular set operation they might be much s...
Message sent by the service to the client to indicate an element that is removed (set intersection) o...
Definition: setu.h:289
configuration data
void GNUNET_SETU_operation_cancel(struct GNUNET_SETU_OperationHandle *oh)
Cancel the given set operation.
Definition: setu_api.c:320
Element should be added to the result set of the remote peer, i.e.
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
Sent to the service by the client in order to cancel a set operation.
Definition: setu.h:349
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:134
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
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
This setting determines to how many IBF buckets an single elements is mapped to.
struct GNUNET_SETU_OperationHandle * ops_tail
Linked list of operations on the set.
Definition: setu_api.c:54
void GNUNET_SETU_listen_cancel(struct GNUNET_SETU_ListenHandle *lh)
Cancel the given listen operation.
Definition: setu_api.c:761
#define GNUNET_MESSAGE_TYPE_SETU_LISTEN
Listen for operation requests.
Header for all communications.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
uint8_t force_delta
Always use delta operation instead of sending full sets, even it it&#39;s less efficient.
Definition: setu.h:99
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_MESSAGE_TYPE_SETU_REJECT
Reject a set request.
#define GNUNET_MESSAGE_TYPE_SETU_EVALUATE
Evaluate a set operation.
Bandwidth latency tradeoff determines how much bytes a single RTT is worth, which is a performance se...
uint32_t accept_id
Id of the request, used to identify the request when accepting/rejecting it.
Definition: setu_api.c:80
uint32_t byzantine_lower_bound
Lower bound for the set size, used only when byzantine mode is enabled.
Definition: setu.h:123
uint16_t size
Number of bytes in the buffer pointed to by data.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
uint32_t request_id
Request ID to identify the operation within the set.
Definition: setu_api.c:138
Message sent by a listening client to the service to reject performing the operation with the other p...
Definition: setu.h:157
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
Definition: crypto_hash.c:364
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_SETU_OperationHandle * ops_head
Linked list of operations on the set.
Definition: setu_api.c:49
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
struct GNUNET_HashCode app_id
application id
Definition: setu.h:70
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Element stored in a set.