-indent, doxygen
[oweals/gnunet.git] / src / psyc / psyc.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 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 /**
22  * @file psyc/psyc.h
23  * @brief Common type definitions for the PSYC service and API.
24  * @author Gabor X Toth
25  */
26
27 #ifndef PSYC_H
28 #define PSYC_H
29
30 #include "platform.h"
31 #include "gnunet_psyc_service.h"
32
33
34 int
35 GNUNET_PSYC_check_message_parts (uint16_t data_size, const char *data,
36                                  uint16_t *first_ptype, uint16_t *last_ptype);
37
38 void
39 GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
40                          const struct GNUNET_MessageHeader *msg);
41
42
43 enum MessageState
44 {
45   MSG_STATE_START    = 0,
46   MSG_STATE_HEADER   = 1,
47   MSG_STATE_METHOD   = 2,
48   MSG_STATE_MODIFIER = 3,
49   MSG_STATE_MOD_CONT = 4,
50   MSG_STATE_DATA     = 5,
51   MSG_STATE_END      = 6,
52   MSG_STATE_CANCEL   = 7,
53   MSG_STATE_ERROR    = 8,
54 };
55
56
57 enum MessageFragmentState
58 {
59   MSG_FRAG_STATE_START    = 0,
60   MSG_FRAG_STATE_HEADER   = 1,
61   MSG_FRAG_STATE_DATA     = 2,
62   MSG_FRAG_STATE_END      = 3,
63   MSG_FRAG_STATE_CANCEL   = 4,
64   MSG_FRAG_STATE_DROP     = 5,
65 };
66
67
68 GNUNET_NETWORK_STRUCT_BEGIN
69
70
71 /**** library -> service ****/
72
73
74 struct MasterStartRequest
75 {
76   /**
77    * Type: GNUNET_MESSAGE_TYPE_PSYC_MASTER_START
78    */
79   struct GNUNET_MessageHeader header;
80
81   struct GNUNET_CRYPTO_EddsaPrivateKey channel_key;
82
83   uint32_t policy GNUNET_PACKED;
84 };
85
86
87 struct SlaveJoinRequest
88 {
89   /**
90    * Type: GNUNET_MESSAGE_TYPE_PSYC_SLAVE_JOIN
91    */
92   struct GNUNET_MessageHeader header;
93
94   uint32_t relay_count GNUNET_PACKED;
95
96   struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
97
98   struct GNUNET_CRYPTO_EddsaPrivateKey slave_key;
99
100   struct GNUNET_PeerIdentity origin;
101
102   /* Followed by struct GNUNET_PeerIdentity relays[relay_count] */
103 };
104
105
106 struct ChannelSlaveAdd
107 {
108   /**
109    * Type: GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_ADD
110    */
111   struct GNUNET_MessageHeader header;
112
113   uint32_t reserved;
114
115   struct GNUNET_CRYPTO_EddsaPublicKey *slave_key;
116
117   uint64_t announced_at;
118
119   uint64_t effective_since;
120 };
121
122
123 struct ChannelSlaveRemove
124 {
125   /**
126    * Type: GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_RM
127    */
128   struct GNUNET_MessageHeader header;
129
130   uint32_t reserved;
131
132   struct GNUNET_CRYPTO_EddsaPublicKey *slave_key;
133
134   uint64_t announced_at;
135 };
136
137
138 struct StoryRequest
139 {
140   /**
141    * Type: GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_STORY_REQUEST
142    */
143   struct GNUNET_MessageHeader header;
144
145   uint64_t op_id;
146
147   uint64_t start_message_id;
148
149   uint64_t end_message_id;
150 };
151
152
153 struct StateRequest
154 {
155   /**
156    * Types:
157    * - GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_STATE_GET
158    * - GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_STATE_GET_PREFIX
159    */
160   struct GNUNET_MessageHeader header;
161
162   /**
163    * ID for this operation.
164    */
165   uint64_t op_id;
166
167   /* Followed by NUL-terminated name. */
168 };
169
170
171 /**** service -> library ****/
172
173
174 struct CountersResult
175 {
176   /**
177    * Type: GNUNET_MESSAGE_TYPE_PSYC_RESULT_COUNTERS
178    */
179   struct GNUNET_MessageHeader header;
180
181   /**
182    * Status code for the operation.
183    */
184   int32_t result_code GNUNET_PACKED;
185
186   /**
187    * Last message ID sent to the channel.
188    */
189   uint64_t max_message_id;
190 };
191
192 /**
193  * Answer from service to client about last operation.
194  */
195 struct OperationResult
196 {
197   /**
198    * Types:
199    * - GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE
200    * - GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_STORY_RESULT
201    * - GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_STATE_RESULT
202    */
203   struct GNUNET_MessageHeader header;
204
205   /**
206    * Operation ID.
207    */
208   uint32_t op_id GNUNET_PACKED;
209
210   /**
211    * Status code for the operation.
212    */
213   int64_t result_code GNUNET_PACKED;
214
215   /* Followed by:
216    * - on error: NUL-terminated error message
217    * - on success: one of the following message types
218    *
219    *   For a STORY_RESULT:
220    *   - GNUNET_MESSAGE_TYPE_PSYC_MESSAGE
221    *
222    *   For a STATE_RESULT, one of:
223    *   - GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER
224    *   - GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT
225    *   - GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END
226    */
227 };
228
229
230 struct MasterJoinRequest
231 {
232   /**
233    * Type: GNUNET_MESSAGE_TYPE_PSYC_MASTER_JOIN_REQUEST
234    */
235   struct GNUNET_MessageHeader header;
236   /**
237    * Public key of the joining slave.
238    */
239   struct GNUNET_CRYPTO_EddsaPublicKey slave_key;
240
241   /* Followed by struct GNUNET_MessageHeader join_request */
242 };
243
244
245 struct MasterJoinDecision
246 {
247   /**
248    * Type: GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION
249    */
250   struct GNUNET_MessageHeader header;
251
252   /**
253    * #GNUNET_YES if the slave was admitted.
254    */
255   int32_t is_admitted;
256
257   /**
258    * Public key of the joining slave.
259    */
260   struct GNUNET_CRYPTO_EddsaPublicKey slave_key;
261
262   /* Followed by struct GNUNET_MessageHeader join_response */
263 };
264
265
266 struct SlaveJoinDecision
267 {
268   /**
269    * Type: GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION
270    */
271   struct GNUNET_MessageHeader header;
272
273   /**
274    * #GNUNET_YES if the slave was admitted.
275    */
276   int32_t is_admitted;
277
278   /* Followed by struct GNUNET_MessageHeader join_response */
279 };
280
281
282
283 GNUNET_NETWORK_STRUCT_END
284
285 #endif