9de72f064e55f409fcc93ad3cf42da0f147454bb
[oweals/gnunet.git] / 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 transmitting content from or to the datastore
184  * service.
185  */
186 struct DataMessage
187 {
188   /**
189    * Type is either GNUNET_MESSAGE_TYPE_DATASTORE_PUT,
190    * GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE or
191    * GNUNET_MESSAGE_TYPE_DATASTORE_DATA.  Depending on the message
192    * type, some fields may simply have values of zero.
193    */
194   struct GNUNET_MessageHeader header;
195
196   /**
197    * Reservation ID to use; use zero for none.
198    */
199   uint32_t rid GNUNET_PACKED;
200
201   /**
202    * Number of bytes in the item (NBO).
203    */
204   uint32_t size GNUNET_PACKED;
205
206   /**
207    * Type of the item (NBO), zero for remove,  (actually an enum GNUNET_BLOCK_Type)
208    */
209   uint32_t type GNUNET_PACKED;
210
211   /**
212    * Priority of the item (NBO), zero for remove.
213    */
214   uint32_t priority GNUNET_PACKED;
215
216   /**
217    * Desired anonymity level (NBO), zero for remove.
218    */
219   uint32_t anonymity GNUNET_PACKED;
220
221   /**
222    * Desired replication level. 0 from service to API.
223    */
224   uint32_t replication GNUNET_PACKED;
225
226   /**
227    * For alignment.
228    */
229   uint32_t reserved GNUNET_PACKED;
230
231   /**
232    * Unique ID for the content (can be used for UPDATE);
233    * can be zero for remove (which indicates that
234    * the datastore should use whatever UID matches
235    * the key and content).
236    */
237   uint64_t uid;
238
239   /**
240    * Expiration time (NBO); zero for remove.
241    */
242   struct GNUNET_TIME_AbsoluteNBO expiration;
243
244   /**
245    * Key under which the item can be found.
246    */
247   struct GNUNET_HashCode key;
248
249 };
250 GNUNET_NETWORK_STRUCT_END
251
252
253
254 #endif