Merge branch 'master' of git+ssh://gnunet.org/gnunet
[oweals/gnunet.git] / src / datastore / datastore.h
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2004, 2005, 2006, 2007, 2009 GNUnet e.V.
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 datastore/datastore.h
23  * @brief structs for communication between datastore service and API
24  * @author Christian Grothoff
25  */
26
27 #ifndef DATASTORE_H
28 #define DATASTORE_H
29
30
31 #include "gnunet_util_lib.h"
32
33 GNUNET_NETWORK_STRUCT_BEGIN
34
35 /**
36  * Message from datastore service informing client about
37  * the current size of the datastore.
38  */
39 struct ReserveMessage
40 {
41   /**
42    * Type is GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE.
43    */
44   struct GNUNET_MessageHeader header;
45
46   /**
47    * Number of items to reserve.
48    */
49   uint32_t entries GNUNET_PACKED;
50
51   /**
52    * Number of bytes to reserve.
53    */
54   uint64_t amount GNUNET_PACKED;
55 };
56
57
58 /**
59  * Message from datastore service informing client about
60  * the success or failure of a requested operation.
61  * This header is optionally followed by a variable-size,
62  * 0-terminated error message.
63  */
64 struct StatusMessage
65 {
66   /**
67    * Type is GNUNET_MESSAGE_TYPE_DATASTORE_STATUS.
68    */
69   struct GNUNET_MessageHeader header;
70
71   /**
72    * Status code, -1 for errors.
73    */
74   int32_t status GNUNET_PACKED;
75
76   /**
77    * Minimum expiration time required for content to be stored
78    * by the datacache at this time, zero for unknown or no limit.
79    */
80   struct GNUNET_TIME_AbsoluteNBO min_expiration;
81
82 };
83
84
85 /**
86  * Message from datastore client informing service that
87  * the remainder of the reserved bytes can now be released
88  * for other requests.
89  */
90 struct ReleaseReserveMessage
91 {
92   /**
93    * Type is GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE.
94    */
95   struct GNUNET_MessageHeader header;
96
97   /**
98    * Reservation id.
99    */
100   int32_t rid GNUNET_PACKED;
101
102 };
103
104
105 /**
106  * Message to the datastore service asking about specific
107  * content.
108  */
109 struct GetKeyMessage
110 {
111   /**
112    * Type is #GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY.
113    */
114   struct GNUNET_MessageHeader header;
115
116   /**
117    * Desired content type.  (actually an enum GNUNET_BLOCK_Type)
118    */
119   uint32_t type GNUNET_PACKED;
120
121   /**
122    * Offset of the result.
123    */
124   uint64_t offset GNUNET_PACKED;
125
126   /**
127    * Desired key.
128    */
129   struct GNUNET_HashCode key;
130
131 };
132
133
134 /**
135  * Message to the datastore service asking about specific
136  * content.
137  */
138 struct GetMessage
139 {
140   /**
141    * Type is #GNUNET_MESSAGE_TYPE_DATASTORE_GET.
142    */
143   struct GNUNET_MessageHeader header;
144
145   /**
146    * Desired content type.  (actually an enum GNUNET_BLOCK_Type)
147    */
148   uint32_t type GNUNET_PACKED;
149
150   /**
151    * Offset of the result.
152    */
153   uint64_t offset GNUNET_PACKED;
154
155 };
156
157
158 /**
159  * Message to the datastore service asking about zero
160  * anonymity content.
161  */
162 struct GetZeroAnonymityMessage
163 {
164   /**
165    * Type is GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY.
166    */
167   struct GNUNET_MessageHeader header;
168
169   /**
170    * Desired content type (actually an enum GNUNET_BLOCK_Type)
171    */
172   uint32_t type GNUNET_PACKED;
173
174   /**
175    * Offset of the result.
176    */
177   uint64_t offset GNUNET_PACKED;
178
179 };
180
181
182 /**
183  * Message to the datastore service requesting an update
184  * to the priority or expiration for some content.
185  */
186 struct UpdateMessage
187 {
188   /**
189    * Type is GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE.
190    */
191   struct GNUNET_MessageHeader header;
192
193   /**
194    * Desired priority increase.
195    */
196   int32_t priority GNUNET_PACKED;
197
198   /**
199    * Desired new expiration time.
200    */
201   struct GNUNET_TIME_AbsoluteNBO expiration;
202
203   /**
204    * Unique ID for the content.
205    */
206   uint64_t uid;
207
208 };
209
210
211 /**
212  * Message transmitting content from or to the datastore
213  * service.
214  */
215 struct DataMessage
216 {
217   /**
218    * Type is either GNUNET_MESSAGE_TYPE_DATASTORE_PUT,
219    * GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE or
220    * GNUNET_MESSAGE_TYPE_DATASTORE_DATA.  Depending on the message
221    * type, some fields may simply have values of zero.
222    */
223   struct GNUNET_MessageHeader header;
224
225   /**
226    * Reservation ID to use; use zero for none.
227    */
228   uint32_t rid GNUNET_PACKED;
229
230   /**
231    * Number of bytes in the item (NBO).
232    */
233   uint32_t size GNUNET_PACKED;
234
235   /**
236    * Type of the item (NBO), zero for remove,  (actually an enum GNUNET_BLOCK_Type)
237    */
238   uint32_t type GNUNET_PACKED;
239
240   /**
241    * Priority of the item (NBO), zero for remove.
242    */
243   uint32_t priority GNUNET_PACKED;
244
245   /**
246    * Desired anonymity level (NBO), zero for remove.
247    */
248   uint32_t anonymity GNUNET_PACKED;
249
250   /**
251    * Desired replication level. 0 from service to API.
252    */
253   uint32_t replication GNUNET_PACKED;
254
255   /**
256    * For alignment.
257    */
258   uint32_t reserved GNUNET_PACKED;
259
260   /**
261    * Unique ID for the content (can be used for UPDATE);
262    * can be zero for remove (which indicates that
263    * the datastore should use whatever UID matches
264    * the key and content).
265    */
266   uint64_t uid;
267
268   /**
269    * Expiration time (NBO); zero for remove.
270    */
271   struct GNUNET_TIME_AbsoluteNBO expiration;
272
273   /**
274    * Key under which the item can be found.
275    */
276   struct GNUNET_HashCode key;
277
278 };
279 GNUNET_NETWORK_STRUCT_END
280
281
282
283 #endif