GNUnet 0.21.1
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__)

Definition at line 33 of file set_api.c.

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.

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,
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;
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 mqm = GNUNET_MQ_msg (copy_msg,
636 copy_msg->cookie = *cookie;
637 }
638 GNUNET_MQ_send (set->mq,
639 mqm);
640 return set;
641}
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static int result
Global testing status.
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
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
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:304
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:78
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE
Give the client an ID for connecting to the set's copy.
#define GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT
Element result for the iterating client.
#define GNUNET_MESSAGE_TYPE_SET_RESULT
Create an empty set.
#define GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT
Sent by the client to the server to connect to an existing, lazily copied set.
#define GNUNET_MESSAGE_TYPE_SET_ITER_DONE
Iteration end marker for the client.
#define GNUNET_MESSAGE_TYPE_SET_CREATE
Create a new local set.
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 LOG(kind,...)
Definition: set_api.c:33
Message handler for a specific message type.
Header for all communications.
Client connects to a lazily copied set.
Definition: set.h:385
uint32_t cookie
Temporary name for the copied set.
Definition: set.h:394
Server responds to a lazy copy request.
Definition: set.h:368
Message sent by the client to the service to ask starting a new set to perform operations with.
Definition: set.h:41
uint32_t operation
Operation type, values of enum GNUNET_SET_OperationType
Definition: set.h:50
Opaque handle to a set.
Definition: set_api.c:50
struct GNUNET_MQ_Handle * mq
Message queue for client.
Definition: set_api.c:54
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration, needed when creating (lazy) copies.
Definition: set_api.c:98
Set element transmitted by service to client in response to a set iteration request.
Definition: set.h:325
Message sent by the service to the client to indicate an element that is removed (set intersection) o...
Definition: set.h:245

References cfg, GNUNET_SET_Handle::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_Handle::mq, op, GNUNET_SET_CreateMessage::operation, and result.

Referenced by GNUNET_SET_create(), and handle_copy_lazy().

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.

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");
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}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_SET_OPERATION_NONE
A purely local set that does not support any operation.
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
struct SetCopyRequest * copy_req_head
Doubly linked list of copy requests.
Definition: set_api.c:103
struct SetCopyRequest * copy_req_tail
Doubly linked list of copy requests.
Definition: set_api.c:108
void * cls
Definition: set_api.c:41
GNUNET_SET_CopyReadyCallback cb
Definition: set_api.c:43

References SetCopyRequest::cb, GNUNET_SET_Handle::cfg, SetCopyRequest::cls, GNUNET_SET_Handle::copy_req_head, GNUNET_SET_Handle::copy_req_tail, create_internal(), GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_SET_OPERATION_NONE, LOG, and msg.

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.

288{
289 /* minimum size was already checked, everything else is OK! */
290 return GNUNET_OK;
291}
@ GNUNET_OK

References GNUNET_OK.

◆ 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 *
msgthe message

Definition at line 302 of file set_api.c.

304{
305 struct GNUNET_SET_Handle *set = cls;
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}
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_MESSAGE_TYPE_SET_ITER_ACK
Acknowledge result from iteration.
int(* GNUNET_SET_ElementIterator)(void *cls, const struct GNUNET_SET_Element *element)
Iterator for set elements.
Element stored in a set.
uint16_t iteration_id
Both client and service count the number of iterators created so far to match replies with iterators.
Definition: set_api.c:93
GNUNET_SET_ElementIterator iterator
Callback for the current iteration over the set, NULL if no iterator is active.
Definition: set_api.c:70
void * iterator_cls
Closure for iterator.
Definition: set_api.c:75
Client acknowledges receiving element in iteration.
Definition: set.h:351
uint32_t send_more
Non-zero if the service should continue sending elements.
Definition: set.h:360

References GNUNET_SET_Element::data, GNUNET_SET_Element::element_type, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_SET_ITER_ACK, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_SET_Handle::iteration_id, GNUNET_SET_Handle::iterator, GNUNET_SET_Handle::iterator_cls, LOG, GNUNET_SET_Handle::mq, msg, GNUNET_SET_IterAckMessage::send_more, GNUNET_MessageHeader::size, and GNUNET_SET_Element::size.

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.

345{
346 struct GNUNET_SET_Handle *set = cls;
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");
360 set->iterator = NULL;
361 set->iteration_id++;
362 iter (set->iterator_cls,
363 NULL);
366 if (GNUNET_YES == set->destroy_requested)
367 GNUNET_SET_destroy (set);
368}
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_INFO
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:745
int destroy_requested
Should the set be destroyed once all operations are gone? GNUNET_SYSERR if GNUNET_SET_destroy() must ...
Definition: set_api.c:82

References GNUNET_SET_Handle::destroy_requested, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_NO, GNUNET_SET_destroy(), GNUNET_SYSERR, GNUNET_YES, GNUNET_SET_Handle::iteration_id, GNUNET_SET_Handle::iterator, GNUNET_SET_Handle::iterator_cls, and LOG.

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.

381{
382 /* minimum size was already checked, everything else is OK! */
383 return GNUNET_OK;
384}

References GNUNET_OK.

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

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
436do_final:
438 "Treating result as final status\n");
440 ntohl (msg->request_id));
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,
453 GNUNET_ntohll (msg->current_size),
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
466do_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,
475 GNUNET_ntohll (msg->current_size),
477}
#define GNUNET_log(kind,...)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:54
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:604
void * GNUNET_MQ_assoc_remove(struct GNUNET_MQ_Handle *mq, uint32_t request_id)
Remove the association for a request_id.
Definition: mq.c:622
GNUNET_SET_Status
Status for the result callback.
@ GNUNET_SET_STATUS_OK
Everything went ok, we are transmitting an element of the result (in set, or to be removed from set,...
@ GNUNET_SET_STATUS_FAILURE
The other peer refused to to the operation with us, or something went wrong.
@ GNUNET_SET_STATUS_ADD_REMOTE
Element should be added to the result set of the remote peer, i.e.
@ GNUNET_SET_STATUS_HALF_DONE
Success, all elements have been returned (but the other peer might still be receiving some from us,...
@ GNUNET_SET_STATUS_DONE
Success, all elements have been sent (and received).
@ GNUNET_SET_STATUS_ADD_LOCAL
Element should be added to the result set of the local peer, i.e.
struct GNUNET_SET_OperationHandle * ops_head
Linked list of operations on the set.
Definition: set_api.c:59
struct GNUNET_SET_OperationHandle * ops_tail
Linked list of operations on the set.
Definition: set_api.c:64
Handle to an operation.
Definition: set_api.c:136
GNUNET_SET_ResultIterator result_cb
Function to be called when we have a result, or an error.
Definition: set_api.c:141
void * result_cls
Closure for result_cb.
Definition: set_api.c:146
uint16_t result_status
Was the evaluation successful? Contains an enum GNUNET_SET_Status in NBO.
Definition: set.h:265

References GNUNET_SET_Element::data, GNUNET_SET_Handle::destroy_requested, GNUNET_SET_Element::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, LOG, GNUNET_SET_Handle::mq, msg, GNUNET_SET_Handle::ops_head, GNUNET_SET_Handle::ops_tail, GNUNET_SET_OperationHandle::result_cb, GNUNET_SET_OperationHandle::result_cls, GNUNET_SET_ResultMessage::result_status, GNUNET_MessageHeader::size, and GNUNET_SET_Element::size.

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.

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 committed? */
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}
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:285
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
uint32_t request_id
Request ID to identify the operation within the set.
Definition: set_api.c:179
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

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

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.

552{
553 struct GNUNET_SET_Handle *set = cls;
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) &&
564 NULL,
565 0,
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}
@ GNUNET_ERROR_TYPE_ERROR
static void set_operation_destroy(struct GNUNET_SET_OperationHandle *oh)
Destroy the given set operation.
Definition: set_api.c:486
int invalid
Has the set become invalid (e.g.
Definition: set_api.c:87

References GNUNET_SET_Handle::destroy_requested, GNUNET_ERROR_TYPE_ERROR, GNUNET_NO, GNUNET_SET_STATUS_FAILURE, GNUNET_YES, GNUNET_SET_Handle::invalid, GNUNET_SET_Handle::iteration_id, GNUNET_SET_Handle::iterator, GNUNET_SET_Handle::iterator_cls, LOG, GNUNET_SET_Handle::ops_head, GNUNET_SET_OperationHandle::result_cb, GNUNET_SET_OperationHandle::result_cls, and set_operation_destroy().

Referenced by create_internal().

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 933 of file set_api.c.

934{
935 struct GNUNET_SET_ListenHandle *lh = cls;
936 struct GNUNET_MQ_MessageHandler mq_handlers[] = {
940 lh),
942 };
943 struct GNUNET_MQ_Envelope *mqm;
945
946 lh->reconnect_task = NULL;
947 GNUNET_assert (NULL == lh->mq);
948 lh->mq = GNUNET_CLIENT_connect (lh->cfg,
949 "set",
950 mq_handlers,
952 lh);
953 if (NULL == lh->mq)
954 return;
956 msg->operation = htonl (lh->operation);
957 msg->app_id = lh->app_id;
958 GNUNET_MQ_send (lh->mq,
959 mqm);
960}
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:40
#define GNUNET_MESSAGE_TYPE_SET_REQUEST
Notify the client of a request from a remote peer.
#define GNUNET_MESSAGE_TYPE_SET_LISTEN
Listen for operation requests.
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:910
Opaque handle to a listen operation.
Definition: set_api.c:187
struct GNUNET_SCHEDULER_Task * reconnect_task
Task for reconnecting when the listener fails.
Definition: set_api.c:224
struct GNUNET_HashCode app_id
Application ID we listen for.
Definition: set_api.c:214
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
enum GNUNET_SET_OperationType operation
Operation we listen for.
Definition: set_api.c:229
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: set_api.c:191
Message sent by the client to the service to start listening for incoming requests to perform a certa...
Definition: set.h:60
A request for an operation with another client.
Definition: set.h:153

References GNUNET_SET_ListenHandle::app_id, GNUNET_SET_ListenHandle::cfg, 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_ListenHandle::operation, GNUNET_SET_ListenHandle::reconnect_task, and request.

Referenced by GNUNET_SET_listen(), and handle_client_listener_error().

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 843 of file set_api.c.

845{
846 const struct GNUNET_MessageHeader *context_msg;
847
848 if (ntohs (msg->header.size) == sizeof(*msg))
849 return GNUNET_OK; /* no context message is OK */
850 context_msg = GNUNET_MQ_extract_nested_mh (msg);
851 if (NULL == context_msg)
852 {
853 /* malformed context message is NOT ok */
854 GNUNET_break_op (0);
855 return GNUNET_SYSERR;
856 }
857 return GNUNET_OK;
858}
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_MQ_extract_nested_mh(var)
Return a pointer to the message at the end of the given message.

References GNUNET_break_op, GNUNET_MQ_extract_nested_mh, GNUNET_OK, GNUNET_SYSERR, msg, and GNUNET_MessageHeader::size.

◆ 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 868 of file set_api.c.

870{
871 struct GNUNET_SET_ListenHandle *lh = cls;
872 struct GNUNET_SET_Request req;
873 const struct GNUNET_MessageHeader *context_msg;
874 struct GNUNET_MQ_Envelope *mqm;
875 struct GNUNET_SET_RejectMessage *rmsg;
876
878 "Processing incoming operation request with id %u\n",
879 ntohl (msg->accept_id));
880 /* we got another valid request => reset the backoff */
882 req.accept_id = ntohl (msg->accept_id);
883 req.accepted = GNUNET_NO;
884 context_msg = GNUNET_MQ_extract_nested_mh (msg);
885 /* calling #GNUNET_SET_accept() in the listen cb will set req->accepted */
886 lh->listen_cb (lh->listen_cls,
887 &msg->peer_id,
888 context_msg,
889 &req);
890 if (GNUNET_YES == req.accepted)
891 return; /* the accept-case is handled in #GNUNET_SET_accept() */
893 "Rejected request %u\n",
894 ntohl (msg->accept_id));
895 mqm = GNUNET_MQ_msg (rmsg,
897 rmsg->accept_reject_id = msg->accept_id;
898 GNUNET_MQ_send (lh->mq, mqm);
899}
#define GNUNET_MESSAGE_TYPE_SET_REJECT
Reject a set request.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Relative reconnect_backoff
Time to wait until we try to reconnect on failure.
Definition: set_api.c:219
void * listen_cls
Closure for listen_cb.
Definition: set_api.c:209
GNUNET_SET_ListenCallback listen_cb
Function to call on a new incoming request, or on error.
Definition: set_api.c:204
Message sent by a listening client to the service to reject performing the operation with the other p...
Definition: set.h:136
uint32_t accept_reject_id
ID of the incoming request we want to reject.
Definition: set.h:145
Handle for a set operation request from another peer.
Definition: set_api.c:116

References GNUNET_SET_Request::accept_id, GNUNET_SET_RejectMessage::accept_reject_id, GNUNET_SET_Request::accepted, 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, msg, and GNUNET_SET_ListenHandle::reconnect_backoff.

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 910 of file set_api.c.

912{
913 struct GNUNET_SET_ListenHandle *lh = cls;
914
916 "Listener broke down (%d), re-connecting\n",
917 (int) error);
918 GNUNET_MQ_destroy (lh->mq);
919 lh->mq = NULL;
922 lh);
924}
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
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:1278
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static void listen_connect(void *cls)
Connect to the set service in order to listen for requests.
Definition: set_api.c:933

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

Here is the call graph for this function:
Here is the caller graph for this function: