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