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_mesh2_service.h"
37 #include "gnunet_set_service.h"
42 struct IntersectionState;
46 struct IntersectionOperation;
50 * Extra state required for set union.
55 * State of a union operation being evaluated.
57 struct UnionEvaluateOperation;
62 * A set that supports a specific operation
68 * Client that owns the set.
69 * Only one client may own a set.
71 struct GNUNET_SERVER_Client *client;
74 * Message queue for the client
76 struct GNUNET_MQ_Handle *client_mq;
79 * Type of operation supported for this set
81 uint32_t operation; // use enum from API
84 * Sets are held in a doubly linked list.
89 * Sets are held in a doubly linked list.
94 * Appropriate state for each type of
98 struct IntersectionState *i;
105 * Detail information about an operation.
107 struct OperationSpecification
110 * The type of the operation.
112 enum GNUNET_SET_OperationType operation;
115 * The remove peer we evaluate the operation with
117 struct GNUNET_PeerIdentity peer;
120 * Application ID for the operation, used to distinguish
121 * multiple operations of the same type with the same peer.
123 struct GNUNET_HashCode app_id;
126 * Context message, may be NULL.
128 struct GNUNET_MessageHeader *context_msg;
131 * Salt to use for the operation.
136 * ID used to identify responses to a client.
138 uint32_t client_request_id;
141 * Set associated with the operation, NULL until the spec has been associated
149 * A listener is inhabited by a client, and
150 * waits for evaluation requests from remote peers.
155 * Listeners are held in a doubly linked list.
157 struct Listener *next;
160 * Listeners are held in a doubly linked list.
162 struct Listener *prev;
165 * Client that owns the listener.
166 * Only one client may own a listener.
168 struct GNUNET_SERVER_Client *client;
171 * Message queue for the client
173 struct GNUNET_MQ_Handle *client_mq;
176 * The type of the operation.
178 enum GNUNET_SET_OperationType operation;
181 * Application ID for the operation, used to distinguish
182 * multiple operations of the same type with the same peer.
184 struct GNUNET_HashCode app_id;
189 * Peer that has connected to us, but is not yet evaluating a set operation.
190 * Once the peer has sent a request, and the client has
191 * accepted or rejected it, this information will be deleted.
197 * Different types a tunnel can be.
199 enum TunnelContextType {
201 * Tunnel is waiting for a set request from the tunnel,
202 * or for the ack/nack of the client for a received request.
207 * The tunnel performs a union operation.
209 CONTEXT_OPERATION_UNION,
212 * The tunnel performs an intersection operation.
214 CONTEXT_OPERATION_INTERSECTION,
219 * State associated with the tunnel, dependent on
222 union TunnelContextData
225 * Valid for tag 'CONTEXT_INCOMING'
227 struct Incoming *incoming;
230 * Valid for tag 'CONTEXT_OPERATION_UNION'
232 struct UnionEvaluateOperation *union_op;
235 * Valid for tag 'CONTEXT_OPERATION_INTERSECTION'
237 struct IntersectionEvaluateOperation *intersection_op;
241 * Information about a tunnel we are connected to.
242 * Used as tunnel context with mesh.
247 * Type of the tunnel.
249 enum TunnelContextType type;
252 * State associated with the tunnel, dependent on
255 union TunnelContextData data;
261 * Configuration of the local peer.
263 extern const struct GNUNET_CONFIGURATION_Handle *configuration;
266 * Handle to the mesh service.
268 extern struct GNUNET_MESH_Handle *mesh;
272 * Create a new set supporting the union operation
274 * @return the newly created set
277 _GSS_union_set_create (void);
281 * Evaluate a union operation with
284 * @param spec specification of the operation the evaluate
285 * @param tunnel tunnel already connected to the partner peer
286 * @return a handle to the operation
288 struct UnionEvaluateOperation *
289 _GSS_union_evaluate (struct OperationSpecification *spec,
290 struct GNUNET_MESH_Tunnel *tunnel);
294 * Add the element from the given element message to the set.
296 * @param m message with the element
297 * @param set set to add the element to
300 _GSS_union_add (struct GNUNET_SET_ElementMessage *m, struct Set *set);
304 * Remove the element given in the element message from the set.
305 * Only marks the element as removed, so that older set operations can still exchange it.
307 * @param m message with the element
308 * @param set set to remove the element from
311 _GSS_union_remove (struct GNUNET_SET_ElementMessage *m, struct Set *set);
315 * Destroy a set that supports the union operation
317 * @param set the set to destroy, must be of type GNUNET_SET_OPERATION_UNION
320 _GSS_union_set_destroy (struct Set *set);
324 * Accept an union operation request from a remote peer
326 * @param spec all necessary information about the operation
327 * @param tunnel open tunnel to the partner's peer
330 struct UnionEvaluateOperation *
331 _GSS_union_accept (struct OperationSpecification *spec,
332 struct GNUNET_MESH_Tunnel *tunnel);
336 * Destroy a union operation, and free all resources
337 * associated with it.
339 * @param eo the union operation to destroy
342 _GSS_union_operation_destroy (struct UnionEvaluateOperation *eo);
346 * Dispatch messages for a union operation.
349 * @param tunnel mesh tunnel
350 * @param tunnel_ctx tunnel context
351 * @param mh message to process
352 * @return GNUNET_SYSERR if the tunnel should be disconnected,
353 * GNUNET_OK otherwise
356 _GSS_union_handle_p2p_message (void *cls,
357 struct GNUNET_MESH_Tunnel *tunnel,
359 const struct GNUNET_MessageHeader *mh);