GNUnet  0.10.x
Data Structures | Macros | Functions
set_api.c File Reference

api for the set service More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_set_service.h"
#include "set.h"
Include dependency graph for set_api.c:

Go to the source code of this file.

Data Structures

struct  SetCopyRequest
 
struct  GNUNET_SET_Handle
 Opaque handle to a set. More...
 
struct  GNUNET_SET_Request
 Handle for a set operation request from another peer. More...
 
struct  GNUNET_SET_OperationHandle
 Handle to an operation. More...
 
struct  GNUNET_SET_ListenHandle
 Opaque handle to a listen operation. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "set-api",__VA_ARGS__)
 

Functions

static struct GNUNET_SET_Handlecreate_internal (const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_SET_OperationType op, const uint32_t *cookie)
 FIXME. More...
 
static void handle_copy_lazy (void *cls, const struct GNUNET_SET_CopyLazyResponseMessage *msg)
 Handle element for iteration over the set. More...
 
static int check_iter_element (void *cls, const struct GNUNET_SET_IterResponseMessage *msg)
 Check that the given msg is well-formed. More...
 
static void handle_iter_element (void *cls, const struct GNUNET_SET_IterResponseMessage *msg)
 Handle element for iteration over the set. More...
 
static void handle_iter_done (void *cls, const struct GNUNET_MessageHeader *mh)
 Handle message signalling conclusion of iteration over the set. More...
 
static int check_result (void *cls, const struct GNUNET_SET_ResultMessage *msg)
 Check that the given msg is well-formed. More...
 
static void handle_result (void *cls, const struct GNUNET_SET_ResultMessage *msg)
 Handle result message for a set operation. More...
 
static void set_operation_destroy (struct GNUNET_SET_OperationHandle *oh)
 Destroy the given set operation. More...
 
void GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh)
 Cancel the given set operation. More...
 
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. More...
 
struct GNUNET_SET_HandleGNUNET_SET_create (const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_SET_OperationType op)
 Create an empty set, supporting the specified operation. More...
 
int GNUNET_SET_add_element (struct GNUNET_SET_Handle *set, const struct GNUNET_SET_Element *element, GNUNET_SET_Continuation cont, void *cont_cls)
 Add an element to the given set. More...
 
int GNUNET_SET_remove_element (struct GNUNET_SET_Handle *set, const struct GNUNET_SET_Element *element, GNUNET_SET_Continuation cont, void *cont_cls)
 Remove an element to the given set. More...
 
void GNUNET_SET_destroy (struct GNUNET_SET_Handle *set)
 Destroy the set handle if no operations are left, mark the set for destruction otherwise. More...
 
struct GNUNET_SET_OperationHandleGNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer, const struct GNUNET_HashCode *app_id, const struct GNUNET_MessageHeader *context_msg, enum GNUNET_SET_ResultMode result_mode, struct GNUNET_SET_Option options[], GNUNET_SET_ResultIterator result_cb, void *result_cls)
 Prepare a set operation to be evaluated with another peer. More...
 
static void listen_connect (void *cls)
 Connect to the set service in order to listen for requests. More...
 
static int check_request (void *cls, const struct GNUNET_SET_RequestMessage *msg)
 Check validity of request message for a listen operation. More...
 
static void handle_request (void *cls, const struct GNUNET_SET_RequestMessage *msg)
 Handle request message for a listen operation. More...
 
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. More...
 
struct GNUNET_SET_ListenHandleGNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_SET_OperationType operation, const struct GNUNET_HashCode *app_id, GNUNET_SET_ListenCallback listen_cb, void *listen_cls)
 Wait for set operation requests for the given application id. More...
 
void GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh)
 Cancel the given listen operation. More...
 
struct GNUNET_SET_OperationHandleGNUNET_SET_accept (struct GNUNET_SET_Request *request, enum GNUNET_SET_ResultMode result_mode, struct GNUNET_SET_Option options[], GNUNET_SET_ResultIterator result_cb, void *result_cls)
 Accept a request we got via GNUNET_SET_listen. More...
 
int GNUNET_SET_commit (struct GNUNET_SET_OperationHandle *oh, struct GNUNET_SET_Handle *set)
 Commit a set to be used with a set operation. More...
 
int GNUNET_SET_iterate (struct GNUNET_SET_Handle *set, GNUNET_SET_ElementIterator iter, void *iter_cls)
 Iterate over all elements in the given set. More...
 
void GNUNET_SET_copy_lazy (struct GNUNET_SET_Handle *set, GNUNET_SET_CopyReadyCallback cb, void *cls)
 
struct GNUNET_SET_ElementGNUNET_SET_element_dup (const struct GNUNET_SET_Element *element)
 Create a copy of an element. More...
 
void GNUNET_SET_element_hash (const struct GNUNET_SET_Element *element, struct GNUNET_HashCode *ret_hash)
 Hash a set element. More...
 

Detailed Description

api for the set service

Author
Florian Dold
Christian Grothoff

Definition in file set_api.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "set-api",__VA_ARGS__)

Function Documentation

◆ create_internal()

static struct GNUNET_SET_Handle * create_internal ( const struct GNUNET_CONFIGURATION_Handle cfg,
enum GNUNET_SET_OperationType  op,
const uint32_t *  cookie 
)
static

FIXME.

Definition at line 581 of file set_api.c.

References cfg, GNUNET_SET_CopyLazyConnectMessage::cookie, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT, GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE, GNUNET_MESSAGE_TYPE_SET_CREATE, GNUNET_MESSAGE_TYPE_SET_ITER_DONE, GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT, GNUNET_MESSAGE_TYPE_SET_RESULT, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_new, handle_client_set_error(), LOG, GNUNET_SET_CreateMessage::operation, and result.

Referenced by GNUNET_SET_create(), and handle_copy_lazy().

584 {
585  struct GNUNET_SET_Handle *set = GNUNET_new (struct GNUNET_SET_Handle);
586  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
590  set),
591  GNUNET_MQ_hd_var_size (iter_element,
594  set),
595  GNUNET_MQ_hd_fixed_size (iter_done,
597  struct GNUNET_MessageHeader,
598  set),
599  GNUNET_MQ_hd_fixed_size (copy_lazy,
602  set),
604  };
605  struct GNUNET_MQ_Envelope *mqm;
606  struct GNUNET_SET_CreateMessage *create_msg;
607  struct GNUNET_SET_CopyLazyConnectMessage *copy_msg;
608 
609  set->cfg = cfg;
610  set->mq = GNUNET_CLIENT_connect (cfg,
611  "set",
612  mq_handlers,
614  set);
615  if (NULL == set->mq)
616  {
617  GNUNET_free (set);
618  return NULL;
619  }
620  if (NULL == cookie)
621  {
623  "Creating new set (operation %u)\n",
624  op);
625  mqm = GNUNET_MQ_msg (create_msg,
627  create_msg->operation = htonl (op);
628  }
629  else
630  {
632  "Creating new set (lazy copy)\n",
633  op);
634  mqm = GNUNET_MQ_msg (copy_msg,
636  copy_msg->cookie = *cookie;
637  }
638  GNUNET_MQ_send (set->mq,
639  mqm);
640  return set;
641 }
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:901
#define GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT
Element result for the iterating client.
#define GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE
Give the client an ID for connecting to the set's copy.
Message sent by the service to the client to indicate an element that is removed (set intersection) o...
Definition: set.h:246
#define GNUNET_MESSAGE_TYPE_SET_RESULT
Create an empty set.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
Set element transmitted by service to client in response to a set iteration request.
Definition: set.h:326
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_MESSAGE_TYPE_SET_CREATE
Create a new local set.
#define LOG(kind,...)
Definition: set_api.c:33
#define GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT
Sent by the client to the server to connect to an existing, lazily copied set.
Message sent by the client to the service to ask starting a new set to perform operations with...
Definition: set.h:40
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
static int result
Global testing status.
uint32_t operation
Operation type, values of enum GNUNET_SET_OperationType
Definition: set.h:50
Message handler for a specific message type.
Client connects to a lazily copied set.
Definition: set.h:386
Opaque handle to a set.
Definition: set_api.c:49
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
uint32_t cookie
Temporary name for the copied set.
Definition: set.h:396
#define GNUNET_MESSAGE_TYPE_SET_ITER_DONE
Iteration end marker for the client.
Server responds to a lazy copy request.
Definition: set.h:369
Header for all communications.
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:353
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
static void handle_client_set_error(void *cls, enum GNUNET_MQ_Error error)
We encountered an error communicating with the set service while performing a set operation...
Definition: set_api.c:549
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_copy_lazy()

static void handle_copy_lazy ( void *  cls,
const struct GNUNET_SET_CopyLazyResponseMessage msg 
)
static

Handle element for iteration over the set.

Notifies the iterator and sends an acknowledgement to the service.

Parameters
clsthe struct GNUNET_SET_Handle *
msgthe message

Definition at line 249 of file set_api.c.

References SetCopyRequest::cb, SetCopyRequest::cls, GNUNET_SET_CopyLazyResponseMessage::cookie, create_internal(), GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_SET_OPERATION_NONE, and LOG.

251 {
252  struct GNUNET_SET_Handle *set = cls;
253  struct SetCopyRequest *req;
254  struct GNUNET_SET_Handle *new_set;
255 
256  req = set->copy_req_head;
257  if (NULL == req)
258  {
259  /* Service sent us unsolicited lazy copy response */
260  GNUNET_break (0);
261  return;
262  }
263 
265  "Handling response to lazy copy\n");
266  GNUNET_CONTAINER_DLL_remove (set->copy_req_head,
267  set->copy_req_tail,
268  req);
269  // We pass none as operation here, since it doesn't matter when
270  // cloning.
271  new_set = create_internal (set->cfg,
273  &msg->cookie);
274  req->cb (req->cls, new_set);
275  GNUNET_free (req);
276 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
A purely local set that does not support any operation.
void * cls
Definition: set_api.c:41
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define LOG(kind,...)
Definition: set_api.c:33
GNUNET_SET_CopyReadyCallback cb
Definition: set_api.c:43
Opaque handle to a set.
Definition: set_api.c:49
uint32_t cookie
Temporary name for the copied set.
Definition: set.h:379
static struct GNUNET_SET_Handle * create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_SET_OperationType op, const uint32_t *cookie)
FIXME.
Definition: set_api.c:581
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ check_iter_element()

static int check_iter_element ( void *  cls,
const struct GNUNET_SET_IterResponseMessage msg 
)
static

Check that the given msg is well-formed.

Parameters
clsclosure
msgmessage to check
Returns
GNUNET_OK if message is well-formed

Definition at line 287 of file set_api.c.

References GNUNET_OK.

289 {
290  /* minimum size was already checked, everything else is OK! */
291  return GNUNET_OK;
292 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78

◆ handle_iter_element()

static void handle_iter_element ( void *  cls,
const struct GNUNET_SET_IterResponseMessage msg 
)
static

Handle element for iteration over the set.

Notifies the iterator and sends an acknowledgement to the service.

Parameters
clsthe struct GNUNET_SET_Handle *
mhthe message

Definition at line 303 of file set_api.c.

References SetCopyRequest::cls, GNUNET_SET_Element::data, GNUNET_SET_Element::element_type, GNUNET_SET_IterResponseMessage::element_type, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_SET_ITER_ACK, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_SET_IterResponseMessage::header, GNUNET_SET_IterResponseMessage::iteration_id, LOG, GNUNET_SET_IterAckMessage::send_more, GNUNET_SET_Element::size, and GNUNET_MessageHeader::size.

305 {
306  struct GNUNET_SET_Handle *set = cls;
307  GNUNET_SET_ElementIterator iter = set->iterator;
308  struct GNUNET_SET_Element element;
309  struct GNUNET_SET_IterAckMessage *ack_msg;
310  struct GNUNET_MQ_Envelope *ev;
311  uint16_t msize;
312 
314  "Received element in set iteration\n");
315  msize = ntohs (msg->header.size);
316  if (set->iteration_id != ntohs (msg->iteration_id))
317  {
318  /* element from a previous iteration, skip! */
319  iter = NULL;
320  }
321  if (NULL != iter)
322  {
323  element.size = msize - sizeof (struct GNUNET_SET_IterResponseMessage);
324  element.element_type = ntohs (msg->element_type);
325  element.data = &msg[1];
326  iter (set->iterator_cls,
327  &element);
328  }
329  ev = GNUNET_MQ_msg (ack_msg,
331  ack_msg->send_more = htonl ((NULL != iter));
332  GNUNET_MQ_send (set->mq, ev);
333 }
Element stored in a set.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
Set element transmitted by service to client in response to a set iteration request.
Definition: set.h:326
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
int(* GNUNET_SET_ElementIterator)(void *cls, const struct GNUNET_SET_Element *element)
Iterator for set elements.
#define LOG(kind,...)
Definition: set_api.c:33
Opaque handle to a set.
Definition: set_api.c:49
Client acknowledges receiving element in iteration.
Definition: set.h:352
#define GNUNET_MESSAGE_TYPE_SET_ITER_ACK
Acknowledge result from iteration.
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:353
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT.
Definition: set.h:331
uint16_t element_type
Type of the element attachted to the message, if any.
Definition: set.h:343
uint16_t iteration_id
To which set iteration does this reponse belong to? First iteration (per client) has counter zero...
Definition: set.h:337
uint32_t send_more
Non-zero if the service should continue sending elements.
Definition: set.h:362
Here is the call graph for this function:

◆ handle_iter_done()

static void handle_iter_done ( void *  cls,
const struct GNUNET_MessageHeader mh 
)
static

Handle message signalling conclusion of iteration over the set.

Notifies the iterator that we are done.

Parameters
clsthe set
mhthe message

Definition at line 344 of file set_api.c.

References SetCopyRequest::cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_NO, GNUNET_SET_destroy(), GNUNET_SYSERR, GNUNET_YES, and LOG.

346 {
347  struct GNUNET_SET_Handle *set = cls;
348  GNUNET_SET_ElementIterator iter = set->iterator;
349 
350  if (NULL == iter)
351  {
352  /* FIXME: if this is true, could cancel+start a fresh one
353  cause elements to go to the wrong iteration? */
355  "Service completed set iteration that was already cancelled\n");
356  return;
357  }
359  "Set iteration completed\n");
360  set->destroy_requested = GNUNET_SYSERR;
361  set->iterator = NULL;
362  set->iteration_id++;
363  iter (set->iterator_cls,
364  NULL);
365  if (GNUNET_SYSERR == set->destroy_requested)
366  set->destroy_requested = GNUNET_NO;
367  if (GNUNET_YES == set->destroy_requested)
368  GNUNET_SET_destroy (set);
369 }
#define GNUNET_NO
Definition: gnunet_common.h:81
int(* GNUNET_SET_ElementIterator)(void *cls, const struct GNUNET_SET_Element *element)
Iterator for set elements.
void GNUNET_SET_destroy(struct GNUNET_SET_Handle *set)
Destroy the set handle if no operations are left, mark the set for destruction otherwise.
Definition: set_api.c:771
#define LOG(kind,...)
Definition: set_api.c:33
Opaque handle to a set.
Definition: set_api.c:49
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:

◆ check_result()

static int check_result ( void *  cls,
const struct GNUNET_SET_ResultMessage msg 
)
static

Check that the given msg is well-formed.

Parameters
clsclosure
msgmessage to check
Returns
GNUNET_OK if message is well-formed

Definition at line 380 of file set_api.c.

References GNUNET_OK.

382 {
383  /* minimum size was already checked, everything else is OK! */
384  return GNUNET_OK;
385 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78

◆ handle_result()

static void handle_result ( void *  cls,
const struct GNUNET_SET_ResultMessage msg 
)
static

Handle result message for a set operation.

Parameters
clsthe set
mhthe message

Definition at line 395 of file set_api.c.

References SetCopyRequest::cls, GNUNET_SET_ResultMessage::current_size, GNUNET_SET_Element::data, GNUNET_SET_Element::element_type, GNUNET_SET_ResultMessage::element_type, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_MQ_assoc_get(), GNUNET_MQ_assoc_remove(), GNUNET_ntohll(), GNUNET_SET_destroy(), GNUNET_SET_STATUS_ADD_LOCAL, GNUNET_SET_STATUS_ADD_REMOTE, GNUNET_SET_STATUS_DONE, GNUNET_SET_STATUS_FAILURE, GNUNET_SET_STATUS_HALF_DONE, GNUNET_SET_STATUS_OK, GNUNET_YES, GNUNET_SET_ResultMessage::header, LOG, oh, GNUNET_SET_ResultMessage::request_id, GNUNET_SET_OperationHandle::result_cb, GNUNET_SET_OperationHandle::result_cls, GNUNET_SET_ResultMessage::result_status, GNUNET_SET_Element::size, and GNUNET_MessageHeader::size.

397 {
398  struct GNUNET_SET_Handle *set = cls;
400  struct GNUNET_SET_Element e;
401  enum GNUNET_SET_Status result_status;
402  int destroy_set;
403 
404  GNUNET_assert (NULL != set->mq);
405  result_status = (enum GNUNET_SET_Status) ntohs (msg->result_status);
407  "Got result message with status %d\n",
408  result_status);
409 
410  oh = GNUNET_MQ_assoc_get (set->mq,
411  ntohl (msg->request_id));
412  if (NULL == oh)
413  {
414  /* 'oh' can be NULL if we canceled the operation, but the service
415  did not get the cancel message yet. */
417  "Ignoring result from canceled operation\n");
418  return;
419  }
420 
421  switch (result_status)
422  {
426  goto do_element;
429  goto do_final;
431  /* not used anymore */
432  GNUNET_assert (0);
433  }
434 
435 do_final:
437  "Treating result as final status\n");
438  GNUNET_MQ_assoc_remove (set->mq,
439  ntohl (msg->request_id));
440  GNUNET_CONTAINER_DLL_remove (set->ops_head,
441  set->ops_tail,
442  oh);
443  /* Need to do this calculation _before_ the result callback,
444  as IF the application still has a valid set handle, it
445  may trigger destruction of the set during the callback. */
446  destroy_set = (GNUNET_YES == set->destroy_requested) &&
447  (NULL == set->ops_head);
448  if (NULL != oh->result_cb)
449  {
450  oh->result_cb (oh->result_cls,
451  NULL,
453  result_status);
454  }
455  else
456  {
458  "No callback for final status\n");
459  }
460  if (destroy_set)
461  GNUNET_SET_destroy (set);
462  GNUNET_free (oh);
463  return;
464 
465 do_element:
467  "Treating result as element\n");
468  e.data = &msg[1];
469  e.size = ntohs (msg->header.size) - sizeof (struct GNUNET_SET_ResultMessage);
470  e.element_type = ntohs (msg->element_type);
471  if (NULL != oh->result_cb)
472  oh->result_cb (oh->result_cls,
473  &e,
475  result_status);
476 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void * result_cls
Closure for result_cb.
Definition: set_api.c:146
Element should be added to the result set of the remote peer, i.e.
Message sent by the service to the client to indicate an element that is removed (set intersection) o...
Definition: set.h:246
Element stored in a set.
Element should be added to the result set of the local peer, i.e.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint32_t request_id
id the result belongs to
Definition: set.h:261
static struct Experiment * e
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
Success, all elements have been sent (and received).
void GNUNET_SET_destroy(struct GNUNET_SET_Handle *set)
Destroy the set handle if no operations are left, mark the set for destruction otherwise.
Definition: set_api.c:771
uint64_t current_size
Current set size.
Definition: set.h:256
#define LOG(kind,...)
Definition: set_api.c:33
GNUNET_SET_ResultIterator result_cb
Function to be called when we have a result, or an error.
Definition: set_api.c:141
The other peer refused to to the operation with us, or something went wrong.
Success, all elements have been returned (but the other peer might still be receiving some from us...
static struct GNUNET_TRANSPORT_OfferHelloHandle * oh
Active HELLO offering to transport service.
Everything went ok, we are transmitting an element of the result (in set, or to be removed from set...
GNUNET_SET_Status
Status for the result callback.
uint16_t result_status
Was the evaluation successful? Contains an enum GNUNET_SET_Status in NBO.
Definition: set.h:267
Opaque handle to a set.
Definition: set_api.c:49
uint16_t element_type
Type of the element attachted to the message, if any.
Definition: set.h:272
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_SET_RESULT.
Definition: set.h:251
Handle to an operation.
Definition: set_api.c:135
void * GNUNET_MQ_assoc_remove(struct GNUNET_MQ_Handle *mq, uint32_t request_id)
Remove the association for a request_id.
Definition: mq.c:752
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
#define GNUNET_free(ptr)
Wrapper around free.
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:736
Here is the call graph for this function:

◆ set_operation_destroy()

static void set_operation_destroy ( struct GNUNET_SET_OperationHandle oh)
static

Destroy the given set operation.

Parameters
ohset operation to destroy

Definition at line 485 of file set_api.c.

References GNUNET_SET_OperationHandle::conclude_mqm, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_assoc_remove(), GNUNET_MQ_discard(), GNUNET_SET_Handle::mq, GNUNET_SET_Handle::ops_head, GNUNET_SET_Handle::ops_tail, GNUNET_SET_OperationHandle::request_id, and GNUNET_SET_OperationHandle::set.

Referenced by GNUNET_SET_operation_cancel(), and handle_client_set_error().

486 {
487  struct GNUNET_SET_Handle *set = oh->set;
488  struct GNUNET_SET_OperationHandle *h_assoc;
489 
490  if (NULL != oh->conclude_mqm)
492  /* is the operation already commited? */
493  if (NULL != set)
494  {
496  set->ops_tail,
497  oh);
498  h_assoc = GNUNET_MQ_assoc_remove (set->mq,
499  oh->request_id);
500  GNUNET_assert ( (NULL == h_assoc) ||
501  (h_assoc == oh) );
502  }
503  GNUNET_free (oh);
504 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_SET_Handle * set
Local set used for the operation, NULL if no set has been provided by conclude yet.
Definition: set_api.c:152
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SET_OperationHandle * ops_tail
Linked list of operations on the set.
Definition: set_api.c:64
uint32_t request_id
Request ID to identify the operation within the set.
Definition: set_api.c:179
struct GNUNET_MQ_Handle * mq
Message queue for client.
Definition: set_api.c:54
Opaque handle to a set.
Definition: set_api.c:49
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:321
Handle to an operation.
Definition: set_api.c:135
struct GNUNET_SET_OperationHandle * ops_head
Linked list of operations on the set.
Definition: set_api.c:59
struct GNUNET_MQ_Envelope * conclude_mqm
Message sent to the server on calling conclude, NULL if conclude has been called. ...
Definition: set_api.c:158
void * GNUNET_MQ_assoc_remove(struct GNUNET_MQ_Handle *mq, uint32_t request_id)
Remove the association for a request_id.
Definition: mq.c:752
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_client_set_error()

static void handle_client_set_error ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

We encountered an error communicating with the set service while performing a set operation.

Report to the application.

Parameters
clsthe struct GNUNET_SET_Handle
errorerror code

Definition at line 549 of file set_api.c.

References SetCopyRequest::cls, GNUNET_ERROR_TYPE_ERROR, GNUNET_NO, GNUNET_SET_STATUS_FAILURE, GNUNET_YES, LOG, and set_operation_destroy().

Referenced by create_internal().

551 {
552  struct GNUNET_SET_Handle *set = cls;
553  GNUNET_SET_ElementIterator iter = set->iterator;
554 
556  "Handling client set error %d\n",
557  error);
558  while (NULL != set->ops_head)
559  {
560  if ( (NULL != set->ops_head->result_cb) &&
561  (GNUNET_NO == set->destroy_requested) )
562  set->ops_head->result_cb (set->ops_head->result_cls,
563  NULL,
564  0,
566  set_operation_destroy (set->ops_head);
567  }
568  set->iterator = NULL;
569  set->iteration_id++;
570  set->invalid = GNUNET_YES;
571  if (NULL != iter)
572  iter (set->iterator_cls,
573  NULL);
574 }
#define GNUNET_NO
Definition: gnunet_common.h:81
int(* GNUNET_SET_ElementIterator)(void *cls, const struct GNUNET_SET_Element *element)
Iterator for set elements.
#define LOG(kind,...)
Definition: set_api.c:33
The other peer refused to to the operation with us, or something went wrong.
Opaque handle to a set.
Definition: set_api.c:49
static void set_operation_destroy(struct GNUNET_SET_OperationHandle *oh)
Destroy the given set operation.
Definition: set_api.c:485
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ listen_connect()

static void listen_connect ( void *  cls)
static

Connect to the set service in order to listen for requests.

Parameters
clsthe struct GNUNET_SET_ListenHandle * to connect

Definition at line 970 of file set_api.c.

References GNUNET_SET_ListenMessage::app_id, GNUNET_SET_ListenHandle::app_id, GNUNET_SET_ListenHandle::cfg, SetCopyRequest::cls, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_SET_LISTEN, GNUNET_MESSAGE_TYPE_SET_REQUEST, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), handle_client_listener_error(), GNUNET_SET_ListenHandle::mq, msg, GNUNET_SET_ListenMessage::operation, GNUNET_SET_ListenHandle::operation, and GNUNET_SET_ListenHandle::reconnect_task.

Referenced by GNUNET_SET_listen(), GNUNET_SET_prepare(), and handle_client_listener_error().

971 {
972  struct GNUNET_SET_ListenHandle *lh = cls;
973  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
977  lh),
979  };
980  struct GNUNET_MQ_Envelope *mqm;
982 
983  lh->reconnect_task = NULL;
984  GNUNET_assert (NULL == lh->mq);
985  lh->mq = GNUNET_CLIENT_connect (lh->cfg,
986  "set",
987  mq_handlers,
989  lh);
990  if (NULL == lh->mq)
991  return;
993  msg->operation = htonl (lh->operation);
994  msg->app_id = lh->app_id;
995  GNUNET_MQ_send (lh->mq,
996  mqm);
997 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
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:901
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: set_api.c:192
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
A request for an operation with another client.
Definition: set.h:154
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
uint32_t operation
Operation type, values of enum GNUNET_SET_OperationType
Definition: set.h:69
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
Message sent by the client to the service to start listening for incoming requests to perform a certa...
Definition: set.h:59
#define GNUNET_MESSAGE_TYPE_SET_LISTEN
Listen for operation requests.
Message handler for a specific message type.
struct GNUNET_HashCode app_id
Application ID we listen for.
Definition: set_api.c:215
struct GNUNET_HashCode app_id
application id
Definition: set.h:74
enum GNUNET_SET_OperationType operation
Operation we listen for.
Definition: set_api.c:230
#define GNUNET_MESSAGE_TYPE_SET_REQUEST
Notify the client of a request from a remote peer.
Opaque handle to a listen operation.
Definition: set_api.c:186
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:353
static void handle_client_listener_error(void *cls, enum GNUNET_MQ_Error error)
Our connection with the set service encountered an error, re-initialize with exponential back-off...
Definition: set_api.c:947
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task for reconnecting when the listener fails.
Definition: set_api.c:225
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration handle for the listener, stored here to be able to reconnect transparently on connectio...
Definition: set_api.c:199
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_request()

static int check_request ( void *  cls,
const struct GNUNET_SET_RequestMessage msg 
)
static

Check validity of request message for a listen operation.

Parameters
clsthe listen handle
msgthe message
Returns
GNUNET_OK if the message is well-formed

Definition at line 880 of file set_api.c.

References GNUNET_break_op, GNUNET_MQ_extract_nested_mh, GNUNET_OK, GNUNET_SYSERR, GNUNET_SET_RequestMessage::header, and GNUNET_MessageHeader::size.

882 {
883  const struct GNUNET_MessageHeader *context_msg;
884 
885  if (ntohs (msg->header.size) == sizeof (*msg))
886  return GNUNET_OK; /* no context message is OK */
887  context_msg = GNUNET_MQ_extract_nested_mh (msg);
888  if (NULL == context_msg)
889  {
890  /* malformed context message is NOT ok */
891  GNUNET_break_op (0);
892  return GNUNET_SYSERR;
893  }
894  return GNUNET_OK;
895 }
#define GNUNET_MQ_extract_nested_mh(var)
Return a pointer to the message at the end of the given message.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_SET_REQUEST.
Definition: set.h:159
Header for all communications.

◆ handle_request()

static void handle_request ( void *  cls,
const struct GNUNET_SET_RequestMessage msg 
)
static

Handle request message for a listen operation.

Parameters
clsthe listen handle
msgthe message

Definition at line 905 of file set_api.c.

References GNUNET_SET_Request::accept_id, GNUNET_SET_RequestMessage::accept_id, GNUNET_SET_RejectMessage::accept_reject_id, GNUNET_SET_Request::accepted, SetCopyRequest::cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_SET_REJECT, GNUNET_MQ_extract_nested_mh, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_NO, GNUNET_TIME_UNIT_MILLISECONDS, GNUNET_YES, GNUNET_SET_ListenHandle::listen_cb, GNUNET_SET_ListenHandle::listen_cls, LOG, GNUNET_SET_ListenHandle::mq, GNUNET_SET_RequestMessage::peer_id, and GNUNET_SET_ListenHandle::reconnect_backoff.

907 {
908  struct GNUNET_SET_ListenHandle *lh = cls;
909  struct GNUNET_SET_Request req;
910  const struct GNUNET_MessageHeader *context_msg;
911  struct GNUNET_MQ_Envelope *mqm;
912  struct GNUNET_SET_RejectMessage *rmsg;
913 
915  "Processing incoming operation request with id %u\n",
916  ntohl (msg->accept_id));
917  /* we got another valid request => reset the backoff */
919  req.accept_id = ntohl (msg->accept_id);
920  req.accepted = GNUNET_NO;
921  context_msg = GNUNET_MQ_extract_nested_mh (msg);
922  /* calling #GNUNET_SET_accept() in the listen cb will set req->accepted */
923  lh->listen_cb (lh->listen_cls,
924  &msg->peer_id,
925  context_msg,
926  &req);
927  if (GNUNET_YES == req.accepted)
928  return; /* the accept-case is handled in #GNUNET_SET_accept() */
930  "Rejected request %u\n",
931  ntohl (msg->accept_id));
932  mqm = GNUNET_MQ_msg (rmsg,
934  rmsg->accept_reject_id = msg->accept_id;
935  GNUNET_MQ_send (lh->mq, mqm);
936 }
Handle for a set operation request from another peer.
Definition: set_api.c:115
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: set_api.c:192
#define GNUNET_MQ_extract_nested_mh(var)
Return a pointer to the message at the end of the given message.
void * listen_cls
Closure for listen_cb.
Definition: set_api.c:210
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_NO
Definition: gnunet_common.h:81
GNUNET_SET_ListenCallback listen_cb
Function to call on a new incoming request, or on error.
Definition: set_api.c:205
#define GNUNET_MESSAGE_TYPE_SET_REJECT
Reject a set request.
#define LOG(kind,...)
Definition: set_api.c:33
struct GNUNET_TIME_Relative reconnect_backoff
Time to wait until we try to reconnect on failure.
Definition: set_api.c:220
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
uint32_t accept_reject_id
ID of the incoming request we want to reject.
Definition: set.h:146
uint32_t accept_id
ID of the to identify the request when accepting or rejecting it.
Definition: set.h:165
Opaque handle to a listen operation.
Definition: set_api.c:186
struct GNUNET_PeerIdentity peer_id
Identity of the requesting peer.
Definition: set.h:170
Header for all communications.
#define GNUNET_YES
Definition: gnunet_common.h:80
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:353
Message sent by a listening client to the service to reject performing the operation with the other p...
Definition: set.h:136
Here is the call graph for this function:

◆ handle_client_listener_error()

static void handle_client_listener_error ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Our connection with the set service encountered an error, re-initialize with exponential back-off.

Parameters
clsthe struct GNUNET_SET_ListenHandle *
errorreason for the disconnect

Definition at line 947 of file set_api.c.

References SetCopyRequest::cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, listen_connect(), LOG, GNUNET_SET_ListenHandle::mq, GNUNET_SET_ListenHandle::reconnect_backoff, and GNUNET_SET_ListenHandle::reconnect_task.

Referenced by listen_connect().

949 {
950  struct GNUNET_SET_ListenHandle *lh = cls;
951 
953  "Listener broke down (%d), re-connecting\n",
954  (int) error);
955  GNUNET_MQ_destroy (lh->mq);
956  lh->mq = NULL;
959  lh);
961 }
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: set_api.c:192
#define LOG(kind,...)
Definition: set_api.c:33
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:1246
struct GNUNET_TIME_Relative reconnect_backoff
Time to wait until we try to reconnect on failure.
Definition: set_api.c:220
static void listen_connect(void *cls)
Connect to the set service in order to listen for requests.
Definition: set_api.c:970
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
Opaque handle to a listen operation.
Definition: set_api.c:186
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
struct GNUNET_SCHEDULER_Task * reconnect_task
Task for reconnecting when the listener fails.
Definition: set_api.c:225
Here is the call graph for this function:
Here is the caller graph for this function: