fast timeout on disconnect
[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   };
81
82
83 /**
84  * @brief keyword block (advertising data under a keyword)
85  */
86 struct KBlock
87 {
88
89   /**
90    * GNUNET_RSA_Signature using RSA-key generated from search keyword.
91    */
92   struct GNUNET_CRYPTO_RsaSignature signature;
93
94   /**
95    * What is being signed and why?
96    */
97   struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
98
99   /**
100    * Key generated (!) from the H(keyword) as the seed!
101    */
102   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
103
104   /* 0-terminated URI here */
105
106   /* variable-size Meta-Data follows here */
107
108 };
109
110
111 /**
112  * @brief namespace content block (advertising data under an identifier in a namespace)
113  */
114 struct SBlock
115 {
116
117   /**
118    * GNUNET_RSA_Signature using RSA-key of the namespace
119    */
120   struct GNUNET_CRYPTO_RsaSignature signature;
121
122   /**
123    * What is being signed and why?
124    */
125   struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
126
127   /**
128    * Hash of the hash of the human-readable identifier used for
129    * this entry (the hash of the human-readable identifier is
130    * used as the key for decryption; the xor of this identifier
131    * and the hash of the "keyspace" is the datastore-query hash).
132    */
133   GNUNET_HashCode identifier;
134
135   /**
136    * Public key of the namespace.
137    */
138   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
139
140   /* 0-terminated update-identifier here */
141
142   /* 0-terminated URI here (except for NBlocks) */
143
144   /* variable-size Meta-Data follows here */
145
146 };
147
148
149 /**
150  * @brief namespace advertisement block (advertising root of a namespace)
151  */
152 struct NBlock
153 {
154
155   /**
156    * GNUNET_RSA_Signature using RSA-key generated from search keyword.
157    */
158   struct GNUNET_CRYPTO_RsaSignature ksk_signature;
159
160   /**
161    * What is being signed and why?
162    */
163   struct GNUNET_CRYPTO_RsaSignaturePurpose ksk_purpose;
164
165   /**
166    * Key generated (!) from the H(keyword) as the seed!
167    */
168   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
169
170   /**
171    * GNUNET_RSA_Signature using RSA-key of the namespace
172    */
173   struct GNUNET_CRYPTO_RsaSignature ns_signature;
174
175   /**
176    * What is being signed and why?
177    */
178   struct GNUNET_CRYPTO_RsaSignaturePurpose ns_purpose;
179
180   /**
181    * Public key of the namespace.
182    */
183   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
184
185   /* from here on, data is encrypted with H(keyword) */
186
187   /* 0-terminated root identifier here */
188
189   /* variable-size Meta-Data follows here */
190
191 };
192
193
194 /**
195  * @brief index block (indexing a DBlock that 
196  *        can be obtained directly from reading
197  *        the plaintext file)
198  */
199 struct OnDemandBlock
200 {
201   /**
202    * Hash code of the entire content of the
203    * file that was indexed (used to uniquely
204    * identify the plaintext file).
205    */
206   GNUNET_HashCode file_id;
207
208   /**
209    * At which offset should we be able to find
210    * this on-demand encoded block? (in NBO)
211    */
212   uint64_t offset GNUNET_PACKED;
213
214 };
215
216
217 /**
218  * Check if the given block is well-formed (and of the given type).
219  *
220  * @param type type of the block
221  * @param block the block data (or at least "size" bytes claiming to be one)
222  * @param size size of "kb" in bytes; check that it is large enough
223  * @param query where to store the query that this block answers
224  * @return GNUNET_OK if this is actually a well-formed KBlock
225  *         GNUNET_NO if we could not determine the query,
226  *         GNUNET_SYSERR if the block is malformed
227  */
228 int
229 GNUNET_BLOCK_check_block (enum GNUNET_BLOCK_Type type,
230                           const void *block,
231                           size_t size,
232                           GNUNET_HashCode *query);
233
234
235 #if 0                           /* keep Emacsens' auto-indent happy */
236 {
237 #endif
238 #ifdef __cplusplus
239 }
240 #endif
241
242
243 /* ifndef GNUNET_BLOCK_LIB_H */
244 #endif
245 /* end of gnunet_block_lib.h */