GNUnet  0.11.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 273 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 286 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 300 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 320 of file gnunet_set_service.h.

◆ GNUNET_SET_CopyReadyCallback

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

Definition at line 327 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.

83 {
88 
93 
98 };
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 104 of file gnunet_set_service.h.

105 {
117 
126 
135 
141 
148 
153 };
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 159 of file gnunet_set_service.h.

160 {
167 
175 
182 
189 };
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 219 of file gnunet_set_service.h.

220 {
244 };
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 657 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().

659 {
660  struct GNUNET_SET_Handle *set;
661 
662  set = create_internal (cfg,
663  op,
664  NULL);
666  "Creating set %p for operation %d\n",
667  set,
668  op);
669  return set;
670 }
#define LOG(kind,...)
Definition: set_api.c:33
Opaque handle to a set.
Definition: set_api.c:49
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
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
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 687 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().

691 {
692  struct GNUNET_MQ_Envelope *mqm;
694 
696  "adding element of type %u to set %p\n",
697  (unsigned int) element->element_type,
698  set);
699  GNUNET_assert (NULL != set);
700  if (GNUNET_YES == set->invalid)
701  {
702  if (NULL != cont)
703  cont (cont_cls);
704  return GNUNET_SYSERR;
705  }
706  mqm = GNUNET_MQ_msg_extra (msg,
707  element->size,
709  msg->element_type = htons (element->element_type);
710  GNUNET_memcpy (&msg[1],
711  element->data,
712  element->size);
714  cont, cont_cls);
715  GNUNET_MQ_send (set->mq, mqm);
716  return GNUNET_OK;
717 }
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:291
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:54
#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:87
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:774
#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:280
#define GNUNET_YES
Definition: gnunet_common.h:77
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
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 734 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().

738 {
739  struct GNUNET_MQ_Envelope *mqm;
741 
743  "Removing element from set %p\n",
744  set);
745  if (GNUNET_YES == set->invalid)
746  {
747  if (NULL != cont)
748  cont (cont_cls);
749  return GNUNET_SYSERR;
750  }
751  mqm = GNUNET_MQ_msg_extra (msg,
752  element->size,
754  msg->element_type = htons (element->element_type);
755  GNUNET_memcpy (&msg[1],
756  element->data,
757  element->size);
759  cont, cont_cls);
760  GNUNET_MQ_send (set->mq, mqm);
761  return GNUNET_OK;
762 }
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:291
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:54
#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:87
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:774
#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:280
#define GNUNET_YES
Definition: gnunet_common.h:77
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
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 1194 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().

1197 {
1198  struct GNUNET_MQ_Envelope *ev;
1199  struct SetCopyRequest *req;
1200 
1202  "Creating lazy copy of set\n");
1204  GNUNET_MQ_send (set->mq, ev);
1205 
1206  req = GNUNET_new (struct SetCopyRequest);
1207  req->cb = cb;
1208  req->cls = cls;
1210  set->copy_req_tail,
1211  req);
1212 }
#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:103
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void * cls
Definition: set_api.c:41
#define LOG(kind,...)
Definition: set_api.c:33
struct GNUNET_MQ_Handle * mq
Message queue for client.
Definition: set_api.c:54
GNUNET_SET_CopyReadyCallback cb
Definition: set_api.c:43
struct SetCopyRequest * copy_req_tail
Doubly linked list of copy requests.
Definition: set_api.c:108
#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:353
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 772 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().

773 {
774  /* destroying set while iterator is active is currently
775  not supported; we should expand the API to allow
776  clients to explicitly cancel the iteration! */
777  GNUNET_assert (NULL != set);
778  if ((NULL != set->ops_head) ||
779  (NULL != set->iterator) ||
781  {
783  "Set operations are pending, delaying set destruction\n");
784  set->destroy_requested = GNUNET_YES;
785  return;
786  }
788  "Really destroying set\n");
789  if (NULL != set->mq)
790  {
791  GNUNET_MQ_destroy (set->mq);
792  set->mq = NULL;
793  }
794  GNUNET_free (set);
795 }
#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:54
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
#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:70
struct GNUNET_SET_OperationHandle * ops_head
Linked list of operations on the set.
Definition: set_api.c:59
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#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 813 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().

820 {
821  struct GNUNET_MQ_Envelope *mqm;
824  struct GNUNET_SET_Option *opt;
825 
827  "Client prepares set operation (%d)\n",
828  result_mode);
830  oh->result_cb = result_cb;
831  oh->result_cls = result_cls;
832  mqm = GNUNET_MQ_msg_nested_mh (msg,
834  context_msg);
835  msg->app_id = *app_id;
836  msg->result_mode = htonl (result_mode);
837  msg->target_peer = *other_peer;
838  for (opt = options; opt->type != 0; opt++)
839  {
840  switch (opt->type)
841  {
843  msg->byzantine = GNUNET_YES;
844  msg->byzantine_lower_bound = opt->v.num;
845  break;
846 
848  msg->force_full = GNUNET_YES;
849  break;
850 
852  msg->force_delta = GNUNET_YES;
853  break;
854 
855  default:
857  "Option with type %d not recognized\n", (int) opt->type);
858  }
859  }
860  oh->conclude_mqm = mqm;
861  oh->request_id_addr = &msg->request_id;
862 
863  return oh;
864 }
struct GNUNET_PeerIdentity target_peer
Peer to evaluate the operation with.
Definition: set.h:196
void * result_cls
Closure for result_cb.
Definition: set_api.c:146
union GNUNET_SET_Option::@54 v
Value for the option, only used with some options.
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:191
uint8_t force_full
Always send full sets, even if delta operations would be more efficient.
Definition: set.h:219
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:141
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:213
uint32_t request_id
Id of our set to evaluate, chosen implicitly by the client when it calls GNUNET_SET_commit().
Definition: set.h:207
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:164
uint8_t byzantine
GNUNET_YES to fail operations where Byzantine faults are suspected
Definition: set.h:225
uint8_t byzantine_lower_bound
Lower bound for the set size, used only when byzantine mode is enabled.
Definition: set.h:231
Message sent by client to service to initiate a set operation as a client (not as listener)...
Definition: set.h:180
Option for set operations.
Handle to an operation.
Definition: set_api.c:135
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
struct GNUNET_HashCode app_id
Application id.
Definition: set.h:201
#define GNUNET_YES
Definition: gnunet_common.h:77
Fail set operations when the other peer shows weird behavior that might by a Byzantine fault...
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 1017 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().

1022 {
1023  struct GNUNET_SET_ListenHandle *lh;
1024 
1026  "Starting listener for app %s\n",
1027  GNUNET_h2s (app_id));
1028  lh = GNUNET_new (struct GNUNET_SET_ListenHandle);
1029  lh->listen_cb = listen_cb;
1030  lh->listen_cls = listen_cls;
1031  lh->cfg = cfg;
1032  lh->operation = operation;
1033  lh->app_id = *app_id;
1035  listen_connect (lh);
1036  if (NULL == lh->mq)
1037  {
1038  GNUNET_free (lh);
1039  return NULL;
1040  }
1041  return lh;
1042 }
static void listen_cb(void *cls)
We have been notified that our listen socket has something to read.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: set_api.c:191
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
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:219
static void listen_connect(void *cls)
Connect to the set service in order to listen for requests.
Definition: set_api.c:974
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_HashCode app_id
Application ID we listen for.
Definition: set_api.c:214
enum GNUNET_SET_OperationType operation
Operation we listen for.
Definition: set_api.c:229
Opaque handle to a listen operation.
Definition: set_api.c:186
#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:198
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 1051 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().

1052 {
1054  "Canceling listener %s\n",
1055  GNUNET_h2s (&lh->app_id));
1056  if (NULL != lh->mq)
1057  {
1058  GNUNET_MQ_destroy (lh->mq);
1059  lh->mq = NULL;
1060  }
1061  if (NULL != lh->reconnect_task)
1062  {
1064  lh->reconnect_task = NULL;
1065  }
1066  GNUNET_free (lh);
1067 }
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: set_api.c:191
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:214
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
struct GNUNET_SCHEDULER_Task * reconnect_task
Task for reconnecting when the listener fails.
Definition: set_api.c:224
#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:966
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 1085 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().

1090 {
1091  struct GNUNET_MQ_Envelope *mqm;
1093  struct GNUNET_SET_AcceptMessage *msg;
1094 
1095  GNUNET_assert (GNUNET_NO == request->accepted);
1097  "Client accepts set operation (%d) with id %u\n",
1098  result_mode,
1099  request->accept_id);
1100  request->accepted = GNUNET_YES;
1101  mqm = GNUNET_MQ_msg (msg,
1103  msg->accept_reject_id = htonl (request->accept_id);
1104  msg->result_mode = htonl (result_mode);
1105  oh = GNUNET_new (struct GNUNET_SET_OperationHandle);
1106  oh->result_cb = result_cb;
1107  oh->result_cls = result_cls;
1108  oh->conclude_mqm = mqm;
1109  oh->request_id_addr = &msg->request_id;
1110  return oh;
1111 }
void * result_cls
Closure for result_cb.
Definition: set_api.c:146
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
uint32_t request_id
Request ID to identify responses.
Definition: set.h:97
#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:127
GNUNET_SET_ResultIterator result_cb
Function to be called when we have a result, or an error.
Definition: set_api.c:141
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:164
uint32_t accept_id
Id of the request, used to identify the request when accepting/rejecting it.
Definition: set_api.c:121
uint32_t result_mode
How should results be sent to us? See enum GNUNET_SET_ResultMode.
Definition: set.h:103
uint32_t accept_reject_id
ID of the incoming request we want to accept.
Definition: set.h:92
Handle to an operation.
Definition: set_api.c:135
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
#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:82
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 1128 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().

1130 {
1131  if (NULL != oh->set)
1132  {
1133  /* Some other set was already committed for this
1134  * operation, there is a logic bug in the client of this API */
1135  GNUNET_break (0);
1136  return GNUNET_OK;
1137  }
1138  GNUNET_assert (NULL != set);
1139  if (GNUNET_YES == set->invalid)
1140  return GNUNET_SYSERR;
1142  "Client commits to SET\n");
1143  GNUNET_assert (NULL != oh->conclude_mqm);
1144  oh->set = set;
1146  set->ops_tail,
1147  oh);
1148  oh->request_id = GNUNET_MQ_assoc_add (set->mq,
1149  oh);
1150  *oh->request_id_addr = htonl (oh->request_id);
1151  GNUNET_MQ_send (set->mq,
1152  oh->conclude_mqm);
1153  oh->conclude_mqm = NULL;
1154  oh->request_id_addr = NULL;
1155  return GNUNET_OK;
1156 }
struct GNUNET_SET_Handle * set
Local set used for the operation, NULL if no set has been provided by conclude yet.
Definition: set_api.c:152
#define GNUNET_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:708
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SET_OperationHandle * ops_tail
Linked list of operations on the set.
Definition: set_api.c:64
#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:179
#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:54
int invalid
Has the set become invalid (e.g.
Definition: set_api.c:87
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:164
#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:59
struct GNUNET_MQ_Envelope * conclude_mqm
Message sent to the server on calling conclude, NULL if conclude has been called. ...
Definition: set_api.c:158
#define GNUNET_YES
Definition: gnunet_common.h:77
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
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 516 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().

517 {
518  struct GNUNET_SET_Handle *set = oh->set;
519  struct GNUNET_SET_CancelMessage *m;
520  struct GNUNET_MQ_Envelope *mqm;
521 
523  "Cancelling SET operation\n");
524  if (NULL != set)
525  {
527  m->request_id = htonl (oh->request_id);
528  GNUNET_MQ_send (set->mq, mqm);
529  }
531  if ((NULL != set) &&
532  (GNUNET_YES == set->destroy_requested) &&
533  (NULL == set->ops_head))
534  {
536  "Destroying set after operation cancel\n");
537  GNUNET_SET_destroy (set);
538  }
539 }
#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:152
#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:179
void GNUNET_SET_destroy(struct GNUNET_SET_Handle *set)
Destroy the set handle if no operations are left, mark the set for destruction otherwise.
Definition: set_api.c:772
#define LOG(kind,...)
Definition: set_api.c:33
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
Opaque handle to a set.
Definition: set_api.c:49
Sent to the service by the client in order to cancel a set operation.
Definition: set.h:306
static void set_operation_destroy(struct GNUNET_SET_OperationHandle *oh)
Destroy the given set operation.
Definition: set_api.c:486
#define GNUNET_YES
Definition: gnunet_common.h:77
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
uint32_t request_id
ID of the request we want to cancel.
Definition: set.h:316
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 1172 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().

1175 {
1176  struct GNUNET_MQ_Envelope *ev;
1177 
1178  GNUNET_assert (NULL != iter);
1179  if (GNUNET_YES == set->invalid)
1180  return GNUNET_SYSERR;
1181  if (NULL != set->iterator)
1182  return GNUNET_NO;
1184  "Iterating over set\n");
1185  set->iterator = iter;
1186  set->iterator_cls = iter_cls;
1188  GNUNET_MQ_send (set->mq, ev);
1189  return GNUNET_YES;
1190 }
#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:54
int invalid
Has the set become invalid (e.g.
Definition: set_api.c:87
#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:70
#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:353
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 1223 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().

1224 {
1225  struct GNUNET_SET_Element *copy;
1226 
1227  copy = GNUNET_malloc (element->size + sizeof(struct GNUNET_SET_Element));
1228  copy->size = element->size;
1229  copy->element_type = element->element_type;
1230  copy->data = &copy[1];
1231  GNUNET_memcpy (&copy[1],
1232  element->data,
1233  copy->size);
1234  return copy;
1235 }
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 1246 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().

1248 {
1250 
1251  /* It's not guaranteed that the element data is always after the element header,
1252  so we need to hash the chunks separately. */
1253  GNUNET_CRYPTO_hash_context_read (ctx, &element->size, sizeof(uint16_t));
1255  sizeof(uint16_t));
1256  GNUNET_CRYPTO_hash_context_read (ctx, element->data, element->size);
1257  GNUNET_CRYPTO_hash_context_finish (ctx, ret_hash);
1258 }
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
Definition: crypto_hash.c:466
Context for cummulative hashing.
Definition: crypto_hash.c:451
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:492
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:509
uint16_t element_type
Application-specific element type.
Here is the call graph for this function:
Here is the caller graph for this function: