doxygen
[oweals/gnunet.git] / src / set / gnunet-service-set.h
1 /*
2       This file is part of GNUnet
3       (C) 2013 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @file set/gnunet-service-set.h
23  * @brief common components for the implementation the different set operations
24  * @author Florian Dold
25  */
26
27 #ifndef GNUNET_SERVICE_SET_H_PRIVATE
28 #define GNUNET_SERVICE_SET_H_PRIVATE
29
30 #include "platform.h"
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"
38 #include "set.h"
39
40
41 /* FIXME: cfuchs */
42 struct IntersectionState;
43
44
45 /* FIXME: cfuchs */
46 struct IntersectionOperation;
47
48
49 /**
50  * Extra state required for set union.
51  */
52 struct UnionState;
53
54 /**
55  * State of a union operation being evaluated.
56  */
57 struct UnionEvaluateOperation;
58
59
60
61 /**
62  * A set that supports a specific operation
63  * with other peers.
64  */
65 struct Set
66 {
67   /**
68    * Client that owns the set.
69    * Only one client may own a set.
70    */
71   struct GNUNET_SERVER_Client *client;
72
73   /**
74    * Message queue for the client
75    */
76   struct GNUNET_MQ_Handle *client_mq;
77
78   /**
79    * Type of operation supported for this set
80    */
81   uint32_t operation; // use enum from API
82
83   /**
84    * Sets are held in a doubly linked list.
85    */
86   struct Set *next;
87
88   /**
89    * Sets are held in a doubly linked list.
90    */
91   struct Set *prev;
92
93   /**
94    * Appropriate state for each type of
95    * operation.
96    */
97   union {
98     struct IntersectionState *i;
99     struct UnionState *u;
100   } state;
101 };
102
103
104 /**
105  * Detail information about an operation.
106  */
107 struct OperationSpecification
108 {
109   /**
110    * The type of the operation.
111    */
112   enum GNUNET_SET_OperationType operation;
113
114   /**
115    * The remove peer we evaluate the operation with
116    */
117   struct GNUNET_PeerIdentity peer;
118
119   /**
120    * Application ID for the operation, used to distinguish
121    * multiple operations of the same type with the same peer.
122    */
123   struct GNUNET_HashCode app_id;
124
125   /**
126    * Context message, may be NULL.
127    */
128   struct GNUNET_MessageHeader *context_msg;
129
130   /**
131    * Salt to use for the operation.
132    */
133   uint32_t salt;
134
135   /**
136    * ID used to identify responses to a client.
137    */
138   uint32_t client_request_id;
139
140   /**
141    * Set associated with the operation, NULL until the spec has been associated
142    * with a set.
143    */
144   struct Set *set;
145 };
146
147
148 /**
149  * A listener is inhabited by a client, and
150  * waits for evaluation requests from remote peers.
151  */
152 struct Listener
153 {
154   /**
155    * Listeners are held in a doubly linked list.
156    */
157   struct Listener *next;
158
159   /**
160    * Listeners are held in a doubly linked list.
161    */
162   struct Listener *prev;
163
164   /**
165    * Client that owns the listener.
166    * Only one client may own a listener.
167    */
168   struct GNUNET_SERVER_Client *client;
169
170   /**
171    * Message queue for the client
172    */
173   struct GNUNET_MQ_Handle *client_mq;
174
175   /**
176    * The type of the operation.
177    */
178   enum GNUNET_SET_OperationType operation;
179
180   /**
181    * Application ID for the operation, used to distinguish
182    * multiple operations of the same type with the same peer.
183    */
184   struct GNUNET_HashCode app_id;
185 };
186
187
188 /**
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.
192  */
193 struct Incoming;
194
195
196 /**
197  * Different types a tunnel can be.
198  */
199 enum TunnelContextType {
200   /**
201    * Tunnel is waiting for a set request from the tunnel,
202    * or for the ack/nack of the client for a received request.
203    */
204   CONTEXT_INCOMING,
205
206   /**
207    * The tunnel performs a union operation.
208    */
209   CONTEXT_OPERATION_UNION,
210
211   /**
212    * The tunnel performs an intersection operation.
213    */
214   CONTEXT_OPERATION_INTERSECTION,
215 };
216
217
218 /**
219  * State associated with the tunnel, dependent on
220  * tunnel type.
221  */
222 union TunnelContextData
223 {
224   /**
225    * Valid for tag 'CONTEXT_INCOMING'
226    */
227   struct Incoming *incoming;
228
229   /**
230    * Valid for tag 'CONTEXT_OPERATION_UNION'
231    */
232   struct UnionEvaluateOperation *union_op;
233
234   /**
235    * Valid for tag 'CONTEXT_OPERATION_INTERSECTION'
236    */
237   struct IntersectionEvaluateOperation *intersection_op;
238 };
239
240 /**
241  * Information about a tunnel we are connected to.
242  * Used as tunnel context with mesh.
243  */
244 struct TunnelContext
245 {
246   /**
247    * Type of the tunnel.
248    */
249   enum TunnelContextType type;
250
251   /**
252    * State associated with the tunnel, dependent on
253    * tunnel type.
254    */
255   union TunnelContextData data;
256 };
257
258
259
260 /**
261  * Configuration of the local peer
262  */
263 extern const struct GNUNET_CONFIGURATION_Handle *configuration;
264
265 extern struct GNUNET_MESH_Handle *mesh;
266
267
268 /**
269  * Create a new set supporting the union operation
270  *
271  * @return the newly created set
272  */
273 struct Set *
274 _GSS_union_set_create (void);
275
276
277 /**
278  * Evaluate a union operation with
279  * a remote peer.
280  *
281  * @param spec specification of the operation the evaluate
282  * @param tunnel tunnel already connected to the partner peer
283  * @return a handle to the operation
284  */
285 struct UnionEvaluateOperation *
286 _GSS_union_evaluate (struct OperationSpecification *spec,
287                      struct GNUNET_MESH_Tunnel *tunnel);
288
289
290 /**
291  * Add the element from the given element message to the set.
292  *
293  * @param m message with the element
294  * @param set set to add the element to
295  */
296 void
297 _GSS_union_add (struct GNUNET_SET_ElementMessage *m, struct Set *set);
298
299
300 /**
301  * Remove the element given in the element message from the set.
302  * Only marks the element as removed, so that older set operations can still exchange it.
303  *
304  * @param m message with the element
305  * @param set set to remove the element from
306  */
307 void
308 _GSS_union_remove (struct GNUNET_SET_ElementMessage *m, struct Set *set);
309
310
311 /**
312  * Destroy a set that supports the union operation
313  *
314  * @param set the set to destroy, must be of type GNUNET_SET_OPERATION_UNION
315  */
316 void
317 _GSS_union_set_destroy (struct Set *set);
318
319
320 /**
321  * Accept an union operation request from a remote peer
322  *
323  * @param spec all necessary information about the operation
324  * @param tunnel open tunnel to the partner's peer
325  * @return operation
326  */
327 struct UnionEvaluateOperation *
328 _GSS_union_accept (struct OperationSpecification *spec,
329                    struct GNUNET_MESH_Tunnel *tunnel);
330
331
332 /**
333  * Destroy a union operation, and free all resources
334  * associated with it.
335  *
336  * @param eo the union operation to destroy
337  */
338 void
339 _GSS_union_operation_destroy (struct UnionEvaluateOperation *eo);
340
341
342 /**
343  * Dispatch messages for a union operation.
344  *
345  * @param cls closure
346  * @param tunnel mesh tunnel
347  * @param tunnel_ctx tunnel context
348  * @param mh message to process
349  * @return ???
350  */
351 int
352 _GSS_union_handle_p2p_message (void *cls,
353                                struct GNUNET_MESH_Tunnel *tunnel,
354                                void **tunnel_ctx,
355                                const struct GNUNET_MessageHeader *mh);
356
357
358 #endif