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;
386 * How many downloads probing availability
387 * of search results do we have running
390 unsigned int active_probes;
396 * Handle for controlling an upload.
398 struct GNUNET_FS_PublishContext
401 * Handle to the global fs context.
403 struct GNUNET_FS_Handle *h;
406 * Argument to pass to the client in callbacks.
411 * File-structure that is being shared.
413 struct GNUNET_FS_FileInformation *fi;
416 * Namespace that we are publishing in, NULL if we have no namespace.
418 struct GNUNET_FS_Namespace *namespace;
421 * ID of the content in the namespace, NULL if we have no namespace.
426 * ID for future updates, NULL if we have no namespace or no updates.
431 * ID of the task performing the upload. NO_TASK
432 * if the upload has completed.
434 GNUNET_SCHEDULER_TaskIdentifier upload_task;
437 * Our own client handle for the FS service;
438 * only briefly used when we start to index a
439 * file, otherwise NULL.
441 struct GNUNET_CLIENT_Connection *client;
444 * Typically GNUNET_NO. Set to GNUNET_YES if
445 * "upload_task" is GNUNET_SCHEDULER_NO_TASK
446 * and we're waiting for a response from the
447 * datastore service (in which case this
448 * struct must not be freed until we have that
449 * response). If someone tries to stop the
450 * download for good during this period,
451 * "in_network_wait" is set to GNUNET_SYSERR
452 * which will cause the struct to be destroyed
453 * right after we have the reply (or timeout)
454 * from the datastore service.
459 * Options for publishing.
461 enum GNUNET_FS_PublishOptions options;
464 * Current position in the file-tree for the
467 struct GNUNET_FS_FileInformation *fi_pos;
470 * Connection to the datastore service.
472 struct GNUNET_DATASTORE_Handle *dsh;
475 * Space reservation ID with datastore service
483 * Phases of unindex processing (state machine).
488 * We're currently hashing the file.
490 UNINDEX_STATE_HASHING = 0,
493 * We're notifying the FS service about
496 UNINDEX_STATE_FS_NOTIFY = 1,
499 * We're telling the datastore to delete
500 * the respective entries.
502 UNINDEX_STATE_DS_REMOVE = 2,
507 UNINDEX_STATE_COMPLETE = 3,
510 * We've encountered a fatal error.
512 UNINDEX_STATE_ERROR = 4,
515 * We've been aborted. The next callback should clean up the
518 UNINDEX_STATE_ABORTED = 5
523 * Handle for controlling an unindexing operation.
525 struct GNUNET_FS_UnindexContext
531 struct GNUNET_FS_Handle *h;
534 * Name of the file that we are unindexing.
539 * Connection to the FS service,
540 * only valid during the UNINDEX_STATE_FS_NOTIFY
543 struct GNUNET_CLIENT_Connection *client;
546 * Connection to the datastore service,
547 * only valid during the UNINDEX_STATE_DS_NOTIFY
550 struct GNUNET_DATASTORE_Handle *dsh;
553 * Pointer kept for the client.
558 * Merkle-ish tree encoder context.
560 struct GNUNET_FS_TreeEncoder *tc;
563 * Handle used to read the file.
565 struct GNUNET_DISK_FileHandle *fh;
568 * Overall size of the file.
575 struct GNUNET_TIME_Absolute start_time;
578 * Hash of the file's contents (once
581 GNUNET_HashCode file_id;
584 * Current operatinonal phase.
586 enum UnindexState state;
592 * Information we store for each search result.
598 * URI to which this search result
601 struct GNUNET_FS_Uri *uri;
604 * Metadata for the search result.
606 struct GNUNET_CONTAINER_MetaData *meta;
609 * Client info for this search result.
614 * ID of a job that is currently probing
615 * this results' availability (NULL if we
616 * are not currently probing).
618 struct GNUNET_FS_DownloadContext *probe_ctx;
621 * ID of the task that will clean up the probe_ctx
622 * should it not complete on time (and that will
623 * need to be cancelled if we clean up the search
624 * result before then).
626 GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
629 * Number of mandatory keywords for which
630 * we have NOT yet found the search result;
631 * when this value hits zero, the search
632 * result is given to the callback.
634 uint32_t mandatory_missing;
637 * Number of optional keywords under which
638 * this result was also found.
640 uint32_t optional_support;
643 * Number of availability tests that
644 * have succeeded for this result.
646 uint32_t availability_success;
649 * Number of availability trials that we
650 * have performed for this search result.
652 uint32_t availability_trials;
658 * Information we keep for each keyword in
661 struct SearchRequestEntry
664 * Hash of the original keyword, also known as the
665 * key (for decrypting the KBlock).
670 * Hash of the public key, also known as the query.
672 GNUNET_HashCode query;
675 * Map that contains a "struct SearchResult" for each result that
676 * was found under this keyword. Note that the entries will point
677 * to the same locations as those in the master result map (in
678 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
679 * The key for each entry is the XOR of the key and query in the CHK
680 * URI (as a unique identifier for the search result).
682 struct GNUNET_CONTAINER_MultiHashMap *results;
685 * Is this keyword a mandatory keyword
686 * (started with '+')?
694 * Handle for controlling a search.
696 struct GNUNET_FS_SearchContext
699 * Handle to the global FS context.
701 struct GNUNET_FS_Handle *h;
704 * List of keywords that we're looking for.
706 struct GNUNET_FS_Uri *uri;
709 * For update-searches, link to the
710 * base-SKS search that triggered the
711 * update search; otherwise NULL.
713 struct GNUNET_FS_SearchContext *parent;
716 * Connection to the FS service.
718 struct GNUNET_CLIENT_Connection *client;
721 * Pointer we keep for the client.
726 * Map that contains a "struct SearchResult" for each result that
727 * was found in the search. The key for each entry is the XOR of
728 * the key and query in the CHK URI (as a unique identifier for the
731 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
734 * Per-keyword information for a keyword search.
735 * This array will have exactly as many entries
736 * as there were keywords.
738 struct SearchRequestEntry *requests;
743 struct GNUNET_TIME_Absolute start_time;
746 * ID of a task that is using this struct
747 * and that must be cancelled when the search
748 * is being stopped (if not GNUNET_SCHEDULER_NO_TASK).
749 * Used for the task that adds some artificial
750 * delay when trying to reconnect to the FS
753 GNUNET_SCHEDULER_TaskIdentifier task;
756 * Anonymity level for the search.
761 * Number of mandatory keywords in this query.
763 uint32_t mandatory_count;
768 * Context for controlling a download.
770 struct GNUNET_FS_DownloadContext
774 struct GNUNET_FS_Namespace
778 * Private key for the namespace.
780 struct GNUNET_CRYPTO_RsaPrivateKey *key;
790 * @brief index block (indexing a DBlock that
791 * can be obtained directly from reading
792 * the plaintext file)
797 * Hash code of the entire content of the
798 * file that was indexed (used to uniquely
799 * identify the plaintext file).
801 GNUNET_HashCode file_id;
804 * At which offset should we be able to find
805 * this on-demand encoded block?
807 uint64_t offset GNUNET_PACKED;
813 * @brief keyword block (advertising data under a keyword)
819 * GNUNET_RSA_Signature using RSA-key generated from search keyword.
821 struct GNUNET_CRYPTO_RsaSignature signature;
824 * What is being signed and why?
826 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
829 * Key generated (!) from the H(keyword) as the seed!
831 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
833 /* 0-terminated URI here */
835 /* variable-size Meta-Data follows here */
840 * @brief namespace content block (advertising data under an identifier in a namespace)
846 * GNUNET_RSA_Signature using RSA-key of the namespace
848 struct GNUNET_CRYPTO_RsaSignature signature;
851 * What is being signed and why?
853 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
856 * Hash of the hash of the human-readable identifier used for
857 * this entry (the hash of the human-readable identifier is
858 * used as the key for decryption; the xor of this identifier
859 * and the hash of the "keyspace" is the datastore-query hash).
861 GNUNET_HashCode identifier;
864 * Public key of the namespace.
866 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
868 /* 0-terminated update-identifier here */
870 /* 0-terminated URI here */
872 /* variable-size Meta-Data follows here */
878 * Message sent from a GNUnet (fs) publishing
879 * activity to the gnunet-fs-service to
880 * initiate indexing of a file. The service
881 * is supposed to check if the specified file
882 * is available and has the same cryptographic
883 * hash. It should then respond with either
884 * a confirmation or a denial.
886 * On OSes where this works, it is considered
887 * acceptable if the service only checks that
888 * the path, device and inode match (it can
889 * then be assumed that the hash will also match
890 * without actually computing it; this is an
891 * optimization that should be safe given that
892 * the client is not our adversary).
894 struct IndexStartMessage
898 * Message type will be
899 * GNUNET_MESSAGE_TYPE_FS_INDEX_START.
901 struct GNUNET_MessageHeader header;
904 * ID of device containing the file, as seen by the client. This
905 * device ID is obtained using a call like "statvfs" (and converting
906 * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
907 * OS does not support this, in which case the service must do a
908 * full hash recomputation.
910 uint32_t device GNUNET_PACKED;
913 * Inode of the file on the given device, as seen by the client
914 * ("st_ino" field from "struct stat"). Use 0 if the OS does not
915 * support this, in which case the service must do a full hash
918 uint64_t inode GNUNET_PACKED;
921 * Hash of the file that we would like to index.
923 GNUNET_HashCode file_id;
925 /* this is followed by a 0-terminated
926 filename of a file with the hash
927 "file_id" as seen by the client */
933 * Message send by FS service in response to a request
934 * asking for a list of all indexed files.
936 struct IndexInfoMessage
939 * Message type will be
940 * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
942 struct GNUNET_MessageHeader header;
947 uint32_t reserved GNUNET_PACKED;
950 * Hash of the indexed file.
952 GNUNET_HashCode file_id;
954 /* this is followed by a 0-terminated
955 filename of a file with the hash
956 "file_id" as seen by the client */
962 * Message sent from a GNUnet (fs) unindexing
963 * activity to the gnunet-fs-service to
964 * indicate that a file will be unindexed. The service
965 * is supposed to remove the file from the
966 * list of indexed files and response with
967 * a confirmation message (even if the file
968 * was already not on the list).
970 struct UnindexMessage
974 * Message type will be
975 * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
977 struct GNUNET_MessageHeader header;
982 uint32_t reserved GNUNET_PACKED;
985 * Hash of the file that we will unindex.
987 GNUNET_HashCode file_id;
993 * Message sent from a GNUnet (fs) search
994 * activity to the gnunet-fs-service to
1001 * Message type will be
1002 * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
1004 struct GNUNET_MessageHeader header;
1009 int32_t reserved GNUNET_PACKED;
1012 * Type of the content that we're looking for.
1015 uint32_t type GNUNET_PACKED;
1018 * Desired anonymity level, big-endian.
1020 uint32_t anonymity_level GNUNET_PACKED;
1023 * If the request is for a DBLOCK or IBLOCK, this is the identity of
1024 * the peer that is known to have a response. Set to all-zeros if
1025 * such a target is not known (note that even if OUR anonymity
1026 * level is >0 we may happen to know the responder's identity;
1027 * nevertheless, we should probably not use it for a DHT-lookup
1028 * or similar blunt actions in order to avoid exposing ourselves).
1030 * If the request is for an SBLOCK, this is the identity of the
1031 * pseudonym to which the SBLOCK belongs.
1033 * If the request is for a KBLOCK, "target" must be all zeros.
1035 GNUNET_HashCode target;
1038 * Hash of the keyword (aka query) for KBLOCKs; Hash of
1039 * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
1040 * and hash of the identifier XORed with the target for
1041 * SBLOCKS (aka query).
1043 GNUNET_HashCode query;
1049 * Response from FS service with a result for
1050 * a previous FS search. Note that queries
1051 * for DBLOCKS and IBLOCKS that have received
1052 * a single response are considered done.
1054 struct ContentMessage
1058 * Message type will be
1059 * GNUNET_MESSAGE_TYPE_FS_CONTENT.
1061 struct GNUNET_MessageHeader header;
1064 * Type of the content that was found,
1065 * should never be 0.
1067 uint32_t type GNUNET_PACKED;
1070 * When will this result expire?
1072 struct GNUNET_TIME_AbsoluteNBO expiration;
1074 /* followed by the actual block of data */