2 This file is part of GNUnet.
3 (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
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.
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.
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.
23 * @brief definitions for the entire fs module
24 * @author Igor Wronsky, Christian Grothoff
29 #include "gnunet_datastore_service.h"
30 #include "gnunet_fs_service.h"
33 * Size of the individual blocks used for file-sharing.
35 #define DBLOCK_SIZE (32*1024)
39 * Pick a multiple of 2 here to achive 8-byte alignment!
40 * We also probably want DBlocks to have (roughly) the
41 * same size as IBlocks. With SHA-512, the optimal
42 * value is 32768 byte / 128 byte = 256
43 * (128 byte = 2 * 512 bits). DO NOT CHANGE!
45 #define CHK_PER_INODE 256
49 * Maximum size for a file to be considered for
50 * inlining in a directory.
52 #define MAX_INLINE_SIZE 65536
57 * @brief content hash key
62 GNUNET_HashCode query;
67 * @brief complete information needed
74 * Total size of the file in bytes. (network byte order (!))
79 * Query and key of the top GNUNET_EC_IBlock.
81 struct ContentHashKey chk;
87 * Information about a file and its location
88 * (peer claiming to share the file).
93 * Information about the shared file.
95 struct FileIdentifier fi;
98 * Identity of the peer sharing the file.
100 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
103 * Time when this location URI expires.
105 struct GNUNET_TIME_Absolute expirationTime;
108 * RSA signature over the GNUNET_EC_FileIdentifier,
109 * GNUNET_hash of the peer and expiration time.
111 struct GNUNET_CRYPTO_RsaSignature contentSignature;
116 { chk, sks, ksk, loc };
119 * A Universal Resource Identifier (URI), opaque.
129 * Keywords start with a '+' if they are
130 * mandatory (in which case the '+' is NOT
131 * part of the keyword) and with a
132 * simple space if they are optional
133 * (in which case the space is ALSO not
134 * part of the actual keyword).
136 * Double-quotes to protect spaces and
137 * %-encoding are NOT used internally
138 * (only in URI-strings).
143 * Size of the keywords array.
145 unsigned int keywordCount;
151 * Hash of the public key for the namespace.
153 GNUNET_HashCode namespace;
156 * Human-readable identifier chosen for this
157 * entry in the namespace.
163 * Information needed to retrieve a file (content-hash-key
166 struct FileIdentifier chk;
169 * Information needed to retrieve a file including signed
170 * location (identity of a peer) of the content.
179 * Information for a file or directory that is
180 * about to be published.
182 struct GNUNET_FS_FileInformation
186 * Files in a directory are kept as a linked list.
188 struct GNUNET_FS_FileInformation *next;
191 * If this is a file in a directory, "dir" refers to
192 * the directory; otherwise NULL.
194 struct GNUNET_FS_FileInformation *dir;
197 * Pointer kept for the client.
202 * Metadata to use for the file.
204 struct GNUNET_CONTAINER_MetaData *meta;
207 * Keywords to use for KBlocks.
209 struct GNUNET_FS_Uri *keywords;
212 * CHK for this file or directory. NULL if
213 * we have not yet computed it.
215 struct GNUNET_FS_Uri *chk_uri;
218 * At what time should the content expire?
220 struct GNUNET_TIME_Absolute expirationTime;
223 * At what time did we start this upload?
225 struct GNUNET_TIME_Absolute start_time;
228 * Under what filename is this struct serialized
229 * (for operational persistence).
234 * In-memory cache of the current CHK tree.
235 * This struct will contain the CHK values
236 * from the root to the currently processed
237 * node in the tree as identified by
238 * "current_depth" and "publish_offset".
239 * The "chktree" will be initially NULL,
240 * then allocated to a sufficient number of
241 * entries for the size of the file and
242 * finally freed once the upload is complete.
244 struct ContentHashKey *chk_tree;
247 * Error message (non-NULL if this operation
253 * Number of entries in "chk_tree".
255 unsigned int chk_tree_depth;
258 * Depth in the CHK-tree at which we are
259 * currently publishing. 0 is the root
262 unsigned int current_depth;
265 * How many bytes of this file or directory have been
268 uint64_t publish_offset;
271 * Data describing either the file or the directory.
282 * Function that can be used to read the data for the file.
284 GNUNET_FS_DataReader reader;
287 * Closure for reader.
292 * Name of the file (must be an absolute path).
293 * Only required for indexing. FIXME: not yet
299 * If this file is being indexed, this value
300 * is set to the hash over the entire file
301 * (when the indexing process is started).
302 * Otherwise this field is not used.
304 GNUNET_HashCode file_id;
307 * Size of the file (in bytes).
312 * Should the file be indexed or inserted?
319 * Data for a directory.
324 * Name of the directory.
329 * Linked list of entries in the directory.
331 struct GNUNET_FS_FileInformation *entries;
334 * Size of the directory itself (in bytes); 0 if the
335 * size has not yet been calculated.
340 * Pointer to the data for the directory (or NULL if not
350 * Is this struct for a file or directory?
355 * Desired anonymity level.
357 unsigned int anonymity;
360 * Desired priority (for keeping the content in the DB).
362 unsigned int priority;
368 * Master context for most FS operations.
370 struct GNUNET_FS_Handle
375 struct GNUNET_SCHEDULER_Handle *sched;
378 * Configuration to use.
380 const struct GNUNET_CONFIGURATION_Handle *cfg;
383 * Name of our client.
388 * Function to call with updates on our progress.
390 GNUNET_FS_ProgressCallback upcb;
398 * Connection to the FS service.
400 struct GNUNET_CLIENT_Connection *client;
407 * Handle for controlling an upload.
409 struct GNUNET_FS_PublishContext
412 * Handle to the global fs context.
414 struct GNUNET_FS_Handle *h;
417 * Argument to pass to the client in callbacks.
422 * File-structure that is being shared.
424 struct GNUNET_FS_FileInformation *fi;
427 * Namespace that we are publishing in, NULL if we have no namespace.
429 struct GNUNET_FS_Namespace *namespace;
432 * ID of the content in the namespace, NULL if we have no namespace.
437 * ID for future updates, NULL if we have no namespace or no updates.
442 * ID of the task performing the upload. NO_TASK
443 * if the upload has completed.
445 GNUNET_SCHEDULER_TaskIdentifier upload_task;
448 * Our own client handle for the FS service;
449 * only briefly used when we start to index a
450 * file, otherwise NULL.
452 struct GNUNET_CLIENT_Connection *client;
455 * Typically GNUNET_NO. Set to GNUNET_YES if
456 * "upload_task" is GNUNET_SCHEDULER_NO_TASK
457 * and we're waiting for a response from the
458 * datastore service (in which case this
459 * struct must not be freed until we have that
460 * response). If someone tries to stop the
461 * download for good during this period,
462 * "in_network_wait" is set to GNUNET_SYSERR
463 * which will cause the struct to be destroyed
464 * right after we have the reply (or timeout)
465 * from the datastore service.
470 * Options for publishing.
472 enum GNUNET_FS_PublishOptions options;
475 * Current position in the file-tree for the
478 struct GNUNET_FS_FileInformation *fi_pos;
481 * Connection to the datastore service.
483 struct GNUNET_DATASTORE_Handle *dsh;
486 * Space reservation ID with datastore service
494 * Handle for controlling an unindexing operation.
496 struct GNUNET_FS_UnindexContext
502 * Handle for controlling a search.
504 struct GNUNET_FS_SearchContext
510 * Context for controlling a download.
512 struct GNUNET_FS_DownloadContext
516 struct GNUNET_FS_Namespace
520 * Private key for the namespace.
522 struct GNUNET_CRYPTO_RsaPrivateKey *key;
532 * @brief index block (indexing a DBlock that
533 * can be obtained directly from reading
534 * the plaintext file)
539 * Hash code of the entire content of the
540 * file that was indexed (used to uniquely
541 * identify the plaintext file).
543 GNUNET_HashCode file_id;
546 * At which offset should we be able to find
547 * this on-demand encoded block?
555 * @brief keyword block (advertising data under a keyword)
561 * GNUNET_RSA_Signature using RSA-key generated from search keyword.
563 struct GNUNET_CRYPTO_RsaSignature signature;
566 * What is being signed and why?
568 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
571 * Key generated (!) from the H(keyword) as the seed!
573 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
575 /* 0-terminated URI here */
577 /* variable-size Meta-Data follows here */
582 * @brief namespace content block (advertising data under an identifier in a namespace)
588 * GNUNET_RSA_Signature using RSA-key of the namespace
590 struct GNUNET_CRYPTO_RsaSignature signature;
593 * What is being signed and why?
595 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
598 * Hash of the hash of the human-readable identifier used for
599 * this entry (the hash of the human-readable identifier is
600 * used as the key for decryption; the xor of this identifier
601 * and the hash of the "keyspace" is the datastore-query hash).
603 GNUNET_HashCode identifier;
606 * Public key of the namespace.
608 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
610 /* 0-terminated update-identifier here */
612 /* 0-terminated URI here */
614 /* variable-size Meta-Data follows here */
620 * Message sent from a GNUnet (fs) publishing
621 * activity to the gnunet-fs-service to
622 * initiate indexing of a file. The service
623 * is supposed to check if the specified file
624 * is available and has the same cryptographic
625 * hash. It should then respond with either
626 * a confirmation or a denial.
628 * On OSes where this works, it is considered
629 * acceptable if the service only checks that
630 * the path, device and inode match (it can
631 * then be assumed that the hash will also match
632 * without actually computing it; this is an
633 * optimization that should be safe given that
634 * the client is not our adversary).
636 struct IndexStartMessage
640 * Message type will be
641 * GNUNET_MESSAGE_TYPE_FS_INDEX_START.
643 struct GNUNET_MessageHeader header;
646 * ID of device containing the file, as seen by the client. This
647 * device ID is obtained using a call like "statvfs" (and converting
648 * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
649 * OS does not support this, in which case the service must do a
650 * full hash recomputation.
655 * Inode of the file on the given device, as seen by the client
656 * ("st_ino" field from "struct stat"). Use 0 if the OS does not
657 * support this, in which case the service must do a full hash
663 * Hash of the file that we would like to index.
665 GNUNET_HashCode file_id;
667 /* this is followed by a 0-terminated
668 filename of a file with the hash
669 "file_id" as seen by the client */