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