GNUnet  0.10.x
Data Structures | Macros | Typedefs | Enumerations | Functions
Set service

Two-peer set operations. More...

Data Structures

struct  GNUNET_SET_Element
 Element stored in a set. More...
 
struct  GNUNET_SET_Option
 Option for set operations. More...
 

Macros

#define GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE   ((1 << 16) - 1024)
 Maximum size of a context message for set operation requests. More...
 

Typedefs

typedef void(* GNUNET_SET_Continuation) (void *cls)
 Continuation used for some of the set operations. More...
 
typedef void(* GNUNET_SET_ResultIterator) (void *cls, const struct GNUNET_SET_Element *element, uint64_t current_size, enum GNUNET_SET_Status status)
 Callback for set operation results. More...
 
typedef int(* GNUNET_SET_ElementIterator) (void *cls, const struct GNUNET_SET_Element *element)
 Iterator for set elements. More...
 
typedef void(* GNUNET_SET_ListenCallback) (void *cls, const struct GNUNET_PeerIdentity *other_peer, const struct GNUNET_MessageHeader *context_msg, struct GNUNET_SET_Request *request)
 Called when another peer wants to do a set operation with the local peer. More...
 
typedef void(* GNUNET_SET_CopyReadyCallback) (void *cls, struct GNUNET_SET_Handle *copy)
 

Enumerations

enum  GNUNET_SET_OperationType { GNUNET_SET_OPERATION_NONE, GNUNET_SET_OPERATION_INTERSECTION, GNUNET_SET_OPERATION_UNION }
 The operation that a set set supports. More...
 
enum  GNUNET_SET_Status {
  GNUNET_SET_STATUS_OK, GNUNET_SET_STATUS_ADD_LOCAL, GNUNET_SET_STATUS_ADD_REMOTE, GNUNET_SET_STATUS_FAILURE,
  GNUNET_SET_STATUS_HALF_DONE, GNUNET_SET_STATUS_DONE
}
 Status for the result callback. More...
 
enum  GNUNET_SET_ResultMode { GNUNET_SET_RESULT_FULL, GNUNET_SET_RESULT_SYMMETRIC, GNUNET_SET_RESULT_REMOVED, GNUNET_SET_RESULT_ADDED }
 The way results are given to the client. More...
 
enum  GNUNET_SET_OptionType { GNUNET_SET_OPTION_END =0, GNUNET_SET_OPTION_BYZANTINE =1, GNUNET_SET_OPTION_FORCE_FULL =2, GNUNET_SET_OPTION_FORCE_DELTA =4 }
 Possible options to pass to a set operation. More...
 

Functions

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_copy_lazy (struct GNUNET_SET_Handle *set, GNUNET_SET_CopyReadyCallback cb, void *cls)
 
void GNUNET_SET_destroy (struct GNUNET_SET_Handle *set)
 Destroy the set handle, and free all associated resources. 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...
 
struct GNUNET_SET_ListenHandleGNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_SET_OperationType op_type, 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...
 
void GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh)
 Cancel the given 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_iterate_cancel (struct GNUNET_SET_Handle *set)
 Stop iteration over all elements in the given set. More...
 
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

Two-peer set operations.

See also
Documentation

Macro Definition Documentation

◆ GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE

#define GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE   ((1 << 16) - 1024)

Maximum size of a context message for set operation requests.

Definition at line 55 of file gnunet_set_service.h.

Referenced by check_incoming_msg().

Typedef Documentation

◆ GNUNET_SET_Continuation

typedef void(* GNUNET_SET_Continuation) (void *cls)

Continuation used for some of the set operations.

Parameters
clsclosure

Definition at line 267 of file gnunet_set_service.h.

◆ GNUNET_SET_ResultIterator

typedef void(* GNUNET_SET_ResultIterator) (void *cls, const struct GNUNET_SET_Element *element, uint64_t current_size, enum GNUNET_SET_Status status)

Callback for set operation results.

Called for each element in the result set.

Parameters
clsclosure
elementa result element, only valid if status is GNUNET_SET_STATUS_OK
current_sizecurrent set size
statussee enum GNUNET_SET_Status

Definition at line 280 of file gnunet_set_service.h.

◆ GNUNET_SET_ElementIterator

typedef int(* GNUNET_SET_ElementIterator) (void *cls, const struct GNUNET_SET_Element *element)

Iterator for set elements.

Parameters
clsclosure
elementthe current element, NULL if all elements have been iterated over
Returns
GNUNET_YES to continue iterating, GNUNET_NO to stop.

Definition at line 294 of file gnunet_set_service.h.

◆ GNUNET_SET_ListenCallback

typedef void(* GNUNET_SET_ListenCallback) (void *cls, const struct GNUNET_PeerIdentity *other_peer, const struct GNUNET_MessageHeader *context_msg, struct GNUNET_SET_Request *request)

Called when another peer wants to do a set operation with the local peer.

If a listen error occurs, the request is NULL.

Parameters
clsclosure
other_peerthe other peer
context_msgmessage with application specific information from the other peer
requestrequest from the other peer (never NULL), use GNUNET_SET_accept() to accept it, otherwise the request will be refused Note that we can't just return value from the listen callback, as it is also necessary to specify the set we want to do the operation with, whith sometimes can be derived from the context message. It's necessary to specify the timeout.

Definition at line 314 of file gnunet_set_service.h.

◆ GNUNET_SET_CopyReadyCallback

typedef void(* GNUNET_SET_CopyReadyCallback) (void *cls, struct GNUNET_SET_Handle *copy)

Definition at line 322 of file gnunet_set_service.h.

Enumeration Type Documentation

◆ GNUNET_SET_OperationType

The operation that a set set supports.

Enumerator
GNUNET_SET_OPERATION_NONE 

A purely local set that does not support any operation.

GNUNET_SET_OPERATION_INTERSECTION 

Set intersection, only return elements that are in both sets.

GNUNET_SET_OPERATION_UNION 

Set union, return all elements that are in at least one of the sets.

Definition at line 82 of file gnunet_set_service.h.

82  {
87 
92 
97 };
A purely local set that does not support any operation.
Set intersection, only return elements that are in both sets.
Set union, return all elements that are in at least one of the sets.

◆ GNUNET_SET_Status

Status for the result callback.

Enumerator
GNUNET_SET_STATUS_OK 

Everything went ok, we are transmitting an element of the result (in set, or to be removed from set, depending on the enum GNUNET_SET_ResultMode).

Only applies to GNUNET_SET_RESULT_FULL, GNUNET_SET_RESULT_ADDED, GNUNET_SET_RESULT_REMOVED,

GNUNET_SET_STATUS_ADD_LOCAL 

Element should be added to the result set of the local peer, i.e.

the local peer is missing an element.

Only applies to GNUNET_SET_RESULT_SYMMETRIC

GNUNET_SET_STATUS_ADD_REMOTE 

Element should be added to the result set of the remote peer, i.e.

the remote peer is missing an element.

Only applies to GNUNET_SET_RESULT_SYMMETRIC

GNUNET_SET_STATUS_FAILURE 

The other peer refused to to the operation with us, or something went wrong.

GNUNET_SET_STATUS_HALF_DONE 

Success, all elements have been returned (but the other peer might still be receiving some from us, so we are not done).

Only used during UNION operation.

GNUNET_SET_STATUS_DONE 

Success, all elements have been sent (and received).

Definition at line 103 of file gnunet_set_service.h.

103  {
115 
124 
133 
139 
146 
151 };
Element should be added to the result set of the remote peer, i.e.
Element should be added to the result set of the local peer, i.e.
Success, all elements have been sent (and received).
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...
Everything went ok, we are transmitting an element of the result (in set, or to be removed from set...

◆ GNUNET_SET_ResultMode

The way results are given to the client.

Enumerator
GNUNET_SET_RESULT_FULL 

Client gets every element in the resulting set.

Only supported for set intersection.

GNUNET_SET_RESULT_SYMMETRIC 

Client gets notified of the required changes for both the local and the remote set.

Only supported for set

GNUNET_SET_RESULT_REMOVED 

Client gets only elements that have been removed from the set.

Only supported for set intersection.

GNUNET_SET_RESULT_ADDED 

Client gets only elements that have been added to the set.

Only supported for set union.

Definition at line 158 of file gnunet_set_service.h.

158  {
165 
173 
180 
187 };
Client gets only elements that have been added to the set.
Client gets every element in the resulting set.
Client gets notified of the required changes for both the local and the remote set.
Client gets only elements that have been removed from the set.

◆ GNUNET_SET_OptionType

Possible options to pass to a set operation.

Used as tag for struct GNUNET_SET_Option.

Enumerator
GNUNET_SET_OPTION_END 

List terminator.

GNUNET_SET_OPTION_BYZANTINE 

Fail set operations when the other peer shows weird behavior that might by a Byzantine fault.

For set union, 'v.num' is a lower bound on elements that the other peer must have in common with us.

GNUNET_SET_OPTION_FORCE_FULL 

Do not use the optimized set operation, but send full sets.

Might trigger Byzantine fault detection.

GNUNET_SET_OPTION_FORCE_DELTA 

Only use optimized set operations, even though for this particular set operation they might be much slower.

Might trigger Byzantine fault detection.

Definition at line 216 of file gnunet_set_service.h.

216  {
240 };
Do not use the optimized set operation, but send full sets.
Only use optimized set operations, even though for this particular set operation they might be much s...
Fail set operations when the other peer shows weird behavior that might by a Byzantine fault...

Function Documentation

◆ GNUNET_SET_create()

struct GNUNET_SET_Handle* GNUNET_SET_create ( const struct GNUNET_CONFIGURATION_Handle cfg,
enum GNUNET_SET_OperationType  op 
)

Create an empty set, supporting the specified operation.

Parameters
cfgconfiguration to use for connecting to the set service
opoperation supported by the set Note that the operation has to be specified beforehand, as certain set operations need to maintain data structures spefific to the operation
Returns
a handle to the set

Definition at line 652 of file set_api.c.

References create_internal(), GNUNET_ERROR_TYPE_DEBUG, and LOG.

Referenced by commit_set(), handle_alice_client_message(), handle_bob_client_message(), handle_client_join(), and run().

654 {
655  struct GNUNET_SET_Handle *set;
656 
657  set = create_internal(cfg,
658  op,
659  NULL);
661  "Creating set %p for operation %d\n",
662  set,
663  op);
664  return set;
665 }
#define LOG(kind,...)
Definition: set_api.c:33
Opaque handle to a set.
Definition: set_api.c:48
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
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SET_add_element()

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.

After the element has been added (in the sense of being transmitted to the set service), cont will be called. Calls to GNUNET_SET_add_element can be queued

Parameters
setset to add element to
elementelement to add to the set
contcontinuation called after the element has been added
cont_clsclosure for cont
Returns
GNUNET_OK on success, GNUNET_SYSERR if the set is invalid (e.g. the set service crashed)

After the element has been added (in the sense of being transmitted to the set service), cont will be called. Multiple calls to GNUNET_SET_add_element() can be queued.

Parameters
setset to add element to
elementelement to add to the set
contcontinuation called after the element has been added
cont_clsclosure for cont
Returns
GNUNET_OK on success, GNUNET_SYSERR if the set is invalid (e.g. the set service crashed)

Definition at line 682 of file set_api.c.

References GNUNET_SET_Element::data, GNUNET_SET_Element::element_type, GNUNET_SET_ElementMessage::element_type, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_SET_ADD, GNUNET_MQ_msg_extra, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, LOG, msg, and GNUNET_SET_Element::size.

Referenced by commit_set(), handle_alice_client_message(), handle_alice_client_message_multipart(), handle_bob_client_message(), handle_bob_client_message_multipart(), handle_client_insert(), publicize_rm(), set_insert_iterator(), set_result_cb(), task_start_apply_round(), and task_start_eval_echo().

686 {
687  struct GNUNET_MQ_Envelope *mqm;
689 
691  "adding element of type %u to set %p\n",
692  (unsigned int)element->element_type,
693  set);
694  GNUNET_assert(NULL != set);
695  if (GNUNET_YES == set->invalid)
696  {
697  if (NULL != cont)
698  cont(cont_cls);
699  return GNUNET_SYSERR;
700  }
701  mqm = GNUNET_MQ_msg_extra(msg,
702  element->size,
704  msg->element_type = htons(element->element_type);
705  GNUNET_memcpy(&msg[1],
706  element->data,
707  element->size);
709  cont, cont_cls);
710  GNUNET_MQ_send(set->mq, mqm);
711  return GNUNET_OK;
712 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_MESSAGE_TYPE_SET_ADD
Add element to set.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t element_type
Type of the element to add or remove.
Definition: set.h:283
const void * data
Actual data of the element.
#define LOG(kind,...)
Definition: set_api.c:33
struct GNUNET_MQ_Handle * mq
Message queue for client.
Definition: set_api.c:52
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
int invalid
Has the set become invalid (e.g.
Definition: set_api.c:85
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:772
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
uint16_t size
Number of bytes in the buffer pointed to by data.
Message sent by client to the service to add or remove an element to/from the set.
Definition: set.h:273
#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
uint16_t element_type
Application-specific element type.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SET_remove_element()

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.

After the element has been removed (in the sense of the request being transmitted to the set service), cont will be called. Calls to remove_element can be queued

Parameters
setset to remove element from
elementelement to remove from the set
contcontinuation called after the element has been removed
cont_clsclosure for cont
Returns
GNUNET_OK on success, GNUNET_SYSERR if the set is invalid (e.g. the set service crashed)

After the element has been removed (in the sense of the request being transmitted to the set service), cont will be called. Multiple calls to GNUNET_SET_remove_element() can be queued

Parameters
setset to remove element from
elementelement to remove from the set
contcontinuation called after the element has been removed
cont_clsclosure for cont
Returns
GNUNET_OK on success, GNUNET_SYSERR if the set is invalid (e.g. the set service crashed)

Definition at line 729 of file set_api.c.

References GNUNET_SET_Element::data, GNUNET_SET_Element::element_type, GNUNET_SET_ElementMessage::element_type, GNUNET_ERROR_TYPE_DEBUG, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_SET_REMOVE, GNUNET_MQ_msg_extra, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, LOG, msg, and GNUNET_SET_Element::size.

Referenced by set_result_cb(), task_start_apply_round(), and task_start_eval_echo().

733 {
734  struct GNUNET_MQ_Envelope *mqm;
736 
738  "Removing element from set %p\n",
739  set);
740  if (GNUNET_YES == set->invalid)
741  {
742  if (NULL != cont)
743  cont(cont_cls);
744  return GNUNET_SYSERR;
745  }
746  mqm = GNUNET_MQ_msg_extra(msg,
747  element->size,
749  msg->element_type = htons(element->element_type);
750  GNUNET_memcpy(&msg[1],
751  element->data,
752  element->size);
754  cont, cont_cls);
755  GNUNET_MQ_send(set->mq, mqm);
756  return GNUNET_OK;
757 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t element_type
Type of the element to add or remove.
Definition: set.h:283
const void * data
Actual data of the element.
#define LOG(kind,...)
Definition: set_api.c:33
struct GNUNET_MQ_Handle * mq
Message queue for client.
Definition: set_api.c:52
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
int invalid
Has the set become invalid (e.g.
Definition: set_api.c:85
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:772
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_MESSAGE_TYPE_SET_REMOVE
Remove element from set.
uint16_t size
Number of bytes in the buffer pointed to by data.
Message sent by client to the service to add or remove an element to/from the set.
Definition: set.h:273
#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
uint16_t element_type
Application-specific element type.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SET_copy_lazy()

void GNUNET_SET_copy_lazy ( struct GNUNET_SET_Handle set,
GNUNET_SET_CopyReadyCallback  cb,
void *  cls 
)

Definition at line 1189 of file set_api.c.

References SetCopyRequest::cb, SetCopyRequest::cls, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE, GNUNET_MQ_msg_header, GNUNET_MQ_send(), GNUNET_new, and LOG.

Referenced by create_set_copy_for_task().

1192 {
1193  struct GNUNET_MQ_Envelope *ev;
1194  struct SetCopyRequest *req;
1195 
1197  "Creating lazy copy of set\n");
1199  GNUNET_MQ_send(set->mq, ev);
1200 
1201  req = GNUNET_new(struct SetCopyRequest);
1202  req->cb = cb;
1203  req->cls = cls;
1205  set->copy_req_tail,
1206  req);
1207 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE
Ask the set service to prepare a copy of a set.
struct SetCopyRequest * copy_req_head
Doubly linked list of copy requests.
Definition: set_api.c:101
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void * cls
Definition: set_api.c:40
#define LOG(kind,...)
Definition: set_api.c:33
struct GNUNET_MQ_Handle * mq
Message queue for client.
Definition: set_api.c:52
GNUNET_SET_CopyReadyCallback cb
Definition: set_api.c:42
struct SetCopyRequest * copy_req_tail
Doubly linked list of copy requests.
Definition: set_api.c:106
#define GNUNET_MQ_msg_header(type)
Allocate a GNUNET_MQ_Envelope, where the message only consists of a header.
Definition: gnunet_mq_lib.h:76
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SET_destroy()

void GNUNET_SET_destroy ( struct GNUNET_SET_Handle set)

Destroy the set handle, and free all associated resources.

Iterations must have completed (or be explicitly canceled) before destroying the corresponding set. Operations may still be pending when a set is destroyed.

Parameters
setset to destroy

Destroy the set handle, and free all associated resources.

Parameters
setset handle to destroy

Definition at line 767 of file set_api.c.

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SYSERR, GNUNET_YES, and LOG.

Referenced by cb_intersection_element_removed(), client_disconnect_cb(), commit_set(), destroy_service_session(), GNUNET_SET_operation_cancel(), handle_iter_done(), handle_result(), handle_shutdown(), run(), and shutdown_task().

768 {
769  /* destroying set while iterator is active is currently
770  not supported; we should expand the API to allow
771  clients to explicitly cancel the iteration! */
772  GNUNET_assert(NULL != set);
773  if ((NULL != set->ops_head) ||
774  (NULL != set->iterator) ||
776  {
778  "Set operations are pending, delaying set destruction\n");
779  set->destroy_requested = GNUNET_YES;
780  return;
781  }
783  "Really destroying set\n");
784  if (NULL != set->mq)
785  {
786  GNUNET_MQ_destroy(set->mq);
787  set->mq = NULL;
788  }
789  GNUNET_free(set);
790 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define LOG(kind,...)
Definition: set_api.c:33
struct GNUNET_MQ_Handle * mq
Message queue for client.
Definition: set_api.c:52
int destroy_requested
Should the set be destroyed once all operations are gone? GNUNET_SYSERR if GNUNET_SET_destroy() must ...
Definition: set_api.c:80
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
GNUNET_SET_ElementIterator iterator
Callback for the current iteration over the set, NULL if no iterator is active.
Definition: set_api.c:68
struct GNUNET_SET_OperationHandle * ops_head
Linked list of operations on the set.
Definition: set_api.c:57
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:821
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SET_prepare()

struct GNUNET_SET_OperationHandle* GNUNET_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.

The evaluation will not start until the client provides a local set with GNUNET_SET_commit().

Parameters
other_peerpeer with the other set
app_idhash for the application using the set
context_msgadditional information for the request
result_modespecified how results will be returned, see enum GNUNET_SET_ResultMode.
result_cbcalled on error or success
result_clsclosure for result_cb
Returns
a handle to cancel the operation

The evaluation will not start until the client provides a local set with GNUNET_SET_commit().

Parameters
other_peerpeer with the other set
app_idhash for the application using the set
context_msgadditional information for the request
result_modespecified how results will be returned, see enum GNUNET_SET_ResultMode.
result_cbcalled on error or success
result_clsclosure for result_cb
Returns
a handle to cancel the operation

Definition at line 808 of file set_api.c.

References app_id, GNUNET_SET_EvaluateMessage::app_id, GNUNET_SET_EvaluateMessage::byzantine, GNUNET_SET_EvaluateMessage::byzantine_lower_bound, SetCopyRequest::cls, GNUNET_SET_OperationHandle::conclude_mqm, GNUNET_SET_EvaluateMessage::force_delta, GNUNET_SET_EvaluateMessage::force_full, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_MESSAGE_TYPE_SET_EVALUATE, GNUNET_MQ_msg_nested_mh, GNUNET_new, GNUNET_SET_OPTION_BYZANTINE, GNUNET_SET_OPTION_FORCE_DELTA, GNUNET_SET_OPTION_FORCE_FULL, GNUNET_YES, listen_connect(), LOG, msg, GNUNET_SET_Option::num, oh, GNUNET_SET_EvaluateMessage::request_id, GNUNET_SET_OperationHandle::request_id_addr, GNUNET_SET_OperationHandle::result_cb, GNUNET_SET_OperationHandle::result_cls, GNUNET_SET_EvaluateMessage::result_mode, GNUNET_SET_EvaluateMessage::target_peer, GNUNET_SET_Option::type, and GNUNET_SET_Option::v.

Referenced by run(), start_intersection(), task_start_reconcile(), and transmit_task_cb().

815 {
816  struct GNUNET_MQ_Envelope *mqm;
819  struct GNUNET_SET_Option *opt;
820 
822  "Client prepares set operation (%d)\n",
823  result_mode);
825  oh->result_cb = result_cb;
826  oh->result_cls = result_cls;
827  mqm = GNUNET_MQ_msg_nested_mh(msg,
829  context_msg);
830  msg->app_id = *app_id;
831  msg->result_mode = htonl(result_mode);
832  msg->target_peer = *other_peer;
833  for (opt = options; opt->type != 0; opt++)
834  {
835  switch (opt->type)
836  {
838  msg->byzantine = GNUNET_YES;
839  msg->byzantine_lower_bound = opt->v.num;
840  break;
841 
843  msg->force_full = GNUNET_YES;
844  break;
845 
847  msg->force_delta = GNUNET_YES;
848  break;
849 
850  default:
852  "Option with type %d not recognized\n", (int)opt->type);
853  }
854  }
855  oh->conclude_mqm = mqm;
856  oh->request_id_addr = &msg->request_id;
857 
858  return oh;
859 }
struct GNUNET_PeerIdentity target_peer
Peer to evaluate the operation with.
Definition: set.h:190
void * result_cls
Closure for result_cb.
Definition: set_api.c:142
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_MQ_msg_nested_mh(mvar, type, mh)
Allocate a GNUNET_MQ_Envelope, and append a payload message after the given message struct...
Do not use the optimized set operation, but send full sets.
#define GNUNET_MESSAGE_TYPE_SET_EVALUATE
Evaluate a set operation.
static struct GNUNET_HashCode app_id
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint32_t result_mode
How should results be sent to us? See enum GNUNET_SET_ResultMode.
Definition: set.h:185
uint8_t force_full
Always send full sets, even if delta operations would be more efficient.
Definition: set.h:213
enum GNUNET_SET_OptionType type
Type of the option.
#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
Only use optimized set operations, even though for this particular set operation they might be much s...
static struct GNUNET_TRANSPORT_OfferHelloHandle * oh
Active HELLO offering to transport service.
uint8_t force_delta
Always use delta operation instead of sending full sets, even it it&#39;s less efficient.
Definition: set.h:207
uint32_t request_id
Id of our set to evaluate, chosen implicitly by the client when it calls GNUNET_SET_commit().
Definition: set.h:201
uint32_t * request_id_addr
Address of the request if in the conclude message, used to patch the request id into the message when...
Definition: set_api.c:160
uint8_t byzantine
GNUNET_YES to fail operations where Byzantine faults are suspected
Definition: set.h:219
uint8_t byzantine_lower_bound
Lower bound for the set size, used only when byzantine mode is enabled.
Definition: set.h:225
Message sent by client to service to initiate a set operation as a client (not as listener)...
Definition: set.h:175
Option for set operations.
Handle to an operation.
Definition: set_api.c:132
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
struct GNUNET_HashCode app_id
Application id.
Definition: set.h:195
#define GNUNET_YES
Definition: gnunet_common.h:77
Fail set operations when the other peer shows weird behavior that might by a Byzantine fault...
union GNUNET_SET_Option::@57 v
Value for the option, only used with some options.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SET_listen()

struct GNUNET_SET_ListenHandle* GNUNET_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.

If the connection to the set service is lost, the listener is re-created transparently with exponential backoff.

Parameters
cfgconfiguration to use for connecting to the set service
operationoperation we want to listen for
app_idid of the application that handles set operation requests
listen_cbcalled for each incoming request matching the operation and application id
listen_clshandle for listen_cb
Returns
a handle that can be used to cancel the listen operation

Wait for set operation requests for the given application ID.

Parameters
cfgconfiguration to use for connecting to the set service, needs to be valid for the lifetime of the listen handle
operationoperation we want to listen for
app_idid of the application that handles set operation requests
listen_cbcalled for each incoming request matching the operation and application id
listen_clshandle for listen_cb
Returns
a handle that can be used to cancel the listen operation

Definition at line 1012 of file set_api.c.

References app_id, GNUNET_SET_ListenHandle::app_id, cfg, GNUNET_SET_ListenHandle::cfg, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_new, GNUNET_TIME_UNIT_MILLISECONDS, GNUNET_SET_ListenHandle::listen_cb, listen_cb(), GNUNET_SET_ListenHandle::listen_cls, listen_connect(), LOG, GNUNET_SET_ListenHandle::mq, GNUNET_SET_ListenHandle::operation, and GNUNET_SET_ListenHandle::reconnect_backoff.

Referenced by client_request_complete_alice(), handle_client_join(), and run().

1017 {
1018  struct GNUNET_SET_ListenHandle *lh;
1019 
1021  "Starting listener for app %s\n",
1022  GNUNET_h2s(app_id));
1023  lh = GNUNET_new(struct GNUNET_SET_ListenHandle);
1024  lh->listen_cb = listen_cb;
1025  lh->listen_cls = listen_cls;
1026  lh->cfg = cfg;
1027  lh->operation = operation;
1028  lh->app_id = *app_id;
1030  listen_connect(lh);
1031  if (NULL == lh->mq)
1032  {
1033  GNUNET_free(lh);
1034  return NULL;
1035  }
1036  return lh;
1037 }
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: set_api.c:186
void * listen_cls
Closure for listen_cb.
Definition: set_api.c:204
GNUNET_SET_ListenCallback listen_cb
Function to call on a new incoming request, or on error.
Definition: set_api.c:199
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
static struct GNUNET_HashCode app_id
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#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
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_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_HashCode app_id
Application ID we listen for.
Definition: set_api.c:209
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
enum GNUNET_SET_OperationType operation
Operation we listen for.
Definition: set_api.c:224
Opaque handle to a listen operation.
Definition: set_api.c:182
#define GNUNET_free(ptr)
Wrapper around free.
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:

◆ GNUNET_SET_listen_cancel()

void GNUNET_SET_listen_cancel ( struct GNUNET_SET_ListenHandle lh)

Cancel the given listen operation.

After calling cancel, the listen callback for this listen handle will not be called again. Note that cancelling a listen operation will automatically reject all operations that have not yet been accepted.

Parameters
lhhandle for the listen operation
lhhandle for the listen operation

Definition at line 1046 of file set_api.c.

References GNUNET_SET_ListenHandle::app_id, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), LOG, GNUNET_SET_ListenHandle::mq, and GNUNET_SET_ListenHandle::reconnect_task.

Referenced by cb_intersection_element_removed(), client_disconnect_cb(), destroy_service_session(), handle_shutdown(), and shutdown_task().

1047 {
1049  "Canceling listener %s\n",
1050  GNUNET_h2s(&lh->app_id));
1051  if (NULL != lh->mq)
1052  {
1053  GNUNET_MQ_destroy(lh->mq);
1054  lh->mq = NULL;
1055  }
1056  if (NULL != lh->reconnect_task)
1057  {
1059  lh->reconnect_task = NULL;
1060  }
1061  GNUNET_free(lh);
1062 }
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: set_api.c:186
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define LOG(kind,...)
Definition: set_api.c:33
struct GNUNET_HashCode app_id
Application ID we listen for.
Definition: set_api.c:209
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
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SET_accept()

struct GNUNET_SET_OperationHandle* GNUNET_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().

Must be called during GNUNET_SET_listen(), as the struct GNUNET_SET_Request becomes invalid afterwards. Call GNUNET_SET_commit() to provide the local set to use for the operation, and to begin the exchange with the remote peer.

Parameters
requestrequest to accept
result_modespecified how results will be returned, see enum GNUNET_SET_ResultMode.
result_cbcallback for the results
result_clsclosure for result_cb
Returns
a handle to cancel the operation

Accept a request we got via GNUNET_SET_listen().

Must be called during GNUNET_SET_listen, as the 'struct GNUNET_SET_Request' becomes invalid afterwards. Call GNUNET_SET_commit to provide the local set to use for the operation, and to begin the exchange with the remote peer.

Parameters
requestrequest to accept
result_modespecified how results will be returned, see enum GNUNET_SET_ResultMode.
result_cbcallback for the results
result_clsclosure for result_cb
Returns
a handle to cancel the operation

Definition at line 1080 of file set_api.c.

References GNUNET_SET_Request::accept_id, GNUNET_SET_AcceptMessage::accept_reject_id, GNUNET_SET_Request::accepted, GNUNET_SET_OperationHandle::conclude_mqm, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_SET_ACCEPT, GNUNET_MQ_msg, GNUNET_new, GNUNET_NO, GNUNET_YES, LOG, msg, oh, GNUNET_SET_AcceptMessage::request_id, GNUNET_SET_OperationHandle::request_id_addr, GNUNET_SET_OperationHandle::result_cb, GNUNET_SET_OperationHandle::result_cls, and GNUNET_SET_AcceptMessage::result_mode.

Referenced by cb_intersection_request_alice(), handle_revocation_union_request(), and set_listen_cb().

1085 {
1086  struct GNUNET_MQ_Envelope *mqm;
1088  struct GNUNET_SET_AcceptMessage *msg;
1089 
1090  GNUNET_assert(GNUNET_NO == request->accepted);
1092  "Client accepts set operation (%d) with id %u\n",
1093  result_mode,
1094  request->accept_id);
1095  request->accepted = GNUNET_YES;
1096  mqm = GNUNET_MQ_msg(msg,
1098  msg->accept_reject_id = htonl(request->accept_id);
1099  msg->result_mode = htonl(result_mode);
1101  oh->result_cb = result_cb;
1102  oh->result_cls = result_cls;
1103  oh->conclude_mqm = mqm;
1104  oh->request_id_addr = &msg->request_id;
1105  return oh;
1106 }
void * result_cls
Closure for result_cb.
Definition: set_api.c:142
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
uint32_t request_id
Request ID to identify responses.
Definition: set.h:94
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MESSAGE_TYPE_SET_ACCEPT
Accept a set request.
#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
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define LOG(kind,...)
Definition: set_api.c:33
int accepted
Has the request been accepted already? GNUNET_YES/GNUNET_NO.
Definition: set_api.c:124
GNUNET_SET_ResultIterator result_cb
Function to be called when we have a result, or an error.
Definition: set_api.c:137
static struct GNUNET_TRANSPORT_OfferHelloHandle * oh
Active HELLO offering to transport service.
uint32_t * request_id_addr
Address of the request if in the conclude message, used to patch the request id into the message when...
Definition: set_api.c:160
uint32_t accept_id
Id of the request, used to identify the request when accepting/rejecting it.
Definition: set_api.c:118
uint32_t result_mode
How should results be sent to us? See enum GNUNET_SET_ResultMode.
Definition: set.h:100
uint32_t accept_reject_id
ID of the incoming request we want to accept.
Definition: set.h:89
Handle to an operation.
Definition: set_api.c:132
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
#define GNUNET_YES
Definition: gnunet_common.h:77
Message sent by a listening client to the service to accept performing the operation with the other p...
Definition: set.h:80
Here is the caller graph for this function:

◆ GNUNET_SET_commit()

int GNUNET_SET_commit ( struct GNUNET_SET_OperationHandle oh,
struct GNUNET_SET_Handle set 
)

Commit a set to be used with a set operation.

This function is called once we have fully constructed the set that we want to use for the operation. At this time, the P2P protocol can then begin to exchange the set information and call the result callback with the result information.

Parameters
ohhandle to the set operation
setthe set to use for the operation
Returns
GNUNET_OK on success, GNUNET_SYSERR if the set is invalid (e.g. the set service crashed)

Definition at line 1123 of file set_api.c.

References GNUNET_SET_OperationHandle::conclude_mqm, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_assoc_add(), GNUNET_MQ_send(), GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, LOG, GNUNET_SET_OperationHandle::request_id, GNUNET_SET_OperationHandle::request_id_addr, and GNUNET_SET_OperationHandle::set.

Referenced by cb_intersection_request_alice(), commit_set(), handle_revocation_union_request(), run(), and set_listen_cb().

1125 {
1126  if (NULL != oh->set)
1127  {
1128  /* Some other set was already committed for this
1129  * operation, there is a logic bug in the client of this API */
1130  GNUNET_break(0);
1131  return GNUNET_OK;
1132  }
1133  GNUNET_assert(NULL != set);
1134  if (GNUNET_YES == set->invalid)
1135  return GNUNET_SYSERR;
1137  "Client commits to SET\n");
1138  GNUNET_assert(NULL != oh->conclude_mqm);
1139  oh->set = set;
1141  set->ops_tail,
1142  oh);
1143  oh->request_id = GNUNET_MQ_assoc_add(set->mq,
1144  oh);
1145  *oh->request_id_addr = htonl(oh->request_id);
1146  GNUNET_MQ_send(set->mq,
1147  oh->conclude_mqm);
1148  oh->conclude_mqm = NULL;
1149  oh->request_id_addr = NULL;
1150  return GNUNET_OK;
1151 }
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_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
uint32_t GNUNET_MQ_assoc_add(struct GNUNET_MQ_Handle *mq, void *assoc_data)
Associate the assoc_data in mq with a unique request id.
Definition: mq.c:706
#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
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint32_t request_id
Request ID to identify the operation within the set.
Definition: set_api.c:175
#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
struct GNUNET_MQ_Handle * mq
Message queue for client.
Definition: set_api.c:52
int invalid
Has the set become invalid (e.g.
Definition: set_api.c:85
uint32_t * request_id_addr
Address of the request if in the conclude message, used to patch the request id into the message when...
Definition: set_api.c:160
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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
#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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SET_operation_cancel()

void GNUNET_SET_operation_cancel ( struct GNUNET_SET_OperationHandle oh)

Cancel the given set operation.

May not be called after the operation's GNUNET_SET_ResultIterator has been called with a status that indicates error, timeout or done.

Parameters
ohset operation to cancel

We need to send an explicit cancel message, as all operations one one set communicate using one handle.

Parameters
ohset operation to cancel

Definition at line 511 of file set_api.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_SET_CANCEL, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_SET_destroy(), GNUNET_YES, LOG, m, GNUNET_SET_OperationHandle::request_id, GNUNET_SET_CancelMessage::request_id, GNUNET_SET_OperationHandle::set, and set_operation_destroy().

Referenced by commit_set(), destroy_service_session(), handle_core_disconnect(), and handle_shutdown().

512 {
513  struct GNUNET_SET_Handle *set = oh->set;
514  struct GNUNET_SET_CancelMessage *m;
515  struct GNUNET_MQ_Envelope *mqm;
516 
518  "Cancelling SET operation\n");
519  if (NULL != set)
520  {
522  m->request_id = htonl(oh->request_id);
523  GNUNET_MQ_send(set->mq, mqm);
524  }
526  if ((NULL != set) &&
527  (GNUNET_YES == set->destroy_requested) &&
528  (NULL == set->ops_head))
529  {
531  "Destroying set after operation cancel\n");
532  GNUNET_SET_destroy(set);
533  }
534 }
#define GNUNET_MESSAGE_TYPE_SET_CANCEL
Cancel a set operation.
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_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
uint32_t request_id
Request ID to identify the operation within the set.
Definition: set_api.c:175
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
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:99
Opaque handle to a set.
Definition: set_api.c:48
Sent to the service by the client in order to cancel a set operation.
Definition: set.h:298
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
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
uint32_t request_id
ID of the request we want to cancel.
Definition: set.h:307
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SET_iterate()

int GNUNET_SET_iterate ( struct GNUNET_SET_Handle set,
GNUNET_SET_ElementIterator  iter,
void *  iter_cls 
)

Iterate over all elements in the given set.

Note that this operation involves transferring every element of the set from the service to the client, and is thus costly. Only one iteration per set may be active at the same time.

Parameters
setthe set to iterate over
iterthe iterator to call for each element
iter_clsclosure for iter
Returns
GNUNET_YES if the iteration started successfuly, GNUNET_NO if another iteration was still active, GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected)

Note that this operation involves transferring every element of the set from the service to the client, and is thus costly.

Parameters
setthe set to iterate over
iterthe iterator to call for each element
iter_clsclosure for iter
Returns
GNUNET_YES if the iteration started successfuly, GNUNET_NO if another iteration is active GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected)

Definition at line 1167 of file set_api.c.

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST, GNUNET_MQ_msg_header, GNUNET_MQ_send(), GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, and LOG.

Referenced by task_start_finish().

1170 {
1171  struct GNUNET_MQ_Envelope *ev;
1172 
1173  GNUNET_assert(NULL != iter);
1174  if (GNUNET_YES == set->invalid)
1175  return GNUNET_SYSERR;
1176  if (NULL != set->iterator)
1177  return GNUNET_NO;
1179  "Iterating over set\n");
1180  set->iterator = iter;
1181  set->iterator_cls = iter_cls;
1183  GNUNET_MQ_send(set->mq, ev);
1184  return GNUNET_YES;
1185 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define LOG(kind,...)
Definition: set_api.c:33
struct GNUNET_MQ_Handle * mq
Message queue for client.
Definition: set_api.c:52
int invalid
Has the set become invalid (e.g.
Definition: set_api.c:85
#define GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST
Start iteration over set elements.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
GNUNET_SET_ElementIterator iterator
Callback for the current iteration over the set, NULL if no iterator is active.
Definition: set_api.c:68
#define GNUNET_MQ_msg_header(type)
Allocate a GNUNET_MQ_Envelope, where the message only consists of a header.
Definition: gnunet_mq_lib.h:76
#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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SET_iterate_cancel()

void GNUNET_SET_iterate_cancel ( struct GNUNET_SET_Handle set)

Stop iteration over all elements in the given set.

Can only be called before the iteration has "naturally" completed its turn.

Parameters
setthe set to stop iterating over

◆ GNUNET_SET_element_dup()

struct GNUNET_SET_Element* GNUNET_SET_element_dup ( const struct GNUNET_SET_Element element)

Create a copy of an element.

The copy must be GNUNET_free-d by the caller.

Parameters
elementthe element to copy
Returns
the copied element

Definition at line 1218 of file set_api.c.

References GNUNET_SET_Element::data, GNUNET_SET_Element::element_type, GNUNET_malloc, GNUNET_memcpy, and GNUNET_SET_Element::size.

Referenced by diff_insert(), and rfn_vote().

1219 {
1220  struct GNUNET_SET_Element *copy;
1221 
1222  copy = GNUNET_malloc(element->size + sizeof(struct GNUNET_SET_Element));
1223  copy->size = element->size;
1224  copy->element_type = element->element_type;
1225  copy->data = &copy[1];
1226  GNUNET_memcpy(&copy[1],
1227  element->data,
1228  copy->size);
1229  return copy;
1230 }
Element stored in a set.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
const void * data
Actual data of the element.
uint16_t size
Number of bytes in the buffer pointed to by data.
#define GNUNET_malloc(size)
Wrapper around malloc.
uint16_t element_type
Application-specific element type.
Here is the caller graph for this function:

◆ GNUNET_SET_element_hash()

void GNUNET_SET_element_hash ( const struct GNUNET_SET_Element element,
struct GNUNET_HashCode ret_hash 
)

Hash a set element.

Parameters
elementthe element that should be hashed
ret_hasha pointer to where the hash of element should be stored
elementthe element that should be hashed
[out]ret_hasha pointer to where the hash of element should be stored

Definition at line 1241 of file set_api.c.

References ctx, GNUNET_SET_Element::data, GNUNET_SET_Element::element_type, GNUNET_CRYPTO_hash_context_finish(), GNUNET_CRYPTO_hash_context_read(), GNUNET_CRYPTO_hash_context_start(), and GNUNET_SET_Element::size.

Referenced by diff_insert(), diffname(), execute_add(), execute_remove(), handle_union_p2p_elements(), handle_union_p2p_full_element(), and rfn_vote().

1243 {
1245 
1246  /* It's not guaranteed that the element data is always after the element header,
1247  so we need to hash the chunks separately. */
1248  GNUNET_CRYPTO_hash_context_read(ctx, &element->size, sizeof(uint16_t));
1249  GNUNET_CRYPTO_hash_context_read(ctx, &element->element_type, sizeof(uint16_t));
1250  GNUNET_CRYPTO_hash_context_read(ctx, element->data, element->size);
1251  GNUNET_CRYPTO_hash_context_finish(ctx, ret_hash);
1252 }
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
Definition: crypto_hash.c:445
Context for cummulative hashing.
Definition: crypto_hash.c:431
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
const void * data
Actual data of the element.
void GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc, const void *buf, size_t size)
Add data to be hashed.
Definition: crypto_hash.c:471
uint16_t size
Number of bytes in the buffer pointed to by data.
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
Definition: crypto_hash.c:488
uint16_t element_type
Application-specific element type.
Here is the call graph for this function:
Here is the caller graph for this function: