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