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 * Encoder being used to publish this file.
258 struct GNUNET_FS_TreeEncoder *te;
261 * Error message (non-NULL if this operation
267 * Number of entries in "chk_tree".
269 // unsigned int chk_tree_depth;
272 * Depth in the CHK-tree at which we are
273 * currently publishing. 0 is the root
276 // unsigned int current_depth;
279 * How many bytes of this file or directory have been
282 // uint64_t publish_offset;
285 * Data describing either the file or the directory.
296 * Function that can be used to read the data for the file.
298 GNUNET_FS_DataReader reader;
301 * Closure for reader.
306 * Name of the file (must be an absolute path).
307 * Only required for indexing. FIXME: not yet
313 * If this file is being indexed, this value
314 * is set to the hash over the entire file
315 * (when the indexing process is started).
316 * Otherwise this field is not used.
318 GNUNET_HashCode file_id;
321 * Size of the file (in bytes).
326 * Should the file be indexed or inserted?
333 * Data for a directory.
338 * Name of the directory.
343 * Linked list of entries in the directory.
345 struct GNUNET_FS_FileInformation *entries;
348 * Size of the directory itself (in bytes); 0 if the
349 * size has not yet been calculated.
354 * Pointer to the data for the directory (or NULL if not
364 * Is this struct for a file or directory?
369 * Desired anonymity level.
371 unsigned int anonymity;
374 * Desired priority (for keeping the content in the DB).
376 unsigned int priority;
382 * Master context for most FS operations.
384 struct GNUNET_FS_Handle
389 struct GNUNET_SCHEDULER_Handle *sched;
392 * Configuration to use.
394 const struct GNUNET_CONFIGURATION_Handle *cfg;
397 * Name of our client.
402 * Function to call with updates on our progress.
404 GNUNET_FS_ProgressCallback upcb;
412 * Connection to the FS service.
414 struct GNUNET_CLIENT_Connection *client;
421 * Handle for controlling an upload.
423 struct GNUNET_FS_PublishContext
426 * Handle to the global fs context.
428 struct GNUNET_FS_Handle *h;
431 * Argument to pass to the client in callbacks.
436 * File-structure that is being shared.
438 struct GNUNET_FS_FileInformation *fi;
441 * Namespace that we are publishing in, NULL if we have no namespace.
443 struct GNUNET_FS_Namespace *namespace;
446 * ID of the content in the namespace, NULL if we have no namespace.
451 * ID for future updates, NULL if we have no namespace or no updates.
456 * ID of the task performing the upload. NO_TASK
457 * if the upload has completed.
459 GNUNET_SCHEDULER_TaskIdentifier upload_task;
462 * Our own client handle for the FS service;
463 * only briefly used when we start to index a
464 * file, otherwise NULL.
466 struct GNUNET_CLIENT_Connection *client;
469 * Typically GNUNET_NO. Set to GNUNET_YES if
470 * "upload_task" is GNUNET_SCHEDULER_NO_TASK
471 * and we're waiting for a response from the
472 * datastore service (in which case this
473 * struct must not be freed until we have that
474 * response). If someone tries to stop the
475 * download for good during this period,
476 * "in_network_wait" is set to GNUNET_SYSERR
477 * which will cause the struct to be destroyed
478 * right after we have the reply (or timeout)
479 * from the datastore service.
484 * Options for publishing.
486 enum GNUNET_FS_PublishOptions options;
489 * Current position in the file-tree for the
492 struct GNUNET_FS_FileInformation *fi_pos;
495 * Connection to the datastore service.
497 struct GNUNET_DATASTORE_Handle *dsh;
500 * Space reservation ID with datastore service
508 * Phases of unindex processing (state machine).
513 * We're currently hashing the file.
515 UNINDEX_STATE_HASHING = 0,
518 * We're notifying the FS service about
521 UNINDEX_STATE_FS_NOTIFY = 1,
524 * We're telling the datastore to delete
525 * the respective entries.
527 UNINDEX_STATE_DS_REMOVE = 2,
532 UNINDEX_STATE_COMPLETE = 3,
535 * We've encountered a fatal error.
537 UNINDEX_STATE_ERROR = 4,
540 * We've been aborted. The next callback should clean up the
543 UNINDEX_STATE_ABORTED = 5
548 * Handle for controlling an unindexing operation.
550 struct GNUNET_FS_UnindexContext
556 struct GNUNET_FS_Handle *h;
559 * Name of the file that we are unindexing.
564 * Connection to the FS service,
565 * only valid during the UNINDEX_STATE_FS_NOTIFY
568 struct GNUNET_CLIENT_Connection *client;
571 * Connection to the datastore service,
572 * only valid during the UNINDEX_STATE_DS_NOTIFY
575 struct GNUNET_DATASTORE_Handle *dsh;
578 * Pointer kept for the client.
583 * Overall size of the file.
588 * How far have we gotten?
590 uint64_t unindex_offset;
595 struct GNUNET_TIME_Absolute start_time;
598 * Hash of the file's contents (once
601 GNUNET_HashCode file_id;
604 * Current operatinonal phase.
606 enum UnindexState state;
612 * Handle for controlling a search.
614 struct GNUNET_FS_SearchContext
620 * Context for controlling a download.
622 struct GNUNET_FS_DownloadContext
626 struct GNUNET_FS_Namespace
630 * Private key for the namespace.
632 struct GNUNET_CRYPTO_RsaPrivateKey *key;
642 * @brief index block (indexing a DBlock that
643 * can be obtained directly from reading
644 * the plaintext file)
649 * Hash code of the entire content of the
650 * file that was indexed (used to uniquely
651 * identify the plaintext file).
653 GNUNET_HashCode file_id;
656 * At which offset should we be able to find
657 * this on-demand encoded block?
665 * @brief keyword block (advertising data under a keyword)
671 * GNUNET_RSA_Signature using RSA-key generated from search keyword.
673 struct GNUNET_CRYPTO_RsaSignature signature;
676 * What is being signed and why?
678 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
681 * Key generated (!) from the H(keyword) as the seed!
683 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
685 /* 0-terminated URI here */
687 /* variable-size Meta-Data follows here */
692 * @brief namespace content block (advertising data under an identifier in a namespace)
698 * GNUNET_RSA_Signature using RSA-key of the namespace
700 struct GNUNET_CRYPTO_RsaSignature signature;
703 * What is being signed and why?
705 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
708 * Hash of the hash of the human-readable identifier used for
709 * this entry (the hash of the human-readable identifier is
710 * used as the key for decryption; the xor of this identifier
711 * and the hash of the "keyspace" is the datastore-query hash).
713 GNUNET_HashCode identifier;
716 * Public key of the namespace.
718 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
720 /* 0-terminated update-identifier here */
722 /* 0-terminated URI here */
724 /* variable-size Meta-Data follows here */
730 * Message sent from a GNUnet (fs) publishing
731 * activity to the gnunet-fs-service to
732 * initiate indexing of a file. The service
733 * is supposed to check if the specified file
734 * is available and has the same cryptographic
735 * hash. It should then respond with either
736 * a confirmation or a denial.
738 * On OSes where this works, it is considered
739 * acceptable if the service only checks that
740 * the path, device and inode match (it can
741 * then be assumed that the hash will also match
742 * without actually computing it; this is an
743 * optimization that should be safe given that
744 * the client is not our adversary).
746 struct IndexStartMessage
750 * Message type will be
751 * GNUNET_MESSAGE_TYPE_FS_INDEX_START.
753 struct GNUNET_MessageHeader header;
756 * ID of device containing the file, as seen by the client. This
757 * device ID is obtained using a call like "statvfs" (and converting
758 * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
759 * OS does not support this, in which case the service must do a
760 * full hash recomputation.
765 * Inode of the file on the given device, as seen by the client
766 * ("st_ino" field from "struct stat"). Use 0 if the OS does not
767 * support this, in which case the service must do a full hash
773 * Hash of the file that we would like to index.
775 GNUNET_HashCode file_id;
777 /* this is followed by a 0-terminated
778 filename of a file with the hash
779 "file_id" as seen by the client */
785 * Message send by FS service in response to a request
786 * asking for a list of all indexed files.
788 struct IndexInfoMessage
791 * Message type will be
792 * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
794 struct GNUNET_MessageHeader header;
797 * Hash of the indexed file.
799 GNUNET_HashCode file_id;
801 /* this is followed by a 0-terminated
802 filename of a file with the hash
803 "file_id" as seen by the client */
809 * Message sent from a GNUnet (fs) unindexing
810 * activity to the gnunet-fs-service to
811 * indicate that a file will be unindexed. The service
812 * is supposed to remove the file from the
813 * list of indexed files and response with
814 * a confirmation message (even if the file
815 * was already not on the list).
817 struct UnindexMessage
821 * Message type will be
822 * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
824 struct GNUNET_MessageHeader header;
832 * Hash of the file that we will unindex.
834 GNUNET_HashCode file_id;