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
56 * Blocksize to use when hashing files
57 * for indexing (blocksize for IO, not for
58 * the DBlocks). Larger blocksizes can
59 * be more efficient but will be more disruptive
60 * as far as the scheduler is concerned.
62 #define HASHING_BLOCKSIZE (1024 * 1024)
66 * @brief content hash key
71 GNUNET_HashCode query;
76 * @brief complete information needed
83 * Total size of the file in bytes. (network byte order (!))
88 * Query and key of the top GNUNET_EC_IBlock.
90 struct ContentHashKey chk;
96 * Information about a file and its location
97 * (peer claiming to share the file).
102 * Information about the shared file.
104 struct FileIdentifier fi;
107 * Identity of the peer sharing the file.
109 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
112 * Time when this location URI expires.
114 struct GNUNET_TIME_Absolute expirationTime;
117 * RSA signature over the GNUNET_EC_FileIdentifier,
118 * GNUNET_hash of the peer and expiration time.
120 struct GNUNET_CRYPTO_RsaSignature contentSignature;
125 { chk, sks, ksk, loc };
128 * A Universal Resource Identifier (URI), opaque.
138 * Keywords start with a '+' if they are
139 * mandatory (in which case the '+' is NOT
140 * part of the keyword) and with a
141 * simple space if they are optional
142 * (in which case the space is ALSO not
143 * part of the actual keyword).
145 * Double-quotes to protect spaces and
146 * %-encoding are NOT used internally
147 * (only in URI-strings).
152 * Size of the keywords array.
154 unsigned int keywordCount;
160 * Hash of the public key for the namespace.
162 GNUNET_HashCode namespace;
165 * Human-readable identifier chosen for this
166 * entry in the namespace.
172 * Information needed to retrieve a file (content-hash-key
175 struct FileIdentifier chk;
178 * Information needed to retrieve a file including signed
179 * location (identity of a peer) of the content.
188 * Information for a file or directory that is
189 * about to be published.
191 struct GNUNET_FS_FileInformation
195 * Files in a directory are kept as a linked list.
197 struct GNUNET_FS_FileInformation *next;
200 * If this is a file in a directory, "dir" refers to
201 * the directory; otherwise NULL.
203 struct GNUNET_FS_FileInformation *dir;
206 * Pointer kept for the client.
211 * Metadata to use for the file.
213 struct GNUNET_CONTAINER_MetaData *meta;
216 * Keywords to use for KBlocks.
218 struct GNUNET_FS_Uri *keywords;
221 * CHK for this file or directory. NULL if
222 * we have not yet computed it.
224 struct GNUNET_FS_Uri *chk_uri;
227 * At what time should the content expire?
229 struct GNUNET_TIME_Absolute expirationTime;
232 * At what time did we start this upload?
234 struct GNUNET_TIME_Absolute start_time;
237 * Under what filename is this struct serialized
238 * (for operational persistence).
243 * In-memory cache of the current CHK tree.
244 * This struct will contain the CHK values
245 * from the root to the currently processed
246 * node in the tree as identified by
247 * "current_depth" and "publish_offset".
248 * The "chktree" will be initially NULL,
249 * then allocated to a sufficient number of
250 * entries for the size of the file and
251 * finally freed once the upload is complete.
253 struct ContentHashKey *chk_tree;
256 * Error message (non-NULL if this operation
262 * Number of entries in "chk_tree".
264 unsigned int chk_tree_depth;
267 * Depth in the CHK-tree at which we are
268 * currently publishing. 0 is the root
271 unsigned int current_depth;
274 * How many bytes of this file or directory have been
277 uint64_t publish_offset;
280 * Data describing either the file or the directory.
291 * Function that can be used to read the data for the file.
293 GNUNET_FS_DataReader reader;
296 * Closure for reader.
301 * Name of the file (must be an absolute path).
302 * Only required for indexing. FIXME: not yet
308 * If this file is being indexed, this value
309 * is set to the hash over the entire file
310 * (when the indexing process is started).
311 * Otherwise this field is not used.
313 GNUNET_HashCode file_id;
316 * Size of the file (in bytes).
321 * Should the file be indexed or inserted?
328 * Data for a directory.
333 * Name of the directory.
338 * Linked list of entries in the directory.
340 struct GNUNET_FS_FileInformation *entries;
343 * Size of the directory itself (in bytes); 0 if the
344 * size has not yet been calculated.
349 * Pointer to the data for the directory (or NULL if not
359 * Is this struct for a file or directory?
364 * Desired anonymity level.
366 unsigned int anonymity;
369 * Desired priority (for keeping the content in the DB).
371 unsigned int priority;
377 * Master context for most FS operations.
379 struct GNUNET_FS_Handle
384 struct GNUNET_SCHEDULER_Handle *sched;
387 * Configuration to use.
389 const struct GNUNET_CONFIGURATION_Handle *cfg;
392 * Name of our client.
397 * Function to call with updates on our progress.
399 GNUNET_FS_ProgressCallback upcb;
407 * Connection to the FS service.
409 struct GNUNET_CLIENT_Connection *client;
416 * Handle for controlling an upload.
418 struct GNUNET_FS_PublishContext
421 * Handle to the global fs context.
423 struct GNUNET_FS_Handle *h;
426 * Argument to pass to the client in callbacks.
431 * File-structure that is being shared.
433 struct GNUNET_FS_FileInformation *fi;
436 * Namespace that we are publishing in, NULL if we have no namespace.
438 struct GNUNET_FS_Namespace *namespace;
441 * ID of the content in the namespace, NULL if we have no namespace.
446 * ID for future updates, NULL if we have no namespace or no updates.
451 * ID of the task performing the upload. NO_TASK
452 * if the upload has completed.
454 GNUNET_SCHEDULER_TaskIdentifier upload_task;
457 * Our own client handle for the FS service;
458 * only briefly used when we start to index a
459 * file, otherwise NULL.
461 struct GNUNET_CLIENT_Connection *client;
464 * Typically GNUNET_NO. Set to GNUNET_YES if
465 * "upload_task" is GNUNET_SCHEDULER_NO_TASK
466 * and we're waiting for a response from the
467 * datastore service (in which case this
468 * struct must not be freed until we have that
469 * response). If someone tries to stop the
470 * download for good during this period,
471 * "in_network_wait" is set to GNUNET_SYSERR
472 * which will cause the struct to be destroyed
473 * right after we have the reply (or timeout)
474 * from the datastore service.
479 * Options for publishing.
481 enum GNUNET_FS_PublishOptions options;
484 * Current position in the file-tree for the
487 struct GNUNET_FS_FileInformation *fi_pos;
490 * Connection to the datastore service.
492 struct GNUNET_DATASTORE_Handle *dsh;
495 * Space reservation ID with datastore service
503 * Phases of unindex processing (state machine).
508 * We're currently hashing the file.
510 UNINDEX_STATE_HASHING = 0,
513 * We're notifying the FS service about
516 UNINDEX_STATE_FS_NOTIFY = 1,
519 * We're telling the datastore to delete
520 * the respective entries.
522 UNINDEX_STATE_DS_REMOVE = 2,
527 UNINDEX_STATE_COMPLETE = 3,
530 * We've encountered a fatal error.
532 UNINDEX_STATE_ERROR = 4,
535 * We've been aborted. The next callback should clean up the
538 UNINDEX_STATE_ABORTED = 5
543 * Handle for controlling an unindexing operation.
545 struct GNUNET_FS_UnindexContext
551 struct GNUNET_FS_Handle *h;
554 * Name of the file that we are unindexing.
559 * Connection to the FS service,
560 * only valid during the UNINDEX_STATE_FS_NOTIFY
563 struct GNUNET_CLIENT_Connection *client;
566 * Connection to the datastore service,
567 * only valid during the UNINDEX_STATE_DS_NOTIFY
570 struct GNUNET_DATASTORE_Handle *dsh;
573 * Pointer kept for the client.
578 * Overall size of the file.
583 * How far have we gotten?
585 uint64_t unindex_offset;
590 struct GNUNET_TIME_Absolute start_time;
593 * Hash of the file's contents (once
596 GNUNET_HashCode file_id;
599 * Current operatinonal phase.
601 enum UnindexState state;
607 * Handle for controlling a search.
609 struct GNUNET_FS_SearchContext
615 * Context for controlling a download.
617 struct GNUNET_FS_DownloadContext
621 struct GNUNET_FS_Namespace
625 * Private key for the namespace.
627 struct GNUNET_CRYPTO_RsaPrivateKey *key;
637 * @brief index block (indexing a DBlock that
638 * can be obtained directly from reading
639 * the plaintext file)
644 * Hash code of the entire content of the
645 * file that was indexed (used to uniquely
646 * identify the plaintext file).
648 GNUNET_HashCode file_id;
651 * At which offset should we be able to find
652 * this on-demand encoded block?
660 * @brief keyword block (advertising data under a keyword)
666 * GNUNET_RSA_Signature using RSA-key generated from search keyword.
668 struct GNUNET_CRYPTO_RsaSignature signature;
671 * What is being signed and why?
673 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
676 * Key generated (!) from the H(keyword) as the seed!
678 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
680 /* 0-terminated URI here */
682 /* variable-size Meta-Data follows here */
687 * @brief namespace content block (advertising data under an identifier in a namespace)
693 * GNUNET_RSA_Signature using RSA-key of the namespace
695 struct GNUNET_CRYPTO_RsaSignature signature;
698 * What is being signed and why?
700 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
703 * Hash of the hash of the human-readable identifier used for
704 * this entry (the hash of the human-readable identifier is
705 * used as the key for decryption; the xor of this identifier
706 * and the hash of the "keyspace" is the datastore-query hash).
708 GNUNET_HashCode identifier;
711 * Public key of the namespace.
713 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
715 /* 0-terminated update-identifier here */
717 /* 0-terminated URI here */
719 /* variable-size Meta-Data follows here */
725 * Message sent from a GNUnet (fs) publishing
726 * activity to the gnunet-fs-service to
727 * initiate indexing of a file. The service
728 * is supposed to check if the specified file
729 * is available and has the same cryptographic
730 * hash. It should then respond with either
731 * a confirmation or a denial.
733 * On OSes where this works, it is considered
734 * acceptable if the service only checks that
735 * the path, device and inode match (it can
736 * then be assumed that the hash will also match
737 * without actually computing it; this is an
738 * optimization that should be safe given that
739 * the client is not our adversary).
741 struct IndexStartMessage
745 * Message type will be
746 * GNUNET_MESSAGE_TYPE_FS_INDEX_START.
748 struct GNUNET_MessageHeader header;
751 * ID of device containing the file, as seen by the client. This
752 * device ID is obtained using a call like "statvfs" (and converting
753 * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
754 * OS does not support this, in which case the service must do a
755 * full hash recomputation.
760 * Inode of the file on the given device, as seen by the client
761 * ("st_ino" field from "struct stat"). Use 0 if the OS does not
762 * support this, in which case the service must do a full hash
768 * Hash of the file that we would like to index.
770 GNUNET_HashCode file_id;
772 /* this is followed by a 0-terminated
773 filename of a file with the hash
774 "file_id" as seen by the client */
780 * Message send by FS service in response to a request
781 * asking for a list of all indexed files.
783 struct IndexInfoMessage
786 * Message type will be
787 * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
789 struct GNUNET_MessageHeader header;
792 * Hash of the indexed file.
794 GNUNET_HashCode file_id;
796 /* this is followed by a 0-terminated
797 filename of a file with the hash
798 "file_id" as seen by the client */
804 * Message sent from a GNUnet (fs) unindexing
805 * activity to the gnunet-fs-service to
806 * indicate that a file will be unindexed. The service
807 * is supposed to remove the file from the
808 * list of indexed files and response with
809 * a confirmation message (even if the file
810 * was already not on the list).
812 struct UnindexMessage
816 * Message type will be
817 * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
819 struct GNUNET_MessageHeader header;
827 * Hash of the file that we will unindex.
829 GNUNET_HashCode file_id;