forgot to commit new files
[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  * @brief common stuff for the set service
23  */
24
25 #ifndef GNUNET_SERVICE_SET_H_PRIVATE
26 #define GNUNET_SERVICE_SET_H_PRIVATE
27
28 #include "platform.h"
29 #include "gnunet_common.h"
30 #include "gnunet_protocols.h"
31 #include "gnunet_applications.h"
32 #include "gnunet_util_lib.h"
33 #include "gnunet_core_service.h"
34 #include "gnunet_stream_lib.h"
35 #include "gnunet_set_service.h"
36 #include "set.h"
37 #include "mq.h"
38
39
40 /* FIXME: cfuchs */
41 struct IntersectionState;
42
43
44 /**
45  * Extra state required for set union.
46  */
47 struct UnionState;
48
49
50 /**
51  * A set that supports a specific operation
52  * with other peers.
53  */
54 struct Set
55 {
56   /**
57    * Client that owns the set.
58    * Only one client may own a set.
59    */
60   struct GNUNET_SERVER_Client *client;
61
62   /**
63    * Message queue for the client
64    */
65   struct GNUNET_MQ_MessageQueue *client_mq;
66
67   /**
68    * Type of operation supported for this set
69    */
70   uint32_t operation;
71
72   /**
73    * Sets are held in a doubly linked list.
74    */
75   struct Set *next;
76
77   /**
78    * Sets are held in a doubly linked list.
79    */
80   struct Set *prev;
81
82   /**
83    * Appropriate state for each type of
84    * operation.
85    */
86   union {
87     struct IntersectionState *i;
88     struct UnionState *u;
89   } extra;
90 };
91
92
93 /**
94  * State for an evaluate operation for a set that
95  * supports set union.
96  */
97 struct UnionEvaluateOperation;
98
99
100 /* FIXME: cfuchs */
101 struct IntersectionEvaluateOperation
102 {
103   /* FIXME: cfuchs */
104 };
105
106
107 /**
108  * State of evaluation a set operation with
109  * another peer
110  */
111 struct EvaluateOperation
112 {
113   /**
114    * Local set the operation is evaluated on
115    */
116   struct Set *set;
117
118   /**
119    * Peer with the remote set
120    */
121   struct GNUNET_PeerIdentity peer;
122
123   /**
124    * Application-specific identifier
125    */
126   struct GNUNET_HashCode app_id;
127
128   /**
129    * Context message, given to us
130    * by the client, may be NULL.
131    */
132   struct GNUNET_MessageHeader *context_msg;
133
134   /**
135    * Stream socket connected to the other peer
136    */
137   struct GNUNET_STREAM_Socket *socket;
138
139   /**
140    * Message queue for the peer on the other
141    * end
142    */
143   struct GNUNET_MQ_MessageQueue *mq;
144
145   /**
146    * Type of this operation
147    */
148   enum GNUNET_SET_OperationType operation;
149
150   /**
151    * GNUNET_YES if we started the operation,
152    * GNUNET_NO if the other peer started it.
153    */
154   int is_outgoing;
155
156   /**
157    * Request id, so we can use one client handle
158    * for multiple operations
159    */
160   uint32_t request_id;
161
162   union {
163     struct UnionEvaluateOperation *u;
164     struct IntersectionEvaluateOperation *i;
165   } extra;
166 };
167
168
169 struct Listener
170 {
171   /**
172    * Listeners are held in a doubly linked list.
173    */
174   struct Listener *next;
175
176   /**
177    * Listeners are held in a doubly linked list.
178    */
179   struct Listener *prev;
180
181   /**
182    * Client that owns the set.
183    * Only one client may own a set.
184    */
185   struct GNUNET_SERVER_Client *client;
186
187   /**
188    * Message queue for the client
189    */
190   struct GNUNET_MQ_MessageQueue *client_mq;
191
192   /**
193    * Type of operation supported for this set
194    */
195   enum GNUNET_SET_OperationType operation;
196
197   /**
198    * Application id of intereset for this listener.
199    */
200   struct GNUNET_HashCode app_id;
201 };
202
203
204 /**
205  * Peer that has connected to us, but is not yet evaluating a set operation.
206  * Once the peer has sent a request, and the client has
207  * accepted or rejected it, this information will be deleted.
208  */
209 struct Incoming
210 {
211   /**
212    * Incoming peers are held in a linked list
213    */
214   struct Incoming *next;
215
216   /**
217    * Incoming peers are held in a linked list
218    */
219   struct Incoming *prev;
220
221   /**
222    * Identity of the peer that connected to us
223    */
224   struct GNUNET_PeerIdentity peer;
225
226   /**
227    * Socket connected to the peer
228    */
229   struct GNUNET_STREAM_Socket *socket;
230
231   /**
232    * Message queue for the peer
233    */
234   struct GNUNET_MQ_MessageQueue *mq;
235
236   /**
237    * App code, set once the peer has
238    * requested an operation
239    */
240   struct GNUNET_HashCode app_id;
241
242   /**
243    * Context message, set once the peer
244    * has requested an operation.
245    */
246   struct GNUNET_MessageHeader *context_msg;
247
248   /**
249    * Operation the other peer wants to do
250    */
251   enum GNUNET_SET_OperationType operation;
252
253   /**
254    * Request id associated with the
255    * request coming from this client
256    */
257   uint32_t request_id;
258 };
259
260
261 /**
262  * Configuration of the local peer
263  */
264 extern const struct GNUNET_CONFIGURATION_Handle *configuration;
265
266
267 /**
268  * Disconnect a client and free all resources
269  * that the client allocated (e.g. Sets or Listeners)
270  *
271  * @param client the client to disconnect
272  */
273 void
274 client_disconnect (struct GNUNET_SERVER_Client *client);
275
276
277 struct Set *
278 union_set_create ();
279
280
281 void
282 union_evaluate (struct EvaluateOperation *eo);
283
284
285 void
286 union_add (struct Set *set, struct ElementMessage *m);
287
288
289 void
290 union_accept (struct EvaluateOperation *eo, struct Incoming *incoming);
291
292
293 #endif