work on gnunet-set, isolated bug in stream
[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; // use enum from API
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   } state;
90 };
91
92
93 struct Listener
94 {
95   /**
96    * Listeners are held in a doubly linked list.
97    */
98   struct Listener *next;
99
100   /**
101    * Listeners are held in a doubly linked list.
102    */
103   struct Listener *prev;
104
105   /**
106    * Client that owns the set.
107    * Only one client may own a set.
108    */
109   struct GNUNET_SERVER_Client *client;
110
111   /**
112    * Message queue for the client
113    */
114   struct GNUNET_MQ_MessageQueue *client_mq;
115
116   /**
117    * Type of operation supported for this set
118    */
119   enum GNUNET_SET_OperationType operation;
120
121   /**
122    * Application id of intereset for this listener.
123    */
124   struct GNUNET_HashCode app_id;
125 };
126
127
128 /**
129  * Peer that has connected to us, but is not yet evaluating a set operation.
130  * Once the peer has sent a request, and the client has
131  * accepted or rejected it, this information will be deleted.
132  */
133 struct Incoming
134 {
135   /**
136    * Incoming peers are held in a linked list
137    */
138   struct Incoming *next;
139
140   /**
141    * Incoming peers are held in a linked list
142    */
143   struct Incoming *prev;
144
145   /**
146    * Identity of the peer that connected to us
147    */
148   struct GNUNET_PeerIdentity peer;
149
150   /**
151    * Socket connected to the peer
152    */
153   struct GNUNET_STREAM_Socket *socket;
154
155   /**
156    * Message queue for the peer
157    */
158   struct GNUNET_MQ_MessageQueue *mq;
159
160   /**
161    * App code, set once the peer has
162    * requested an operation
163    */
164   struct GNUNET_HashCode app_id;
165
166   /**
167    * Context message, set once the peer
168    * has requested an operation.
169    */
170   struct GNUNET_MessageHeader *context_msg;
171
172   /**
173    * Salt the peer has requested to use for the
174    * operation
175    */
176   uint16_t salt;
177
178   /**
179    * Operation the other peer wants to do
180    */
181   enum GNUNET_SET_OperationType operation;
182
183   /**
184    * Request id associated with the
185    * request coming from this client
186    */
187   uint32_t request_id;
188 };
189
190
191 /**
192  * Configuration of the local peer
193  */
194 extern const struct GNUNET_CONFIGURATION_Handle *configuration;
195
196
197 /**
198  * Disconnect a client and free all resources
199  * that the client allocated (e.g. Sets or Listeners)
200  *
201  * @param client the client to disconnect
202  */
203 void
204 _GSS_client_disconnect (struct GNUNET_SERVER_Client *client);
205
206
207 struct Set *
208 _GSS_union_set_create (void);
209
210
211 void
212 _GSS_union_evaluate (struct EvaluateMessage *m, struct Set *set);
213
214
215 void
216 _GSS_union_add (struct ElementMessage *m, struct Set *set);
217
218
219 void
220 _GSS_union_accept (struct AcceptMessage *m, struct Set *set,
221                    struct Incoming *incoming);
222
223
224 #endif