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  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_protocols.h"
29 #include "gnunet_setu_service.h"
30 #include "setu.h"
31 
32 
33 #define LOG(kind, ...) GNUNET_log_from (kind, "set-api", __VA_ARGS__)
34 
39 {
44 
49 
54 
61 
65  int invalid;
66 
67 };
68 
69 
74 {
79  uint32_t accept_id;
80 
85  int accepted;
86 };
87 
88 
94 {
100 
104  void *result_cls;
105 
110  struct GNUNET_SETU_Handle *set;
111 
117 
122  uint32_t *request_id_addr;
123 
128 
133 
137  uint32_t request_id;
138 };
139 
140 
145 {
150 
157 
163 
167  void *listen_cls;
168 
173 
177  struct GNUNET_TIME_Relative reconnect_backoff;
178 
183 
184 };
185 
186 
194 static int
195 check_result (void *cls,
196  const struct GNUNET_SETU_ResultMessage *msg)
197 {
198  /* minimum size was already checked, everything else is OK! */
199  return GNUNET_OK;
200 }
201 
202 
209 static void
210 handle_result (void *cls,
211  const struct GNUNET_SETU_ResultMessage *msg)
212 {
213  struct GNUNET_SETU_Handle *set = cls;
215  struct GNUNET_SETU_Element e;
216  enum GNUNET_SETU_Status result_status;
217  int destroy_set;
218 
219  GNUNET_assert (NULL != set->mq);
220  result_status = (enum GNUNET_SETU_Status) ntohs (msg->result_status);
222  "Got result message with status %d\n",
223  result_status);
224  oh = GNUNET_MQ_assoc_get (set->mq,
225  ntohl (msg->request_id));
226  if (NULL == oh)
227  {
228  /* 'oh' can be NULL if we canceled the operation, but the service
229  did not get the cancel message yet. */
231  "Ignoring result from canceled operation\n");
232  return;
233  }
234 
235  switch (result_status)
236  {
239  e.data = &msg[1];
240  e.size = ntohs (msg->header.size)
241  - sizeof(struct GNUNET_SETU_ResultMessage);
242  e.element_type = ntohs (msg->element_type);
243  if (NULL != oh->result_cb)
244  oh->result_cb (oh->result_cls,
245  &e,
247  result_status);
248  return;
252  "Treating result as final status\n");
253  GNUNET_MQ_assoc_remove (set->mq,
254  ntohl (msg->request_id));
255  GNUNET_CONTAINER_DLL_remove (set->ops_head,
256  set->ops_tail,
257  oh);
258  /* Need to do this calculation _before_ the result callback,
259  as IF the application still has a valid set handle, it
260  may trigger destruction of the set during the callback. */
261  destroy_set = (GNUNET_YES == set->destroy_requested) &&
262  (NULL == set->ops_head);
263  if (NULL != oh->result_cb)
264  {
265  oh->result_cb (oh->result_cls,
266  NULL,
268  result_status);
269  }
270  else
271  {
273  "No callback for final status\n");
274  }
275  if (destroy_set)
276  GNUNET_SETU_destroy (set);
277  GNUNET_free (oh);
278  return;
279  }
280 }
281 
282 
288 static void
290 {
291  struct GNUNET_SETU_Handle *set = oh->set;
292  struct GNUNET_SETU_OperationHandle *h_assoc;
293 
294  if (NULL != oh->conclude_mqm)
296  /* is the operation already commited? */
297  if (NULL != set)
298  {
300  set->ops_tail,
301  oh);
302  h_assoc = GNUNET_MQ_assoc_remove (set->mq,
303  oh->request_id);
304  GNUNET_assert ((NULL == h_assoc) ||
305  (h_assoc == oh));
306  }
307  GNUNET_free (oh);
308 }
309 
310 
318 void
320 {
321  struct GNUNET_SETU_Handle *set = oh->set;
323  struct GNUNET_MQ_Envelope *mqm;
324 
326  "Cancelling SET operation\n");
327  if (NULL != set)
328  {
330  m->request_id = htonl (oh->request_id);
331  GNUNET_MQ_send (set->mq, mqm);
332  }
334  if ((NULL != set) &&
335  (GNUNET_YES == set->destroy_requested) &&
336  (NULL == set->ops_head))
337  {
339  "Destroying set after operation cancel\n");
340  GNUNET_SETU_destroy (set);
341  }
342 }
343 
344 
352 static void
354  enum GNUNET_MQ_Error error)
355 {
356  struct GNUNET_SETU_Handle *set = cls;
357 
359  "Handling client set error %d\n",
360  error);
361  while (NULL != set->ops_head)
362  {
363  if ((NULL != set->ops_head->result_cb) &&
364  (GNUNET_NO == set->destroy_requested))
365  set->ops_head->result_cb (set->ops_head->result_cls,
366  NULL,
367  0,
369  set_operation_destroy (set->ops_head);
370  }
371  set->invalid = GNUNET_YES;
372 }
373 
374 
382 struct GNUNET_SETU_Handle *
384 {
385  struct GNUNET_SETU_Handle *set = GNUNET_new (struct GNUNET_SETU_Handle);
386  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
390  set),
392  };
393  struct GNUNET_MQ_Envelope *mqm;
394  struct GNUNET_SETU_CreateMessage *create_msg;
395 
396  set->mq = GNUNET_CLIENT_connect (cfg,
397  "setu",
398  mq_handlers,
400  set);
401  if (NULL == set->mq)
402  {
403  GNUNET_free (set);
404  return NULL;
405  }
406  mqm = GNUNET_MQ_msg (create_msg,
408  GNUNET_MQ_send (set->mq,
409  mqm);
410  return set;
411 }
412 
413 
427 int
429  const struct GNUNET_SETU_Element *element,
431  void *cb_cls)
432 {
433  struct GNUNET_MQ_Envelope *mqm;
435 
437  "adding element of type %u to set %p\n",
438  (unsigned int) element->element_type,
439  set);
440  GNUNET_assert (NULL != set);
441  if (GNUNET_YES == set->invalid)
442  {
443  if (NULL != cb)
444  cb (cb_cls);
445  return GNUNET_SYSERR;
446  }
447  mqm = GNUNET_MQ_msg_extra (msg,
448  element->size,
450  msg->element_type = htons (element->element_type);
451  GNUNET_memcpy (&msg[1],
452  element->data,
453  element->size);
455  cb,
456  cb_cls);
457  GNUNET_MQ_send (set->mq,
458  mqm);
459  return GNUNET_OK;
460 }
461 
462 
469 void
471 {
472  /* destroying set while iterator is active is currently
473  not supported; we should expand the API to allow
474  clients to explicitly cancel the iteration! */
475  GNUNET_assert (NULL != set);
476  if ((NULL != set->ops_head) ||
477  (GNUNET_SYSERR == set->destroy_requested))
478  {
480  "Set operations are pending, delaying set destruction\n");
481  set->destroy_requested = GNUNET_YES;
482  return;
483  }
485  "Really destroying set\n");
486  if (NULL != set->mq)
487  {
488  GNUNET_MQ_destroy (set->mq);
489  set->mq = NULL;
490  }
491  GNUNET_free (set);
492 }
493 
494 
508 GNUNET_SETU_prepare (const struct GNUNET_PeerIdentity *other_peer,
509  const struct GNUNET_HashCode *app_id,
510  const struct GNUNET_MessageHeader *context_msg,
511  const struct GNUNET_SETU_Option options[],
513  void *result_cls)
514 {
515  struct GNUNET_MQ_Envelope *mqm;
518 
520  "Client prepares set union operation\n");
522  oh->result_cb = result_cb;
523  oh->result_cls = result_cls;
524  mqm = GNUNET_MQ_msg_nested_mh (msg,
526  context_msg);
527  msg->app_id = *app_id;
528  msg->target_peer = *other_peer;
529  for (const struct GNUNET_SETU_Option *opt = options; opt->type != 0; opt++)
530  {
531  switch (opt->type)
532  {
534  msg->byzantine = GNUNET_YES;
535  msg->byzantine_lower_bound = htonl (opt->v.num);
536  break;
538  msg->force_full = GNUNET_YES;
539  break;
541  msg->force_delta = GNUNET_YES;
542  break;
544  msg->symmetric = GNUNET_YES;
545  break;
546  default:
548  "Option with type %d not recognized\n",
549  (int) opt->type);
550  }
551  }
552  oh->conclude_mqm = mqm;
553  oh->request_id_addr = &msg->request_id;
554  return oh;
555 }
556 
557 
563 static void
564 listen_connect (void *cls);
565 
566 
574 static int
575 check_request (void *cls,
576  const struct GNUNET_SETU_RequestMessage *msg)
577 {
578  const struct GNUNET_MessageHeader *context_msg;
579 
580  if (ntohs (msg->header.size) == sizeof(*msg))
581  return GNUNET_OK; /* no context message is OK */
582  context_msg = GNUNET_MQ_extract_nested_mh (msg);
583  if (NULL == context_msg)
584  {
585  /* malformed context message is NOT ok */
586  GNUNET_break_op (0);
587  return GNUNET_SYSERR;
588  }
589  return GNUNET_OK;
590 }
591 
592 
599 static void
600 handle_request (void *cls,
601  const struct GNUNET_SETU_RequestMessage *msg)
602 {
603  struct GNUNET_SETU_ListenHandle *lh = cls;
604  struct GNUNET_SETU_Request req;
605  const struct GNUNET_MessageHeader *context_msg;
606  struct GNUNET_MQ_Envelope *mqm;
607  struct GNUNET_SETU_RejectMessage *rmsg;
608 
610  "Processing incoming operation request with id %u\n",
611  ntohl (msg->accept_id));
612  /* we got another valid request => reset the backoff */
614  req.accept_id = ntohl (msg->accept_id);
615  req.accepted = GNUNET_NO;
616  context_msg = GNUNET_MQ_extract_nested_mh (msg);
617  /* calling #GNUNET_SETU_accept() in the listen cb will set req->accepted */
618  lh->listen_cb (lh->listen_cls,
619  &msg->peer_id,
620  context_msg,
621  &req);
622  if (GNUNET_YES == req.accepted)
623  return; /* the accept-case is handled in #GNUNET_SETU_accept() */
625  "Rejected request %u\n",
626  ntohl (msg->accept_id));
627  mqm = GNUNET_MQ_msg (rmsg,
629  rmsg->accept_reject_id = msg->accept_id;
630  GNUNET_MQ_send (lh->mq,
631  mqm);
632 }
633 
634 
642 static void
644  enum GNUNET_MQ_Error error)
645 {
646  struct GNUNET_SETU_ListenHandle *lh = cls;
647 
649  "Listener broke down (%d), re-connecting\n",
650  (int) error);
651  GNUNET_MQ_destroy (lh->mq);
652  lh->mq = NULL;
655  lh);
657 }
658 
659 
665 static void
666 listen_connect (void *cls)
667 {
668  struct GNUNET_SETU_ListenHandle *lh = cls;
669  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
673  lh),
675  };
676  struct GNUNET_MQ_Envelope *mqm;
678 
679  lh->reconnect_task = NULL;
680  GNUNET_assert (NULL == lh->mq);
681  lh->mq = GNUNET_CLIENT_connect (lh->cfg,
682  "setu",
683  mq_handlers,
685  lh);
686  if (NULL == lh->mq)
687  return;
688  mqm = GNUNET_MQ_msg (msg,
690  msg->app_id = lh->app_id;
691  GNUNET_MQ_send (lh->mq,
692  mqm);
693 }
694 
695 
709  const struct GNUNET_HashCode *app_id,
711  void *listen_cls)
712 {
713  struct GNUNET_SETU_ListenHandle *lh;
714 
716  "Starting listener for app %s\n",
717  GNUNET_h2s (app_id));
718  lh = GNUNET_new (struct GNUNET_SETU_ListenHandle);
719  lh->listen_cb = listen_cb;
720  lh->listen_cls = listen_cls;
721  lh->cfg = cfg;
722  lh->app_id = *app_id;
724  listen_connect (lh);
725  if (NULL == lh->mq)
726  {
727  GNUNET_free (lh);
728  return NULL;
729  }
730  return lh;
731 }
732 
733 
739 void
741 {
743  "Canceling listener %s\n",
744  GNUNET_h2s (&lh->app_id));
745  if (NULL != lh->mq)
746  {
747  GNUNET_MQ_destroy (lh->mq);
748  lh->mq = NULL;
749  }
750  if (NULL != lh->reconnect_task)
751  {
753  lh->reconnect_task = NULL;
754  }
755  GNUNET_free (lh);
756 }
757 
758 
775  const struct GNUNET_SETU_Option options[],
777  void *result_cls)
778 {
779  struct GNUNET_MQ_Envelope *mqm;
782 
783  GNUNET_assert (GNUNET_NO == request->accepted);
785  "Client accepts set union operation with id %u\n",
786  request->accept_id);
787  request->accepted = GNUNET_YES;
788  mqm = GNUNET_MQ_msg (msg,
790  msg->accept_reject_id = htonl (request->accept_id);
791  for (const struct GNUNET_SETU_Option *opt = options; opt->type != 0; opt++)
792  {
793  switch (opt->type)
794  {
796  msg->byzantine = GNUNET_YES;
797  msg->byzantine_lower_bound = htonl (opt->v.num);
798  break;
800  msg->force_full = GNUNET_YES;
801  break;
803  msg->force_delta = GNUNET_YES;
804  break;
806  msg->symmetric = GNUNET_YES;
807  break;
808  default:
810  "Option with type %d not recognized\n",
811  (int) opt->type);
812  }
813  }
815  oh->result_cb = result_cb;
816  oh->result_cls = result_cls;
817  oh->conclude_mqm = mqm;
818  oh->request_id_addr = &msg->request_id;
819  return oh;
820 }
821 
822 
836 int
838  struct GNUNET_SETU_Handle *set)
839 {
840  if (NULL != oh->set)
841  {
842  /* Some other set was already committed for this
843  * operation, there is a logic bug in the client of this API */
844  GNUNET_break (0);
845  return GNUNET_OK;
846  }
847  GNUNET_assert (NULL != set);
848  if (GNUNET_YES == set->invalid)
849  return GNUNET_SYSERR;
851  "Client commits to SET\n");
852  GNUNET_assert (NULL != oh->conclude_mqm);
853  oh->set = set;
854  GNUNET_CONTAINER_DLL_insert (set->ops_head,
855  set->ops_tail,
856  oh);
857  oh->request_id = GNUNET_MQ_assoc_add (set->mq,
858  oh);
859  *oh->request_id_addr = htonl (oh->request_id);
860  GNUNET_MQ_send (set->mq,
861  oh->conclude_mqm);
862  oh->conclude_mqm = NULL;
863  oh->request_id_addr = NULL;
864  return GNUNET_OK;
865 }
866 
867 
875 void
877  struct GNUNET_HashCode *ret_hash)
878 {
880 
881  /* It's not guaranteed that the element data is always after the element header,
882  so we need to hash the chunks separately. */
884  &element->size,
885  sizeof(uint16_t));
887  &element->element_type,
888  sizeof(uint16_t));
890  element->data,
891  element->size);
893  ret_hash);
894 }
895 
896 
897 /* 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:167
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: setu_api.c:149
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:65
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:73
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:508
struct GNUNET_SCHEDULER_Task * reconnect_task
Task for reconnecting when the listener fails.
Definition: setu_api.c:182
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:122
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:244
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:837
#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:197
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:110
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:85
uint8_t symmetric
Also return set elements we are sending to the remote peer.
Definition: setu.h:220
uint32_t accept_reject_id
ID of the incoming request we want to reject.
Definition: setu.h:141
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:353
#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.
uint32_t request_id
ID of the request we want to cancel.
Definition: setu.h:309
Option for set operations.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_SETU_REQUEST.
Definition: setu.h:153
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:172
#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:177
void * result_cls
Closure for result_cb.
Definition: setu_api.c:104
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:483
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:254
Context for cumulative hashing.
Definition: crypto_hash.c:468
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:43
uint16_t element_type
Type of the element attachted to the message, if any.
Definition: setu.h:265
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:383
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:144
uint8_t force_full
Always send full sets, even if delta operations would be more efficient.
Definition: setu.h:209
static int check_result(void *cls, const struct GNUNET_SETU_ResultMessage *msg)
Check that the given msg is well-formed.
Definition: setu_api.c:195
#define LOG(kind,...)
Definition: setu_api.c:33
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:116
uint16_t element_type
Type of the element to add or remove.
Definition: setu.h:285
Message sent by client to service to initiate a set operation as a client (not as listener)...
Definition: setu.h:176
#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:132
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:38
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:774
static void listen_connect(void *cls)
Connect to the set service in order to listen for requests.
Definition: setu_api.c:666
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:159
#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:226
static void handle_request(void *cls, const struct GNUNET_SETU_RequestMessage *msg)
Handle request message for a listen operation.
Definition: setu_api.c:600
A 512-bit hashcode.
uint16_t result_status
Was the evaluation successful? Contains an enum GNUNET_SETU_Status in NBO.
Definition: setu.h:260
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:203
void GNUNET_SETU_element_hash(const struct GNUNET_SETU_Element *element, struct GNUNET_HashCode *ret_hash)
Hash a set element.
Definition: setu_api.c:876
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
Message handler for a specific message type.
Handle to an operation.
Definition: setu_api.c:93
GNUNET_SETU_ResultIterator result_cb
Function to be called when we have a result, or an error.
Definition: setu_api.c:99
uint8_t byzantine
GNUNET_YES to fail operations where Byzantine faults are suspected
Definition: setu.h:215
GNUNET_SETU_ListenCallback listen_cb
Function to call on a new incoming request, or on error.
Definition: setu_api.c:162
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:60
struct GNUNET_SETU_OperationHandle * prev
Handles are kept in a linked list.
Definition: setu_api.c:127
#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:708
static void set_operation_destroy(struct GNUNET_SETU_OperationHandle *oh)
Destroy the given set operation.
Definition: setu_api.c:289
uint64_t current_size
Current set size.
Definition: setu.h:249
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:509
Message sent by client to the service to add an element to the set.
Definition: setu.h:275
struct GNUNET_PeerIdentity target_peer
Peer to evaluate the operation with.
Definition: setu.h:192
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:470
A request for an operation with another client.
Definition: setu.h:148
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:643
uint32_t request_id
Id of our set to evaluate, chosen implicitly by the client when it calls GNUNET_SETU_commit().
Definition: setu.h:187
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:575
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:210
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:164
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
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:239
configuration data
Definition: configuration.c:84
void GNUNET_SETU_operation_cancel(struct GNUNET_SETU_OperationHandle *oh)
Cancel the given set operation.
Definition: setu_api.c:319
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:299
#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:156
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:428
struct GNUNET_SETU_OperationHandle * ops_tail
Linked list of operations on the set.
Definition: setu_api.c:53
void GNUNET_SETU_listen_cancel(struct GNUNET_SETU_ListenHandle *lh)
Cancel the given listen operation.
Definition: setu_api.c:740
#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.
uint32_t accept_id
Id of the request, used to identify the request when accepting/rejecting it.
Definition: setu_api.c:79
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:137
Message sent by a listening client to the service to reject performing the operation with the other p...
Definition: setu.h:131
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
Definition: crypto_hash.c:526
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:48
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.