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 * Encoder being used to publish this file.
245 struct GNUNET_FS_TreeEncoder *te;
248 * Error message (non-NULL if this operation
254 * Data describing either the file or the directory.
265 * Function that can be used to read the data for the file.
267 GNUNET_FS_DataReader reader;
270 * Closure for reader.
275 * Name of the file (must be an absolute path).
276 * Only required for indexing. FIXME: not yet
282 * If this file is being indexed, this value
283 * is set to the hash over the entire file
284 * (when the indexing process is started).
285 * Otherwise this field is not used.
287 GNUNET_HashCode file_id;
290 * Size of the file (in bytes).
295 * Should the file be indexed or inserted?
302 * Data for a directory.
307 * Name of the directory.
312 * Linked list of entries in the directory.
314 struct GNUNET_FS_FileInformation *entries;
317 * Size of the directory itself (in bytes); 0 if the
318 * size has not yet been calculated.
323 * Pointer to the data for the directory (or NULL if not
333 * Is this struct for a file or directory?
338 * Desired anonymity level.
340 unsigned int anonymity;
343 * Desired priority (for keeping the content in the DB).
345 unsigned int priority;
351 * Master context for most FS operations.
353 struct GNUNET_FS_Handle
358 struct GNUNET_SCHEDULER_Handle *sched;
361 * Configuration to use.
363 const struct GNUNET_CONFIGURATION_Handle *cfg;
366 * Name of our client.
371 * Function to call with updates on our progress.
373 GNUNET_FS_ProgressCallback upcb;
381 * Connection to the FS service.
383 struct GNUNET_CLIENT_Connection *client;
390 * Handle for controlling an upload.
392 struct GNUNET_FS_PublishContext
395 * Handle to the global fs context.
397 struct GNUNET_FS_Handle *h;
400 * Argument to pass to the client in callbacks.
405 * File-structure that is being shared.
407 struct GNUNET_FS_FileInformation *fi;
410 * Namespace that we are publishing in, NULL if we have no namespace.
412 struct GNUNET_FS_Namespace *namespace;
415 * ID of the content in the namespace, NULL if we have no namespace.
420 * ID for future updates, NULL if we have no namespace or no updates.
425 * ID of the task performing the upload. NO_TASK
426 * if the upload has completed.
428 GNUNET_SCHEDULER_TaskIdentifier upload_task;
431 * Our own client handle for the FS service;
432 * only briefly used when we start to index a
433 * file, otherwise NULL.
435 struct GNUNET_CLIENT_Connection *client;
438 * Typically GNUNET_NO. Set to GNUNET_YES if
439 * "upload_task" is GNUNET_SCHEDULER_NO_TASK
440 * and we're waiting for a response from the
441 * datastore service (in which case this
442 * struct must not be freed until we have that
443 * response). If someone tries to stop the
444 * download for good during this period,
445 * "in_network_wait" is set to GNUNET_SYSERR
446 * which will cause the struct to be destroyed
447 * right after we have the reply (or timeout)
448 * from the datastore service.
453 * Options for publishing.
455 enum GNUNET_FS_PublishOptions options;
458 * Current position in the file-tree for the
461 struct GNUNET_FS_FileInformation *fi_pos;
464 * Connection to the datastore service.
466 struct GNUNET_DATASTORE_Handle *dsh;
469 * Space reservation ID with datastore service
477 * Phases of unindex processing (state machine).
482 * We're currently hashing the file.
484 UNINDEX_STATE_HASHING = 0,
487 * We're notifying the FS service about
490 UNINDEX_STATE_FS_NOTIFY = 1,
493 * We're telling the datastore to delete
494 * the respective entries.
496 UNINDEX_STATE_DS_REMOVE = 2,
501 UNINDEX_STATE_COMPLETE = 3,
504 * We've encountered a fatal error.
506 UNINDEX_STATE_ERROR = 4,
509 * We've been aborted. The next callback should clean up the
512 UNINDEX_STATE_ABORTED = 5
517 * Handle for controlling an unindexing operation.
519 struct GNUNET_FS_UnindexContext
525 struct GNUNET_FS_Handle *h;
528 * Name of the file that we are unindexing.
533 * Connection to the FS service,
534 * only valid during the UNINDEX_STATE_FS_NOTIFY
537 struct GNUNET_CLIENT_Connection *client;
540 * Connection to the datastore service,
541 * only valid during the UNINDEX_STATE_DS_NOTIFY
544 struct GNUNET_DATASTORE_Handle *dsh;
547 * Pointer kept for the client.
552 * Merkle-ish tree encoder context.
554 struct GNUNET_FS_TreeEncoder *tc;
557 * Handle used to read the file.
559 struct GNUNET_DISK_FileHandle *fh;
562 * Overall size of the file.
569 struct GNUNET_TIME_Absolute start_time;
572 * Hash of the file's contents (once
575 GNUNET_HashCode file_id;
578 * Current operatinonal phase.
580 enum UnindexState state;
586 * Information we keep for each keyword in
589 struct SearchRequestEntry
592 * Hash of the original keyword, also known as the
593 * key (for decrypting the KBlock).
598 * Hash of the public key, also known as the query.
600 GNUNET_HashCode query;
605 * Handle for controlling a search.
607 struct GNUNET_FS_SearchContext
610 * Handle to the global FS context.
612 struct GNUNET_FS_Handle *h;
615 * List of keywords that we're looking for.
617 struct GNUNET_FS_Uri *uri;
620 * Connection to the FS service.
622 struct GNUNET_CLIENT_Connection *client;
625 * Per-keyword information for a keyword search.
627 struct SearchRequestEntry *requests;
632 struct GNUNET_TIME_Absolute start_time;
635 * ID of a task that is using this struct
636 * and that must be cancelled when the search
637 * is being stopped (if not GNUNET_SCHEDULER_NO_TASK).
638 * Used for the task that adds some artificial
639 * delay when trying to reconnect to the FS
642 GNUNET_SCHEDULER_TaskIdentifier task;
645 * Anonymity level for the search.
647 unsigned int anonymity;
654 * Context for controlling a download.
656 struct GNUNET_FS_DownloadContext
660 struct GNUNET_FS_Namespace
664 * Private key for the namespace.
666 struct GNUNET_CRYPTO_RsaPrivateKey *key;
676 * @brief index block (indexing a DBlock that
677 * can be obtained directly from reading
678 * the plaintext file)
683 * Hash code of the entire content of the
684 * file that was indexed (used to uniquely
685 * identify the plaintext file).
687 GNUNET_HashCode file_id;
690 * At which offset should we be able to find
691 * this on-demand encoded block?
693 uint64_t offset GNUNET_PACKED;
699 * @brief keyword block (advertising data under a keyword)
705 * GNUNET_RSA_Signature using RSA-key generated from search keyword.
707 struct GNUNET_CRYPTO_RsaSignature signature;
710 * What is being signed and why?
712 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
715 * Key generated (!) from the H(keyword) as the seed!
717 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
719 /* 0-terminated URI here */
721 /* variable-size Meta-Data follows here */
726 * @brief namespace content block (advertising data under an identifier in a namespace)
732 * GNUNET_RSA_Signature using RSA-key of the namespace
734 struct GNUNET_CRYPTO_RsaSignature signature;
737 * What is being signed and why?
739 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
742 * Hash of the hash of the human-readable identifier used for
743 * this entry (the hash of the human-readable identifier is
744 * used as the key for decryption; the xor of this identifier
745 * and the hash of the "keyspace" is the datastore-query hash).
747 GNUNET_HashCode identifier;
750 * Public key of the namespace.
752 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
754 /* 0-terminated update-identifier here */
756 /* 0-terminated URI here */
758 /* variable-size Meta-Data follows here */
764 * Message sent from a GNUnet (fs) publishing
765 * activity to the gnunet-fs-service to
766 * initiate indexing of a file. The service
767 * is supposed to check if the specified file
768 * is available and has the same cryptographic
769 * hash. It should then respond with either
770 * a confirmation or a denial.
772 * On OSes where this works, it is considered
773 * acceptable if the service only checks that
774 * the path, device and inode match (it can
775 * then be assumed that the hash will also match
776 * without actually computing it; this is an
777 * optimization that should be safe given that
778 * the client is not our adversary).
780 struct IndexStartMessage
784 * Message type will be
785 * GNUNET_MESSAGE_TYPE_FS_INDEX_START.
787 struct GNUNET_MessageHeader header;
790 * ID of device containing the file, as seen by the client. This
791 * device ID is obtained using a call like "statvfs" (and converting
792 * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
793 * OS does not support this, in which case the service must do a
794 * full hash recomputation.
796 uint32_t device GNUNET_PACKED;
799 * Inode of the file on the given device, as seen by the client
800 * ("st_ino" field from "struct stat"). Use 0 if the OS does not
801 * support this, in which case the service must do a full hash
804 uint64_t inode GNUNET_PACKED;
807 * Hash of the file that we would like to index.
809 GNUNET_HashCode file_id;
811 /* this is followed by a 0-terminated
812 filename of a file with the hash
813 "file_id" as seen by the client */
819 * Message send by FS service in response to a request
820 * asking for a list of all indexed files.
822 struct IndexInfoMessage
825 * Message type will be
826 * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
828 struct GNUNET_MessageHeader header;
833 uint32_t reserved GNUNET_PACKED;
836 * Hash of the indexed file.
838 GNUNET_HashCode file_id;
840 /* this is followed by a 0-terminated
841 filename of a file with the hash
842 "file_id" as seen by the client */
848 * Message sent from a GNUnet (fs) unindexing
849 * activity to the gnunet-fs-service to
850 * indicate that a file will be unindexed. The service
851 * is supposed to remove the file from the
852 * list of indexed files and response with
853 * a confirmation message (even if the file
854 * was already not on the list).
856 struct UnindexMessage
860 * Message type will be
861 * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
863 struct GNUNET_MessageHeader header;
868 uint32_t reserved GNUNET_PACKED;
871 * Hash of the file that we will unindex.
873 GNUNET_HashCode file_id;
879 * Message sent from a GNUnet (fs) search
880 * activity to the gnunet-fs-service to
887 * Message type will be
888 * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
890 struct GNUNET_MessageHeader header;
895 int32_t reserved GNUNET_PACKED;
898 * Type of the content that we're looking for.
901 uint32_t type GNUNET_PACKED;
904 * Desired anonymity level, big-endian.
906 uint32_t anonymity_level GNUNET_PACKED;
909 * If the request is for a DBLOCK or IBLOCK, this is the identity of
910 * the peer that is known to have a response. Set to all-zeros if
911 * such a target is not known (note that even if OUR anonymity
912 * level is >0 we may happen to know the responder's identity;
913 * nevertheless, we should probably not use it for a DHT-lookup
914 * or similar blunt actions in order to avoid exposing ourselves).
916 * If the request is for an SBLOCK, this is the identity of the
917 * pseudonym to which the SBLOCK belongs.
919 * If the request is for a KBLOCK, "target" must be all zeros.
921 GNUNET_HashCode target;
924 * Hash of the keyword (aka query) for KBLOCKs; Hash of
925 * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
926 * and hash of the identifier XORed with the target for
927 * SBLOCKS (aka query).
929 GNUNET_HashCode query;
935 * Response from FS service with a result for
936 * a previous FS search. Note that queries
937 * for DBLOCKS and IBLOCKS that have received
938 * a single response are considered done.
940 struct ContentMessage
944 * Message type will be
945 * GNUNET_MESSAGE_TYPE_FS_CONTENT.
947 struct GNUNET_MessageHeader header;
950 * Type of the content that was found,
953 uint32_t type GNUNET_PACKED;
956 * When will this result expire?
958 struct GNUNET_TIME_AbsoluteNBO expiration;
960 /* followed by the actual block of data */