GNUnet  0.11.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 582 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().

585 {
586  struct GNUNET_SET_Handle *set = GNUNET_new (struct GNUNET_SET_Handle);
587  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
591  set),
592  GNUNET_MQ_hd_var_size (iter_element,
595  set),
596  GNUNET_MQ_hd_fixed_size (iter_done,
598  struct GNUNET_MessageHeader,
599  set),
600  GNUNET_MQ_hd_fixed_size (copy_lazy,
603  set),
605  };
606  struct GNUNET_MQ_Envelope *mqm;
607  struct GNUNET_SET_CreateMessage *create_msg;
608  struct GNUNET_SET_CopyLazyConnectMessage *copy_msg;
609 
610  set->cfg = cfg;
611  set->mq = GNUNET_CLIENT_connect (cfg,
612  "set",
613  mq_handlers,
615  set);
616  if (NULL == set->mq)
617  {
618  GNUNET_free (set);
619  return NULL;
620  }
621  if (NULL == cookie)
622  {
624  "Creating new set (operation %u)\n",
625  op);
626  mqm = GNUNET_MQ_msg (create_msg,
628  create_msg->operation = htonl (op);
629  }
630  else
631  {
633  "Creating new set (lazy copy)\n",
634  op);
635  mqm = GNUNET_MQ_msg (copy_msg,
637  copy_msg->cookie = *cookie;
638  }
639  GNUNET_MQ_send (set->mq,
640  mqm);
641  return set;
642 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
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:1057
#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:244
#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:324
#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:384
Opaque handle to a set.
Definition: set_api.c:49
uint32_t cookie
Temporary name for the copied set.
Definition: set.h:394
#define GNUNET_MESSAGE_TYPE_SET_ITER_DONE
Iteration end marker for the client.
Server responds to a lazy copy request.
Definition: set.h:367
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:144
static void handle_client_set_error(void *cls, enum GNUNET_MQ_Error error)
We encountered an error communicating with the set service while performing a set operation...
Definition: set_api.c:550
#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 248 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.

250 {
251  struct GNUNET_SET_Handle *set = cls;
252  struct SetCopyRequest *req;
253  struct GNUNET_SET_Handle *new_set;
254 
255  req = set->copy_req_head;
256  if (NULL == req)
257  {
258  /* Service sent us unsolicited lazy copy response */
259  GNUNET_break (0);
260  return;
261  }
262 
264  "Handling response to lazy copy\n");
265  GNUNET_CONTAINER_DLL_remove (set->copy_req_head,
266  set->copy_req_tail,
267  req);
268  // We pass none as operation here, since it doesn't matter when
269  // cloning.
270  new_set = create_internal (set->cfg,
272  &msg->cookie);
273  req->cb (req->cls, new_set);
274  GNUNET_free (req);
275 }
#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:377
static struct GNUNET_SET_Handle * create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_SET_OperationType op, const uint32_t *cookie)
FIXME.
Definition: set_api.c:582
#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 286 of file set_api.c.

References GNUNET_OK.

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

◆ 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 302 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.

304 {
305  struct GNUNET_SET_Handle *set = cls;
306  GNUNET_SET_ElementIterator iter = set->iterator;
307  struct GNUNET_SET_Element element;
308  struct GNUNET_SET_IterAckMessage *ack_msg;
309  struct GNUNET_MQ_Envelope *ev;
310  uint16_t msize;
311 
313  "Received element in set iteration\n");
314  msize = ntohs (msg->header.size);
315  if (set->iteration_id != ntohs (msg->iteration_id))
316  {
317  /* element from a previous iteration, skip! */
318  iter = NULL;
319  }
320  if (NULL != iter)
321  {
322  element.size = msize - sizeof(struct GNUNET_SET_IterResponseMessage);
323  element.element_type = ntohs (msg->element_type);
324  element.data = &msg[1];
325  iter (set->iterator_cls,
326  &element);
327  }
328  ev = GNUNET_MQ_msg (ack_msg,
330  ack_msg->send_more = htonl ((NULL != iter));
331  GNUNET_MQ_send (set->mq, ev);
332 }
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:324
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:350
#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:329
uint16_t element_type
Type of the element attachted to the message, if any.
Definition: set.h:341
uint16_t iteration_id
To which set iteration does this reponse belong to? First iteration (per client) has counter zero...
Definition: set.h:335
uint32_t send_more
Non-zero if the service should continue sending elements.
Definition: set.h:360
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 343 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.

345 {
346  struct GNUNET_SET_Handle *set = cls;
347  GNUNET_SET_ElementIterator iter = set->iterator;
348 
349  if (NULL == iter)
350  {
351  /* FIXME: if this is true, could cancel+start a fresh one
352  cause elements to go to the wrong iteration? */
354  "Service completed set iteration that was already cancelled\n");
355  return;
356  }
358  "Set iteration completed\n");
359  set->destroy_requested = GNUNET_SYSERR;
360  set->iterator = NULL;
361  set->iteration_id++;
362  iter (set->iterator_cls,
363  NULL);
364  if (GNUNET_SYSERR == set->destroy_requested)
365  set->destroy_requested = GNUNET_NO;
366  if (GNUNET_YES == set->destroy_requested)
367  GNUNET_SET_destroy (set);
368 }
#define GNUNET_NO
Definition: gnunet_common.h:78
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:772
#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:76
#define GNUNET_YES
Definition: gnunet_common.h:77
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 379 of file set_api.c.

References GNUNET_OK.

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

◆ 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 394 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.

396 {
397  struct GNUNET_SET_Handle *set = cls;
399  struct GNUNET_SET_Element e;
400  enum GNUNET_SET_Status result_status;
401  int destroy_set;
402 
403  GNUNET_assert (NULL != set->mq);
404  result_status = (enum GNUNET_SET_Status) ntohs (msg->result_status);
406  "Got result message with status %d\n",
407  result_status);
408 
409  oh = GNUNET_MQ_assoc_get (set->mq,
410  ntohl (msg->request_id));
411  if (NULL == oh)
412  {
413  /* 'oh' can be NULL if we canceled the operation, but the service
414  did not get the cancel message yet. */
416  "Ignoring result from canceled operation\n");
417  return;
418  }
419 
420  switch (result_status)
421  {
425  goto do_element;
426 
429  goto do_final;
430 
432  /* not used anymore */
433  GNUNET_assert (0);
434  }
435 
436 do_final:
438  "Treating result as final status\n");
439  GNUNET_MQ_assoc_remove (set->mq,
440  ntohl (msg->request_id));
441  GNUNET_CONTAINER_DLL_remove (set->ops_head,
442  set->ops_tail,
443  oh);
444  /* Need to do this calculation _before_ the result callback,
445  as IF the application still has a valid set handle, it
446  may trigger destruction of the set during the callback. */
447  destroy_set = (GNUNET_YES == set->destroy_requested) &&
448  (NULL == set->ops_head);
449  if (NULL != oh->result_cb)
450  {
451  oh->result_cb (oh->result_cls,
452  NULL,
454  result_status);
455  }
456  else
457  {
459  "No callback for final status\n");
460  }
461  if (destroy_set)
462  GNUNET_SET_destroy (set);
463  GNUNET_free (oh);
464  return;
465 
466 do_element:
468  "Treating result as element\n");
469  e.data = &msg[1];
470  e.size = ntohs (msg->header.size) - sizeof(struct GNUNET_SET_ResultMessage);
471  e.element_type = ntohs (msg->element_type);
472  if (NULL != oh->result_cb)
473  oh->result_cb (oh->result_cls,
474  &e,
476  result_status);
477 }
#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:244
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:259
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:772
uint64_t current_size
Current set size.
Definition: set.h:254
#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:265
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:270
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_SET_RESULT.
Definition: set.h:249
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:77
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 486 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().

487 {
488  struct GNUNET_SET_Handle *set = oh->set;
489  struct GNUNET_SET_OperationHandle *h_assoc;
490 
491  if (NULL != oh->conclude_mqm)
493  /* is the operation already commited? */
494  if (NULL != set)
495  {
497  set->ops_tail,
498  oh);
499  h_assoc = GNUNET_MQ_assoc_remove (set->mq,
500  oh->request_id);
501  GNUNET_assert ((NULL == h_assoc) ||
502  (h_assoc == oh));
503  }
504  GNUNET_free (oh);
505 }
#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 550 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().

552 {
553  struct GNUNET_SET_Handle *set = cls;
554  GNUNET_SET_ElementIterator iter = set->iterator;
555 
557  "Handling client set error %d\n",
558  error);
559  while (NULL != set->ops_head)
560  {
561  if ((NULL != set->ops_head->result_cb) &&
562  (GNUNET_NO == set->destroy_requested))
563  set->ops_head->result_cb (set->ops_head->result_cls,
564  NULL,
565  0,
567  set_operation_destroy (set->ops_head);
568  }
569  set->iterator = NULL;
570  set->iteration_id++;
571  set->invalid = GNUNET_YES;
572  if (NULL != iter)
573  iter (set->iterator_cls,
574  NULL);
575 }
#define GNUNET_NO
Definition: gnunet_common.h:78
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:486
#define GNUNET_YES
Definition: gnunet_common.h:77
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 974 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, GNUNET_SET_ListenHandle::reconnect_task, and request.

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

975 {
976  struct GNUNET_SET_ListenHandle *lh = cls;
977  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
981  lh),
983  };
984  struct GNUNET_MQ_Envelope *mqm;
986 
987  lh->reconnect_task = NULL;
988  GNUNET_assert (NULL == lh->mq);
989  lh->mq = GNUNET_CLIENT_connect (lh->cfg,
990  "set",
991  mq_handlers,
993  lh);
994  if (NULL == lh->mq)
995  return;
997  msg->operation = htonl (lh->operation);
998  msg->app_id = lh->app_id;
999  GNUNET_MQ_send (lh->mq,
1000  mqm);
1001 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
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:1057
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: set_api.c:191
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
A request for an operation with another client.
Definition: set.h:152
#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:214
struct GNUNET_HashCode app_id
application id
Definition: set.h:74
enum GNUNET_SET_OperationType operation
Operation we listen for.
Definition: set_api.c:229
#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:951
#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:224
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration handle for the listener, stored here to be able to reconnect transparently on connectio...
Definition: set_api.c:198
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 884 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.

886 {
887  const struct GNUNET_MessageHeader *context_msg;
888 
889  if (ntohs (msg->header.size) == sizeof(*msg))
890  return GNUNET_OK; /* no context message is OK */
891  context_msg = GNUNET_MQ_extract_nested_mh (msg);
892  if (NULL == context_msg)
893  {
894  /* malformed context message is NOT ok */
895  GNUNET_break_op (0);
896  return GNUNET_SYSERR;
897  }
898  return GNUNET_OK;
899 }
#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:75
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:76
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_SET_REQUEST.
Definition: set.h:157
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 909 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.

911 {
912  struct GNUNET_SET_ListenHandle *lh = cls;
913  struct GNUNET_SET_Request req;
914  const struct GNUNET_MessageHeader *context_msg;
915  struct GNUNET_MQ_Envelope *mqm;
916  struct GNUNET_SET_RejectMessage *rmsg;
917 
919  "Processing incoming operation request with id %u\n",
920  ntohl (msg->accept_id));
921  /* we got another valid request => reset the backoff */
923  req.accept_id = ntohl (msg->accept_id);
924  req.accepted = GNUNET_NO;
925  context_msg = GNUNET_MQ_extract_nested_mh (msg);
926  /* calling #GNUNET_SET_accept() in the listen cb will set req->accepted */
927  lh->listen_cb (lh->listen_cls,
928  &msg->peer_id,
929  context_msg,
930  &req);
931  if (GNUNET_YES == req.accepted)
932  return; /* the accept-case is handled in #GNUNET_SET_accept() */
934  "Rejected request %u\n",
935  ntohl (msg->accept_id));
936  mqm = GNUNET_MQ_msg (rmsg,
938  rmsg->accept_reject_id = msg->accept_id;
939  GNUNET_MQ_send (lh->mq, mqm);
940 }
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:191
#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:209
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_NO
Definition: gnunet_common.h:78
GNUNET_SET_ListenCallback listen_cb
Function to call on a new incoming request, or on error.
Definition: set_api.c:204
#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:219
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
uint32_t accept_reject_id
ID of the incoming request we want to reject.
Definition: set.h:145
uint32_t accept_id
ID of the to identify the request when accepting or rejecting it.
Definition: set.h:163
Opaque handle to a listen operation.
Definition: set_api.c:186
struct GNUNET_PeerIdentity peer_id
Identity of the requesting peer.
Definition: set.h:168
Header for all communications.
#define GNUNET_YES
Definition: gnunet_common.h:77
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:135
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 951 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().

953 {
954  struct GNUNET_SET_ListenHandle *lh = cls;
955 
957  "Listener broke down (%d), re-connecting\n",
958  (int) error);
959  GNUNET_MQ_destroy (lh->mq);
960  lh->mq = NULL;
963  lh);
965 }
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: set_api.c:191
#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:1253
struct GNUNET_TIME_Relative reconnect_backoff
Time to wait until we try to reconnect on failure.
Definition: set_api.c:219
static void listen_connect(void *cls)
Connect to the set service in order to listen for requests.
Definition: set_api.c:974
#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:224
Here is the call graph for this function:
Here is the caller graph for this function: