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 * Extra state required for set union.
50 struct UnionEvaluateOperation;
54 * A set that supports a specific operation
60 * Client that owns the set.
61 * Only one client may own a set.
63 struct GNUNET_SERVER_Client *client;
66 * Message queue for the client
68 struct GNUNET_MQ_Handle *client_mq;
71 * Type of operation supported for this set
73 uint32_t operation; // use enum from API
76 * Sets are held in a doubly linked list.
81 * Sets are held in a doubly linked list.
86 * Appropriate state for each type of
90 struct IntersectionState *i;
97 * A listener is inhabited by a client, and
98 * waits for evaluation requests from remote peers.
103 * Listeners are held in a doubly linked list.
105 struct Listener *next;
108 * Listeners are held in a doubly linked list.
110 struct Listener *prev;
113 * Client that owns the listener.
114 * Only one client may own a listener.
116 struct GNUNET_SERVER_Client *client;
119 * Message queue for the client
121 struct GNUNET_MQ_Handle *client_mq;
124 * Type of operation supported for this set
126 enum GNUNET_SET_OperationType operation;
129 * Application id of intereset for this listener.
131 struct GNUNET_HashCode app_id;
136 * Peer that has connected to us, but is not yet evaluating a set operation.
137 * Once the peer has sent a request, and the client has
138 * accepted or rejected it, this information will be deleted.
143 * Incoming peers are held in a linked list
145 struct Incoming *next;
148 * Incoming peers are held in a linked list
150 struct Incoming *prev;
153 * Tunnel context, stores information about
154 * the tunnel and its peer.
156 struct TunnelContext *tc;
159 * GNUNET_YES if the incoming peer has sent
160 * an operation request (and we are waiting
161 * for the client to ack/nack), GNUNET_NO otherwise.
163 int received_request;
166 * App code, set once the peer has
167 * requested an operation
169 struct GNUNET_HashCode app_id;
172 * Context message, set once the peer
173 * has requested an operation.
175 struct GNUNET_MessageHeader *context_msg;
178 * Salt the peer has requested to use for the
184 * Operation the other peer wants to do
186 enum GNUNET_SET_OperationType operation;
189 * Unique request id for the request from
190 * a remote peer, sent to the client, which will
191 * accept or reject the request.
197 enum TunnelContextType {
199 CONTEXT_OPERATION_UNION,
200 CONTEXT_OPERATION_INTERSECTION,
204 * Information about a tunnel we are connected to.
205 * Used as tunnel context with mesh.
210 * The mesh tunnel that has this context
212 struct GNUNET_MESH_Tunnel *tunnel;
215 * The peer on the other side.
217 struct GNUNET_PeerIdentity peer;
220 * Handle to the message queue for the tunnel.
222 struct GNUNET_MQ_Handle *mq;
225 * Type of the tunnel.
227 enum TunnelContextType type;
230 * State associated with the tunnel, dependent on
239 * Configuration of the local peer
241 extern const struct GNUNET_CONFIGURATION_Handle *configuration;
243 extern struct GNUNET_MESH_Handle *mesh;
247 * Create a new set supporting the union operation
249 * @return the newly created set
252 _GSS_union_set_create (void);
256 * Evaluate a union operation with
259 * @param m the evaluate request message from the client
260 * @parem set the set to evaluate the operation with
263 _GSS_union_evaluate (struct GNUNET_SET_EvaluateMessage *m, struct Set *set);
267 * Add the element from the given element message to the set.
269 * @param m message with the element
270 * @param set set to add the element to
273 _GSS_union_add (struct GNUNET_SET_ElementMessage *m, struct Set *set);
277 * Remove the element given in the element message from the set.
278 * Only marks the element as removed, so that older set operations can still exchange it.
280 * @param m message with the element
281 * @param set set to remove the element from
284 _GSS_union_remove (struct GNUNET_SET_ElementMessage *m, struct Set *set);
288 * Destroy a set that supports the union operation
290 * @param the set to destroy, must be of type GNUNET_SET_OPERATION_UNION
293 _GSS_union_set_destroy (struct Set *set);
297 * Accept an union operation request from a remote peer
299 * @param m the accept message from the client
300 * @param set the set of the client
301 * @param incoming information about the requesting remote peer
304 _GSS_union_accept (struct GNUNET_SET_AcceptRejectMessage *m, struct Set *set,
305 struct Incoming *incoming);
309 * Destroy a union operation, and free all resources
310 * associated with it.
312 * @param eo the union operation to destroy
315 _GSS_union_operation_destroy (struct UnionEvaluateOperation *eo);
319 * Dispatch messages for a union operation.
322 * @param tunnel mesh tunnel
323 * @param tunnel_ctx tunnel context
324 * @param mh message to process
328 _GSS_union_handle_p2p_message (void *cls,
329 struct GNUNET_MESH_Tunnel *tunnel,
331 const struct GNUNET_MessageHeader *mh);