2 This file is part of GNUnet
3 (C) 2013 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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file set/gnunet-service-set.h
23 * @brief common components for the implementation the different set operations
24 * @author Florian Dold
27 #ifndef GNUNET_SERVICE_SET_H_PRIVATE
28 #define GNUNET_SERVICE_SET_H_PRIVATE
31 #include "gnunet_util_lib.h"
32 #include "gnunet_protocols.h"
33 #include "gnunet_applications.h"
34 #include "gnunet_core_service.h"
35 #include "gnunet_mesh_service.h"
36 #include "gnunet_set_service.h"
41 * Implementation-specific set state.
42 * Used as opaque pointer, and specified further
43 * in the respective implementation.
49 * Implementation-specific set operation.
50 * Used as opaque pointer, and specified further
51 * in the respective implementation.
53 struct OperationState;
56 /* forward declarations */
63 * Detail information about an operation.
65 struct OperationSpecification
68 * The type of the operation.
70 enum GNUNET_SET_OperationType operation;
73 * The remove peer we evaluate the operation with
75 struct GNUNET_PeerIdentity peer;
78 * Application ID for the operation, used to distinguish
79 * multiple operations of the same type with the same peer.
81 struct GNUNET_HashCode app_id;
84 * Context message, may be NULL.
86 struct GNUNET_MessageHeader *context_msg;
89 * Salt to use for the operation.
94 * ID used to identify an operation between service and client
96 uint32_t client_request_id;
99 * Set associated with the operation, NULL until the spec has been associated
105 * When are elements sent to the client, and which elements are sent?
107 enum GNUNET_SET_ResultMode result_mode;
114 * Signature of functions that create the implementation-specific
115 * state for a set supporting a specific operation.
117 * @return a set state specific to the supported operation
119 typedef struct SetState *(*CreateImpl) (void);
123 * Signature of functions that implement the add/remove functionality
124 * for a set supporting a specific operation.
126 * @param set implementation-specific set state
127 * @param msg element message from the client
129 typedef void (*AddRemoveImpl) (struct SetState *state, struct ElementEntry *ee);
133 * Signature of functions that handle disconnection
134 * of the remote peer.
136 * @param op the set operation, contains implementation-specific data
138 typedef void (*PeerDisconnectImpl) (struct Operation *op);
142 * Signature of functions that implement the destruction of the
143 * implementation-specific set state.
145 * @param state the set state, contains implementation-specific data
147 typedef void (*DestroySetImpl) (struct SetState *state);
151 * Signature of functions that implement the creation of set operations
152 * (currently evaluate and accept).
154 * @param op operation that is created, should be initialized by the implementation
156 typedef void (*OpCreateImpl) (struct Operation *op);
160 * Signature of functions that implement the message handling for
161 * the different set operations.
163 * @param op operation state
164 * @param msg received message
165 * @return GNUNET_OK on success, GNUNET_SYSERR to
166 * destroy the operation and the tunnel
168 typedef int (*MsgHandlerImpl) (struct Operation *op,
169 const struct GNUNET_MessageHeader *msg);
172 * Signature of functions that implement operation cancellation
174 * @param op operation state
176 typedef void (*CancelImpl) (struct Operation *op);
180 * Dispatch table for a specific set operation.
181 * Every set operation has to implement the callback
187 * Callback for the set creation.
192 * Callback for element insertion
197 * Callback for element removal.
199 AddRemoveImpl remove;
202 * Callback for accepting a set operation request
207 * Callback for starting evaluation with a remote peer.
209 OpCreateImpl evaluate;
212 * Callback for destruction of the set state.
214 DestroySetImpl destroy_set;
217 * Callback for handling operation-specific messages.
219 MsgHandlerImpl msg_handler;
222 * Callback for handling the remote peer's
225 PeerDisconnectImpl peer_disconnect;
228 * Callback for canceling an operation by
236 * Information about an element element in the set.
237 * All elements are stored in a hash-table
238 * from their hash-code to their 'struct Element',
239 * so that the remove and add operations are reasonably
245 * The actual element. The data for the element
246 * should be allocated at the end of this struct.
248 struct GNUNET_SET_Element element;
251 * Hash of the element.
253 * Will be used to derive the different IBF keys
254 * for different salts.
256 struct GNUNET_HashCode element_hash;
259 * Generation the element was added by the client.
260 * Operations of earlier generations will not consider the element.
262 unsigned int generation_added;
265 * GNUNET_YES if the element has been removed in some generation.
270 * Generation the element was removed by the client.
271 * Operations of later generations will not consider the element.
272 * Only valid if is_removed is GNUNET_YES.
274 unsigned int generation_removed;
277 * GNUNET_YES if the element is a remote element, and does not belong
278 * to the operation's set.
280 * //TODO: Move to Union, unless additional set-operations are implemented ever
289 * V-Table for the operation belonging
290 * to the tunnel contest.
292 * Used for all operation specific operations after receiving the ops request
294 const struct SetVT *vt;
297 * Tunnel to the peer.
299 struct GNUNET_MESH_Tunnel *tunnel;
302 * Message queue for the tunnel.
304 struct GNUNET_MQ_Handle *mq;
307 * GNUNET_YES if this is not a "real" set operation yet, and we still
308 * need to wait for the other peer to give us more details.
310 * //TODO: replace with state-enum
315 * Generation in which the operation handle
318 unsigned int generation_created;
321 * Detail information about the set operation,
322 * including the set to use.
323 * When 'spec' is NULL, the operation is not yet entirely
326 struct OperationSpecification *spec;
329 * Operation-specific operation state.
331 struct OperationState *state;
334 * Evaluate operations are held in
337 struct Operation *next;
340 * Evaluate operations are held in
343 struct Operation *prev;
348 * A set that supports a specific operation
354 * Client that owns the set.
355 * Only one client may own a set.
357 struct GNUNET_SERVER_Client *client;
360 * Message queue for the client
362 struct GNUNET_MQ_Handle *client_mq;
365 * Type of operation supported for this set
367 enum GNUNET_SET_OperationType operation;
370 * Virtual table for this set.
371 * Determined by the operation type of this set.
373 * Used only for Add/remove of elements and when receiving an incoming
374 * operation from a remote peer.
376 const struct SetVT *vt;
379 * Sets are held in a doubly linked list.
384 * Sets are held in a doubly linked list.
389 * Implementation-specific state.
391 struct SetState *state;
394 * Current state of iterating elements for the client.
395 * NULL if we are not currently iterating.
397 struct GNUNET_CONTAINER_MultiHashMapIterator *iter;
400 * Maps 'struct GNUNET_HashCode' to 'struct ElementEntry'.
402 struct GNUNET_CONTAINER_MultiHashMap *elements;
405 * Current generation, that is, number of
406 * previously executed operations on this set
408 unsigned int current_generation;
411 * Evaluate operations are held in
414 struct Operation *ops_head;
417 * Evaluate operations are held in
420 struct Operation *ops_tail;
425 * Destroy the given operation. Call the implementation-specific cancel function
426 * of the operation. Disconnects from the remote peer.
427 * Does not disconnect the client, as there may be multiple operations per set.
429 * @param op operation to destroy
432 _GSS_operation_destroy (struct Operation *op);
436 * Get the table with implementing functions for
439 * @return the operation specific VTable
442 _GSS_union_vt (void);
446 * Get the table with implementing functions for
449 * @return the operation specific VTable
452 _GSS_intersection_vt (void);