c3d307e65eab7920e7fb73788c08696bf37ac77c
[oweals/gnunet.git] / src / psycstore / psycstore.h
1 /*
2  * This file is part of GNUnet
3  * Copyright (C) 2013 GNUnet e.V.
4  *
5  * GNUnet is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU Affero General Public License as published
7  * by the Free Software Foundation, either version 3 of the License,
8  * or (at your 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  * Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 /**
20  * @file psycstore/psycstore.h
21  * @brief Common type definitions for the PSYCstore service and API.
22  * @author Gabor X Toth
23  */
24
25 #ifndef GNUNET_PSYCSTORE_H
26 #define GNUNET_PSYCSTORE_H
27
28 #include "gnunet_common.h"
29
30
31 GNUNET_NETWORK_STRUCT_BEGIN
32
33 /**
34  * Answer from service to client about last operation.
35  */
36 struct OperationResult
37 {
38   /**
39    * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE
40    */
41   struct GNUNET_MessageHeader header;
42
43   uint32_t reserved GNUNET_PACKED;
44
45   /**
46    * Operation ID.
47    */
48   uint64_t op_id GNUNET_PACKED;
49
50   /**lowed by
51    * Status code for the operation.
52    */
53   uint64_t result_code GNUNET_PACKED;
54
55   /* followed by 0-terminated error message (on error) */
56
57 };
58
59
60 /**
61  * Answer from service to client about master counters.
62  *
63  * @see GNUNET_PSYCSTORE_counters_get()
64  */
65 struct CountersResult
66 {
67   /**
68    * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS
69    */
70   struct GNUNET_MessageHeader header;
71
72   /**
73    * Status code for the operation:
74    * #GNUNET_OK: success, counter values are returned.
75    * #GNUNET_NO: no message has been sent to the channel yet.
76    * #GNUNET_SYSERR: an error occurred.
77    */
78   uint32_t result_code GNUNET_PACKED;
79
80   /**
81    * Operation ID.
82    */
83   uint64_t op_id GNUNET_PACKED;
84
85   uint64_t max_fragment_id GNUNET_PACKED;
86
87   uint64_t max_message_id GNUNET_PACKED;
88
89   uint64_t max_group_generation GNUNET_PACKED;
90
91   uint64_t max_state_message_id GNUNET_PACKED;
92 };
93
94
95 /**
96  * Answer from service to client containing a message fragment.
97  */
98 struct FragmentResult
99 {
100   /**
101    * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE
102    */
103   struct GNUNET_MessageHeader header;
104
105   uint32_t psycstore_flags GNUNET_PACKED;
106
107   /**
108    * Operation ID.
109    */
110   uint64_t op_id GNUNET_PACKED;
111
112   /* Followed by GNUNET_MULTICAST_MessageHeader */
113 };
114
115
116 /**
117  * Answer from service to client containing a state variable.
118  */
119 struct StateResult
120 {
121   /**
122    * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE
123    */
124   struct GNUNET_MessageHeader header;
125
126   uint16_t name_size GNUNET_PACKED;
127
128   uint16_t reserved GNUNET_PACKED;
129
130   /**
131    * Operation ID.
132    */
133   uint64_t op_id GNUNET_PACKED;
134
135   /* Followed by name and value */
136 };
137
138
139 /**
140  * Generic operation request.
141  */
142 struct OperationRequest
143 {
144   struct GNUNET_MessageHeader header;
145
146   uint32_t reserved GNUNET_PACKED;
147
148   /**
149    * Operation ID.
150    */
151   uint64_t op_id GNUNET_PACKED;
152
153   struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
154 };
155
156
157 /**
158  * @see GNUNET_PSYCSTORE_membership_store()
159  */
160 struct MembershipStoreRequest
161 {
162   /**
163    * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_STORE
164    */
165   struct GNUNET_MessageHeader header;
166
167   uint32_t reserved GNUNET_PACKED;
168
169   /**
170    * Operation ID.
171    */
172   uint64_t op_id GNUNET_PACKED;
173
174   /**
175    * Channel's public key.
176    */
177   struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
178
179   /**
180    * Slave's public key.
181    */
182   struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
183
184   uint64_t announced_at GNUNET_PACKED;
185   uint64_t effective_since GNUNET_PACKED;
186   uint64_t group_generation GNUNET_PACKED;
187   uint8_t did_join;
188 };
189
190
191 /**
192  * @see GNUNET_PSYCSTORE_membership_test()
193  */
194 struct MembershipTestRequest
195 {
196   /**
197    * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_TEST
198    */
199   struct GNUNET_MessageHeader header;
200
201   uint32_t reserved GNUNET_PACKED;
202
203   /**
204    * Operation ID.
205    */
206   uint64_t op_id GNUNET_PACKED;
207
208   /**
209    * Channel's public key.
210    */
211   struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
212
213   /**
214    * Slave's public key.
215    */
216   struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
217
218   uint64_t message_id GNUNET_PACKED;
219
220   uint64_t group_generation GNUNET_PACKED;
221 };
222
223
224 /**
225  * @see GNUNET_PSYCSTORE_fragment_store()
226  */
227 struct FragmentStoreRequest
228 {
229   /**
230    * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_STORE
231    */
232   struct GNUNET_MessageHeader header;
233
234   /**
235    * enum GNUNET_PSYCSTORE_MessageFlags
236    */
237   uint32_t psycstore_flags GNUNET_PACKED;
238
239   /**
240    * Channel's public key.
241    */
242   struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
243
244   /**
245    * Operation ID.
246    */
247   uint64_t op_id;
248
249   /* Followed by fragment */
250 };
251
252
253 /**
254  * @see GNUNET_PSYCSTORE_fragment_get()
255  */
256 struct FragmentGetRequest
257 {
258   /**
259    * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_GET
260    */
261   struct GNUNET_MessageHeader header;
262
263   uint32_t reserved GNUNET_PACKED;
264
265   /**
266    * Operation ID.
267    */
268   uint64_t op_id GNUNET_PACKED;
269
270   /**
271    * Channel's public key.
272    */
273   struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
274
275   /**
276    * Slave's public key.
277    */
278   struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
279
280   /**
281    * First fragment ID to request.
282    */
283   uint64_t first_fragment_id GNUNET_PACKED;
284
285   /**
286    * Last fragment ID to request.
287    */
288   uint64_t last_fragment_id GNUNET_PACKED;
289
290   /**
291    * Maximum number of fragments to retrieve.
292    */
293   uint64_t fragment_limit GNUNET_PACKED;
294
295   /**
296    * Do membership test with @a slave_key before returning fragment?
297    * #GNUNET_YES or #GNUNET_NO
298    */
299   uint8_t do_membership_test;
300 };
301
302
303 /**
304  * @see GNUNET_PSYCSTORE_message_get()
305  */
306 struct MessageGetRequest
307 {
308   /**
309    * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET
310    */
311   struct GNUNET_MessageHeader header;
312
313   uint32_t reserved GNUNET_PACKED;
314
315   /**
316    * Operation ID.
317    */
318   uint64_t op_id GNUNET_PACKED;
319
320   /**
321    * Channel's public key.
322    */
323   struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
324
325   /**
326    * Slave's public key.
327    */
328   struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
329
330   /**
331    * First message ID to request.
332    */
333   uint64_t first_message_id GNUNET_PACKED;
334
335   /**
336    * Last message ID to request.
337    */
338   uint64_t last_message_id GNUNET_PACKED;
339
340   /**
341    * Maximum number of messages to retrieve.
342    */
343   uint64_t message_limit GNUNET_PACKED;
344
345   /**
346    * Maximum number of fragments to retrieve.
347    */
348   uint64_t fragment_limit GNUNET_PACKED;
349
350   /**
351    * Do membership test with @a slave_key before returning fragment?
352    * #GNUNET_YES or #GNUNET_NO
353    */
354   uint8_t do_membership_test;
355
356   /* Followed by method_prefix */
357 };
358
359
360 /**
361  * @see GNUNET_PSYCSTORE_message_get_fragment()
362  */
363 struct MessageGetFragmentRequest
364 {
365   /**
366    * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_FRAGMENT_GET
367    */
368   struct GNUNET_MessageHeader header;
369
370   uint32_t reserved GNUNET_PACKED;
371
372   /**
373    * Operation ID.
374    */
375   uint64_t op_id GNUNET_PACKED;
376
377   /**
378    * Channel's public key.
379    */
380   struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
381
382   /**
383    * Slave's public key.
384    */
385   struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
386
387   /**
388    * Requested message ID.
389    */
390   uint64_t message_id GNUNET_PACKED;
391
392   /**
393    * Requested fragment offset.
394    */
395   uint64_t fragment_offset GNUNET_PACKED;
396
397   /**
398    * Do membership test with @a slave_key before returning fragment?
399    * #GNUNET_YES or #GNUNET_NO
400    */
401   uint8_t do_membership_test;
402 };
403
404
405 /**
406  * @see GNUNET_PSYCSTORE_state_hash_update()
407  */
408 struct StateHashUpdateRequest
409 {
410   /**
411    * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_HASH_UPDATE
412    */
413   struct GNUNET_MessageHeader header;
414
415   uint32_t reserved GNUNET_PACKED;
416
417   /**
418    * Operation ID.
419    */
420   uint64_t op_id GNUNET_PACKED;
421
422   /**
423    * Channel's public key.
424    */
425   struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
426
427   struct GNUNET_HashCode hash;
428 };
429
430
431 enum StateOpFlags
432 {
433   STATE_OP_FIRST = 1 << 0,
434   STATE_OP_LAST = 1 << 1
435 };
436
437
438 /**
439  * @see GNUNET_PSYCSTORE_state_modify()
440  */
441 struct StateModifyRequest
442 {
443   /**
444    * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_MODIFY
445    */
446   struct GNUNET_MessageHeader header;
447
448   /**
449    * Operation ID.
450    */
451   uint64_t op_id GNUNET_PACKED;
452
453   /**
454    * ID of the message to apply the state changes in.
455    */
456   uint64_t message_id GNUNET_PACKED;
457
458   /**
459    * State delta of the message with ID @a message_id.
460    */
461   uint64_t state_delta GNUNET_PACKED;
462
463   /**
464    * Channel's public key.
465    */
466   struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
467 };
468
469
470 /**
471  * @see GNUNET_PSYCSTORE_state_sync()
472  */
473 struct StateSyncRequest
474 {
475   /**
476    * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_SYNC
477    */
478   struct GNUNET_MessageHeader header;
479
480   /**
481    * Size of name, including NUL terminator.
482    */
483   uint16_t name_size GNUNET_PACKED;
484
485   /**
486    * OR'd StateOpFlags
487    */
488   uint8_t flags;
489
490   uint8_t reserved;
491
492   /**
493    * Operation ID.
494    */
495   uint64_t op_id GNUNET_PACKED;
496
497   /**
498    * ID of the message that contains the state_hash PSYC header variable.
499    */
500   uint64_t state_hash_message_id GNUNET_PACKED;
501
502   /**
503    * ID of the last stateful message before @a state_hash_message_id.
504    */
505   uint64_t max_state_message_id GNUNET_PACKED;
506
507   /**
508    * Channel's public key.
509    */
510   struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
511
512   /* Followed by NUL-terminated name, then the value. */
513 };
514
515
516 GNUNET_NETWORK_STRUCT_END
517
518 #endif