GNUnet  0.10.x
Data Structures | Typedefs | Functions | Variables
gnunet-service-set.h File Reference

common components for the implementation the different set operations More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_applications.h"
#include "gnunet_core_service.h"
#include "gnunet_cadet_service.h"
#include "gnunet_set_service.h"
#include "set.h"
Include dependency graph for gnunet-service-set.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SetVT
 Dispatch table for a specific set operation. More...
 
struct  MutationEvent
 MutationEvent gives information about changes to an element (removal / addition) in a set content. More...
 
struct  ElementEntry
 Information about an element element in the set. More...
 
struct  ClientState
 State we keep per client. More...
 
struct  Operation
 Operation context used to execute a set operation. More...
 
struct  SetContent
 SetContent stores the actual set elements, which may be shared by multiple generations derived from one set. More...
 
struct  GenerationRange
 
struct  PendingMutation
 Information about a mutation to apply to a set. More...
 
struct  Set
 A set that supports a specific operation with other peers. More...
 

Typedefs

typedef struct SetState *(* SetCreateImpl) (void)
 Signature of functions that create the implementation-specific state for a set supporting a specific operation. More...
 
typedef void(* SetAddRemoveImpl) (struct SetState *state, struct ElementEntry *ee)
 Signature of functions that implement the add/remove functionality for a set supporting a specific operation. More...
 
typedef struct SetState *(* SetCopyStateImpl) (struct SetState *state)
 Make a copy of a set's internal state. More...
 
typedef void(* SetDestroyImpl) (struct SetState *state)
 Signature of functions that implement the destruction of the implementation-specific set state. More...
 
typedef struct OperationState *(* OpAcceptImpl) (struct Operation *op)
 Signature of functions that implement accepting a set operation. More...
 
typedef struct OperationState *(* OpEvaluateImpl) (struct Operation *op, const struct GNUNET_MessageHeader *opaque_context)
 Signature of functions that implement starting the evaluation of set operations. More...
 
typedef void(* OpCancelImpl) (struct Operation *op)
 Signature of functions that implement operation cancelation. More...
 
typedef void(* OpChannelDeathImpl) (struct Operation *op)
 Signature of functions called when the CADET channel died. More...
 

Functions

void _GSS_operation_destroy (struct Operation *op, int gc)
 Destroy the given operation. More...
 
void _GSS_operation_destroy2 (struct Operation *op)
 This function probably should not exist and be replaced by inlining more specific logic in the various places where it is called. More...
 
const struct SetVT_GSS_union_vt (void)
 Get the table with implementing functions for set union. More...
 
const struct SetVT_GSS_intersection_vt (void)
 Get the table with implementing functions for set intersection. More...
 
int _GSS_is_element_of_operation (struct ElementEntry *ee, struct Operation *op)
 Is element ee part of the set used by op? More...
 

Variables

struct GNUNET_STATISTICS_Handle_GSS_statistics
 Statistics handle. More...
 

Detailed Description

common components for the implementation the different set operations

Author
Florian Dold
Christian Grothoff

Definition in file gnunet-service-set.h.

Typedef Documentation

◆ SetCreateImpl

typedef struct SetState*(* SetCreateImpl) (void)

Signature of functions that create the implementation-specific state for a set supporting a specific operation.

Returns
a set state specific to the supported operation, NULL on error

Definition at line 77 of file gnunet-service-set.h.

◆ SetAddRemoveImpl

typedef void(* SetAddRemoveImpl) (struct SetState *state, struct ElementEntry *ee)

Signature of functions that implement the add/remove functionality for a set supporting a specific operation.

Parameters
setimplementation-specific set state
eeelement message from the client

Definition at line 88 of file gnunet-service-set.h.

◆ SetCopyStateImpl

typedef struct SetState*(* SetCopyStateImpl) (struct SetState *state)

Make a copy of a set's internal state.

Parameters
stateset state to copy
Returns
copy of the internal state

Definition at line 99 of file gnunet-service-set.h.

◆ SetDestroyImpl

typedef void(* SetDestroyImpl) (struct SetState *state)

Signature of functions that implement the destruction of the implementation-specific set state.

Parameters
statethe set state, contains implementation-specific data

Definition at line 109 of file gnunet-service-set.h.

◆ OpAcceptImpl

typedef struct OperationState*(* OpAcceptImpl) (struct Operation *op)

Signature of functions that implement accepting a set operation.

Parameters
opoperation that is created by accepting the operation, should be initialized by the implementation
Returns
operation-specific state to keep in op

Definition at line 120 of file gnunet-service-set.h.

◆ OpEvaluateImpl

typedef struct OperationState*(* OpEvaluateImpl) (struct Operation *op, const struct GNUNET_MessageHeader *opaque_context)

Signature of functions that implement starting the evaluation of set operations.

Parameters
opoperation that is created, should be initialized to begin the evaluation
opaque_contextmessage to be transmitted to the listener to convince it to accept, may be NULL
Returns
operation-specific state to keep in op

Definition at line 134 of file gnunet-service-set.h.

◆ OpCancelImpl

typedef void(* OpCancelImpl) (struct Operation *op)

Signature of functions that implement operation cancelation.

This includes notifying the client about the operation's final state.

Parameters
opoperation state

Definition at line 145 of file gnunet-service-set.h.

◆ OpChannelDeathImpl

typedef void(* OpChannelDeathImpl) (struct Operation *op)

Signature of functions called when the CADET channel died.

Parameters
opoperation state

Definition at line 154 of file gnunet-service-set.h.

Function Documentation

◆ _GSS_operation_destroy()

void _GSS_operation_destroy ( struct Operation op,
int  gc 
)

Destroy the given operation.

Used for any operation where both peers were known and that thus actually had a vt and channel. Must not be used for operations where 'listener' is still set and we do not know the other peer.

Call the implementation-specific cancel function of the operation. Disconnects from the remote peer. Does not disconnect the client, as there may be multiple operations per set.

Parameters
opoperation to destroy
gcGNUNET_YES to perform garbage collection on the set

Definition at line 418 of file gnunet-service-set.c.

References Operation::channel, collect_generation_garbage(), Operation::context_msg, GNUNET_assert, GNUNET_CADET_channel_destroy(), GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_YES, Operation::listener, Operation::set, and Operation::state.

Referenced by _GSS_operation_destroy2(), client_disconnect_cb(), fail_intersection_operation(), fail_union_operation(), handle_client_cancel(), intersection_channel_death(), send_client_done_and_destroy(), and union_channel_death().

419 {
420  struct Set *set = op->set;
421  struct GNUNET_CADET_Channel *channel;
422 
423  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying operation %p\n", op);
424  GNUNET_assert(NULL == op->listener);
425  if (NULL != op->state)
426  {
427  set->vt->cancel(op);
428  op->state = NULL;
429  }
430  if (NULL != set)
431  {
432  GNUNET_CONTAINER_DLL_remove(set->ops_head, set->ops_tail, op);
433  op->set = NULL;
434  }
435  if (NULL != op->context_msg)
436  {
438  op->context_msg = NULL;
439  }
440  if (NULL != (channel = op->channel))
441  {
442  /* This will free op; called conditionally as this helper function
443  is also called from within the channel disconnect handler. */
444  op->channel = NULL;
446  }
447  if ((NULL != set) && (GNUNET_YES == gc))
449  /* We rely on the channel end handler to free 'op'. When 'op->channel' was NULL,
450  * there was a channel end handler that will free 'op' on the call stack. */
451 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct Set * set
Set associated with the operation, NULL until the spec has been associated with a set...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CADET_Channel * channel
Channel to the peer.
Opaque handle to a channel.
Definition: cadet_api.c:79
struct Listener * listener
Port this operation runs on.
A set that supports a specific operation with other peers.
struct GNUNET_MessageHeader * context_msg
Context message, may be NULL.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static void collect_generation_garbage(struct Set *set)
Collect and destroy elements that are not needed anymore, because their lifetime (as determined by th...
struct OperationState * state
Operation-specific operation state.
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition: cadet_api.c:900
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _GSS_operation_destroy2()

void _GSS_operation_destroy2 ( struct Operation op)

This function probably should not exist and be replaced by inlining more specific logic in the various places where it is called.

Definition at line 1151 of file gnunet-service-set.c.

References _GSS_operation_destroy(), Operation::channel, SetVT::channel_death, GNUNET_CADET_channel_destroy(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_YES, incoming_destroy(), Operation::listener, Operation::set, and Set::vt.

Referenced by channel_end_cb(), handle_client_reject(), handle_union_p2p_full_done(), incoming_destroy(), and maybe_finish().

1152 {
1153  struct GNUNET_CADET_Channel *channel;
1154 
1155  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "channel_end_cb called\n");
1156  if (NULL != (channel = op->channel))
1157  {
1158  /* This will free op; called conditionally as this helper function
1159  is also called from within the channel disconnect handler. */
1160  op->channel = NULL;
1162  }
1163  if (NULL != op->listener)
1164  {
1165  incoming_destroy(op);
1166  return;
1167  }
1168  if (NULL != op->set)
1169  op->set->vt->channel_death(op);
1170  else
1172  GNUNET_free(op);
1173 }
struct Set * set
Set associated with the operation, NULL until the spec has been associated with a set...
struct GNUNET_CADET_Channel * channel
Channel to the peer.
void _GSS_operation_destroy(struct Operation *op, int gc)
Destroy the given operation.
Opaque handle to a channel.
Definition: cadet_api.c:79
struct Listener * listener
Port this operation runs on.
OpChannelDeathImpl channel_death
Callback called in case the CADET channel died.
static void incoming_destroy(struct Operation *op)
Destroy an incoming request from a remote peer.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
const struct SetVT * vt
Virtual table for this set.
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition: cadet_api.c:900
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _GSS_union_vt()

const struct SetVT* _GSS_union_vt ( void  )

Get the table with implementing functions for set union.

Returns
the operation specific VTable

Definition at line 2431 of file gnunet-service-set_union.c.

References SetVT::create, union_accept(), union_add(), union_channel_death(), union_copy_state(), union_evaluate(), union_op_cancel(), union_remove(), union_set_create(), and union_set_destroy().

Referenced by handle_client_copy_lazy_connect(), and handle_client_create_set().

2432 {
2433  static const struct SetVT union_vt = {
2435  .add = &union_add,
2436  .remove = &union_remove,
2437  .destroy_set = &union_set_destroy,
2438  .evaluate = &union_evaluate,
2439  .accept = &union_accept,
2440  .cancel = &union_op_cancel,
2441  .copy_state = &union_copy_state,
2442  .channel_death = &union_channel_death
2443  };
2444 
2445  return &union_vt;
2446 }
static struct OperationState * union_accept(struct Operation *op)
Accept an union operation request from a remote peer.
static void union_set_destroy(struct SetState *set_state)
Destroy a set that supports the union operation.
static void union_add(struct SetState *set_state, struct ElementEntry *ee)
Add the element from the given element message to the set.
static struct OperationState * union_evaluate(struct Operation *op, const struct GNUNET_MessageHeader *opaque_context)
Initiate operation to evaluate a set union with a remote peer.
static struct SetState * union_set_create(void)
Create a new set supporting the union operation.
Dispatch table for a specific set operation.
static void union_op_cancel(struct Operation *op)
Destroy the union operation.
static void union_channel_death(struct Operation *op)
Handle case where channel went down for an operation.
SetCreateImpl create
Callback for the set creation.
static struct SetState * union_copy_state(struct SetState *state)
Copy union-specific set state.
static void union_remove(struct SetState *set_state, struct ElementEntry *ee)
Remove the element given in the element message from the set.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _GSS_intersection_vt()

const struct SetVT* _GSS_intersection_vt ( void  )

Get the table with implementing functions for set intersection.

Returns
the operation specific VTable

Definition at line 1307 of file gnunet-service-set_intersection.c.

References SetVT::create, intersection_accept(), intersection_add(), intersection_channel_death(), intersection_evaluate(), intersection_op_cancel(), intersection_remove(), intersection_set_create(), and intersection_set_destroy().

Referenced by handle_client_copy_lazy_connect(), and handle_client_create_set().

1308 {
1309  static const struct SetVT intersection_vt = {
1311  .add = &intersection_add,
1312  .remove = &intersection_remove,
1313  .destroy_set = &intersection_set_destroy,
1314  .evaluate = &intersection_evaluate,
1315  .accept = &intersection_accept,
1316  .cancel = &intersection_op_cancel,
1317  .channel_death = &intersection_channel_death,
1318  };
1319 
1320  return &intersection_vt;
1321 }
static void intersection_add(struct SetState *set_state, struct ElementEntry *ee)
Add the element from the given element message to the set.
static struct OperationState * intersection_evaluate(struct Operation *op, const struct GNUNET_MessageHeader *opaque_context)
Initiate a set intersection operation with a remote peer.
Dispatch table for a specific set operation.
static struct SetState * intersection_set_create()
Create a new set supporting the intersection operation.
static void intersection_remove(struct SetState *set_state, struct ElementEntry *element)
Remove the element given in the element message from the set.
static void intersection_channel_death(struct Operation *op)
Callback for channel death for the intersection operation.
static void intersection_set_destroy(struct SetState *set_state)
Destroy a set that supports the intersection operation.
SetCreateImpl create
Callback for the set creation.
static struct OperationState * intersection_accept(struct Operation *op)
Accept an intersection operation request from a remote peer.
static void intersection_op_cancel(struct Operation *op)
Destroy the intersection operation.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _GSS_is_element_of_operation()

int _GSS_is_element_of_operation ( struct ElementEntry ee,
struct Operation op 
)

Is element ee part of the set used by op?

Parameters
eeelement to test
opoperation the defines the set and its generation
Returns
GNUNET_YES if the element is in the set, GNUNET_NO if not

Definition at line 395 of file gnunet-service-set.c.

References Set::excluded_generations, Set::excluded_generations_size, Operation::generation_created, is_element_of_generation(), and Operation::set.

Referenced by filtered_map_initialization(), handle_union_p2p_demand(), handle_union_p2p_offer(), init_key_to_element_iterator(), and initialize_map_unfiltered().

396 {
397  return is_element_of_generation(ee,
398  op->generation_created,
401 }
struct Set * set
Set associated with the operation, NULL until the spec has been associated with a set...
struct GenerationRange * excluded_generations
List of generations we have to exclude, due to lazy copies.
unsigned int excluded_generations_size
Number of elements in array excluded_generations.
unsigned int generation_created
Generation in which the operation handle was created.
static int is_element_of_generation(struct ElementEntry *ee, unsigned int query_generation, struct GenerationRange *excluded, unsigned int excluded_size)
Is element ee part of the set during query_generation?
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _GSS_statistics

struct GNUNET_STATISTICS_Handle* _GSS_statistics