Smallers steps to keep plugin running
[oweals/gnunet.git] / src / include / gnunet_block_lib.h
1 /*
2      This file is part of GNUnet.
3      (C) 2010 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 include/gnunet_block_lib.h
23  * @brief library for data block manipulation
24  * @author Christian Grothoff
25  */
26 #ifndef GNUNET_BLOCK_LIB_H
27 #define GNUNET_BLOCK_LIB_H
28
29 #include "gnunet_util_lib.h"
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 /**
39  * Blocks in the datastore and the datacache must have a unique type.
40  */
41 enum GNUNET_BLOCK_Type 
42   {
43     /**
44      * Any type of block, used as a wildcard when searching.  Should
45      * never be attached to a specific block.
46      */
47     GNUNET_BLOCK_TYPE_ANY = 0,
48
49     /**
50      * Data block (leaf) in the CHK tree.
51      */
52     GNUNET_BLOCK_TYPE_DBLOCK = 1,
53
54     /**
55      * Inner block in the CHK tree.
56      */
57     GNUNET_BLOCK_TYPE_IBLOCK = 2,
58
59     /**
60      * Type of a block representing a keyword search result.
61      */
62     GNUNET_BLOCK_TYPE_KBLOCK = 3,
63
64     /**
65      * Type of a block that is used to advertise content in a namespace.
66      */
67     GNUNET_BLOCK_TYPE_SBLOCK = 4,
68
69     /**
70      * Type of a block representing a block to be encoded on demand from disk.
71      * Should never appear on the network directly.
72      */
73     GNUNET_BLOCK_TYPE_ONDEMAND = 5,
74
75     /**
76      * Type of a block that is used to advertise a namespace.  
77      */
78     GNUNET_BLOCK_TYPE_NBLOCK = 6,
79
80     GNUNET_BLOCK_TYPE_TEST = 9999
81
82   };
83
84
85 /**
86  * @brief keyword block (advertising data under a keyword)
87  */
88 struct KBlock
89 {
90
91   /**
92    * GNUNET_RSA_Signature using RSA-key generated from search keyword.
93    */
94   struct GNUNET_CRYPTO_RsaSignature signature;
95
96   /**
97    * What is being signed and why?
98    */
99   struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
100
101   /**
102    * Key generated (!) from the H(keyword) as the seed!
103    */
104   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
105
106   /* 0-terminated URI here */
107
108   /* variable-size Meta-Data follows here */
109
110 };
111
112
113 /**
114  * @brief namespace content block (advertising data under an identifier in a namespace)
115  */
116 struct SBlock
117 {
118
119   /**
120    * GNUNET_RSA_Signature using RSA-key of the namespace
121    */
122   struct GNUNET_CRYPTO_RsaSignature signature;
123
124   /**
125    * What is being signed and why?
126    */
127   struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
128
129   /**
130    * Hash of the hash of the human-readable identifier used for
131    * this entry (the hash of the human-readable identifier is
132    * used as the key for decryption; the xor of this identifier
133    * and the hash of the "keyspace" is the datastore-query hash).
134    */
135   GNUNET_HashCode identifier;
136
137   /**
138    * Public key of the namespace.
139    */
140   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
141
142   /* 0-terminated update-identifier here */
143
144   /* 0-terminated URI here (except for NBlocks) */
145
146   /* variable-size Meta-Data follows here */
147
148 };
149
150
151 /**
152  * @brief namespace advertisement block (advertising root of a namespace)
153  */
154 struct NBlock
155 {
156
157   /**
158    * GNUNET_RSA_Signature using RSA-key generated from search keyword.
159    */
160   struct GNUNET_CRYPTO_RsaSignature ksk_signature;
161
162   /**
163    * What is being signed and why?
164    */
165   struct GNUNET_CRYPTO_RsaSignaturePurpose ksk_purpose;
166
167   /**
168    * Key generated (!) from the H(keyword) as the seed!
169    */
170   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
171
172   /**
173    * GNUNET_RSA_Signature using RSA-key of the namespace
174    */
175   struct GNUNET_CRYPTO_RsaSignature ns_signature;
176
177   /**
178    * What is being signed and why?
179    */
180   struct GNUNET_CRYPTO_RsaSignaturePurpose ns_purpose;
181
182   /**
183    * Public key of the namespace.
184    */
185   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
186
187   /* from here on, data is encrypted with H(keyword) */
188
189   /* 0-terminated root identifier here */
190
191   /* variable-size Meta-Data follows here */
192
193 };
194
195
196 /**
197  * @brief index block (indexing a DBlock that 
198  *        can be obtained directly from reading
199  *        the plaintext file)
200  */
201 struct OnDemandBlock
202 {
203   /**
204    * Hash code of the entire content of the
205    * file that was indexed (used to uniquely
206    * identify the plaintext file).
207    */
208   GNUNET_HashCode file_id;
209
210   /**
211    * At which offset should we be able to find
212    * this on-demand encoded block? (in NBO)
213    */
214   uint64_t offset GNUNET_PACKED;
215
216 };
217
218
219 /**
220  * Check if the given block is well-formed (and of the given type).
221  *
222  * @param type type of the block
223  * @param block the block data (or at least "size" bytes claiming to be one)
224  * @param size size of "kb" in bytes; check that it is large enough
225  * @param query where to store the query that this block answers
226  * @return GNUNET_OK if this is actually a well-formed KBlock
227  *         GNUNET_NO if we could not determine the query,
228  *         GNUNET_SYSERR if the block is malformed
229  */
230 int
231 GNUNET_BLOCK_check_block (enum GNUNET_BLOCK_Type type,
232                           const void *block,
233                           size_t size,
234                           GNUNET_HashCode *query);
235
236
237 #if 0                           /* keep Emacsens' auto-indent happy */
238 {
239 #endif
240 #ifdef __cplusplus
241 }
242 #endif
243
244
245 /* ifndef GNUNET_BLOCK_LIB_H */
246 #endif
247 /* end of gnunet_block_lib.h */