hxing
[oweals/gnunet.git] / src / fs / fs.h
1 /*
2      This file is part of GNUnet.
3      (C) 2003, 2004, 2005, 2006, 2007, 2008, 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 fs/fs.h
23  * @brief definitions for the entire fs module
24  * @author Igor Wronsky, Christian Grothoff
25  */
26 #ifndef FS_H
27 #define FS_H
28
29 /**
30  * Size of the individual blocks used for file-sharing.
31  */
32 #define GNUNET_FS_DBLOCK_SIZE (32*1024)
33
34 /**
35  * @brief content hash key
36  */
37 struct ContentHashKey 
38 {
39   GNUNET_HashCode key;
40   GNUNET_HashCode query;
41 };
42
43
44 /**
45  * @brief complete information needed
46  * to download a file.
47  */
48 struct FileIdentifier
49 {
50
51   /**
52    * Total size of the file in bytes. (network byte order (!))
53    */
54   unsigned long long file_length;
55
56   /**
57    * Query and key of the top GNUNET_EC_IBlock.
58    */
59   struct ContentHashKey chk;
60
61 };
62
63
64 /**
65  * Information about a file and its location
66  * (peer claiming to share the file).
67  */
68 struct Location
69 {
70   /**
71    * Information about the shared file.
72    */
73   struct FileIdentifier fi;
74
75   /**
76    * Identity of the peer sharing the file.
77    */
78   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
79
80   /**
81    * Time when this location URI expires.
82    */
83   struct GNUNET_TIME_Absolute expirationTime;
84
85   /**
86    * RSA signature over the GNUNET_EC_FileIdentifier,
87    * GNUNET_hash of the peer and expiration time.
88    */
89   struct GNUNET_CRYPTO_RsaSignature contentSignature;
90
91 };
92
93 enum uri_types
94 { chk, sks, ksk, loc };
95
96 /**
97  * A Universal Resource Identifier (URI), opaque.
98  */
99 struct GNUNET_FS_Uri
100 {
101   enum uri_types type;
102   union
103   {
104     struct
105     {
106       /**
107        * Keywords start with a '+' if they are
108        * mandatory (in which case the '+' is NOT
109        * part of the keyword) and with a
110        * simple space if they are optional
111        * (in which case the space is ALSO not
112        * part of the actual keyword).
113        *
114        * Double-quotes to protect spaces and
115        * %-encoding are NOT used internally
116        * (only in URI-strings).
117        */
118       char **keywords;
119       
120       /**
121        * Size of the keywords array.
122        */
123       unsigned int keywordCount;
124     } ksk;
125
126     struct
127     {
128       /**
129        * Hash of the public key for the namespace.
130        */
131       GNUNET_HashCode namespace;
132
133       /**
134        * Human-readable identifier chosen for this
135        * entry in the namespace.
136        */
137       char *identifier;
138     } sks;
139
140     /**
141      * Information needed to retrieve a file (content-hash-key
142      * plus file size).
143      */
144     struct FileIdentifier chk;
145
146     /**
147      * Information needed to retrieve a file including signed
148      * location (identity of a peer) of the content.
149      */
150     struct Location loc;
151   } data;
152
153 };
154
155
156 /**
157  * Information for a file or directory that is
158  * about to be published.
159  */
160 struct GNUNET_FS_FileInformation
161 {
162
163   /**
164    * Files in a directory are kept as a linked list.
165    */
166   struct GNUNET_FS_FileInformation *next;
167
168   /**
169    * If this is a file in a directory, "dir" refers to
170    * the directory; otherwise NULL.
171    */
172   struct GNUNET_FS_FileInformation *dir;
173
174   /**
175    * Pointer kept for the client.
176    */
177   void *client_info;
178
179   /**
180    * Metadata to use for the file.
181    */
182   struct GNUNET_CONTAINER_MetaData *meta;
183
184   /**
185    * Keywords to use for KBlocks.
186    */
187   struct GNUNET_FS_Uri *keywords;
188
189   /**
190    * At what time should the content expire?
191    */
192   struct GNUNET_TIME_Absolute expirationTime;
193
194   /**
195    * Under what filename is this struct serialized
196    * (for operational persistence).
197    */
198   char *serialization;
199
200   /**
201    * How many bytes of this file or directory have been
202    * published so far?
203    */
204   uint64_t publish_offset;
205
206   /**
207    * Data describing either the file or the directory.
208    */
209   union
210   {
211
212     /**
213      * Data for a file.
214      */
215     struct {
216
217       /**
218        * Function that can be used to read the data for the file.
219        */
220       GNUNET_FS_DataReader reader;
221
222       /**
223        * Closure for reader.
224        */
225       void *reader_cls;
226
227       /**
228        * Size of the file (in bytes).
229        */
230       uint64_t file_size;
231
232       /**
233        * Should the file be indexed or inserted?
234        */
235       int do_index;
236
237     } file;
238
239     /**
240      * Data for a directory.
241      */
242     struct {
243       
244       /**
245        * Name of the directory.
246        */
247       char *dirname;
248       
249       /**
250        * Linked list of entries in the directory.
251        */
252       struct GNUNET_FS_FileInformation *entries;
253
254       /**
255        * Size of the directory itself (in bytes); 0 if the
256        * size has not yet been calculated.
257        */
258       uint64_t dir_size;
259
260     } dir;
261
262   } data;
263
264   /**
265    * Is this struct for a file or directory?
266    */
267   int is_directory;
268
269   /**
270    * Desired anonymity level.
271    */
272   unsigned int anonymity;
273
274   /**
275    * Desired priority (for keeping the content in the DB).
276    */
277   unsigned int priority;
278
279 };
280
281
282 #endif