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 577 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().

580 {
581  struct GNUNET_SET_Handle *set = GNUNET_new(struct GNUNET_SET_Handle);
582  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
586  set),
587  GNUNET_MQ_hd_var_size(iter_element,
590  set),
591  GNUNET_MQ_hd_fixed_size(iter_done,
593  struct GNUNET_MessageHeader,
594  set),
595  GNUNET_MQ_hd_fixed_size(copy_lazy,
598  set),
600  };
601  struct GNUNET_MQ_Envelope *mqm;
602  struct GNUNET_SET_CreateMessage *create_msg;
603  struct GNUNET_SET_CopyLazyConnectMessage *copy_msg;
604 
605  set->cfg = cfg;
606  set->mq = GNUNET_CLIENT_connect(cfg,
607  "set",
608  mq_handlers,
610  set);
611  if (NULL == set->mq)
612  {
613  GNUNET_free(set);
614  return NULL;
615  }
616  if (NULL == cookie)
617  {
619  "Creating new set (operation %u)\n",
620  op);
621  mqm = GNUNET_MQ_msg(create_msg,
623  create_msg->operation = htonl(op);
624  }
625  else
626  {
628  "Creating new set (lazy copy)\n",
629  op);
630  mqm = GNUNET_MQ_msg(copy_msg,
632  copy_msg->cookie = *cookie;
633  }
634  GNUNET_MQ_send(set->mq,
635  mqm);
636  return set;
637 }
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:900
#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:238
#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:315
#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:49
Message handler for a specific message type.
Client connects to a lazily copied set.
Definition: set.h:372
Opaque handle to a set.
Definition: set_api.c:48
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:381
#define GNUNET_MESSAGE_TYPE_SET_ITER_DONE
Iteration end marker for the client.
Server responds to a lazy copy request.
Definition: set.h:356
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:351
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:545
#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 243 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.

245 {
246  struct GNUNET_SET_Handle *set = cls;
247  struct SetCopyRequest *req;
248  struct GNUNET_SET_Handle *new_set;
249 
250  req = set->copy_req_head;
251  if (NULL == req)
252  {
253  /* Service sent us unsolicited lazy copy response */
254  GNUNET_break(0);
255  return;
256  }
257 
259  "Handling response to lazy copy\n");
260  GNUNET_CONTAINER_DLL_remove(set->copy_req_head,
261  set->copy_req_tail,
262  req);
263  // We pass none as operation here, since it doesn't matter when
264  // cloning.
265  new_set = create_internal(set->cfg,
267  &msg->cookie);
268  req->cb(req->cls, new_set);
269  GNUNET_free(req);
270 }
#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:40
#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:42
Opaque handle to a set.
Definition: set_api.c:48
uint32_t cookie
Temporary name for the copied set.
Definition: set.h:365
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:577
#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 281 of file set_api.c.

References GNUNET_OK.

283 {
284  /* minimum size was already checked, everything else is OK! */
285  return GNUNET_OK;
286 }
#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 297 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.

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

340 {
341  struct GNUNET_SET_Handle *set = cls;
342  GNUNET_SET_ElementIterator iter = set->iterator;
343 
344  if (NULL == iter)
345  {
346  /* FIXME: if this is true, could cancel+start a fresh one
347  cause elements to go to the wrong iteration? */
349  "Service completed set iteration that was already cancelled\n");
350  return;
351  }
353  "Set iteration completed\n");
354  set->destroy_requested = GNUNET_SYSERR;
355  set->iterator = NULL;
356  set->iteration_id++;
357  iter(set->iterator_cls,
358  NULL);
359  if (GNUNET_SYSERR == set->destroy_requested)
360  set->destroy_requested = GNUNET_NO;
361  if (GNUNET_YES == set->destroy_requested)
362  GNUNET_SET_destroy(set);
363 }
#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:767
#define LOG(kind,...)
Definition: set_api.c:33
Opaque handle to a set.
Definition: set_api.c:48
#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 374 of file set_api.c.

References GNUNET_OK.

376 {
377  /* minimum size was already checked, everything else is OK! */
378  return GNUNET_OK;
379 }
#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 389 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.

391 {
392  struct GNUNET_SET_Handle *set = cls;
394  struct GNUNET_SET_Element e;
395  enum GNUNET_SET_Status result_status;
396  int destroy_set;
397 
398  GNUNET_assert(NULL != set->mq);
399  result_status = (enum GNUNET_SET_Status)ntohs(msg->result_status);
401  "Got result message with status %d\n",
402  result_status);
403 
404  oh = GNUNET_MQ_assoc_get(set->mq,
405  ntohl(msg->request_id));
406  if (NULL == oh)
407  {
408  /* 'oh' can be NULL if we canceled the operation, but the service
409  did not get the cancel message yet. */
411  "Ignoring result from canceled operation\n");
412  return;
413  }
414 
415  switch (result_status)
416  {
420  goto do_element;
421 
424  goto do_final;
425 
427  /* not used anymore */
428  GNUNET_assert(0);
429  }
430 
431 do_final:
433  "Treating result as final status\n");
434  GNUNET_MQ_assoc_remove(set->mq,
435  ntohl(msg->request_id));
436  GNUNET_CONTAINER_DLL_remove(set->ops_head,
437  set->ops_tail,
438  oh);
439  /* Need to do this calculation _before_ the result callback,
440  as IF the application still has a valid set handle, it
441  may trigger destruction of the set during the callback. */
442  destroy_set = (GNUNET_YES == set->destroy_requested) &&
443  (NULL == set->ops_head);
444  if (NULL != oh->result_cb)
445  {
446  oh->result_cb(oh->result_cls,
447  NULL,
449  result_status);
450  }
451  else
452  {
454  "No callback for final status\n");
455  }
456  if (destroy_set)
457  GNUNET_SET_destroy(set);
458  GNUNET_free(oh);
459  return;
460 
461 do_element:
463  "Treating result as element\n");
464  e.data = &msg[1];
465  e.size = ntohs(msg->header.size) - sizeof(struct GNUNET_SET_ResultMessage);
466  e.element_type = ntohs(msg->element_type);
467  if (NULL != oh->result_cb)
468  oh->result_cb(oh->result_cls,
469  &e,
471  result_status);
472 }
#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:142
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:238
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:252
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:767
uint64_t current_size
Current set size.
Definition: set.h:247
#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:137
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:258
Opaque handle to a set.
Definition: set_api.c:48
uint16_t element_type
Type of the element attachted to the message, if any.
Definition: set.h:263
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_SET_RESULT.
Definition: set.h:242
Handle to an operation.
Definition: set_api.c:132
void * GNUNET_MQ_assoc_remove(struct GNUNET_MQ_Handle *mq, uint32_t request_id)
Remove the association for a request_id.
Definition: mq.c:750
#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:734
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 481 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().

482 {
483  struct GNUNET_SET_Handle *set = oh->set;
484  struct GNUNET_SET_OperationHandle *h_assoc;
485 
486  if (NULL != oh->conclude_mqm)
488  /* is the operation already commited? */
489  if (NULL != set)
490  {
492  set->ops_tail,
493  oh);
494  h_assoc = GNUNET_MQ_assoc_remove(set->mq,
495  oh->request_id);
496  GNUNET_assert((NULL == h_assoc) ||
497  (h_assoc == oh));
498  }
499  GNUNET_free(oh);
500 }
#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:148
#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:62
uint32_t request_id
Request ID to identify the operation within the set.
Definition: set_api.c:175
struct GNUNET_MQ_Handle * mq
Message queue for client.
Definition: set_api.c:52
Opaque handle to a set.
Definition: set_api.c:48
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:319
Handle to an operation.
Definition: set_api.c:132
struct GNUNET_SET_OperationHandle * ops_head
Linked list of operations on the set.
Definition: set_api.c:57
struct GNUNET_MQ_Envelope * conclude_mqm
Message sent to the server on calling conclude, NULL if conclude has been called. ...
Definition: set_api.c:154
void * GNUNET_MQ_assoc_remove(struct GNUNET_MQ_Handle *mq, uint32_t request_id)
Remove the association for a request_id.
Definition: mq.c:750
#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 545 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().

547 {
548  struct GNUNET_SET_Handle *set = cls;
549  GNUNET_SET_ElementIterator iter = set->iterator;
550 
552  "Handling client set error %d\n",
553  error);
554  while (NULL != set->ops_head)
555  {
556  if ((NULL != set->ops_head->result_cb) &&
557  (GNUNET_NO == set->destroy_requested))
558  set->ops_head->result_cb(set->ops_head->result_cls,
559  NULL,
560  0,
562  set_operation_destroy(set->ops_head);
563  }
564  set->iterator = NULL;
565  set->iteration_id++;
566  set->invalid = GNUNET_YES;
567  if (NULL != iter)
568  iter(set->iterator_cls,
569  NULL);
570 }
#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:48
static void set_operation_destroy(struct GNUNET_SET_OperationHandle *oh)
Destroy the given set operation.
Definition: set_api.c:481
#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 969 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().

970 {
971  struct GNUNET_SET_ListenHandle *lh = cls;
972  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
976  lh),
978  };
979  struct GNUNET_MQ_Envelope *mqm;
981 
982  lh->reconnect_task = NULL;
983  GNUNET_assert(NULL == lh->mq);
984  lh->mq = GNUNET_CLIENT_connect(lh->cfg,
985  "set",
986  mq_handlers,
988  lh);
989  if (NULL == lh->mq)
990  return;
992  msg->operation = htonl(lh->operation);
993  msg->app_id = lh->app_id;
994  GNUNET_MQ_send(lh->mq,
995  mqm);
996 }
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:900
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: set_api.c:186
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
A request for an operation with another client.
Definition: set.h:148
#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:67
#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:58
#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:209
struct GNUNET_HashCode app_id
application id
Definition: set.h:72
enum GNUNET_SET_OperationType operation
Operation we listen for.
Definition: set_api.c:224
#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:182
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:351
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:946
#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:219
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:193
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 879 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.

881 {
882  const struct GNUNET_MessageHeader *context_msg;
883 
884  if (ntohs(msg->header.size) == sizeof(*msg))
885  return GNUNET_OK; /* no context message is OK */
886  context_msg = GNUNET_MQ_extract_nested_mh(msg);
887  if (NULL == context_msg)
888  {
889  /* malformed context message is NOT ok */
890  GNUNET_break_op(0);
891  return GNUNET_SYSERR;
892  }
893  return GNUNET_OK;
894 }
#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:152
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 904 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.

906 {
907  struct GNUNET_SET_ListenHandle *lh = cls;
908  struct GNUNET_SET_Request req;
909  const struct GNUNET_MessageHeader *context_msg;
910  struct GNUNET_MQ_Envelope *mqm;
911  struct GNUNET_SET_RejectMessage *rmsg;
912 
914  "Processing incoming operation request with id %u\n",
915  ntohl(msg->accept_id));
916  /* we got another valid request => reset the backoff */
918  req.accept_id = ntohl(msg->accept_id);
919  req.accepted = GNUNET_NO;
920  context_msg = GNUNET_MQ_extract_nested_mh(msg);
921  /* calling #GNUNET_SET_accept() in the listen cb will set req->accepted */
922  lh->listen_cb(lh->listen_cls,
923  &msg->peer_id,
924  context_msg,
925  &req);
926  if (GNUNET_YES == req.accepted)
927  return; /* the accept-case is handled in #GNUNET_SET_accept() */
929  "Rejected request %u\n",
930  ntohl(msg->accept_id));
931  mqm = GNUNET_MQ_msg(rmsg,
933  rmsg->accept_reject_id = msg->accept_id;
934  GNUNET_MQ_send(lh->mq, mqm);
935 }
Handle for a set operation request from another peer.
Definition: set_api.c:113
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: set_api.c:186
#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:204
#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:199
#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:214
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
uint32_t accept_reject_id
ID of the incoming request we want to reject.
Definition: set.h:141
uint32_t accept_id
ID of the to identify the request when accepting or rejecting it.
Definition: set.h:158
Opaque handle to a listen operation.
Definition: set_api.c:182
struct GNUNET_PeerIdentity peer_id
Identity of the requesting peer.
Definition: set.h:163
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:351
Message sent by a listening client to the service to reject performing the operation with the other p...
Definition: set.h:132
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 946 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().

948 {
949  struct GNUNET_SET_ListenHandle *lh = cls;
950 
952  "Listener broke down (%d), re-connecting\n",
953  (int)error);
954  GNUNET_MQ_destroy(lh->mq);
955  lh->mq = NULL;
958  lh);
960 }
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: set_api.c:186
#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:1237
struct GNUNET_TIME_Relative reconnect_backoff
Time to wait until we try to reconnect on failure.
Definition: set_api.c:214
static void listen_connect(void *cls)
Connect to the set service in order to listen for requests.
Definition: set_api.c:969
#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:182
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:821
struct GNUNET_SCHEDULER_Task * reconnect_task
Task for reconnecting when the listener fails.
Definition: set_api.c:219
Here is the call graph for this function:
Here is the caller graph for this function: