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