clean up internal set API, avoid copying context message needlessly
[oweals/gnunet.git] / src / set / set.h
1 /*
2      This file is part of GNUnet.
3      (C) 2012, 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 3, 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  * @file set/set.h
22  * @brief messages used for the set api
23  * @author Florian Dold
24  * @author Christian Grothoff
25  */
26 #ifndef SET_H
27 #define SET_H
28
29 #include "platform.h"
30 #include "gnunet_common.h"
31
32 /**
33  * FIXME
34  */
35 #define GNUNET_SET_ACK_WINDOW 10
36
37
38 GNUNET_NETWORK_STRUCT_BEGIN
39
40 /**
41  * Message sent by the client to the service to ask starting
42  * a new set to perform operations with.  Includes the desired
43  * set operation type.
44  */
45 struct GNUNET_SET_CreateMessage
46 {
47   /**
48    * Type: #GNUNET_MESSAGE_TYPE_SET_CREATE
49    */
50   struct GNUNET_MessageHeader header;
51
52   /**
53    * Operation type, values of `enum GNUNET_SET_OperationType`
54    */
55   uint32_t operation GNUNET_PACKED;
56 };
57
58
59 /**
60  * Message sent by the client to the service to start listening for
61  * incoming requests to perform a certain type of set operation for a
62  * certain type of application.
63  */
64 struct GNUNET_SET_ListenMessage
65 {
66   /**
67    * Type: #GNUNET_MESSAGE_TYPE_SET_LISTEN
68    */
69   struct GNUNET_MessageHeader header;
70
71   /**
72    * Operation type, values of `enum GNUNET_SET_OperationType`
73    */
74   uint32_t operation GNUNET_PACKED;
75
76   /**
77    * application id
78    */
79   struct GNUNET_HashCode app_id;
80
81 };
82
83
84 /**
85  * Message sent by a listening client to the service to accept
86  * performing the operation with the other peer.
87  */
88 struct GNUNET_SET_AcceptMessage
89 {
90   /**
91    * Type: #GNUNET_MESSAGE_TYPE_SET_ACCEPT
92    */
93   struct GNUNET_MessageHeader header;
94
95   /**
96    * ID of the incoming request we want to accept.
97    */
98   uint32_t accept_reject_id GNUNET_PACKED;
99
100   /**
101    * Request ID to identify responses.
102    */
103   uint32_t request_id GNUNET_PACKED;
104
105   /**
106    * How should results be sent to us?
107    * See `enum GNUNET_SET_ResultMode`.
108    */
109   uint32_t result_mode GNUNET_PACKED;
110 };
111
112
113 /**
114  * Message sent by a listening client to the service to reject
115  * performing the operation with the other peer.
116  */
117 struct GNUNET_SET_RejectMessage
118 {
119   /**
120    * Type: #GNUNET_MESSAGE_TYPE_SET_REJECT
121    */
122   struct GNUNET_MessageHeader header;
123
124   /**
125    * ID of the incoming request we want to reject.
126    */
127   uint32_t accept_reject_id GNUNET_PACKED;
128
129 };
130
131
132 /**
133  * A request for an operation with another client.
134  */
135 struct GNUNET_SET_RequestMessage
136 {
137   /**
138    * Type: #GNUNET_MESSAGE_TYPE_SET_REQUEST.
139    */
140   struct GNUNET_MessageHeader header;
141
142   /**
143    * ID of the to identify the request when accepting or
144    * rejecting it.
145    */
146   uint32_t accept_id GNUNET_PACKED;
147
148   /**
149    * Identity of the requesting peer.
150    */
151   struct GNUNET_PeerIdentity peer_id;
152
153   /* rest: context message, that is, application-specific
154      message to convince listener to pick up */
155 };
156
157
158 /**
159  * Message sent by client to service to initiate a set operation as a
160  * client (not as listener).  A set (which determines the operation
161  * type) must already exist in association with this client.
162  */
163 struct GNUNET_SET_EvaluateMessage
164 {
165   /**
166    * Type: #GNUNET_MESSAGE_TYPE_SET_EVALUATE
167    */
168   struct GNUNET_MessageHeader header;
169
170   /**
171    * How should results be sent to us?
172    * See `enum GNUNET_SET_ResultMode`.
173    */
174   uint32_t result_mode GNUNET_PACKED;
175
176   /**
177    * Peer to evaluate the operation with
178    */
179   struct GNUNET_PeerIdentity target_peer;
180
181   /**
182    * Application id
183    */
184   struct GNUNET_HashCode app_id;
185
186   /**
187    * Id of our set to evaluate, chosen implicitly by the client when it
188    * calls #GNUNE_SET_commit().
189    */
190   uint32_t request_id GNUNET_PACKED;
191
192   /* rest: context message, that is, application-specific
193      message to convince listener to pick up */
194 };
195
196
197 struct GNUNET_SET_ResultMessage
198 {
199   /**
200    * Type: #GNUNET_MESSAGE_TYPE_SET_RESULT
201    */
202   struct GNUNET_MessageHeader header;
203
204   /**
205    * id the result belongs to
206    */
207   uint32_t request_id GNUNET_PACKED;
208
209   /**
210    * Was the evaluation successful?
211    */
212   uint16_t result_status GNUNET_PACKED;
213
214   /**
215    * Type of the element attachted to the message,
216    * if any.
217    */
218   uint16_t element_type GNUNET_PACKED;
219
220   /* rest: the actual element */
221 };
222
223
224 /**
225  * Message sent by client to the service to add or remove
226  * an element to/from the set.
227  */
228 struct GNUNET_SET_ElementMessage
229 {
230   /**
231    * Type: #GNUNET_MESSAGE_TYPE_SET_ADD or
232    *       #GNUNET_MESSAGE_TYPE_SET_REMOVE
233    */
234   struct GNUNET_MessageHeader header;
235
236   /**
237    * Type of the element to add or remove.
238    */
239   uint16_t element_type GNUNET_PACKED;
240
241   /**
242    * For alignment, always zero.
243    */
244   uint16_t reserved GNUNET_PACKED;
245
246   /* rest: the actual element */
247 };
248
249
250 /**
251  * Sent to the service by the client
252  * in order to cancel a set operation.
253  */
254 struct GNUNET_SET_CancelMessage
255 {
256   /**
257    * Type: #GNUNET_MESSAGE_TYPE_SET_CANCEL
258    */
259   struct GNUNET_MessageHeader header;
260
261   /**
262    * ID of the request we want to cancel.
263    */
264   uint32_t request_id GNUNET_PACKED;
265 };
266
267
268 struct GNUNET_SET_IterResponseMessage
269 {
270   /**
271    * Type: #GNUNET_MESSAGE_TYPE_SET_ITER_RESPONSE
272    */
273   struct GNUNET_MessageHeader header;
274
275   /**
276    * Type of the element attachted to the message,
277    * if any.
278    */
279   uint16_t element_type GNUNET_PACKED;
280
281   /* rest: element */
282 };
283
284 struct GNUNET_SET_IterAckMessage
285 {
286   /**
287    * Type: #GNUNET_MESSAGE_TYPE_SET_ITER_ACK
288    */
289   struct GNUNET_MessageHeader header;
290
291   /**
292    * Non-zero if the service should continue sending elements.
293    */
294   uint32_t send_more;
295 };
296
297 GNUNET_NETWORK_STRUCT_END
298
299 #endif