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 3, 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_constants.h"
30 #include "gnunet_datastore_service.h"
31 #include "gnunet_dht_service.h"
32 #include "gnunet_fs_service.h"
33 #include "gnunet_block_lib.h"
38 * Maximum number of outgoing messages we queue per peer.
40 * Performance measurements for 2 peer setup for 50 MB file
41 * (with MAX_DATASTORE_QUEUE = 1 and RETRY_PROBABILITY_INV = 1):
43 * 2: 1700 kb/s, 1372 kb/s
44 * 8: 2117 kb/s, 1284 kb/s, 1112 kb/s
45 * 16: 3500 kb/s, 3200 kb/s, 3388 kb/s
46 * 32: 3441 kb/s, 3163 kb/s, 3277 kb/s
47 * 128: 1700 kb/s; 2010 kb/s, 3383 kb/s, 1156 kb/s
49 * Conclusion: 16 seems to be a pretty good value (stable
50 * and high performance, no excessive memory use).
52 #define MAX_QUEUE_PER_PEER 16
55 * Maximum size of the datastore queue for P2P operations.
56 * Needs to be large enough to queue MAX_QUEUE_PER_PEER
57 * operations for roughly the number of active (connected)
60 #define MAX_DATASTORE_QUEUE (16 * MAX_QUEUE_PER_PEER)
63 * Maximum number of blocks we keep in memory for migration.
65 #define MAX_MIGRATION_QUEUE 8
68 * Blocks are at most migrated to this number of peers
69 * plus one, each time they are fetched from the database.
71 #define MIGRATION_LIST_SIZE 2
74 * To how many peers do we forward each migration block ultimately?
75 * This number must be smaller or equal to MIGRATION_LIST_SIZE. Using
76 * a smaller value allows for variation in available bandwidth (for
77 * migration) between the peers.
79 #define MIGRATION_TARGET_COUNT 2
82 * Ratio for moving average delay calculation. The previous
83 * average goes in with a factor of (n-1) into the calculation.
86 #define RUNAVG_DELAY_N 16
89 * Size of the individual blocks used for file-sharing.
91 #define DBLOCK_SIZE (32*1024)
94 * Maximum legal size for a kblock.
96 #define MAX_KBLOCK_SIZE (60 * 1024)
99 * Maximum legal size for an sblock.
101 #define MAX_SBLOCK_SIZE (60 * 1024)
104 * Maximum legal size for an nblock.
106 #define MAX_NBLOCK_SIZE (60 * 1024)
109 * Pick a multiple of 2 here to achive 8-byte alignment!
110 * We also probably want DBlocks to have (roughly) the
111 * same size as IBlocks. With SHA-512, the optimal
112 * value is 32768 byte / 128 byte = 256
113 * (128 byte = 2 * 512 bits). DO NOT CHANGE!
115 #define CHK_PER_INODE 256
119 * Maximum size for a file to be considered for
120 * inlining in a directory.
122 #define MAX_INLINE_SIZE 65536
126 * Blocksize to use when hashing files
127 * for indexing (blocksize for IO, not for
128 * the DBlocks). Larger blocksizes can
129 * be more efficient but will be more disruptive
130 * as far as the scheduler is concerned.
132 #define HASHING_BLOCKSIZE (1024 * 128)
135 * Number of availability trials we perform per search result.
137 #define AVAILABILITY_TRIALS_MAX 8
140 * Length of the P2P success tracker. Note that
141 * having a very long list can also hurt performance.
143 #define P2P_SUCCESS_LIST_SIZE 8
147 * Length of the CS-2-P success tracker. Note that
148 * having a very long list can also hurt performance.
150 #define CS2P_SUCCESS_LIST_SIZE 8
153 * How long are we willing to wait for the datastore to be ready to
154 * process a request for a query without priority?
156 #define BASIC_DATASTORE_REQUEST_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
160 * How long are we willing to wait for the core to be ready to
161 * transmit a reply to the target peer (if we can not transmit
162 * until then, we will discard the reply).
164 #define ACCEPTABLE_REPLY_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
168 * Bandwidth value of an (effectively) 0-priority query.
170 #define QUERY_BANDWIDTH_VALUE 1
173 * Bandwidth value of a 0-priority content (must be
174 * fairly high compared to query since content is
175 * typically significantly larger -- and more valueable
176 * since it can take many queries to get one piece of
179 #define CONTENT_BANDWIDTH_VALUE 800
182 * By which amount do we decrement the TTL for simple forwarding /
183 * indirection of the query; in milli-seconds. Set somewhat in
184 * accordance to your network latency (above the time it'll take you
185 * to send a packet and get a reply).
187 #define TTL_DECREMENT 5000
190 * Until which load do we consider the peer idle and do not
191 * charge at all? (should be larger than GNUNET_IDLE_LOAD_THRESHOLD used
192 * by the rest of the code)!
194 #define IDLE_LOAD_THRESHOLD ((100 + GNUNET_CONSTANTS_IDLE_LOAD_THRESHOLD) / 2)
197 * Name of the directory with top-level searches.
199 #define GNUNET_FS_SYNC_PATH_MASTER_SEARCH "search"
202 * Name of the directory with sub-searches (namespace-updates).
204 #define GNUNET_FS_SYNC_PATH_CHILD_SEARCH "search-child"
207 * Name of the directory with master downloads (not associated
208 * with search or part of another download).
210 #define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD "download"
213 * Name of the directory with downloads that are part of another
214 * download or a search.
216 #define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD "download-child"
219 * Name of the directory with publishing operations.
221 #define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH "publish"
224 * Name of the directory with files that are being published
226 #define GNUNET_FS_SYNC_PATH_FILE_INFO "publish-file"
229 * Name of the directory with unindex operations.
231 #define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX "unindex"
235 * @brief content hash key
237 struct ContentHashKey
240 * Hash of the original content, used for encryption.
245 * Hash of the encrypted content, used for querying.
247 GNUNET_HashCode query;
252 * @brief complete information needed
253 * to download a file.
255 struct FileIdentifier
259 * Total size of the file in bytes. (network byte order (!))
261 uint64_t file_length;
264 * Query and key of the top GNUNET_EC_IBlock.
266 struct ContentHashKey chk;
272 * Information about a file and its location
273 * (peer claiming to share the file).
278 * Information about the shared file.
280 struct FileIdentifier fi;
283 * Identity of the peer sharing the file.
285 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
288 * Time when this location URI expires.
290 struct GNUNET_TIME_Absolute expirationTime;
293 * RSA signature over the GNUNET_EC_FileIdentifier,
294 * GNUNET_hash of the peer and expiration time.
296 struct GNUNET_CRYPTO_RsaSignature contentSignature;
306 * Content-hash-key (simple file).
311 * Signed key space (file in namespace).
316 * Keyword search key (query with keywords).
321 * Location (chk with identity of hosting peer).
327 * A Universal Resource Identifier (URI), opaque.
341 * Keywords start with a '+' if they are
342 * mandatory (in which case the '+' is NOT
343 * part of the keyword) and with a
344 * simple space if they are optional
345 * (in which case the space is ALSO not
346 * part of the actual keyword).
348 * Double-quotes to protect spaces and
349 * %-encoding are NOT used internally
350 * (only in URI-strings).
355 * Size of the keywords array.
357 unsigned int keywordCount;
363 * Hash of the public key for the namespace.
365 GNUNET_HashCode namespace;
368 * Human-readable identifier chosen for this
369 * entry in the namespace.
375 * Information needed to retrieve a file (content-hash-key
378 struct FileIdentifier chk;
381 * Information needed to retrieve a file including signed
382 * location (identity of a peer) of the content.
391 * Information for a file or directory that is
392 * about to be published.
394 struct GNUNET_FS_FileInformation
398 * Files in a directory are kept as a linked list.
400 struct GNUNET_FS_FileInformation *next;
403 * If this is a file in a directory, "dir" refers to
404 * the directory; otherwise NULL.
406 struct GNUNET_FS_FileInformation *dir;
409 * Handle to the master context.
411 struct GNUNET_FS_Handle *h;
414 * Pointer kept for the client.
419 * Metadata to use for the file.
421 struct GNUNET_CONTAINER_MetaData *meta;
424 * Keywords to use for KBlocks.
426 struct GNUNET_FS_Uri *keywords;
429 * CHK for this file or directory. NULL if
430 * we have not yet computed it.
432 struct GNUNET_FS_Uri *chk_uri;
435 * Block options for the file.
437 struct GNUNET_FS_BlockOptions bo;
440 * At what time did we start this upload?
442 struct GNUNET_TIME_Absolute start_time;
445 * Under what filename is this struct serialized
446 * (for operational persistence). Should be determined
452 * Encoder being used to publish this file.
454 struct GNUNET_FS_TreeEncoder *te;
457 * Error message (non-NULL if this operation failed).
462 * Name of the file or directory (must be an absolute path).
467 * Data describing either the file or the directory.
479 * Function that can be used to read the data for the file.
481 GNUNET_FS_DataReader reader;
484 * Closure for reader.
489 * If this file is being indexed, this value is set to the hash
490 * over the entire file (when the indexing process is started).
491 * Otherwise this field is not used.
493 GNUNET_HashCode file_id;
496 * Size of the file (in bytes).
501 * Should the file be indexed or inserted?
506 * Is "file_id" already valid? Set to GNUNET_YES once the hash
507 * has been calculated.
512 * Has the service confirmed our INDEX_START request?
513 * GNUNET_YES if this step has been completed.
515 int index_start_confirmed;
520 * Data for a directory.
526 * Linked list of entries in the directory.
528 struct GNUNET_FS_FileInformation *entries;
531 * Size of the directory itself (in bytes); 0 if the
532 * size has not yet been calculated.
537 * Pointer to the data for the directory (or NULL if not
547 * Is this struct for a file or directory?
552 * Are we done publishing this file?
560 * The job is now ready to run and should use the given client
561 * handle to communicate with the FS service.
564 * @param client handle to use for FS communication
566 typedef void (*GNUNET_FS_QueueStart) (void *cls,
567 struct GNUNET_CLIENT_Connection * client);
571 * The job must now stop to run and should destry the client handle as
572 * soon as possible (ideally prior to returning).
574 typedef void (*GNUNET_FS_QueueStop) (void *cls);
578 * Entry in the job queue.
580 struct GNUNET_FS_QueueEntry
583 * This is a linked list.
585 struct GNUNET_FS_QueueEntry *next;
588 * This is a linked list.
590 struct GNUNET_FS_QueueEntry *prev;
593 * Function to call when the job is started.
595 GNUNET_FS_QueueStart start;
598 * Function to call when the job needs to stop (or is done / dequeued).
600 GNUNET_FS_QueueStop stop;
603 * Closure for start and stop.
608 * Handle to FS primary context.
610 struct GNUNET_FS_Handle *h;
613 * Client handle, or NULL if job is not running.
615 struct GNUNET_CLIENT_Connection *client;
618 * Time the job was originally queued.
620 struct GNUNET_TIME_Absolute queue_time;
623 * Time the job was started last.
625 struct GNUNET_TIME_Absolute start_time;
628 * Total amount of time the job has been running (except for the
631 struct GNUNET_TIME_Relative run_time;
634 * How many blocks do the active downloads have?
639 * How often have we (re)started this download?
641 unsigned int start_times;
649 * Information we store for each search result.
651 struct GNUNET_FS_SearchResult
655 * Search context this result belongs to.
657 struct GNUNET_FS_SearchContext *sc;
660 * URI to which this search result refers to.
662 struct GNUNET_FS_Uri *uri;
665 * Metadata for the search result.
667 struct GNUNET_CONTAINER_MetaData *meta;
670 * Client info for this search result.
675 * ID of a job that is currently probing this results' availability
676 * (NULL if we are not currently probing).
678 struct GNUNET_FS_DownloadContext *probe_ctx;
681 * ID of an associated download based on this search result (or
684 struct GNUNET_FS_DownloadContext *download;
687 * If this search result triggered an update search, this field
688 * links to the update search.
690 struct GNUNET_FS_SearchContext *update_search;
693 * Name under which this search result is stored on disk.
698 * Key for the search result
703 * ID of the task that will clean up the probe_ctx should it not
704 * complete on time (and that will need to be cancelled if we clean
705 * up the search result before then).
707 GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
710 * When did the current probe become active?
712 struct GNUNET_TIME_Absolute probe_active_time;
715 * How much longer should we run the current probe before giving up?
717 struct GNUNET_TIME_Relative remaining_probe_time;
720 * Number of mandatory keywords for which we have NOT yet found the
721 * search result; when this value hits zero, the search result is
722 * given to the callback.
724 uint32_t mandatory_missing;
727 * Number of optional keywords under which this result was also
730 uint32_t optional_support;
733 * Number of availability tests that have succeeded for this result.
735 uint32_t availability_success;
738 * Number of availability trials that we have performed for this
741 uint32_t availability_trials;
747 * Add a job to the queue.
749 * @param h handle to the overall FS state
750 * @param start function to call to begin the job
751 * @param stop function to call to pause the job, or on dequeue (if the job was running)
752 * @param cls closure for start and stop
753 * @param blocks number of blocks this download has
754 * @return queue handle
756 struct GNUNET_FS_QueueEntry *
757 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, GNUNET_FS_QueueStart start,
758 GNUNET_FS_QueueStop stop, void *cls, unsigned int blocks);
762 * Dequeue a job from the queue.
763 * @param qh handle for the job
766 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
770 * Function that provides data by reading from a file.
772 * @param cls closure (points to the file information)
773 * @param offset offset to read from; it is possible
774 * that the caller might need to go backwards
776 * @param max maximum number of bytes that should be
777 * copied to buf; readers are not allowed
778 * to provide less data unless there is an error;
779 * a value of "0" will be used at the end to allow
780 * the reader to clean up its internal state
781 * @param buf where the reader should write the data
782 * @param emsg location for the reader to store an error message
783 * @return number of bytes written, usually "max", 0 on error
786 GNUNET_FS_data_reader_file_ (void *cls, uint64_t offset, size_t max, void *buf,
791 * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
793 * @param filename file to read
794 * @return closure to use
797 GNUNET_FS_make_file_reader_context_ (const char *filename);
802 * Function that provides data by copying from a buffer.
804 * @param cls closure (points to the buffer)
805 * @param offset offset to read from; it is possible
806 * that the caller might need to go backwards
808 * @param max maximum number of bytes that should be
809 * copied to buf; readers are not allowed
810 * to provide less data unless there is an error;
811 * a value of "0" will be used at the end to allow
812 * the reader to clean up its internal state
813 * @param buf where the reader should write the data
814 * @param emsg location for the reader to store an error message
815 * @return number of bytes written, usually "max", 0 on error
818 GNUNET_FS_data_reader_copy_ (void *cls, uint64_t offset, size_t max, void *buf,
822 * Notification of FS that a search probe has made progress.
823 * This function is used INSTEAD of the client's event handler
824 * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
826 * @param cls closure, always NULL (!), actual closure
827 * is in the client-context of the info struct
828 * @param info details about the event, specifying the event type
829 * and various bits about the event
830 * @return client-context (for the next progress call
831 * for this operation; should be set to NULL for
832 * SUSPEND and STOPPED events). The value returned
833 * will be passed to future callbacks in the respective
834 * field in the GNUNET_FS_ProgressInfo struct.
837 GNUNET_FS_search_probe_progress_ (void *cls,
838 const struct GNUNET_FS_ProgressInfo *info);
842 * Main function that performs the upload.
844 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
845 * @param tc task context
848 GNUNET_FS_publish_main_ (void *cls,
849 const struct GNUNET_SCHEDULER_TaskContext *tc);
853 * Function called once the hash of the file
854 * that is being unindexed has been computed.
856 * @param cls closure, unindex context
857 * @param file_id computed hash, NULL on error
860 GNUNET_FS_unindex_process_hash_ (void *cls, const GNUNET_HashCode * file_id);
864 * Fill in all of the generic fields for a publish event and call the
867 * @param pi structure to fill in
868 * @param pc overall publishing context
869 * @param p file information for the file being published
870 * @param offset where in the file are we so far
871 * @return value returned from callback
874 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
875 struct GNUNET_FS_PublishContext *pc,
876 const struct GNUNET_FS_FileInformation *p,
881 * Fill in all of the generic fields for a download event and call the
884 * @param pi structure to fill in
885 * @param dc overall download context
888 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
889 struct GNUNET_FS_DownloadContext *dc);
893 * Task that creates the initial (top-level) download
894 * request for the file.
896 * @param cls the 'struct GNUNET_FS_DownloadContext'
897 * @param tc scheduler context
900 GNUNET_FS_download_start_task_ (void *cls,
901 const struct GNUNET_SCHEDULER_TaskContext *tc);
906 * Fill in all of the generic fields for
907 * an unindex event and call the callback.
909 * @param pi structure to fill in
910 * @param uc overall unindex context
911 * @param offset where we are in the file (for progress)
914 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
915 struct GNUNET_FS_UnindexContext *uc,
919 * Fill in all of the generic fields for a search event and
922 * @param pi structure to fill in
923 * @param sc overall search context
924 * @return value returned by the callback
927 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
928 struct GNUNET_FS_SearchContext *sc);
932 * Connect to the datastore and remove the blocks.
934 * @param uc context for the unindex operation.
937 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
940 * Build the request and actually initiate the search using the
943 * @param sc search context
944 * @return GNUNET_OK on success, GNUNET_SYSERR on error
947 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
950 * Start the downloading process (by entering the queue).
952 * @param dc our download context
955 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
959 * Start download probes for the given search result.
961 * @param sr the search result
964 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
967 * Remove serialization/deserialization file from disk.
969 * @param h master context
970 * @param ext component of the path
971 * @param ent entity identifier
974 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, const char *ext,
979 * Remove serialization/deserialization directory from disk.
981 * @param h master context
982 * @param ext component of the path
983 * @param uni unique name of parent
986 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, const char *ext,
991 * Synchronize this file-information struct with its mirror
992 * on disk. Note that all internal FS-operations that change
993 * file information data should already call "sync" internally,
994 * so this function is likely not useful for clients.
996 * @param fi the struct to sync
999 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
1002 * Synchronize this publishing struct with its mirror
1003 * on disk. Note that all internal FS-operations that change
1004 * publishing structs should already call "sync" internally,
1005 * so this function is likely not useful for clients.
1007 * @param pc the struct to sync
1010 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
1013 * Synchronize this unindex struct with its mirror
1014 * on disk. Note that all internal FS-operations that change
1015 * publishing structs should already call "sync" internally,
1016 * so this function is likely not useful for clients.
1018 * @param uc the struct to sync
1021 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
1024 * Synchronize this search struct with its mirror
1025 * on disk. Note that all internal FS-operations that change
1026 * publishing structs should already call "sync" internally,
1027 * so this function is likely not useful for clients.
1029 * @param sc the struct to sync
1032 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
1035 * Synchronize this search result with its mirror
1036 * on disk. Note that all internal FS-operations that change
1037 * publishing structs should already call "sync" internally,
1038 * so this function is likely not useful for clients.
1040 * @param sr the struct to sync
1043 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
1046 * Synchronize this download struct with its mirror
1047 * on disk. Note that all internal FS-operations that change
1048 * publishing structs should already call "sync" internally,
1049 * so this function is likely not useful for clients.
1051 * @param dc the struct to sync
1054 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
1057 * Create SUSPEND event for the given publish operation
1058 * and then clean up our state (without stop signal).
1060 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
1063 GNUNET_FS_publish_signal_suspend_ (void *cls);
1066 * Create SUSPEND event for the given search operation
1067 * and then clean up our state (without stop signal).
1069 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
1072 GNUNET_FS_search_signal_suspend_ (void *cls);
1075 * Create SUSPEND event for the given download operation
1076 * and then clean up our state (without stop signal).
1078 * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
1081 GNUNET_FS_download_signal_suspend_ (void *cls);
1084 * Create SUSPEND event for the given unindex operation
1085 * and then clean up our state (without stop signal).
1087 * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
1090 GNUNET_FS_unindex_signal_suspend_ (void *cls);
1093 * Function signature of the functions that can be called
1094 * to trigger suspend signals and clean-up for top-level
1097 * @param cls closure
1099 typedef void (*SuspendSignalFunction) (void *cls);
1102 * We track all of the top-level activities of FS
1103 * so that we can signal 'suspend' on shutdown.
1105 struct TopLevelActivity
1108 * This is a doubly-linked list.
1110 struct TopLevelActivity *next;
1113 * This is a doubly-linked list.
1115 struct TopLevelActivity *prev;
1118 * Function to call for suspend-signalling and clean up.
1120 SuspendSignalFunction ssf;
1123 * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1130 * Create a top-level activity entry.
1132 * @param h global fs handle
1133 * @param ssf suspend signal function to use
1134 * @param ssf_cls closure for ssf
1135 * @return fresh top-level activity handle
1137 struct TopLevelActivity *
1138 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, SuspendSignalFunction ssf,
1143 * Destroy a top-level activity entry.
1145 * @param h global fs handle
1146 * @param top top level activity entry
1149 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top);
1154 * Master context for most FS operations.
1156 struct GNUNET_FS_Handle
1159 * Configuration to use.
1161 const struct GNUNET_CONFIGURATION_Handle *cfg;
1164 * Name of our client.
1169 * Function to call with updates on our progress.
1171 GNUNET_FS_ProgressCallback upcb;
1179 * Head of DLL of top-level activities.
1181 struct TopLevelActivity *top_head;
1184 * Tail of DLL of top-level activities.
1186 struct TopLevelActivity *top_tail;
1189 * Head of DLL of running jobs.
1191 struct GNUNET_FS_QueueEntry *running_head;
1194 * Tail of DLL of running jobs.
1196 struct GNUNET_FS_QueueEntry *running_tail;
1199 * Head of DLL of pending jobs.
1201 struct GNUNET_FS_QueueEntry *pending_head;
1204 * Tail of DLL of pending jobs.
1206 struct GNUNET_FS_QueueEntry *pending_tail;
1209 * Task that processes the jobs in the running and pending queues
1210 * (and moves jobs around as needed).
1212 GNUNET_SCHEDULER_TaskIdentifier queue_job;
1215 * Average time we take for a single request to be satisfied.
1216 * FIXME: not yet calcualted properly...
1218 struct GNUNET_TIME_Relative avg_block_latency;
1221 * How many actual downloads do we have running right now?
1223 unsigned int active_downloads;
1226 * How many blocks do the active downloads have?
1228 unsigned int active_blocks;
1233 enum GNUNET_FS_Flags flags;
1236 * Maximum number of parallel downloads.
1238 unsigned int max_parallel_downloads;
1241 * Maximum number of parallel requests.
1243 unsigned int max_parallel_requests;
1249 * Handle for controlling a publication process.
1251 struct GNUNET_FS_PublishContext
1254 * Handle to the global fs context.
1256 struct GNUNET_FS_Handle *h;
1259 * Our top-level activity entry (if we are top-level, otherwise NULL).
1261 struct TopLevelActivity *top;
1264 * File-structure that is being shared.
1266 struct GNUNET_FS_FileInformation *fi;
1269 * Namespace that we are publishing in, NULL if we have no namespace.
1271 struct GNUNET_FS_Namespace *namespace;
1274 * ID of the content in the namespace, NULL if we have no namespace.
1279 * ID for future updates, NULL if we have no namespace or no updates.
1284 * Filename used for serializing information about this operation
1285 * (should be determined using 'mktemp').
1287 char *serialization;
1290 * Our own client handle for the FS service; only briefly used when
1291 * we start to index a file, otherwise NULL.
1293 struct GNUNET_CLIENT_Connection *client;
1296 * Current position in the file-tree for the upload.
1298 struct GNUNET_FS_FileInformation *fi_pos;
1301 * Non-null if we are currently hashing a file.
1303 struct GNUNET_CRYPTO_FileHashContext *fhc;
1306 * Connection to the datastore service.
1308 struct GNUNET_DATASTORE_Handle *dsh;
1311 * Queue entry for reservation/unreservation.
1313 struct GNUNET_DATASTORE_QueueEntry *qre;
1316 * ID of the task performing the upload. NO_TASK if the upload has
1319 GNUNET_SCHEDULER_TaskIdentifier upload_task;
1322 * Storage space to reserve for the operation.
1324 uint64_t reserve_space;
1327 * Overall number of entries to reserve for the
1328 * publish operation.
1330 uint32_t reserve_entries;
1333 * Typically GNUNET_NO. Set to GNUNET_YES if "upload_task" is
1334 * GNUNET_SCHEDULER_NO_TASK and we're waiting for a response from
1335 * the datastore service (in which case this struct must not be
1336 * freed until we have that response). If someone tries to stop the
1337 * download for good during this period, "in_network_wait" is set to
1338 * GNUNET_SYSERR which will cause the struct to be destroyed right
1339 * after we have the reply (or timeout) from the datastore service.
1341 int in_network_wait;
1344 * Options for publishing.
1346 enum GNUNET_FS_PublishOptions options;
1349 * Space reservation ID with datastore service
1355 * Set to GNUNET_YES if all processing has completed.
1362 * Phases of unindex processing (state machine).
1367 * We're currently hashing the file.
1369 UNINDEX_STATE_HASHING = 0,
1372 * We're telling the datastore to delete
1373 * the respective entries.
1375 UNINDEX_STATE_DS_REMOVE = 1,
1378 * We're notifying the FS service about
1381 UNINDEX_STATE_FS_NOTIFY = 2,
1386 UNINDEX_STATE_COMPLETE = 3,
1389 * We've encountered a fatal error.
1391 UNINDEX_STATE_ERROR = 4
1396 * Handle for controlling an unindexing operation.
1398 struct GNUNET_FS_UnindexContext
1402 * Global FS context.
1404 struct GNUNET_FS_Handle *h;
1407 * Our top-level activity entry.
1409 struct TopLevelActivity *top;
1412 * Name of the file that we are unindexing.
1417 * Short name under which we are serializing the state of this operation.
1419 char *serialization;
1422 * Connection to the FS service, only valid during the
1423 * UNINDEX_STATE_FS_NOTIFY phase.
1425 struct GNUNET_CLIENT_Connection *client;
1428 * Connection to the datastore service, only valid during the
1429 * UNINDEX_STATE_DS_NOTIFY phase.
1431 struct GNUNET_DATASTORE_Handle *dsh;
1434 * Pointer kept for the client.
1439 * Merkle-ish tree encoder context.
1441 struct GNUNET_FS_TreeEncoder *tc;
1444 * Handle used to read the file.
1446 struct GNUNET_DISK_FileHandle *fh;
1449 * Error message, NULL on success.
1454 * Context for hashing of the file.
1456 struct GNUNET_CRYPTO_FileHashContext *fhc;
1459 * Overall size of the file.
1464 * When did we start?
1466 struct GNUNET_TIME_Absolute start_time;
1469 * Hash of the file's contents (once computed).
1471 GNUNET_HashCode file_id;
1474 * Current operatinonal phase.
1476 enum UnindexState state;
1482 * Information we keep for each keyword in
1485 struct SearchRequestEntry
1488 * Hash of the original keyword, also known as the
1489 * key (for decrypting the KBlock).
1491 GNUNET_HashCode key;
1494 * Hash of the public key, also known as the query.
1496 GNUNET_HashCode query;
1499 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1500 * was found under this keyword. Note that the entries will point
1501 * to the same locations as those in the master result map (in
1502 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1503 * The key for each entry is the XOR of the key and query in the CHK
1504 * URI (as a unique identifier for the search result).
1506 struct GNUNET_CONTAINER_MultiHashMap *results;
1509 * Is this keyword a mandatory keyword
1510 * (started with '+')?
1518 * Handle for controlling a search.
1520 struct GNUNET_FS_SearchContext
1523 * Handle to the global FS context.
1525 struct GNUNET_FS_Handle *h;
1528 * Our top-level activity entry (if we are top-level, otherwise NULL).
1530 struct TopLevelActivity *top;
1533 * List of keywords that we're looking for.
1535 struct GNUNET_FS_Uri *uri;
1538 * For update-searches, link to the search result that triggered
1539 * the update search; otherwise NULL.
1541 struct GNUNET_FS_SearchResult *psearch_result;
1544 * Connection to the FS service.
1546 struct GNUNET_CLIENT_Connection *client;
1549 * Pointer we keep for the client.
1554 * Name of the file on disk we use for persistence.
1556 char *serialization;
1559 * Error message (non-NULL if this operation failed).
1564 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1565 * was found in the search. The key for each entry is the XOR of
1566 * the key and query in the CHK URI (as a unique identifier for the
1569 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1572 * Per-keyword information for a keyword search. This array will
1573 * have exactly as many entries as there were keywords.
1575 struct SearchRequestEntry *requests;
1578 * When did we start?
1580 struct GNUNET_TIME_Absolute start_time;
1583 * ID of a task that is using this struct and that must be cancelled
1584 * when the search is being stopped (if not
1585 * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
1586 * artificial delay when trying to reconnect to the FS service.
1588 GNUNET_SCHEDULER_TaskIdentifier task;
1591 * How many of the entries in the search request
1592 * map have been passed to the service so far?
1594 unsigned int search_request_map_offset;
1597 * How many of the keywords in the KSK
1598 * map have been passed to the service so far?
1600 unsigned int keyword_offset;
1603 * Anonymity level for the search.
1608 * Number of mandatory keywords in this query.
1610 uint32_t mandatory_count;
1613 * Options for the search.
1615 enum GNUNET_FS_SearchOptions options;
1620 * FSM for possible states a block can go through. The typical
1621 * order of progression is linear through the states, alternatives
1622 * are documented in the comments.
1624 enum BlockRequestState
1627 * Initial state, block has only been allocated (since it is
1628 * relevant to the overall download request).
1633 * We've checked the block on the path down the tree, and the
1634 * content on disk did match the desired CHK, but not all
1635 * the way down, so at the bottom some blocks will still
1636 * need to be reconstructed).
1638 BRS_RECONSTRUCT_DOWN = 1,
1641 * We've calculated the CHK bottom-up based on the meta data.
1642 * This may work, but if it did we have to write the meta data to
1643 * disk at the end (and we still need to check against the
1646 BRS_RECONSTRUCT_META_UP = 2,
1649 * We've calculated the CHK bottom-up based on what we have on
1650 * disk, which may not be what the desired CHK is. If the
1651 * reconstructed CHKs match whatever comes from above, we're
1652 * done with the respective subtree.
1654 BRS_RECONSTRUCT_UP = 3,
1657 * We've determined the real, desired CHK for this block
1658 * (full tree reconstruction failed), request is now pending.
1659 * If the CHK that bubbled up through reconstruction did match
1660 * the top-level request, the state machine for the subtree
1661 * would have moved to BRS_DOWNLOAD_UP.
1666 * We've successfully downloaded this block, but the children
1667 * still need to be either downloaded or verified (download
1668 * request propagates down). If the download fails, the
1669 * state machine for this block may move to
1670 * BRS_DOWNLOAD_ERROR instead.
1672 BRS_DOWNLOAD_DOWN = 5,
1675 * This block and all of its children have been downloaded
1676 * successfully (full completion propagates up).
1678 BRS_DOWNLOAD_UP = 6,
1681 * We got a block back that matched the query but did not hash to
1682 * the key (malicious publisher or hash collision); this block
1683 * can never be downloaded (error propagates up).
1690 * Information about an active download request.
1692 struct DownloadRequest
1695 * While pending, we keep all download requests in a doubly-linked list.
1697 struct DownloadRequest *next;
1700 * While pending, we keep all download requests in a doubly-linked list.
1702 struct DownloadRequest *prev;
1705 * Parent in the CHK-tree.
1707 struct DownloadRequest *parent;
1710 * Array (!) of child-requests, or NULL for the bottom of the tree.
1712 struct DownloadRequest **children;
1715 * CHK for the request for this block (set during reconstruction
1716 * to what we have on disk, later to what we want to have).
1718 struct ContentHashKey chk;
1721 * Offset of the corresponding block. Specifically, first (!) byte of
1722 * the first DBLOCK in the subtree induced by block represented by
1728 * Number of entries in 'children' array.
1730 unsigned int num_children;
1733 * Depth of the corresponding block in the tree. 0==DBLOCKs.
1740 enum BlockRequestState state;
1743 * GNUNET_YES if this entry is in the pending list.
1751 * (recursively) free download request structure
1753 * @param dr request to free
1756 GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
1760 * Context for controlling a download.
1762 struct GNUNET_FS_DownloadContext
1766 * Global FS context.
1768 struct GNUNET_FS_Handle *h;
1771 * Our top-level activity entry (if we are top-level, otherwise NULL).
1773 struct TopLevelActivity *top;
1776 * Connection to the FS service.
1778 struct GNUNET_CLIENT_Connection *client;
1781 * Parent download (used when downloading files
1784 struct GNUNET_FS_DownloadContext *parent;
1787 * Associated search (used when downloading files
1788 * based on search results), or NULL for none.
1790 struct GNUNET_FS_SearchResult *search;
1793 * Head of list of child downloads.
1795 struct GNUNET_FS_DownloadContext *child_head;
1798 * Tail of list of child downloads.
1800 struct GNUNET_FS_DownloadContext *child_tail;
1803 * Previous download belonging to the same parent.
1805 struct GNUNET_FS_DownloadContext *prev;
1808 * Next download belonging to the same parent.
1810 struct GNUNET_FS_DownloadContext *next;
1813 * Context kept for the client.
1818 * URI that identifies the file that we are downloading.
1820 struct GNUNET_FS_Uri *uri;
1823 * Known meta-data for the file (can be NULL).
1825 struct GNUNET_CONTAINER_MetaData *meta;
1828 * Error message, NULL if we're doing OK.
1833 * Random portion of filename we use for syncing state of this
1836 char *serialization;
1839 * Where are we writing the data (name of the
1840 * file, can be NULL!).
1845 * Where are we writing the data temporarily (name of the
1846 * file, can be NULL!); used if we do not have a permanent
1847 * name and we are a directory and we do a recursive download.
1849 char *temp_filename;
1852 * Our entry in the job queue.
1854 struct GNUNET_FS_QueueEntry *job_queue;
1857 * Non-NULL if we are currently having a request for
1858 * transmission pending with the client handle.
1860 struct GNUNET_CLIENT_TransmitHandle *th;
1863 * Tree encoder used for the reconstruction.
1865 struct GNUNET_FS_TreeEncoder *te;
1868 * File handle for reading data from an existing file
1869 * (to pass to tree encoder).
1871 struct GNUNET_DISK_FileHandle *rfh;
1874 * Map of active requests (those waiting for a response). The key
1875 * is the hash of the encryped block (aka query).
1877 struct GNUNET_CONTAINER_MultiHashMap *active;
1880 * Head of linked list of pending requests.
1882 struct DownloadRequest *pending_head;
1885 * Head of linked list of pending requests.
1887 struct DownloadRequest *pending_tail;
1890 * Top-level download request.
1892 struct DownloadRequest *top_request;
1895 * Identity of the peer having the content, or all-zeros
1896 * if we don't know of such a peer.
1898 struct GNUNET_PeerIdentity target;
1901 * ID of a task that is using this struct and that must be cancelled
1902 * when the download is being stopped (if not
1903 * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
1904 * artificial delay when trying to reconnect to the FS service or
1905 * the task processing incrementally the data on disk, or the
1906 * task requesting blocks, etc.
1908 GNUNET_SCHEDULER_TaskIdentifier task;
1911 * What is the first offset that we're interested
1917 * How many bytes starting from offset are desired?
1918 * This is NOT the overall length of the file!
1923 * How many bytes have we already received within
1924 * the specified range (DBlocks only).
1929 * What was the size of the file on disk that we're downloading
1930 * before we started? Used to detect if there is a point in
1931 * checking an existing block on disk for matching the desired
1932 * content. 0 if the file did not exist already.
1934 uint64_t old_file_size;
1937 * Time download was started.
1939 struct GNUNET_TIME_Absolute start_time;
1942 * Desired level of anonymity.
1947 * The depth of the file-tree.
1949 unsigned int treedepth;
1952 * Options for the download.
1954 enum GNUNET_FS_DownloadOptions options;
1957 * Flag set upon transitive completion (includes child downloads).
1958 * This flag is only set to GNUNET_YES for directories where all
1959 * child-downloads have also completed (and signalled completion).
1964 * Have we started the receive continuation yet?
1972 * Information about an (updateable) node in the
1975 struct NamespaceUpdateNode
1978 * Identifier for this node.
1983 * Identifier of children of this node.
1988 * Metadata for this entry.
1990 struct GNUNET_CONTAINER_MetaData *md;
1993 * URI of this entry in the namespace.
1995 struct GNUNET_FS_Uri *uri;
1998 * Namespace update generation ID. Used to ensure
1999 * freshness of the tree_id.
2004 * TREE this entry belongs to (if nug is current).
2006 unsigned int tree_id;
2011 struct GNUNET_FS_Namespace
2015 * Handle to the FS service context.
2017 struct GNUNET_FS_Handle *h;
2020 * Array with information about nodes in the namespace.
2022 struct NamespaceUpdateNode **update_nodes;
2025 * Private key for the namespace.
2027 struct GNUNET_CRYPTO_RsaPrivateKey *key;
2030 * Hash map mapping identifiers of update nodes
2031 * to the update nodes (initialized on-demand).
2033 struct GNUNET_CONTAINER_MultiHashMap *update_map;
2036 * Name of the file with the private key.
2041 * Name of the namespace.
2046 * Size of the update nodes array.
2048 unsigned int update_node_count;
2051 * Reference counter.
2056 * Generator for unique nug numbers.
2058 unsigned int nug_gen;
2063 * Message sent from a GNUnet (fs) publishing activity to the
2064 * gnunet-fs-service to initiate indexing of a file. The service is
2065 * supposed to check if the specified file is available and has the
2066 * same cryptographic hash. It should then respond with either a
2067 * confirmation or a denial.
2069 * On OSes where this works, it is considered acceptable if the
2070 * service only checks that the path, device and inode match (it can
2071 * then be assumed that the hash will also match without actually
2072 * computing it; this is an optimization that should be safe given
2073 * that the client is not our adversary).
2075 struct IndexStartMessage
2079 * Message type will be GNUNET_MESSAGE_TYPE_FS_INDEX_START.
2081 struct GNUNET_MessageHeader header;
2086 uint32_t reserved GNUNET_PACKED;
2089 * ID of device containing the file, as seen by the client. This
2090 * device ID is obtained using a call like "statvfs" (and converting
2091 * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
2092 * OS does not support this, in which case the service must do a
2093 * full hash recomputation.
2095 uint64_t device GNUNET_PACKED;
2098 * Inode of the file on the given device, as seen by the client
2099 * ("st_ino" field from "struct stat"). Use 0 if the OS does not
2100 * support this, in which case the service must do a full hash
2103 uint64_t inode GNUNET_PACKED;
2106 * Hash of the file that we would like to index.
2108 GNUNET_HashCode file_id;
2110 /* this is followed by a 0-terminated
2111 * filename of a file with the hash
2112 * "file_id" as seen by the client */
2118 * Message send by FS service in response to a request
2119 * asking for a list of all indexed files.
2121 struct IndexInfoMessage
2124 * Message type will be
2125 * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
2127 struct GNUNET_MessageHeader header;
2132 uint32_t reserved GNUNET_PACKED;
2135 * Hash of the indexed file.
2137 GNUNET_HashCode file_id;
2139 /* this is followed by a 0-terminated
2140 * filename of a file with the hash
2141 * "file_id" as seen by the client */
2147 * Message sent from a GNUnet (fs) unindexing activity to the
2148 * gnunet-service-fs to indicate that a file will be unindexed. The
2149 * service is supposed to remove the file from the list of indexed
2150 * files and response with a confirmation message (even if the file
2151 * was already not on the list).
2153 struct UnindexMessage
2157 * Message type will be
2158 * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
2160 struct GNUNET_MessageHeader header;
2165 uint32_t reserved GNUNET_PACKED;
2168 * Hash of the file that we will unindex.
2170 GNUNET_HashCode file_id;
2176 * Message sent from a GNUnet (fs) search activity to the
2177 * gnunet-service-fs to start a search.
2179 struct SearchMessage
2183 * Message type will be
2184 * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
2186 struct GNUNET_MessageHeader header;
2189 * Bitmask with options. Zero for no options, one for loopback-only.
2190 * Other bits are currently not defined.
2192 int32_t options GNUNET_PACKED;
2195 * Type of the content that we're looking for.
2197 uint32_t type GNUNET_PACKED;
2200 * Desired anonymity level, big-endian.
2202 uint32_t anonymity_level GNUNET_PACKED;
2205 * If the request is for a DBLOCK or IBLOCK, this is the identity of
2206 * the peer that is known to have a response. Set to all-zeros if
2207 * such a target is not known (note that even if OUR anonymity
2208 * level is >0 we may happen to know the responder's identity;
2209 * nevertheless, we should probably not use it for a DHT-lookup
2210 * or similar blunt actions in order to avoid exposing ourselves).
2212 * If the request is for an SBLOCK, this is the identity of the
2213 * pseudonym to which the SBLOCK belongs.
2215 * If the request is for a KBLOCK, "target" must be all zeros.
2217 GNUNET_HashCode target;
2220 * Hash of the keyword (aka query) for KBLOCKs; Hash of
2221 * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
2222 * and hash of the identifier XORed with the target for
2223 * SBLOCKS (aka query).
2225 GNUNET_HashCode query;
2227 /* this is followed by the hash codes of already-known
2228 * results (which should hence be excluded from what
2229 * the service returns); naturally, this only applies
2230 * to queries that can have multiple results, such as
2231 * those for KBLOCKS (KSK) and SBLOCKS (SKS) */
2236 * Only the (mandatory) query is included.
2238 #define GET_MESSAGE_BIT_QUERY_ONLY 0
2241 * The peer identity of a peer waiting for the
2242 * reply is included (used if the response
2243 * should be transmitted to someone other than
2244 * the sender of the GET).
2246 #define GET_MESSAGE_BIT_RETURN_TO 1
2249 * The hash of the public key of the target
2250 * namespace is included (for SKS queries).
2252 #define GET_MESSAGE_BIT_SKS_NAMESPACE 2
2255 * The peer identity of a peer that had claimed to have the content
2256 * previously is included (can be used if responder-anonymity is not
2257 * desired; note that the precursor presumably lacked a direct
2258 * connection to the specified peer; still, the receiver is in no way
2259 * required to limit forwarding only to the specified peer, it should
2260 * only prefer it somewhat if possible).
2262 #define GET_MESSAGE_BIT_TRANSMIT_TO 4
2266 * Message sent between peers asking for FS-content.
2272 * Message type will be GNUNET_MESSAGE_TYPE_FS_GET.
2274 struct GNUNET_MessageHeader header;
2277 * Type of the query (block type).
2279 uint32_t type GNUNET_PACKED;
2282 * How important is this request (network byte order)
2284 uint32_t priority GNUNET_PACKED;
2287 * Relative time to live in MILLISECONDS (network byte order)
2289 int32_t ttl GNUNET_PACKED;
2292 * The content hash should be mutated using this value
2293 * before checking against the bloomfilter (used to
2294 * get many different filters for the same hash codes).
2295 * The number should be in big-endian format when used
2298 uint32_t filter_mutator GNUNET_PACKED;
2301 * Which of the optional hash codes are present at the end of the
2302 * message? See GET_MESSAGE_BIT_xx constants. For each bit that is
2303 * set, an additional GNUNET_HashCode with the respective content
2304 * (in order of the bits) will be appended to the end of the GET
2307 uint32_t hash_bitmap GNUNET_PACKED;
2310 * Hashcodes of the file(s) we're looking for.
2311 * Details depend on the query type.
2313 GNUNET_HashCode query GNUNET_PACKED;
2315 /* this is followed by hash codes
2316 * as specified in the "hash_bitmap";
2317 * after that, an optional bloomfilter
2318 * (with bits set for replies that should
2319 * be suppressed) can be present */
2324 * Response from FS service with a result for a previous FS search.
2325 * Note that queries for DBLOCKS and IBLOCKS that have received a
2326 * single response are considered done. This message is transmitted
2327 * between peers as well as between the service and a client.
2333 * Message type will be GNUNET_MESSAGE_TYPE_FS_PUT.
2335 struct GNUNET_MessageHeader header;
2338 * Type of the block (in big endian). Should never be zero.
2340 uint32_t type GNUNET_PACKED;
2343 * When does this result expire?
2345 struct GNUNET_TIME_AbsoluteNBO expiration;
2347 /* this is followed by the actual encrypted content */
2353 * Message send by a peer that wants to be excluded
2354 * from migration for a while.
2356 struct MigrationStopMessage
2359 * Message type will be
2360 * GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP.
2362 struct GNUNET_MessageHeader header;
2367 uint32_t reserved GNUNET_PACKED;
2370 * How long should the block last?
2372 struct GNUNET_TIME_RelativeNBO duration;