2 This file is part of GNUnet
3 Copyright (C) 2013, 2014 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file set/gnunet-service-set.h
22 * @brief common components for the implementation the different set operations
23 * @author Florian Dold
24 * @author Christian Grothoff
26 #ifndef GNUNET_SERVICE_SET_H_PRIVATE
27 #define GNUNET_SERVICE_SET_H_PRIVATE
30 #include "gnunet_util_lib.h"
31 #include "gnunet_protocols.h"
32 #include "gnunet_applications.h"
33 #include "gnunet_core_service.h"
34 #include "gnunet_cadet_service.h"
35 #include "gnunet_set_service.h"
40 * Implementation-specific set state. Used as opaque pointer, and
41 * specified further in the respective implementation.
46 * Implementation-specific set operation. Used as opaque pointer, and
47 * specified further in the respective implementation.
49 struct OperationState;
52 * A set that supports a specific operation with other peers.
57 * Information about an element element in the set. All elements are
58 * stored in a hash-table from their hash-code to their 'struct
59 * Element', so that the remove and add operations are reasonably
65 * Operation context used to execute a set operation.
71 * Detail information about an operation.
73 struct OperationSpecification
77 * The remove peer we evaluate the operation with.
79 struct GNUNET_PeerIdentity peer;
82 * Application ID for the operation, used to distinguish
83 * multiple operations of the same type with the same peer.
85 struct GNUNET_HashCode app_id;
88 * Context message, may be NULL.
90 struct GNUNET_MessageHeader *context_msg;
93 * Set associated with the operation, NULL until the spec has been
94 * associated with a set.
99 * Salt to use for the operation.
104 * Remote peers element count
106 uint32_t remote_element_count;
109 * ID used to identify an operation between service and client
111 uint32_t client_request_id;
114 * The type of the operation.
116 enum GNUNET_SET_OperationType operation;
119 * When are elements sent to the client, and which elements are sent?
121 enum GNUNET_SET_ResultMode result_mode;
126 * Signature of functions that create the implementation-specific
127 * state for a set supporting a specific operation.
129 * @return a set state specific to the supported operation
131 typedef struct SetState *
132 (*CreateImpl) (void);
136 * Signature of functions that implement the add/remove functionality
137 * for a set supporting a specific operation.
139 * @param set implementation-specific set state
140 * @param ee element message from the client
143 (*AddRemoveImpl) (struct SetState *state,
144 struct ElementEntry *ee);
148 * Signature of functions that handle disconnection of the remote
151 * @param op the set operation, contains implementation-specific data
154 (*PeerDisconnectImpl) (struct Operation *op);
158 * Signature of functions that implement the destruction of the
159 * implementation-specific set state.
161 * @param state the set state, contains implementation-specific data
164 (*DestroySetImpl) (struct SetState *state);
168 * Signature of functions that implement accepting a set operation.
170 * @param op operation that is created by accepting the operation,
171 * should be initialized by the implementation
174 (*OpAcceptImpl) (struct Operation *op);
178 * Signature of functions that implement starting the evaluation of
181 * @param op operation that is created, should be initialized to
182 * begin the evaluation
183 * @param opaque_context message to be transmitted to the listener
184 * to convince him to accept, may be NULL
187 (*OpEvaluateImpl) (struct Operation *op,
188 const struct GNUNET_MessageHeader *opaque_context);
192 * Signature of functions that implement the message handling for
193 * the different set operations.
195 * @param op operation state
196 * @param msg received message
197 * @return #GNUNET_OK on success, #GNUNET_SYSERR to
198 * destroy the operation and the tunnel
201 (*MsgHandlerImpl) (struct Operation *op,
202 const struct GNUNET_MessageHeader *msg);
206 * Signature of functions that implement operation cancellation
208 * @param op operation state
211 (*CancelImpl) (struct Operation *op);
214 typedef struct SetState *
215 (*CopyStateImpl) (struct Set *op);
219 * Dispatch table for a specific set operation. Every set operation
220 * has to implement the callback in this struct.
225 * Callback for the set creation.
230 * Callback for element insertion
235 * Callback for element removal.
237 AddRemoveImpl remove;
240 * Callback for accepting a set operation request
245 * Callback for starting evaluation with a remote peer.
247 OpEvaluateImpl evaluate;
250 * Callback for destruction of the set state.
252 DestroySetImpl destroy_set;
255 * Callback for handling operation-specific messages.
257 MsgHandlerImpl msg_handler;
260 * Callback for handling the remote peer's disconnect.
262 PeerDisconnectImpl peer_disconnect;
265 * Callback for canceling an operation by its ID.
269 CopyStateImpl copy_state;
274 * MutationEvent gives information about changes
275 * to an element (removal / addition) in a set content.
280 * First generation affected by this mutation event.
282 * If @a generation is 0, this mutation event is a list
285 unsigned int generation;
288 * If @a added is #GNUNET_YES, then this is a
289 * `remove` event, otherwise it is an `add` event.
296 * Information about an element element in the set. All elements are
297 * stored in a hash-table from their hash-code to their `struct
298 * Element`, so that the remove and add operations are reasonably
304 * The actual element. The data for the element
305 * should be allocated at the end of this struct.
307 struct GNUNET_SET_Element element;
310 * Hash of the element. For set union: Will be used to derive the
311 * different IBF keys for different salts.
313 struct GNUNET_HashCode element_hash;
316 * If @a mutations is not NULL, it contains
317 * a list of mutations, ordered by increasing generation.
318 * The list is terminated by a sentinel event with `generation`
321 * If @a mutations is NULL, then this element exists in all generations
322 * of the respective set content this element belongs to.
324 struct MutationEvent *mutations;
326 unsigned int mutations_size;
329 * #GNUNET_YES if the element is a remote element, and does not belong
330 * to the operation's set.
337 * Operation context used to execute a set operation.
342 * V-Table for the operation belonging to the tunnel contest.
344 * Used for all operation specific operations after receiving the ops request
346 const struct SetVT *vt;
349 * Channel to the peer.
351 struct GNUNET_CADET_Channel *channel;
354 * Message queue for the channel.
356 struct GNUNET_MQ_Handle *mq;
359 * Detail information about the set operation, including the set to
360 * use. When 'spec' is NULL, the operation is not yet entirely
363 struct OperationSpecification *spec;
366 * Operation-specific operation state. Note that the exact
367 * type depends on this being a union or intersection operation
368 * (and thus on @e vt).
370 struct OperationState *state;
373 * Evaluate operations are held in a linked list.
375 struct Operation *next;
378 * Evaluate operations are held in a linked list.
380 struct Operation *prev;
383 * The identity of the requesting peer. Needs to
384 * be stored here as the op spec might not have been created yet.
386 struct GNUNET_PeerIdentity peer;
389 * Timeout task, if the incoming peer has not been accepted
390 * after the timeout, it will be disconnected.
392 struct GNUNET_SCHEDULER_Task *timeout_task;
395 * Unique request id for the request from a remote peer, sent to the
396 * client, which will accept or reject the request. Set to '0' iff
397 * the request has not been suggested yet.
402 * #GNUNET_YES if this is not a "real" set operation yet, and we still
403 * need to wait for the other peer to give us more details.
408 * Generation in which the operation handle
411 unsigned int generation_created;
414 * Incremented whenever (during shutdown) some component still
415 * needs to do something with this before the operation is freed.
416 * (Used as a reference counter, but only during termination.)
423 * SetContent stores the actual set elements,
424 * which may be shared by multiple generations derived
430 * Number of references to the content.
432 unsigned int refcount;
435 * Maps `struct GNUNET_HashCode *` to `struct ElementEntry *`.
437 struct GNUNET_CONTAINER_MultiHashMap *elements;
439 unsigned int latest_generation;
443 struct GenerationRange
446 * First generation that is excluded.
451 * Generation after the last excluded generation.
458 * A set that supports a specific operation with other peers.
464 * Sets are held in a doubly linked list (in `sets_head` and `sets_tail`).
469 * Sets are held in a doubly linked list.
474 * Client that owns the set. Only one client may own a set,
475 * and there can only be one set per client.
477 struct GNUNET_SERVER_Client *client;
480 * Message queue for the client.
482 struct GNUNET_MQ_Handle *client_mq;
485 * Virtual table for this set. Determined by the operation type of
488 * Used only for Add/remove of elements and when receiving an incoming
489 * operation from a remote peer.
491 const struct SetVT *vt;
494 * Implementation-specific state.
496 struct SetState *state;
499 * Current state of iterating elements for the client.
500 * NULL if we are not currently iterating.
502 struct GNUNET_CONTAINER_MultiHashMapIterator *iter;
505 * Evaluate operations are held in a linked list.
507 struct Operation *ops_head;
510 * Evaluate operations are held in a linked list.
512 struct Operation *ops_tail;
515 * Current generation, that is, number of previously executed
516 * operations and lazy copies on the underlying set content.
518 unsigned int current_generation;
521 * List of generations we have to exclude, due to lazy copies.
523 struct GenerationRange *excluded_generations;
525 unsigned int excluded_generations_size;
528 * Type of operation supported for this set
530 enum GNUNET_SET_OperationType operation;
533 * Each @e iter is assigned a unique number, so that the client
534 * can distinguish iterations.
536 uint16_t iteration_id;
539 * Content, possibly shared by multiple sets,
540 * and thus reference counted.
542 struct SetContent *content;
548 * Destroy the given operation. Call the implementation-specific
549 * cancel function of the operation. Disconnects from the remote
550 * peer. Does not disconnect the client, as there may be multiple
551 * operations per set.
553 * @param op operation to destroy
554 * @param gc #GNUNET_YES to perform garbage collection on the set
557 _GSS_operation_destroy (struct Operation *op,
562 * Get the table with implementing functions for set union.
564 * @return the operation specific VTable
567 _GSS_union_vt (void);
571 * Get the table with implementing functions for set intersection.
573 * @return the operation specific VTable
576 _GSS_intersection_vt (void);
580 _GSS_is_element_of_set (struct ElementEntry *ee,
584 _GSS_is_element_of_operation (struct ElementEntry *ee,
585 struct Operation *op);