- make sure handle is NULL
[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 uint16_t
35 GNUNET_PSYC_message_last_part (uint16_t data_size, const char *data);
36
37 void
38 GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
39                          const struct GNUNET_MessageHeader *msg);
40
41
42 enum MessageState
43 {
44   MSG_STATE_START = 0,
45   MSG_STATE_HEADER = 1,
46   MSG_STATE_METHOD = 2,
47   MSG_STATE_MODIFIER = 3,
48   MSG_STATE_MOD_CONT = 4,
49   MSG_STATE_DATA = 5,
50   MSG_STATE_END = 6,
51   MSG_STATE_CANCEL = 7,
52 };
53
54
55 GNUNET_NETWORK_STRUCT_BEGIN
56
57
58 /**** library -> service ****/
59
60
61 struct MasterStartRequest
62 {
63   /**
64    * Type: GNUNET_MESSAGE_TYPE_PSYC_MASTER_START
65    */
66   struct GNUNET_MessageHeader header;
67
68   struct GNUNET_CRYPTO_EddsaPrivateKey channel_key;
69
70   uint32_t policy GNUNET_PACKED;
71 };
72
73
74 struct SlaveJoinRequest
75 {
76   /**
77    * Type: GNUNET_MESSAGE_TYPE_PSYC_SLAVE_JOIN
78    */
79   struct GNUNET_MessageHeader header;
80
81   uint32_t relay_count GNUNET_PACKED;
82
83   struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
84
85   struct GNUNET_CRYPTO_EddsaPrivateKey slave_key;
86
87   struct GNUNET_PeerIdentity origin;
88
89   /* Followed by struct GNUNET_PeerIdentity relays[relay_count] */
90 };
91
92
93 struct ChannelSlaveAdd
94 {
95   /**
96    * Type: GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_ADD
97    */
98   struct GNUNET_MessageHeader header;
99
100   uint32_t reserved;
101
102   struct GNUNET_CRYPTO_EddsaPublicKey *slave_key;
103
104   uint64_t announced_at;
105
106   uint64_t effective_since;
107 };
108
109
110 struct ChannelSlaveRemove
111 {
112   /**
113    * Type: GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_RM
114    */
115   struct GNUNET_MessageHeader header;
116
117   uint32_t reserved;
118
119   struct GNUNET_CRYPTO_EddsaPublicKey *slave_key;
120
121   uint64_t announced_at;
122 };
123
124
125 struct StoryRequest
126 {
127   /**
128    * Type: GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_STORY_REQUEST
129    */
130   struct GNUNET_MessageHeader header;
131
132   uint64_t op_id;
133
134   uint64_t start_message_id;
135
136   uint64_t end_message_id;
137 };
138
139
140 struct StateRequest
141 {
142   /**
143    * Types:
144    * - GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_STATE_GET
145    * - GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_STATE_GET_PREFIX
146    */
147   struct GNUNET_MessageHeader header;
148
149   /**
150    * ID for this operation.
151    */
152   uint64_t op_id;
153
154   /* Followed by NUL-terminated name. */
155 };
156
157
158 /**** service -> library ****/
159
160
161 struct CountersResult
162 {
163   /**
164    * Type: GNUNET_MESSAGE_TYPE_PSYC_RESULT_COUNTERS
165    */
166   struct GNUNET_MessageHeader header;
167
168   /**
169    * Status code for the operation.
170    */
171   int32_t result_code GNUNET_PACKED;
172
173   /**
174    * Last message ID sent to the channel.
175    */
176   uint64_t max_message_id;
177 };
178
179 /**
180  * Answer from service to client about last operation.
181  */
182 struct OperationResult
183 {
184   /**
185    * Types:
186    * - GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE
187    * - GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_STORY_RESULT
188    * - GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_STATE_RESULT
189    */
190   struct GNUNET_MessageHeader header;
191
192   /**
193    * Operation ID.
194    */
195   uint32_t op_id GNUNET_PACKED;
196
197   /**
198    * Status code for the operation.
199    */
200   int64_t result_code GNUNET_PACKED;
201
202   /* Followed by:
203    * - on error: NUL-terminated error message
204    * - on success: one of the following message types
205    *
206    *   For a STORY_RESULT:
207    *   - GNUNET_MESSAGE_TYPE_PSYC_MESSAGE
208    *
209    *   For a STATE_RESULT, one of:
210    *   - GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER
211    *   - GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT
212    *   - GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END
213    */
214 };
215
216
217 GNUNET_NETWORK_STRUCT_END
218
219 #endif