a5a53671c4e02d98e0656336566696d7d3b5b3da
[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_stream_lib.h"
37 #include "gnunet_set_service.h"
38 #include "set.h"
39 #include "mq.h"
40
41
42 /* FIXME: cfuchs */
43 struct IntersectionState;
44
45
46 /**
47  * Extra state required for set union.
48  */
49 struct UnionState;
50
51
52 /**
53  * A set that supports a specific operation
54  * with other peers.
55  */
56 struct Set
57 {
58   /**
59    * Client that owns the set.
60    * Only one client may own a set.
61    */
62   struct GNUNET_SERVER_Client *client;
63
64   /**
65    * Message queue for the client
66    */
67   struct GNUNET_MQ_MessageQueue *client_mq;
68
69   /**
70    * Type of operation supported for this set
71    */
72   uint32_t operation; // use enum from API
73
74   /**
75    * Sets are held in a doubly linked list.
76    */
77   struct Set *next;
78
79   /**
80    * Sets are held in a doubly linked list.
81    */
82   struct Set *prev;
83
84   /**
85    * Appropriate state for each type of
86    * operation.
87    */
88   union {
89     struct IntersectionState *i;
90     struct UnionState *u;
91   } state;
92 };
93
94
95 /**
96  * A listener is inhabited by a client, and
97  * waits for evaluation requests from remote peers.
98  */
99 struct Listener
100 {
101   /**
102    * Listeners are held in a doubly linked list.
103    */
104   struct Listener *next;
105
106   /**
107    * Listeners are held in a doubly linked list.
108    */
109   struct Listener *prev;
110
111   /**
112    * Client that owns the set.
113    * Only one client may own a set.
114    */
115   struct GNUNET_SERVER_Client *client;
116
117   /**
118    * Message queue for the client
119    */
120   struct GNUNET_MQ_MessageQueue *client_mq;
121
122   /**
123    * Type of operation supported for this set
124    */
125   enum GNUNET_SET_OperationType operation;
126
127   /**
128    * Application id of intereset for this listener.
129    */
130   struct GNUNET_HashCode app_id;
131 };
132
133
134 /**
135  * Peer that has connected to us, but is not yet evaluating a set operation.
136  * Once the peer has sent a request, and the client has
137  * accepted or rejected it, this information will be deleted.
138  */
139 struct Incoming
140 {
141   /**
142    * Incoming peers are held in a linked list
143    */
144   struct Incoming *next;
145
146   /**
147    * Incoming peers are held in a linked list
148    */
149   struct Incoming *prev;
150
151   /**
152    * Identity of the peer that connected to us
153    */
154   struct GNUNET_PeerIdentity peer;
155
156   /**
157    * Socket connected to the peer
158    */
159   struct GNUNET_STREAM_Socket *socket;
160
161   /**
162    * Message queue for the peer
163    */
164   struct GNUNET_MQ_MessageQueue *mq;
165
166   /**
167    * App code, set once the peer has
168    * requested an operation
169    */
170   struct GNUNET_HashCode app_id;
171
172   /**
173    * Context message, set once the peer
174    * has requested an operation.
175    */
176   struct GNUNET_MessageHeader *context_msg;
177
178   /**
179    * Salt the peer has requested to use for the
180    * operation
181    */
182   uint16_t salt;
183
184   /**
185    * Operation the other peer wants to do
186    */
187   enum GNUNET_SET_OperationType operation;
188
189   /**
190    * Unique request id for the request from
191    * a remote peer.
192    */
193   uint32_t request_id;
194 };
195
196
197 /**
198  * Configuration of the local peer
199  */
200 extern const struct GNUNET_CONFIGURATION_Handle *configuration;
201
202
203 /**
204  * Disconnect a client and free all resources
205  * that the client allocated (e.g. Sets or Listeners)
206  *
207  * @param client the client to disconnect
208  */
209 void
210 _GSS_client_disconnect (struct GNUNET_SERVER_Client *client);
211
212
213 /**
214  * Create a new set supporting the union operation
215  *
216  * @return the newly created set
217  */
218 struct Set *
219 _GSS_union_set_create (void);
220
221
222 /**
223  * Evaluate a union operation with
224  * a remote peer.
225  *
226  * @param m the evaluate request message from the client
227  * @parem set the set to evaluate the operation with
228  */
229 void
230 _GSS_union_evaluate (struct EvaluateMessage *m, struct Set *set);
231
232
233 /**
234  * Add the element from the given element message to the set.
235  *
236  * @param m message with the element
237  * @param set set to add the element to
238  */
239 void
240 _GSS_union_add (struct ElementMessage *m, struct Set *set);
241
242
243 /**
244  * Remove the element given in the element message from the set.
245  * Only marks the element as removed, so that older set operations can still exchange it.
246  *
247  * @param m message with the element
248  * @param set set to remove the element from
249  */
250 void
251 _GSS_union_remove (struct ElementMessage *m, struct Set *set);
252
253
254 /**
255  * Accept an union operation request from a remote peer
256  *
257  * @param m the accept message from the client
258  * @param set the set of the client
259  * @param incoming information about the requesting remote peer
260  */
261 void
262 _GSS_union_accept (struct AcceptMessage *m, struct Set *set,
263                    struct Incoming *incoming);
264
265
266 #endif