3 This file is part of GNUnet.
4 (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
6 GNUnet is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 3, or (at your
9 option) any later version.
11 GNUnet is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNUnet; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
24 * @brief definitions for the entire fs module
25 * @author Igor Wronsky, Christian Grothoff
30 #include "gnunet_constants.h"
31 #include "gnunet_datastore_service.h"
32 #include "gnunet_dht_service.h"
33 #include "gnunet_fs_service.h"
34 #include "gnunet_block_lib.h"
38 * Maximum size of the datastore queue for P2P operations.
40 #define MAX_DATASTORE_QUEUE 16
43 * Maximum number of blocks we keep in memory for migration.
45 #define MAX_MIGRATION_QUEUE 32
48 * How many peers do we select as possible
49 * targets per block obtained for migration?
51 #define MIGRATION_LIST_SIZE 4
54 * To how many peers do we forward each migration block ultimately?
55 * This number must be smaller or equal to MIGRATION_LIST_SIZE. Using
56 * a smaller value allows for variation in available bandwidth (for
57 * migration) between the peers.
59 #define MIGRATION_TARGET_COUNT 2
62 * Ratio for moving average delay calculation. The previous
63 * average goes in with a factor of (n-1) into the calculation.
66 #define RUNAVG_DELAY_N 16
69 * Size of the individual blocks used for file-sharing.
71 #define DBLOCK_SIZE (32*1024)
74 * Maximum legal size for a kblock.
76 #define MAX_KBLOCK_SIZE (60 * 1024)
79 * Maximum legal size for an sblock.
81 #define MAX_SBLOCK_SIZE (60 * 1024)
84 * Maximum legal size for an nblock.
86 #define MAX_NBLOCK_SIZE (60 * 1024)
89 * Pick a multiple of 2 here to achive 8-byte alignment!
90 * We also probably want DBlocks to have (roughly) the
91 * same size as IBlocks. With SHA-512, the optimal
92 * value is 32768 byte / 128 byte = 256
93 * (128 byte = 2 * 512 bits). DO NOT CHANGE!
95 #define CHK_PER_INODE 256
99 * Maximum size for a file to be considered for
100 * inlining in a directory.
102 #define MAX_INLINE_SIZE 65536
106 * Blocksize to use when hashing files
107 * for indexing (blocksize for IO, not for
108 * the DBlocks). Larger blocksizes can
109 * be more efficient but will be more disruptive
110 * as far as the scheduler is concerned.
112 #define HASHING_BLOCKSIZE (1024 * 1024)
115 * Number of bits we set per entry in the bloomfilter.
118 #define BLOOMFILTER_K GNUNET_DHT_GET_BLOOMFILTER_K
121 * Number of availability trials we perform per search result.
123 #define AVAILABILITY_TRIALS_MAX 8
126 * By how much (in ms) do we decrement the TTL
129 #define TTL_DECREMENT 5000
132 * Length of the P2P success tracker. Note that
133 * having a very long list can also hurt performance.
135 #define P2P_SUCCESS_LIST_SIZE 8
139 * Length of the CS-2-P success tracker. Note that
140 * having a very long list can also hurt performance.
142 #define CS2P_SUCCESS_LIST_SIZE 8
145 * How long are we willing to wait for the datastore to be ready to
146 * process a request for a query without priority?
148 #define BASIC_DATASTORE_REQUEST_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
152 * How long are we willing to wait for the core to be ready to
153 * transmit a reply to the target peer (if we can not transmit
154 * until then, we will discard the reply).
156 #define ACCEPTABLE_REPLY_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
160 * Bandwidth value of an (effectively) 0-priority query.
162 #define QUERY_BANDWIDTH_VALUE 1
165 * Bandwidth value of a 0-priority content (must be
166 * fairly high compared to query since content is
167 * typically significantly larger -- and more valueable
168 * since it can take many queries to get one piece of
171 #define CONTENT_BANDWIDTH_VALUE 800
174 * By which amount do we decrement the TTL for simple forwarding /
175 * indirection of the query; in milli-seconds. Set somewhat in
176 * accordance to your network latency (above the time it'll take you
177 * to send a packet and get a reply).
179 #define TTL_DECREMENT 5000
182 * Until which load do we consider the peer idle and do not
183 * charge at all? (should be larger than GNUNET_IDLE_LOAD_THRESHOLD used
184 * by the rest of the code)!
186 #define IDLE_LOAD_THRESHOLD ((100 + GNUNET_CONSTANTS_IDLE_LOAD_THRESHOLD) / 2)
189 * Name of the directory with top-level searches.
191 #define GNUNET_FS_SYNC_PATH_MASTER_SEARCH "search"
194 * Name of the directory with sub-searches (namespace-updates).
196 #define GNUNET_FS_SYNC_PATH_CHILD_SEARCH "search-child"
199 * Name of the directory with master downloads (not associated
200 * with search or part of another download).
202 #define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD "download"
205 * Name of the directory with downloads that are part of another
206 * download or a search.
208 #define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD "download-child"
211 * Name of the directory with publishing operations.
213 #define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH "publish"
216 * Name of the directory with files that are being published
218 #define GNUNET_FS_SYNC_PATH_FILE_INFO "publish-file"
221 * Name of the directory with unindex operations.
223 #define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX "unindex"
227 * @brief content hash key
229 struct ContentHashKey
232 * Hash of the original content, used for encryption.
237 * Hash of the encrypted content, used for querying.
239 GNUNET_HashCode query;
244 * @brief complete information needed
245 * to download a file.
247 struct FileIdentifier
251 * Total size of the file in bytes. (network byte order (!))
253 uint64_t file_length;
256 * Query and key of the top GNUNET_EC_IBlock.
258 struct ContentHashKey chk;
264 * Information about a file and its location
265 * (peer claiming to share the file).
270 * Information about the shared file.
272 struct FileIdentifier fi;
275 * Identity of the peer sharing the file.
277 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
280 * Time when this location URI expires.
282 struct GNUNET_TIME_Absolute expirationTime;
285 * RSA signature over the GNUNET_EC_FileIdentifier,
286 * GNUNET_hash of the peer and expiration time.
288 struct GNUNET_CRYPTO_RsaSignature contentSignature;
298 * Content-hash-key (simple file).
303 * Signed key space (file in namespace).
308 * Keyword search key (query with keywords).
313 * Location (chk with identity of hosting peer).
319 * A Universal Resource Identifier (URI), opaque.
333 * Keywords start with a '+' if they are
334 * mandatory (in which case the '+' is NOT
335 * part of the keyword) and with a
336 * simple space if they are optional
337 * (in which case the space is ALSO not
338 * part of the actual keyword).
340 * Double-quotes to protect spaces and
341 * %-encoding are NOT used internally
342 * (only in URI-strings).
347 * Size of the keywords array.
349 unsigned int keywordCount;
355 * Hash of the public key for the namespace.
357 GNUNET_HashCode namespace;
360 * Human-readable identifier chosen for this
361 * entry in the namespace.
367 * Information needed to retrieve a file (content-hash-key
370 struct FileIdentifier chk;
373 * Information needed to retrieve a file including signed
374 * location (identity of a peer) of the content.
383 * Information for a file or directory that is
384 * about to be published.
386 struct GNUNET_FS_FileInformation
390 * Files in a directory are kept as a linked list.
392 struct GNUNET_FS_FileInformation *next;
395 * If this is a file in a directory, "dir" refers to
396 * the directory; otherwise NULL.
398 struct GNUNET_FS_FileInformation *dir;
401 * Handle to the master context.
403 struct GNUNET_FS_Handle *h;
406 * Pointer kept for the client.
411 * Metadata to use for the file.
413 struct GNUNET_CONTAINER_MetaData *meta;
416 * Keywords to use for KBlocks.
418 struct GNUNET_FS_Uri *keywords;
421 * CHK for this file or directory. NULL if
422 * we have not yet computed it.
424 struct GNUNET_FS_Uri *chk_uri;
427 * At what time should the content expire?
429 struct GNUNET_TIME_Absolute expirationTime;
432 * At what time did we start this upload?
434 struct GNUNET_TIME_Absolute start_time;
437 * Under what filename is this struct serialized
438 * (for operational persistence). Should be determined
444 * Encoder being used to publish this file.
446 struct GNUNET_FS_TreeEncoder *te;
449 * Error message (non-NULL if this operation failed).
454 * Name of the file or directory (must be an absolute path).
459 * Data describing either the file or the directory.
470 * Function that can be used to read the data for the file.
472 GNUNET_FS_DataReader reader;
475 * Closure for reader.
480 * If this file is being indexed, this value is set to the hash
481 * over the entire file (when the indexing process is started).
482 * Otherwise this field is not used.
484 GNUNET_HashCode file_id;
487 * Size of the file (in bytes).
492 * Should the file be indexed or inserted?
497 * Is "file_id" already valid? Set to GNUNET_YES once the hash
498 * has been calculated.
503 * Has the service confirmed our INDEX_START request?
504 * GNUNET_YES if this step has been completed.
506 int index_start_confirmed;
511 * Data for a directory.
516 * Linked list of entries in the directory.
518 struct GNUNET_FS_FileInformation *entries;
521 * Size of the directory itself (in bytes); 0 if the
522 * size has not yet been calculated.
527 * Pointer to the data for the directory (or NULL if not
537 * Desired anonymity level.
542 * Desired priority (for keeping the content in the DB).
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,
758 GNUNET_FS_QueueStart start,
759 GNUNET_FS_QueueStop stop,
761 unsigned int blocks);
765 * Dequeue a job from the queue.
766 * @param qh handle for the job
769 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
773 * Function that provides data by reading from a file.
775 * @param cls closure (points to the file information)
776 * @param offset offset to read from; it is possible
777 * that the caller might need to go backwards
779 * @param max maximum number of bytes that should be
780 * copied to buf; readers are not allowed
781 * to provide less data unless there is an error;
782 * a value of "0" will be used at the end to allow
783 * the reader to clean up its internal state
784 * @param buf where the reader should write the data
785 * @param emsg location for the reader to store an error message
786 * @return number of bytes written, usually "max", 0 on error
789 GNUNET_FS_data_reader_file_(void *cls,
797 * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
799 * @param filename file to read
800 * @return closure to use
803 GNUNET_FS_make_file_reader_context_ (const char *filename);
808 * Function that provides data by copying from a buffer.
810 * @param cls closure (points to the buffer)
811 * @param offset offset to read from; it is possible
812 * that the caller might need to go backwards
814 * @param max maximum number of bytes that should be
815 * copied to buf; readers are not allowed
816 * to provide less data unless there is an error;
817 * a value of "0" will be used at the end to allow
818 * the reader to clean up its internal state
819 * @param buf where the reader should write the data
820 * @param emsg location for the reader to store an error message
821 * @return number of bytes written, usually "max", 0 on error
824 GNUNET_FS_data_reader_copy_(void *cls,
831 * Notification of FS that a search probe has made progress.
832 * This function is used INSTEAD of the client's event handler
833 * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
835 * @param cls closure, always NULL (!), actual closure
836 * is in the client-context of the info struct
837 * @param info details about the event, specifying the event type
838 * and various bits about the event
839 * @return client-context (for the next progress call
840 * for this operation; should be set to NULL for
841 * SUSPEND and STOPPED events). The value returned
842 * will be passed to future callbacks in the respective
843 * field in the GNUNET_FS_ProgressInfo struct.
846 GNUNET_FS_search_probe_progress_ (void *cls,
847 const struct GNUNET_FS_ProgressInfo *info);
851 * Main function that performs the upload.
853 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
854 * @param tc task context
857 GNUNET_FS_publish_main_ (void *cls,
858 const struct GNUNET_SCHEDULER_TaskContext *tc);
862 * Function called once the hash of the file
863 * that is being unindexed has been computed.
865 * @param cls closure, unindex context
866 * @param file_id computed hash, NULL on error
869 GNUNET_FS_unindex_process_hash_ (void *cls,
870 const GNUNET_HashCode *file_id);
874 * Fill in all of the generic fields for a publish event and call the
877 * @param pi structure to fill in
878 * @param sc overall publishing context
879 * @param p file information for the file being published
880 * @param offset where in the file are we so far
881 * @return value returned from callback
884 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
885 struct GNUNET_FS_PublishContext *sc,
886 const struct GNUNET_FS_FileInformation *p,
891 * Fill in all of the generic fields for a download event and call the
894 * @param pi structure to fill in
895 * @param dc overall download context
898 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
899 struct GNUNET_FS_DownloadContext *dc);
903 * Fill in all of the generic fields for
904 * an unindex event and call the callback.
906 * @param pi structure to fill in
907 * @param uc overall unindex context
908 * @param offset where we are in the file (for progress)
911 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
912 struct GNUNET_FS_UnindexContext *uc,
916 * Fill in all of the generic fields for a search event and
919 * @param pi structure to fill in
920 * @param sc overall search context
921 * @return value returned by the callback
924 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
925 struct GNUNET_FS_SearchContext *sc);
929 * Connect to the datastore and remove the blocks.
931 * @param uc context for the unindex operation.
934 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
937 * Build the request and actually initiate the search using the
940 * @param sc search context
941 * @return GNUNET_OK on success, GNUNET_SYSERR on error
944 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
947 * Start the downloading process (by entering the queue).
949 * @param dc our download context
952 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
956 * Start download probes for the given search result.
958 * @param sr the search result
961 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
964 * Remove serialization/deserialization file from disk.
966 * @param h master context
967 * @param ext component of the path
968 * @param ent entity identifier
971 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
977 * Remove serialization/deserialization directory from disk.
979 * @param h master context
980 * @param ext component of the path
981 * @param uni unique name of parent
984 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
990 * Synchronize this file-information struct with its mirror
991 * on disk. Note that all internal FS-operations that change
992 * file information data should already call "sync" internally,
993 * so this function is likely not useful for clients.
995 * @param fi the struct to sync
998 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
1001 * Synchronize this publishing struct with its mirror
1002 * on disk. Note that all internal FS-operations that change
1003 * publishing structs should already call "sync" internally,
1004 * so this function is likely not useful for clients.
1006 * @param pc the struct to sync
1009 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
1012 * Synchronize this unindex struct with its mirror
1013 * on disk. Note that all internal FS-operations that change
1014 * publishing structs should already call "sync" internally,
1015 * so this function is likely not useful for clients.
1017 * @param uc the struct to sync
1020 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
1023 * Synchronize this search struct with its mirror
1024 * on disk. Note that all internal FS-operations that change
1025 * publishing structs should already call "sync" internally,
1026 * so this function is likely not useful for clients.
1028 * @param sc the struct to sync
1031 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
1034 * Synchronize this search result with its mirror
1035 * on disk. Note that all internal FS-operations that change
1036 * publishing structs should already call "sync" internally,
1037 * so this function is likely not useful for clients.
1039 * @param sr the struct to sync
1042 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
1045 * Synchronize this download struct with its mirror
1046 * on disk. Note that all internal FS-operations that change
1047 * publishing structs should already call "sync" internally,
1048 * so this function is likely not useful for clients.
1050 * @param dc the struct to sync
1053 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
1056 * Create SUSPEND event for the given publish operation
1057 * and then clean up our state (without stop signal).
1059 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
1062 GNUNET_FS_publish_signal_suspend_ (void *cls);
1065 * Create SUSPEND event for the given search operation
1066 * and then clean up our state (without stop signal).
1068 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
1071 GNUNET_FS_search_signal_suspend_ (void *cls);
1074 * Create SUSPEND event for the given download operation
1075 * and then clean up our state (without stop signal).
1077 * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
1080 GNUNET_FS_download_signal_suspend_ (void *cls);
1083 * Create SUSPEND event for the given unindex operation
1084 * and then clean up our state (without stop signal).
1086 * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
1089 GNUNET_FS_unindex_signal_suspend_ (void *cls);
1092 * Function signature of the functions that can be called
1093 * to trigger suspend signals and clean-up for top-level
1096 * @param cls closure
1098 typedef void (*SuspendSignalFunction)(void *cls);
1101 * We track all of the top-level activities of FS
1102 * so that we can signal 'suspend' on shutdown.
1104 struct TopLevelActivity
1107 * This is a doubly-linked list.
1109 struct TopLevelActivity *next;
1112 * This is a doubly-linked list.
1114 struct TopLevelActivity *prev;
1117 * Function to call for suspend-signalling and clean up.
1119 SuspendSignalFunction ssf;
1122 * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1129 * Create a top-level activity entry.
1131 * @param h global fs handle
1132 * @param ssf suspend signal function to use
1133 * @param ssf_cls closure for ssf
1134 * @return fresh top-level activity handle
1136 struct TopLevelActivity *
1137 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1138 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,
1150 struct TopLevelActivity *top);
1155 * Master context for most FS operations.
1157 struct GNUNET_FS_Handle
1162 struct GNUNET_SCHEDULER_Handle *sched;
1165 * Configuration to use.
1167 const struct GNUNET_CONFIGURATION_Handle *cfg;
1170 * Name of our client.
1175 * Function to call with updates on our progress.
1177 GNUNET_FS_ProgressCallback upcb;
1185 * Head of DLL of top-level activities.
1187 struct TopLevelActivity *top_head;
1190 * Tail of DLL of top-level activities.
1192 struct TopLevelActivity *top_tail;
1195 * Head of DLL of running jobs.
1197 struct GNUNET_FS_QueueEntry *running_head;
1200 * Tail of DLL of running jobs.
1202 struct GNUNET_FS_QueueEntry *running_tail;
1205 * Head of DLL of pending jobs.
1207 struct GNUNET_FS_QueueEntry *pending_head;
1210 * Tail of DLL of pending jobs.
1212 struct GNUNET_FS_QueueEntry *pending_tail;
1215 * Task that processes the jobs in the running and pending queues
1216 * (and moves jobs around as needed).
1218 GNUNET_SCHEDULER_TaskIdentifier queue_job;
1221 * Average time we take for a single request to be satisfied.
1222 * FIXME: not yet calcualted properly...
1224 struct GNUNET_TIME_Relative avg_block_latency;
1227 * How many actual downloads do we have running right now?
1229 unsigned int active_downloads;
1232 * How many blocks do the active downloads have?
1234 unsigned int active_blocks;
1239 enum GNUNET_FS_Flags flags;
1242 * Maximum number of parallel downloads.
1244 unsigned int max_parallel_downloads;
1247 * Maximum number of parallel requests.
1249 unsigned int max_parallel_requests;
1255 * Handle for controlling a publication process.
1257 struct GNUNET_FS_PublishContext
1260 * Handle to the global fs context.
1262 struct GNUNET_FS_Handle *h;
1265 * Our top-level activity entry (if we are top-level, otherwise NULL).
1267 struct TopLevelActivity *top;
1270 * File-structure that is being shared.
1272 struct GNUNET_FS_FileInformation *fi;
1275 * Namespace that we are publishing in, NULL if we have no namespace.
1277 struct GNUNET_FS_Namespace *namespace;
1280 * ID of the content in the namespace, NULL if we have no namespace.
1285 * ID for future updates, NULL if we have no namespace or no updates.
1290 * Filename used for serializing information about this operation
1291 * (should be determined using 'mktemp').
1293 char *serialization;
1296 * Our own client handle for the FS service; only briefly used when
1297 * we start to index a file, otherwise NULL.
1299 struct GNUNET_CLIENT_Connection *client;
1302 * Current position in the file-tree for the upload.
1304 struct GNUNET_FS_FileInformation *fi_pos;
1307 * Non-null if we are currently hashing a file.
1309 struct GNUNET_CRYPTO_FileHashContext *fhc;
1312 * Connection to the datastore service.
1314 struct GNUNET_DATASTORE_Handle *dsh;
1317 * Queue entry for reservation/unreservation.
1319 struct GNUNET_DATASTORE_QueueEntry *qre;
1322 * ID of the task performing the upload. NO_TASK if the upload has
1325 GNUNET_SCHEDULER_TaskIdentifier upload_task;
1328 * Storage space to reserve for the operation.
1330 uint64_t reserve_space;
1333 * Overall number of entries to reserve for the
1334 * publish operation.
1336 uint32_t reserve_entries;
1339 * Typically GNUNET_NO. Set to GNUNET_YES if "upload_task" is
1340 * GNUNET_SCHEDULER_NO_TASK and we're waiting for a response from
1341 * the datastore service (in which case this struct must not be
1342 * freed until we have that response). If someone tries to stop the
1343 * download for good during this period, "in_network_wait" is set to
1344 * GNUNET_SYSERR which will cause the struct to be destroyed right
1345 * after we have the reply (or timeout) from the datastore service.
1347 int in_network_wait;
1350 * Options for publishing.
1352 enum GNUNET_FS_PublishOptions options;
1355 * Space reservation ID with datastore service
1361 * Set to GNUNET_YES if all processing has completed.
1368 * Phases of unindex processing (state machine).
1373 * We're currently hashing the file.
1375 UNINDEX_STATE_HASHING = 0,
1378 * We're telling the datastore to delete
1379 * the respective entries.
1381 UNINDEX_STATE_DS_REMOVE = 1,
1384 * We're notifying the FS service about
1387 UNINDEX_STATE_FS_NOTIFY = 2,
1392 UNINDEX_STATE_COMPLETE = 3,
1395 * We've encountered a fatal error.
1397 UNINDEX_STATE_ERROR = 4
1403 * Handle for controlling an unindexing operation.
1405 struct GNUNET_FS_UnindexContext
1409 * Global FS context.
1411 struct GNUNET_FS_Handle *h;
1414 * Our top-level activity entry.
1416 struct TopLevelActivity *top;
1419 * Name of the file that we are unindexing.
1424 * Short name under which we are serializing the state of this operation.
1426 char *serialization;
1429 * Connection to the FS service, only valid during the
1430 * UNINDEX_STATE_FS_NOTIFY phase.
1432 struct GNUNET_CLIENT_Connection *client;
1435 * Connection to the datastore service, only valid during the
1436 * UNINDEX_STATE_DS_NOTIFY phase.
1438 struct GNUNET_DATASTORE_Handle *dsh;
1441 * Pointer kept for the client.
1446 * Merkle-ish tree encoder context.
1448 struct GNUNET_FS_TreeEncoder *tc;
1451 * Handle used to read the file.
1453 struct GNUNET_DISK_FileHandle *fh;
1456 * Error message, NULL on success.
1461 * Context for hashing of the file.
1463 struct GNUNET_CRYPTO_FileHashContext *fhc;
1466 * Overall size of the file.
1471 * When did we start?
1473 struct GNUNET_TIME_Absolute start_time;
1476 * Hash of the file's contents (once computed).
1478 GNUNET_HashCode file_id;
1481 * Current operatinonal phase.
1483 enum UnindexState state;
1489 * Information we keep for each keyword in
1492 struct SearchRequestEntry
1495 * Hash of the original keyword, also known as the
1496 * key (for decrypting the KBlock).
1498 GNUNET_HashCode key;
1501 * Hash of the public key, also known as the query.
1503 GNUNET_HashCode query;
1506 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1507 * was found under this keyword. Note that the entries will point
1508 * to the same locations as those in the master result map (in
1509 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1510 * The key for each entry is the XOR of the key and query in the CHK
1511 * URI (as a unique identifier for the search result).
1513 struct GNUNET_CONTAINER_MultiHashMap *results;
1516 * Is this keyword a mandatory keyword
1517 * (started with '+')?
1525 * Handle for controlling a search.
1527 struct GNUNET_FS_SearchContext
1530 * Handle to the global FS context.
1532 struct GNUNET_FS_Handle *h;
1535 * Our top-level activity entry (if we are top-level, otherwise NULL).
1537 struct TopLevelActivity *top;
1540 * List of keywords that we're looking for.
1542 struct GNUNET_FS_Uri *uri;
1545 * For update-searches, link to the search result that triggered
1546 * the update search; otherwise NULL.
1548 struct GNUNET_FS_SearchResult *psearch_result;
1551 * Connection to the FS service.
1553 struct GNUNET_CLIENT_Connection *client;
1556 * Pointer we keep for the client.
1561 * Name of the file on disk we use for persistence.
1563 char *serialization;
1566 * Error message (non-NULL if this operation failed).
1571 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1572 * was found in the search. The key for each entry is the XOR of
1573 * the key and query in the CHK URI (as a unique identifier for the
1576 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1579 * Per-keyword information for a keyword search. This array will
1580 * have exactly as many entries as there were keywords.
1582 struct SearchRequestEntry *requests;
1585 * When did we start?
1587 struct GNUNET_TIME_Absolute start_time;
1590 * ID of a task that is using this struct and that must be cancelled
1591 * when the search is being stopped (if not
1592 * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
1593 * artificial delay when trying to reconnect to the FS service.
1595 GNUNET_SCHEDULER_TaskIdentifier task;
1598 * Anonymity level for the search.
1603 * Number of mandatory keywords in this query.
1605 uint32_t mandatory_count;
1608 * Options for the search.
1610 enum GNUNET_FS_SearchOptions options;
1615 * Information about an active download request.
1617 struct DownloadRequest
1620 * While pending, we keep all download requests in a linked list.
1622 struct DownloadRequest *next;
1625 * CHK for the request.
1627 struct ContentHashKey chk;
1630 * Offset of the corresponding block.
1635 * Depth of the corresponding block in the tree.
1640 * Set if this request is currently in the linked list of pending
1641 * requests. Needed in case we get a response for a request that we
1642 * have not yet send (i.e. due to two blocks with identical
1643 * content); in this case, we would need to remove the block from
1644 * the pending list (and need a fast way to check if the block is on
1653 * Context for controlling a download.
1655 struct GNUNET_FS_DownloadContext
1659 * Global FS context.
1661 struct GNUNET_FS_Handle *h;
1664 * Our top-level activity entry (if we are top-level, otherwise NULL).
1666 struct TopLevelActivity *top;
1669 * Connection to the FS service.
1671 struct GNUNET_CLIENT_Connection *client;
1674 * Parent download (used when downloading files
1677 struct GNUNET_FS_DownloadContext *parent;
1680 * Associated search (used when downloading files
1681 * based on search results), or NULL for none.
1683 struct GNUNET_FS_SearchResult *search;
1686 * Head of list of child downloads.
1688 struct GNUNET_FS_DownloadContext *child_head;
1691 * Tail of list of child downloads.
1693 struct GNUNET_FS_DownloadContext *child_tail;
1696 * Previous download belonging to the same parent.
1698 struct GNUNET_FS_DownloadContext *prev;
1701 * Next download belonging to the same parent.
1703 struct GNUNET_FS_DownloadContext *next;
1706 * Context kept for the client.
1711 * URI that identifies the file that
1712 * we are downloading.
1714 struct GNUNET_FS_Uri *uri;
1717 * Known meta-data for the file (can be NULL).
1719 struct GNUNET_CONTAINER_MetaData *meta;
1722 * Error message, NULL if we're doing OK.
1727 * Random portion of filename we use for syncing state of this
1730 char *serialization;
1733 * Where are we writing the data (name of the
1734 * file, can be NULL!).
1739 * Where are we writing the data temporarily (name of the
1740 * file, can be NULL!); used if we do not have a permanent
1741 * name and we are a directory and we do a recursive download.
1743 char *temp_filename;
1746 * Map of active requests (those waiting
1747 * for a response). The key is the hash
1748 * of the encryped block (aka query).
1750 struct GNUNET_CONTAINER_MultiHashMap *active;
1753 * Linked list of pending requests.
1755 struct DownloadRequest *pending;
1758 * Non-NULL if we are currently having a request for
1759 * transmission pending with the client handle.
1761 struct GNUNET_CLIENT_TransmitHandle *th;
1764 * Our entry in the job queue.
1766 struct GNUNET_FS_QueueEntry *job_queue;
1769 * Identity of the peer having the content, or all-zeros
1770 * if we don't know of such a peer.
1772 struct GNUNET_PeerIdentity target;
1775 * ID of a task that is using this struct
1776 * and that must be cancelled when the download
1777 * is being stopped (if not GNUNET_SCHEDULER_NO_TASK).
1778 * Used for the task that adds some artificial
1779 * delay when trying to reconnect to the FS
1782 GNUNET_SCHEDULER_TaskIdentifier task;
1785 * What was the size of the file on disk that we're downloading
1786 * before we started? Used to detect if there is a point in
1787 * checking an existing block on disk for matching the desired
1788 * content. 0 if the file did not exist already.
1790 uint64_t old_file_size;
1793 * What is the first offset that we're interested
1799 * How many bytes starting from offset are desired?
1800 * This is NOT the overall length of the file!
1805 * How many bytes have we already received within
1806 * the specified range (DBlocks only).
1811 * Time download was started.
1813 struct GNUNET_TIME_Absolute start_time;
1816 * Desired level of anonymity.
1821 * The depth of the file-tree.
1823 unsigned int treedepth;
1826 * Options for the download.
1828 enum GNUNET_FS_DownloadOptions options;
1831 * Flag set upon transitive completion (includes child downloads).
1832 * This flag is only set to GNUNET_YES for directories where all
1833 * child-downloads have also completed (and signalled completion).
1838 * Have we tried (and failed) to find matching full
1839 * data from the meta data yet?
1841 int tried_full_data;
1846 * Information about an (updateable) node in the
1849 struct NamespaceUpdateNode
1852 * Identifier for this node.
1857 * Identifier of children of this node.
1862 * Metadata for this entry.
1864 struct GNUNET_CONTAINER_MetaData *md;
1867 * URI of this entry in the namespace.
1869 struct GNUNET_FS_Uri *uri;
1872 * Namespace update generation ID. Used to ensure
1873 * freshness of the scc_id.
1878 * SCC this entry belongs to (if nug is current).
1880 unsigned int scc_id;
1885 struct GNUNET_FS_Namespace
1889 * Handle to the FS service context.
1891 struct GNUNET_FS_Handle *h;
1894 * Array with information about nodes in the namespace.
1896 struct NamespaceUpdateNode **update_nodes;
1899 * Private key for the namespace.
1901 struct GNUNET_CRYPTO_RsaPrivateKey *key;
1904 * Hash map mapping identifiers of update nodes
1905 * to the update nodes (initialized on-demand).
1907 struct GNUNET_CONTAINER_MultiHashMap *update_map;
1910 * Name of the file with the private key.
1915 * Name of the namespace.
1920 * Size of the update nodes array.
1922 unsigned int update_node_count;
1925 * Reference counter.
1930 * Generator for unique nug numbers.
1932 unsigned int nug_gen;
1937 * Message sent from a GNUnet (fs) publishing activity to the
1938 * gnunet-fs-service to initiate indexing of a file. The service is
1939 * supposed to check if the specified file is available and has the
1940 * same cryptographic hash. It should then respond with either a
1941 * confirmation or a denial.
1943 * On OSes where this works, it is considered acceptable if the
1944 * service only checks that the path, device and inode match (it can
1945 * then be assumed that the hash will also match without actually
1946 * computing it; this is an optimization that should be safe given
1947 * that the client is not our adversary).
1949 struct IndexStartMessage
1953 * Message type will be GNUNET_MESSAGE_TYPE_FS_INDEX_START.
1955 struct GNUNET_MessageHeader header;
1960 uint32_t reserved GNUNET_PACKED;
1963 * ID of device containing the file, as seen by the client. This
1964 * device ID is obtained using a call like "statvfs" (and converting
1965 * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
1966 * OS does not support this, in which case the service must do a
1967 * full hash recomputation.
1969 uint64_t device GNUNET_PACKED;
1972 * Inode of the file on the given device, as seen by the client
1973 * ("st_ino" field from "struct stat"). Use 0 if the OS does not
1974 * support this, in which case the service must do a full hash
1977 uint64_t inode GNUNET_PACKED;
1980 * Hash of the file that we would like to index.
1982 GNUNET_HashCode file_id;
1984 /* this is followed by a 0-terminated
1985 filename of a file with the hash
1986 "file_id" as seen by the client */
1992 * Message send by FS service in response to a request
1993 * asking for a list of all indexed files.
1995 struct IndexInfoMessage
1998 * Message type will be
1999 * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
2001 struct GNUNET_MessageHeader header;
2006 uint32_t reserved GNUNET_PACKED;
2009 * Hash of the indexed file.
2011 GNUNET_HashCode file_id;
2013 /* this is followed by a 0-terminated
2014 filename of a file with the hash
2015 "file_id" as seen by the client */
2021 * Message sent from a GNUnet (fs) unindexing activity to the
2022 * gnunet-service-fs to indicate that a file will be unindexed. The
2023 * service is supposed to remove the file from the list of indexed
2024 * files and response with a confirmation message (even if the file
2025 * was already not on the list).
2027 struct UnindexMessage
2031 * Message type will be
2032 * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
2034 struct GNUNET_MessageHeader header;
2039 uint32_t reserved GNUNET_PACKED;
2042 * Hash of the file that we will unindex.
2044 GNUNET_HashCode file_id;
2050 * Message sent from a GNUnet (fs) search activity to the
2051 * gnunet-service-fs to start a search.
2053 struct SearchMessage
2057 * Message type will be
2058 * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
2060 struct GNUNET_MessageHeader header;
2063 * Bitmask with options. Zero for no options, one for loopback-only.
2064 * Other bits are currently not defined.
2066 int32_t options GNUNET_PACKED;
2069 * Type of the content that we're looking for.
2071 uint32_t type GNUNET_PACKED;
2074 * Desired anonymity level, big-endian.
2076 uint32_t anonymity_level GNUNET_PACKED;
2079 * If the request is for a DBLOCK or IBLOCK, this is the identity of
2080 * the peer that is known to have a response. Set to all-zeros if
2081 * such a target is not known (note that even if OUR anonymity
2082 * level is >0 we may happen to know the responder's identity;
2083 * nevertheless, we should probably not use it for a DHT-lookup
2084 * or similar blunt actions in order to avoid exposing ourselves).
2086 * If the request is for an SBLOCK, this is the identity of the
2087 * pseudonym to which the SBLOCK belongs.
2089 * If the request is for a KBLOCK, "target" must be all zeros.
2091 GNUNET_HashCode target;
2094 * Hash of the keyword (aka query) for KBLOCKs; Hash of
2095 * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
2096 * and hash of the identifier XORed with the target for
2097 * SBLOCKS (aka query).
2099 GNUNET_HashCode query;
2101 /* this is followed by the hash codes of already-known
2102 results (which should hence be excluded from what
2103 the service returns); naturally, this only applies
2104 to queries that can have multiple results, such as
2105 those for KBLOCKS (KSK) and SBLOCKS (SKS) */
2110 * Only the (mandatory) query is included.
2112 #define GET_MESSAGE_BIT_QUERY_ONLY 0
2115 * The peer identity of a peer waiting for the
2116 * reply is included (used if the response
2117 * should be transmitted to someone other than
2118 * the sender of the GET).
2120 #define GET_MESSAGE_BIT_RETURN_TO 1
2123 * The hash of the public key of the target
2124 * namespace is included (for SKS queries).
2126 #define GET_MESSAGE_BIT_SKS_NAMESPACE 2
2129 * The peer identity of a peer that had claimed to have the content
2130 * previously is included (can be used if responder-anonymity is not
2131 * desired; note that the precursor presumably lacked a direct
2132 * connection to the specified peer; still, the receiver is in no way
2133 * required to limit forwarding only to the specified peer, it should
2134 * only prefer it somewhat if possible).
2136 #define GET_MESSAGE_BIT_TRANSMIT_TO 4
2140 * Message sent between peers asking for FS-content.
2146 * Message type will be GNUNET_MESSAGE_TYPE_FS_GET.
2148 struct GNUNET_MessageHeader header;
2151 * Type of the query (block type).
2153 uint32_t type GNUNET_PACKED;
2156 * How important is this request (network byte order)
2158 uint32_t priority GNUNET_PACKED;
2161 * Relative time to live in MILLISECONDS (network byte order)
2163 int32_t ttl GNUNET_PACKED;
2166 * The content hash should be mutated using this value
2167 * before checking against the bloomfilter (used to
2168 * get many different filters for the same hash codes).
2169 * The number should be in big-endian format when used
2172 int32_t filter_mutator GNUNET_PACKED;
2175 * Which of the optional hash codes are present at the end of the
2176 * message? See GET_MESSAGE_BIT_xx constants. For each bit that is
2177 * set, an additional GNUNET_HashCode with the respective content
2178 * (in order of the bits) will be appended to the end of the GET
2181 uint32_t hash_bitmap GNUNET_PACKED;
2184 * Hashcodes of the file(s) we're looking for.
2185 * Details depend on the query type.
2187 GNUNET_HashCode query GNUNET_PACKED;
2189 /* this is followed by hash codes
2190 as specified in the "hash_bitmap";
2191 after that, an optional bloomfilter
2192 (with bits set for replies that should
2193 be suppressed) can be present */
2198 * Response from FS service with a result for a previous FS search.
2199 * Note that queries for DBLOCKS and IBLOCKS that have received a
2200 * single response are considered done. This message is transmitted
2201 * between peers as well as between the service and a client.
2207 * Message type will be GNUNET_MESSAGE_TYPE_FS_PUT.
2209 struct GNUNET_MessageHeader header;
2212 * Type of the block (in big endian). Should never be zero.
2214 uint32_t type GNUNET_PACKED;
2217 * When does this result expire?
2219 struct GNUNET_TIME_AbsoluteNBO expiration;
2221 /* this is followed by the actual encrypted content */
2227 * Message send by a peer that wants to be excluded
2228 * from migration for a while.
2230 struct MigrationStopMessage
2233 * Message type will be
2234 * GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP.
2236 struct GNUNET_MessageHeader header;
2241 uint32_t reserved GNUNET_PACKED;
2244 * How long should the block last?
2246 struct GNUNET_TIME_RelativeNBO duration;