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 2, 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_common.h"
32 #include "gnunet_protocols.h"
33 #include "gnunet_applications.h"
34 #include "gnunet_util_lib.h"
35 #include "gnunet_core_service.h"
36 #include "gnunet_mesh_service.h"
37 #include "gnunet_set_service.h"
42 * Implementation-specific set state.
43 * Used as opaque pointer, and specified further
44 * in the respective implementation.
50 * Implementation-specific set operation.
51 * Used as opaque pointer, and specified further
52 * in the respective implementation.
54 struct OperationState;
57 /* forward declarations */
64 * Detail information about an operation.
66 struct OperationSpecification
69 * The type of the operation.
71 enum GNUNET_SET_OperationType operation;
74 * The remove peer we evaluate the operation with
76 struct GNUNET_PeerIdentity peer;
79 * Application ID for the operation, used to distinguish
80 * multiple operations of the same type with the same peer.
82 struct GNUNET_HashCode app_id;
85 * Context message, may be NULL.
87 struct GNUNET_MessageHeader *context_msg;
90 * Salt to use for the operation.
95 * ID used to identify responses to a client.
97 uint32_t client_request_id;
100 * Set associated with the operation, NULL until the spec has been associated
110 * Signature of functions that create the implementation-specific
111 * state for a set supporting a specific operation.
113 * @return a set state specific to the supported operation
115 typedef struct SetState *(*CreateImpl) (void);
119 * Signature of functions that implement the add/remove functionality
120 * for a set supporting a specific operation.
122 * @param set implementation-specific set state
123 * @param msg element message from the client
125 typedef void (*AddRemoveImpl) (struct SetState *state, struct ElementEntry *ee);
129 * Signature of functions that handle disconnection
130 * of the remote peer.
132 * @param op the set operation, contains implementation-specific data
134 typedef void (*PeerDisconnectImpl) (struct OperationState *op);
138 * Signature of functions that implement the destruction of the
139 * implementation-specific set state.
141 * @param state the set state, contains implementation-specific data
143 typedef void (*DestroySetImpl) (struct SetState *state);
147 * Signature of functions that implement the creation of set operations
148 * (currently evaluate and accept).
150 * @param spec specification of the set operation to be created
151 * @param tunnel the tunnel with the other peer
152 * @param tc tunnel context
154 typedef void (*OpCreateImpl) (struct OperationSpecification *spec,
155 struct GNUNET_MESH_Tunnel *tunnel,
156 struct TunnelContext *tc);
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 OperationState *op,
169 const struct GNUNET_MessageHeader *msg);
171 typedef void (*CancelImpl) (struct SetState *set,
172 uint32_t request_id);
176 * Signature of functions that implement sending all the set's
177 * elements to the client.
179 * @param set set that should be iterated over
181 typedef void (*IterateImpl) (struct Set *set);
185 * Dispatch table for a specific set operation.
186 * Every set operation has to implement the callback
192 * Callback for the set creation.
197 * Callback for element insertion
202 * Callback for element removal.
204 AddRemoveImpl remove;
207 * Callback for accepting a set operation request
212 * Callback for starting evaluation with a remote peer.
214 OpCreateImpl evaluate;
217 * Callback for destruction of the set state.
219 DestroySetImpl destroy_set;
222 * Callback for handling operation-specific messages.
224 MsgHandlerImpl msg_handler;
227 * Callback for handling the remote peer's
230 PeerDisconnectImpl peer_disconnect;
233 * Callback for canceling an operation by
239 * Callback for iterating over all set elements.
246 * Information about an element element in the set.
247 * All elements are stored in a hash-table
248 * from their hash-code to their 'struct Element',
249 * so that the remove and add operations are reasonably
255 * The actual element. The data for the element
256 * should be allocated at the end of this struct.
258 struct GNUNET_SET_Element element;
261 * Hash of the element.
262 * Will be used to derive the different IBF keys
263 * for different salts.
265 struct GNUNET_HashCode element_hash;
268 * Generation the element was added by the client.
269 * Operations of earlier generations will not consider the element.
271 unsigned int generation_added;
274 * GNUNET_YES if the element has been removed in some generation.
279 * Generation the element was removed by the client.
280 * Operations of later generations will not consider the element.
281 * Only valid if is_removed is GNUNET_YES.
283 unsigned int generation_removed;
286 * GNUNET_YES if the element is a remote element, and does not belong
287 * to the operation's set.
294 * A set that supports a specific operation
300 * Client that owns the set.
301 * Only one client may own a set.
303 struct GNUNET_SERVER_Client *client;
306 * Message queue for the client
308 struct GNUNET_MQ_Handle *client_mq;
311 * Type of operation supported for this set
313 enum GNUNET_SET_OperationType operation;
316 * Virtual table for this set.
317 * Determined by the operation type of this set.
319 const struct SetVT *vt;
322 * Sets are held in a doubly linked list.
327 * Sets are held in a doubly linked list.
332 * Implementation-specific state.
334 struct SetState *state;
337 * Current state of iterating elements for the client.
338 * NULL if we are not currently iterating.
340 struct GNUNET_CONTAINER_MultiHashMapIterator *iter;
343 * Maps 'struct GNUNET_HashCode' to 'struct ElementEntry'.
345 struct GNUNET_CONTAINER_MultiHashMap *elements;
348 * Current generation, that is, number of
349 * previously executed operations on this set
351 unsigned int current_generation;
356 * Information about a tunnel we are connected to.
357 * Used as tunnel context with mesh.
362 * V-Table for the operation belonging
363 * to the tunnel contest.
365 const struct SetVT *vt;
368 * Implementation-specific operation state.
370 struct OperationState *op;
375 * Get the table with implementing functions for
379 _GSS_union_vt (void);