GNUnet  0.11.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 421 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().

422 {
423  struct Set *set = op->set;
424  struct GNUNET_CADET_Channel *channel;
425 
426  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying operation %p\n", op);
427  GNUNET_assert (NULL == op->listener);
428  if (NULL != op->state)
429  {
430  set->vt->cancel (op);
431  op->state = NULL;
432  }
433  if (NULL != set)
434  {
435  GNUNET_CONTAINER_DLL_remove (set->ops_head, set->ops_tail, op);
436  op->set = NULL;
437  }
438  if (NULL != op->context_msg)
439  {
440  GNUNET_free (op->context_msg);
441  op->context_msg = NULL;
442  }
443  if (NULL != (channel = op->channel))
444  {
445  /* This will free op; called conditionally as this helper function
446  is also called from within the channel disconnect handler. */
447  op->channel = NULL;
449  }
450  if ((NULL != set) && (GNUNET_YES == gc))
452  /* We rely on the channel end handler to free 'op'. When 'op->channel' was NULL,
453  * there was a channel end handler that will free 'op' on the call stack. */
454 }
#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:80
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:903
#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 1154 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().

1155 {
1156  struct GNUNET_CADET_Channel *channel;
1157 
1158  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "channel_end_cb called\n");
1159  if (NULL != (channel = op->channel))
1160  {
1161  /* This will free op; called conditionally as this helper function
1162  is also called from within the channel disconnect handler. */
1163  op->channel = NULL;
1164  GNUNET_CADET_channel_destroy (channel);
1165  }
1166  if (NULL != op->listener)
1167  {
1168  incoming_destroy (op);
1169  return;
1170  }
1171  if (NULL != op->set)
1172  op->set->vt->channel_death (op);
1173  else
1175  GNUNET_free (op);
1176 }
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:80
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:903
#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 2454 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().

2455 {
2456  static const struct SetVT union_vt = {
2458  .add = &union_add,
2459  .remove = &union_remove,
2460  .destroy_set = &union_set_destroy,
2461  .evaluate = &union_evaluate,
2462  .accept = &union_accept,
2463  .cancel = &union_op_cancel,
2464  .copy_state = &union_copy_state,
2465  .channel_death = &union_channel_death
2466  };
2467 
2468  return &union_vt;
2469 }
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 1317 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().

1318 {
1319  static const struct SetVT intersection_vt = {
1321  .add = &intersection_add,
1322  .remove = &intersection_remove,
1323  .destroy_set = &intersection_set_destroy,
1324  .evaluate = &intersection_evaluate,
1325  .accept = &intersection_accept,
1326  .cancel = &intersection_op_cancel,
1327  .channel_death = &intersection_channel_death,
1328  };
1329 
1330  return &intersection_vt;
1331 }
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 398 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().

399 {
400  return is_element_of_generation (ee,
401  op->generation_created,
404 }
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