2 This file is part of GNUnet.
3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @brief shared definitions for the FS library
22 * @author Igor Wronsky, Christian Grothoff
27 #include "gnunet_constants.h"
28 #include "gnunet_datastore_service.h"
29 #include "gnunet_dht_service.h"
30 #include "gnunet_fs_service.h"
31 #include "gnunet_block_lib.h"
36 * Pick a multiple of 2 here to achive 8-byte alignment! We also
37 * probably want DBlocks to have (roughly) the same size as IBlocks.
38 * With SHA-512, the optimal value is 32768 byte / 128 byte = 256 (128
39 * byte = 2 * 512 bits). DO NOT CHANGE!
41 #define CHK_PER_INODE 256
44 * Maximum size for a file to be considered for inlining in a
47 #define MAX_INLINE_SIZE 65536
50 * Name of the directory with top-level searches.
52 #define GNUNET_FS_SYNC_PATH_MASTER_SEARCH "search"
55 * Name of the directory with sub-searches (namespace-updates).
57 #define GNUNET_FS_SYNC_PATH_CHILD_SEARCH "search-child"
60 * Name of the directory with master downloads (not associated
61 * with search or part of another download).
63 #define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD "download"
66 * Name of the directory with downloads that are part of another
67 * download or a search.
69 #define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD "download-child"
72 * Name of the directory with publishing operations.
74 #define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH "publish"
77 * Name of the directory with files that are being published
79 #define GNUNET_FS_SYNC_PATH_FILE_INFO "publish-file"
82 * Name of the directory with unindex operations.
84 #define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX "unindex"
88 * @brief complete information needed
95 * Total size of the file in bytes. (network byte order (!))
100 * Query and key of the top GNUNET_EC_IBlock.
102 struct ContentHashKey chk;
108 * Information about a file and its location
109 * (peer claiming to share the file).
114 * Information about the shared file.
116 struct FileIdentifier fi;
119 * Identity of the peer sharing the file.
121 struct GNUNET_PeerIdentity peer;
124 * Time when this location URI expires.
126 struct GNUNET_TIME_Absolute expirationTime;
129 * Signature over the GNUNET_EC_FileIdentifier,
130 * peer identity and expiration time.
132 struct GNUNET_CRYPTO_EddsaSignature contentSignature;
139 enum GNUNET_FS_UriType
142 * Content-hash-key (simple file).
147 * Signed key space (file in namespace).
152 * Keyword search key (query with keywords).
157 * Location (chk with identity of hosting peer).
164 * A Universal Resource Identifier (URI), opaque.
171 enum GNUNET_FS_UriType type;
178 * Keywords start with a '+' if they are mandatory (in which
179 * case the '+' is NOT part of the keyword) and with a simple
180 * space if they are optional (in which case the space is ALSO
181 * not part of the actual keyword).
183 * Double-quotes to protect spaces and %-encoding are NOT used
184 * internally (only in URI-strings).
189 * Size of the keywords array.
191 unsigned int keywordCount;
197 * Identifier of the namespace.
199 struct GNUNET_CRYPTO_EcdsaPublicKey ns;
202 * Human-readable identifier chosen for this entry in the
210 * Information needed to retrieve a file (content-hash-key
213 struct FileIdentifier chk;
216 * Information needed to retrieve a file including signed
217 * location (identity of a peer) of the content.
226 * Information for a file or directory that is
227 * about to be published.
229 struct GNUNET_FS_FileInformation
233 * Files in a directory are kept as a linked list.
235 struct GNUNET_FS_FileInformation *next;
238 * If this is a file in a directory, "dir" refers to
239 * the directory; otherwise NULL.
241 struct GNUNET_FS_FileInformation *dir;
244 * Handle to the master context.
246 struct GNUNET_FS_Handle *h;
249 * Pointer kept for the client.
254 * Metadata to use for the file.
256 struct GNUNET_CONTAINER_MetaData *meta;
259 * Keywords to use for KBlocks.
261 struct GNUNET_FS_Uri *keywords;
264 * CHK for this file or directory. NULL if
265 * we have not yet computed it.
267 struct GNUNET_FS_Uri *chk_uri;
270 * SKS URI for this file or directory. NULL if
271 * we have not yet computed it.
273 struct GNUNET_FS_Uri *sks_uri;
276 * Block options for the file.
278 struct GNUNET_FS_BlockOptions bo;
281 * At what time did we start this upload?
283 struct GNUNET_TIME_Absolute start_time;
286 * Under what filename is this struct serialized
287 * (for operational persistence). Should be determined
293 * Encoder being used to publish this file.
295 struct GNUNET_FS_TreeEncoder *te;
298 * Error message (non-NULL if this operation failed).
303 * Name of the file or directory (must be an absolute path).
308 * Data describing either the file or the directory.
320 * Function that can be used to read the data for the file.
322 GNUNET_FS_DataReader reader;
325 * Closure for reader.
330 * If this file is being indexed, this value is set to the hash
331 * over the entire file (when the indexing process is started).
332 * Otherwise this field is not used.
334 struct GNUNET_HashCode file_id;
337 * Size of the file (in bytes).
342 * Should the file be indexed or inserted?
347 * Is "file_id" already valid? Set to #GNUNET_YES once the hash
348 * has been calculated.
353 * Has the service confirmed our INDEX_START request?
354 * #GNUNET_YES if this step has been completed.
356 int index_start_confirmed;
361 * Data for a directory.
367 * Linked list of entries in the directory.
369 struct GNUNET_FS_FileInformation *entries;
372 * Size of the directory itself (in bytes); 0 if the
373 * size has not yet been calculated.
378 * Pointer to the data for the directory (or NULL if not
384 * How much of the directory have we published (relative to @e contents_size).
386 uint64_t contents_completed;
389 * Sum of all of the sizes of all of the files in the directory.
391 uint64_t contents_size;
398 * Is this struct for a file or directory?
403 * Are we done publishing this file?
411 * Priorities for the queue.
413 enum GNUNET_FS_QueuePriority
416 * This is a probe (low priority).
418 GNUNET_FS_QUEUE_PRIORITY_PROBE,
423 GNUNET_FS_QUEUE_PRIORITY_NORMAL
428 * Entry in the job queue.
430 struct GNUNET_FS_QueueEntry
433 * This is a linked list.
435 struct GNUNET_FS_QueueEntry *next;
438 * This is a linked list.
440 struct GNUNET_FS_QueueEntry *prev;
443 * Function to call when the job is started.
445 GNUNET_SCHEDULER_TaskCallback start;
448 * Function to call when the job needs to stop (or is done / dequeued).
450 GNUNET_SCHEDULER_TaskCallback stop;
453 * Closure for start and stop.
458 * Handle to FS primary context.
460 struct GNUNET_FS_Handle *h;
463 * Message queue handle, or NULL if job is not running.
465 struct GNUNET_MQ_Handle *mq;
468 * Time the job was originally queued.
470 struct GNUNET_TIME_Absolute queue_time;
473 * Time the job was started last.
475 struct GNUNET_TIME_Absolute start_time;
478 * Total amount of time the job has been running (except for the
481 struct GNUNET_TIME_Relative run_time;
484 * How many blocks do the active downloads have?
489 * How important is this download?
491 enum GNUNET_FS_QueuePriority priority;
494 * How often have we (re)started this download?
496 unsigned int start_times;
499 * #GNUNET_YES if the job is active now.
507 * Information we store for each search result.
509 struct GNUNET_FS_SearchResult
513 * File-sharing context this result belongs to.
515 struct GNUNET_FS_Handle *h;
518 * Kept in a DLL while probing.
520 struct GNUNET_FS_SearchResult *next;
523 * Kept in a DLL while probing.
525 struct GNUNET_FS_SearchResult *prev;
528 * Search context this result belongs to; can be NULL
529 * for probes that come from a directory result.
531 struct GNUNET_FS_SearchContext *sc;
534 * URI to which this search result refers to.
536 struct GNUNET_FS_Uri *uri;
539 * Metadata for the search result.
541 struct GNUNET_CONTAINER_MetaData *meta;
544 * Client info for this search result.
549 * ID of a job that is currently probing this results' availability
550 * (NULL if we are not currently probing).
552 struct GNUNET_FS_DownloadContext *probe_ctx;
555 * ID of an associated download based on this search result (or
558 struct GNUNET_FS_DownloadContext *download;
561 * If this search result triggered an update search, this field
562 * links to the update search.
564 struct GNUNET_FS_SearchContext *update_search;
567 * Name under which this search result is stored on disk.
572 * Bitmap that specifies precisely which keywords have been matched already.
574 uint8_t *keyword_bitmap;
577 * Key for the search result based on the URI.
579 struct GNUNET_HashCode key;
582 * ID of the task that will clean up the probe_ctx should it not
583 * complete on time (and that will need to be cancelled if we clean
584 * up the search result before then).
586 struct GNUNET_SCHEDULER_Task * probe_cancel_task;
589 * When did the current probe become active?
591 struct GNUNET_TIME_Absolute probe_active_time;
594 * How much longer should we run the current probe before giving up?
596 struct GNUNET_TIME_Relative remaining_probe_time;
599 * Anonymity level to use for probes using this search result.
604 * Number of mandatory keywords for which we have NOT yet found the
605 * search result; when this value hits zero, the search result is
606 * given to the callback.
608 uint32_t mandatory_missing;
611 * Number of optional keywords under which this result was also
614 uint32_t optional_support;
617 * Number of availability tests that have succeeded for this result.
619 uint32_t availability_success;
622 * Number of availability trials that we have performed for this
625 uint32_t availability_trials;
631 * Add a job to the queue.
633 * @param h handle to the overall FS state
634 * @param start function to call to begin the job
635 * @param stop function to call to pause the job, or on dequeue (if the job was running)
636 * @param cls closure for start and stop
637 * @param blocks number of blocks this download has
638 * @param priority how important is this download
639 * @return queue handle
641 struct GNUNET_FS_QueueEntry *
642 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
643 GNUNET_SCHEDULER_TaskCallback start,
644 GNUNET_SCHEDULER_TaskCallback stop,
647 enum GNUNET_FS_QueuePriority priority);
651 * Dequeue a job from the queue.
653 * @param qe handle for the job
656 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe);
660 * Function that provides data by reading from a file.
662 * @param cls closure (points to the file information)
663 * @param offset offset to read from; it is possible
664 * that the caller might need to go backwards
666 * @param max maximum number of bytes that should be
667 * copied to @a buf; readers are not allowed
668 * to provide less data unless there is an error;
669 * a value of "0" will be used at the end to allow
670 * the reader to clean up its internal state
671 * @param buf where the reader should write the data
672 * @param emsg location for the reader to store an error message
673 * @return number of bytes written, usually "max", 0 on error
676 GNUNET_FS_data_reader_file_ (void *cls,
684 * Create the closure for the #GNUNET_FS_data_reader_file_() callback.
686 * @param filename file to read
687 * @return closure to use
690 GNUNET_FS_make_file_reader_context_ (const char *filename);
695 * Function that provides data by copying from a buffer.
697 * @param cls closure (points to the buffer)
698 * @param offset offset to read from; it is possible
699 * that the caller might need to go backwards
701 * @param max maximum number of bytes that should be
702 * copied to @a buf; readers are not allowed
703 * to provide less data unless there is an error;
704 * a value of "0" will be used at the end to allow
705 * the reader to clean up its internal state
706 * @param buf where the reader should write the data
707 * @param emsg location for the reader to store an error message
708 * @return number of bytes written, usually @a max, 0 on error
711 GNUNET_FS_data_reader_copy_ (void *cls,
719 * Notification of FS that a search probe has made progress.
720 * This function is used INSTEAD of the client's event handler
721 * for downloads where the #GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
723 * @param cls closure, always NULL (!), actual closure
724 * is in the client-context of the info struct
725 * @param info details about the event, specifying the event type
726 * and various bits about the event
727 * @return client-context (for the next progress call
728 * for this operation; should be set to NULL for
729 * SUSPEND and STOPPED events). The value returned
730 * will be passed to future callbacks in the respective
731 * field in the `struct GNUNET_FS_ProgressInfo`.
734 GNUNET_FS_search_probe_progress_ (void *cls,
735 const struct GNUNET_FS_ProgressInfo *info);
739 * Main function that performs the upload.
741 * @param cls `struct GNUNET_FS_PublishContext` identifies the upload
744 GNUNET_FS_publish_main_ (void *cls);
748 * Function called once the hash of the file
749 * that is being unindexed has been computed.
751 * @param cls closure, unindex context
752 * @param file_id computed hash, NULL on error
755 GNUNET_FS_unindex_process_hash_ (void *cls,
756 const struct GNUNET_HashCode *file_id);
760 * Extract the keywords for KBlock removal
762 * @param uc context for the unindex operation.
765 GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc);
769 * If necessary, connect to the datastore and remove the KBlocks.
771 * @param uc context for the unindex operation.
774 GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc);
778 * Fill in all of the generic fields for a publish event and call the
781 * @param pi structure to fill in
782 * @param pc overall publishing context
783 * @param p file information for the file being published
784 * @param offset where in the file are we so far
785 * @return value returned from callback
788 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
789 struct GNUNET_FS_PublishContext *pc,
790 const struct GNUNET_FS_FileInformation *p,
795 * Fill in all of the generic fields for a download event and call the
798 * @param pi structure to fill in
799 * @param dc overall download context
802 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
803 struct GNUNET_FS_DownloadContext *dc);
807 * Task that creates the initial (top-level) download
808 * request for the file.
810 * @param cls the 'struct GNUNET_FS_DownloadContext'
813 GNUNET_FS_download_start_task_ (void *cls);
818 * Fill in all of the generic fields for
819 * an unindex event and call the callback.
821 * @param pi structure to fill in
822 * @param uc overall unindex context
823 * @param offset where we are in the file (for progress)
826 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
827 struct GNUNET_FS_UnindexContext *uc,
831 * Fill in all of the generic fields for a search event and
834 * @param pi structure to fill in
835 * @param h file-sharing handle
836 * @param sc overall search context
837 * @return value returned by the callback
840 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
841 struct GNUNET_FS_Handle *h,
842 struct GNUNET_FS_SearchContext *sc);
846 * Connect to the datastore and remove the blocks.
848 * @param uc context for the unindex operation.
851 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
854 * Build the request and actually initiate the search using the
857 * @param sc search context
858 * @return GNUNET_OK on success, GNUNET_SYSERR on error
861 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
864 * Start the downloading process (by entering the queue).
866 * @param dc our download context
869 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
873 * Start download probes for the given search result.
875 * @param sr the search result
878 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
882 * Remove serialization/deserialization file from disk.
884 * @param h master context
885 * @param ext component of the path
886 * @param ent entity identifier
889 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
895 * Remove serialization/deserialization directory from disk.
897 * @param h master context
898 * @param ext component of the path
899 * @param uni unique name of parent
902 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
908 * Synchronize this file-information struct with its mirror
909 * on disk. Note that all internal FS-operations that change
910 * file information data should already call "sync" internally,
911 * so this function is likely not useful for clients.
913 * @param fi the struct to sync
916 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
920 * Synchronize this publishing struct with its mirror
921 * on disk. Note that all internal FS-operations that change
922 * publishing structs should already call "sync" internally,
923 * so this function is likely not useful for clients.
925 * @param pc the struct to sync
928 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
932 * Synchronize this unindex struct with its mirror
933 * on disk. Note that all internal FS-operations that change
934 * publishing structs should already call "sync" internally,
935 * so this function is likely not useful for clients.
937 * @param uc the struct to sync
940 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
944 * Synchronize this search struct with its mirror
945 * on disk. Note that all internal FS-operations that change
946 * publishing structs should already call "sync" internally,
947 * so this function is likely not useful for clients.
949 * @param sc the struct to sync
952 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
956 * Synchronize this search result with its mirror
957 * on disk. Note that all internal FS-operations that change
958 * publishing structs should already call "sync" internally,
959 * so this function is likely not useful for clients.
961 * @param sr the struct to sync
964 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
968 * Synchronize this download struct with its mirror
969 * on disk. Note that all internal FS-operations that change
970 * publishing structs should already call "sync" internally,
971 * so this function is likely not useful for clients.
973 * @param dc the struct to sync
976 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
980 * Create SUSPEND event for the given publish operation
981 * and then clean up our state (without stop signal).
983 * @param cls the `struct GNUNET_FS_PublishContext` to signal for
986 GNUNET_FS_publish_signal_suspend_ (void *cls);
990 * Create SUSPEND event for the given search operation
991 * and then clean up our state (without stop signal).
993 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
996 GNUNET_FS_search_signal_suspend_ (void *cls);
1000 * Create SUSPEND event for the given download operation
1001 * and then clean up our state (without stop signal).
1003 * @param cls the `struct GNUNET_FS_DownloadContext` to signal for
1006 GNUNET_FS_download_signal_suspend_ (void *cls);
1010 * Create SUSPEND event for the given unindex operation
1011 * and then clean up our state (without stop signal).
1013 * @param cls the `struct GNUNET_FS_UnindexContext` to signal for
1016 GNUNET_FS_unindex_signal_suspend_ (void *cls);
1020 * Function signature of the functions that can be called
1021 * to trigger suspend signals and clean-up for top-level
1024 * @param cls closure
1026 typedef void (*SuspendSignalFunction) (void *cls);
1029 * We track all of the top-level activities of FS
1030 * so that we can signal 'suspend' on shutdown.
1032 struct TopLevelActivity
1035 * This is a doubly-linked list.
1037 struct TopLevelActivity *next;
1040 * This is a doubly-linked list.
1042 struct TopLevelActivity *prev;
1045 * Function to call for suspend-signalling and clean up.
1047 SuspendSignalFunction ssf;
1050 * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1057 * Create a top-level activity entry.
1059 * @param h global fs handle
1060 * @param ssf suspend signal function to use
1061 * @param ssf_cls closure for @a ssf
1062 * @return fresh top-level activity handle
1064 struct TopLevelActivity *
1065 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1066 SuspendSignalFunction ssf,
1071 * Destroy a top-level activity entry.
1073 * @param h global fs handle
1074 * @param top top level activity entry
1077 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
1078 struct TopLevelActivity *top);
1083 * Master context for most FS operations.
1085 struct GNUNET_FS_Handle
1088 * Configuration to use.
1090 const struct GNUNET_CONFIGURATION_Handle *cfg;
1093 * Name of our client.
1098 * Function to call with updates on our progress.
1100 GNUNET_FS_ProgressCallback upcb;
1108 * Head of DLL of top-level activities.
1110 struct TopLevelActivity *top_head;
1113 * Tail of DLL of top-level activities.
1115 struct TopLevelActivity *top_tail;
1118 * Head of DLL of running jobs.
1120 struct GNUNET_FS_QueueEntry *running_head;
1123 * Tail of DLL of running jobs.
1125 struct GNUNET_FS_QueueEntry *running_tail;
1128 * Head of DLL of pending jobs.
1130 struct GNUNET_FS_QueueEntry *pending_head;
1133 * Tail of DLL of pending jobs.
1135 struct GNUNET_FS_QueueEntry *pending_tail;
1138 * Head of active probes.
1140 struct GNUNET_FS_SearchResult *probes_head;
1143 * Tail of active probes.
1145 struct GNUNET_FS_SearchResult *probes_tail;
1148 * Task that processes the jobs in the running and pending queues
1149 * (and moves jobs around as needed).
1151 struct GNUNET_SCHEDULER_Task * queue_job;
1154 * Task we use to report periodically to the application that
1155 * certain search probes (from @e probes_head) are still running.
1157 struct GNUNET_SCHEDULER_Task * probe_ping_task;
1160 * Average time we take for a single request to be satisfied.
1161 * FIXME: not yet calcualted properly...
1163 struct GNUNET_TIME_Relative avg_block_latency;
1166 * How many actual downloads do we have running right now?
1168 unsigned int active_downloads;
1171 * How many blocks do the active downloads have?
1173 unsigned int active_blocks;
1178 enum GNUNET_FS_Flags flags;
1181 * Maximum number of parallel downloads.
1183 unsigned int max_parallel_downloads;
1186 * Maximum number of parallel requests.
1188 unsigned int max_parallel_requests;
1194 * Handle for controlling a publication process.
1196 struct GNUNET_FS_PublishContext
1199 * Handle to the global fs context.
1201 struct GNUNET_FS_Handle *h;
1204 * Our top-level activity entry (if we are top-level, otherwise NULL).
1206 struct TopLevelActivity *top;
1209 * File-structure that is being shared.
1211 struct GNUNET_FS_FileInformation *fi;
1214 * Namespace that we are publishing in, NULL if we have no namespace.
1216 struct GNUNET_CRYPTO_EcdsaPrivateKey *ns;
1219 * ID of the content in the namespace, NULL if we have no namespace.
1224 * ID for future updates, NULL if we have no namespace or no updates.
1229 * Filename used for serializing information about this operation
1230 * (should be determined using 'mktemp').
1232 char *serialization;
1235 * Our own message queue for the FS service; only briefly used when
1236 * we start to index a file, otherwise NULL.
1238 struct GNUNET_MQ_Handle *mq;
1241 * Current position in the file-tree for the upload.
1243 struct GNUNET_FS_FileInformation *fi_pos;
1246 * Non-null if we are currently hashing a file.
1248 struct GNUNET_CRYPTO_FileHashContext *fhc;
1251 * Connection to the datastore service.
1253 struct GNUNET_DATASTORE_Handle *dsh;
1256 * Queue entry for reservation/unreservation.
1258 struct GNUNET_DATASTORE_QueueEntry *qre;
1261 * Context for SKS publishing operation that is part of this publishing operation
1262 * (NULL if not active).
1264 struct GNUNET_FS_PublishSksContext *sks_pc;
1267 * Context for KSK publishing operation that is part of this publishing operation
1268 * (NULL if not active).
1270 struct GNUNET_FS_PublishKskContext *ksk_pc;
1273 * ID of the task performing the upload. NO_TASK if the upload has
1276 struct GNUNET_SCHEDULER_Task * upload_task;
1279 * Storage space to reserve for the operation.
1281 uint64_t reserve_space;
1284 * Overall number of entries to reserve for the
1285 * publish operation.
1287 uint32_t reserve_entries;
1290 * Options for publishing.
1292 enum GNUNET_FS_PublishOptions options;
1295 * Space reservation ID with datastore service
1301 * Set to #GNUNET_YES if we were able to publish any block.
1302 * (and thus unindexing on error might make sense).
1307 * Set to #GNUNET_YES if all processing has completed.
1312 * Flag set to #GNUNET_YES if the next callback from
1313 * #GNUNET_FS_file_information_inspect should be skipped because it
1314 * is for the directory which was already processed with the parent.
1316 int skip_next_fi_callback;
1321 * Phases of unindex processing (state machine).
1326 * We're currently hashing the file.
1328 UNINDEX_STATE_HASHING = 0,
1331 * We're telling the datastore to delete
1332 * the respective DBlocks and IBlocks.
1334 UNINDEX_STATE_DS_REMOVE = 1,
1337 * Find out which keywords apply.
1339 UNINDEX_STATE_EXTRACT_KEYWORDS = 2,
1342 * We're telling the datastore to remove KBlocks.
1344 UNINDEX_STATE_DS_REMOVE_KBLOCKS = 3,
1347 * We're notifying the FS service about
1350 UNINDEX_STATE_FS_NOTIFY = 4,
1355 UNINDEX_STATE_COMPLETE = 5,
1358 * We've encountered a fatal error.
1360 UNINDEX_STATE_ERROR = 6
1365 * Handle for controlling an unindexing operation.
1367 struct GNUNET_FS_UnindexContext
1371 * The content hash key of the last block we processed, will in the
1372 * end be set to the CHK from the URI. Used to remove the KBlocks.
1374 struct ContentHashKey chk;
1377 * Global FS context.
1379 struct GNUNET_FS_Handle *h;
1382 * Our top-level activity entry.
1384 struct TopLevelActivity *top;
1387 * Directory scanner to find keywords (KBlock removal).
1389 struct GNUNET_FS_DirScanner *dscan;
1392 * Keywords found (telling us which KBlocks to remove).
1394 struct GNUNET_FS_Uri *ksk_uri;
1397 * Current offset in KSK removal.
1399 uint32_t ksk_offset;
1402 * Name of the file that we are unindexing.
1407 * Short name under which we are serializing the state of this operation.
1409 char *serialization;
1412 * Connection to the FS service, only valid during the
1413 * #UNINDEX_STATE_FS_NOTIFY phase.
1415 struct GNUNET_MQ_Handle *mq;
1418 * Connection to the datastore service, only valid during the
1419 * UNINDEX_STATE_DS_NOTIFY phase.
1421 struct GNUNET_DATASTORE_Handle *dsh;
1424 * Pointer kept for the client.
1429 * Merkle-ish tree encoder context.
1431 struct GNUNET_FS_TreeEncoder *tc;
1434 * Handle used to read the file.
1436 struct GNUNET_DISK_FileHandle *fh;
1439 * Handle to datastore 'get_key' operation issued for
1440 * obtaining KBlocks.
1442 struct GNUNET_DATASTORE_QueueEntry *dqe;
1445 * Current key for decrypting UBLocks from 'get_key' operation.
1447 struct GNUNET_HashCode ukey;
1450 * Current query of 'get_key' operation.
1452 struct GNUNET_HashCode uquery;
1455 * Error message, NULL on success.
1460 * Context for hashing of the file.
1462 struct GNUNET_CRYPTO_FileHashContext *fhc;
1465 * Overall size of the file.
1470 * When did we start?
1472 struct GNUNET_TIME_Absolute start_time;
1475 * Hash of the file's contents (once computed).
1477 struct GNUNET_HashCode file_id;
1480 * Current operatinonal phase.
1482 enum UnindexState state;
1488 * Information we keep for each keyword in a keyword search.
1490 struct SearchRequestEntry
1494 * Hash of the public key, also known as the query.
1496 struct GNUNET_HashCode uquery;
1499 * Derived public key, hashes to 'uquery'.
1501 struct GNUNET_CRYPTO_EcdsaPublicKey dpub;
1504 * The original keyword, used to derive the
1505 * key (for decrypting the UBlock).
1510 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1511 * was found under this keyword. Note that the entries will point
1512 * to the same locations as those in the master result map (in
1513 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1514 * The key for each entry is the XOR of the key and query in the CHK
1515 * URI (as a unique identifier for the search result).
1517 struct GNUNET_CONTAINER_MultiHashMap *results;
1520 * Is this keyword a mandatory keyword
1521 * (started with '+')?
1529 * Handle for controlling a search.
1531 struct GNUNET_FS_SearchContext
1534 * Handle to the global FS context.
1536 struct GNUNET_FS_Handle *h;
1539 * Our top-level activity entry (if we are top-level, otherwise NULL).
1541 struct TopLevelActivity *top;
1544 * List of keywords that we're looking for.
1546 struct GNUNET_FS_Uri *uri;
1549 * For update-searches, link to the search result that triggered
1550 * the update search; otherwise NULL.
1552 struct GNUNET_FS_SearchResult *psearch_result;
1555 * Connection to the FS service.
1557 struct GNUNET_MQ_Handle *mq;
1560 * Pointer we keep for the client.
1565 * Name of the file on disk we use for persistence.
1567 char *serialization;
1570 * Error message (non-NULL if this operation failed).
1575 * Map that contains a `struct GNUNET_FS_SearchResult` for each result that
1576 * was found in the search. The key for each entry is the XOR of
1577 * the key and query in the CHK URI (as a unique identifier for the
1580 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1583 * Per-keyword information for a keyword search. This array will
1584 * have exactly as many entries as there were keywords.
1586 struct SearchRequestEntry *requests;
1589 * When did we start?
1591 struct GNUNET_TIME_Absolute start_time;
1594 * How long to wait before we try to reconnect to FS service?
1596 struct GNUNET_TIME_Relative reconnect_backoff;
1599 * ID of a task that is using this struct and that must be cancelled
1600 * when the search is being stopped (if not
1601 * NULL). Used for the task that adds some
1602 * artificial delay when trying to reconnect to the FS service.
1604 struct GNUNET_SCHEDULER_Task *task;
1607 * Anonymity level for the search.
1612 * Number of mandatory keywords in this query.
1614 uint32_t mandatory_count;
1617 * Options for the search.
1619 enum GNUNET_FS_SearchOptions options;
1624 * FSM for possible states a block can go through. The typical
1625 * order of progression is linear through the states, alternatives
1626 * are documented in the comments.
1628 enum BlockRequestState
1631 * Initial state, block has only been allocated (since it is
1632 * relevant to the overall download request).
1637 * We've checked the block on the path down the tree, and the
1638 * content on disk did match the desired CHK, but not all
1639 * the way down, so at the bottom some blocks will still
1640 * need to be reconstructed).
1642 BRS_RECONSTRUCT_DOWN = 1,
1645 * We've calculated the CHK bottom-up based on the meta data.
1646 * This may work, but if it did we have to write the meta data to
1647 * disk at the end (and we still need to check against the
1650 BRS_RECONSTRUCT_META_UP = 2,
1653 * We've calculated the CHK bottom-up based on what we have on
1654 * disk, which may not be what the desired CHK is. If the
1655 * reconstructed CHKs match whatever comes from above, we're
1656 * done with the respective subtree.
1658 BRS_RECONSTRUCT_UP = 3,
1661 * We've determined the real, desired CHK for this block
1662 * (full tree reconstruction failed), request is now pending.
1663 * If the CHK that bubbled up through reconstruction did match
1664 * the top-level request, the state machine for the subtree
1665 * would have moved to BRS_DOWNLOAD_UP.
1670 * We've successfully downloaded this block, but the children
1671 * still need to be either downloaded or verified (download
1672 * request propagates down). If the download fails, the
1673 * state machine for this block may move to
1674 * BRS_DOWNLOAD_ERROR instead.
1676 BRS_DOWNLOAD_DOWN = 5,
1679 * This block and all of its children have been downloaded
1680 * successfully (full completion propagates up).
1682 BRS_DOWNLOAD_UP = 6,
1685 * We got a block back that matched the query but did not hash to
1686 * the key (malicious publisher or hash collision); this block
1687 * can never be downloaded (error propagates up).
1694 * Information about an active download request.
1696 struct DownloadRequest
1700 * Parent in the CHK-tree.
1702 struct DownloadRequest *parent;
1705 * Array (!) of child-requests, or NULL for the bottom of the tree.
1707 struct DownloadRequest **children;
1710 * CHK for the request for this block (set during reconstruction
1711 * to what we have on disk, later to what we want to have).
1713 struct ContentHashKey chk;
1716 * Offset of the corresponding block. Specifically, first (!) byte of
1717 * the first DBLOCK in the subtree induced by block represented by
1723 * Number of entries in @e children array.
1725 unsigned int num_children;
1728 * Depth of the corresponding block in the tree. 0==DBLOCKs.
1733 * Offset of the CHK for this block in the parent block
1735 unsigned int chk_idx;
1740 enum BlockRequestState state;
1746 * (recursively) free download request structure
1748 * @param dr request to free
1751 GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
1755 * Stop the ping task for this search result.
1757 * @param sr result to start pinging for.
1760 GNUNET_FS_stop_probe_ping_task_ (struct GNUNET_FS_SearchResult *sr);
1764 * Context for controlling a download.
1766 struct GNUNET_FS_DownloadContext
1770 * Global FS context.
1772 struct GNUNET_FS_Handle *h;
1775 * Our top-level activity entry (if we are top-level, otherwise NULL).
1777 struct TopLevelActivity *top;
1780 * Connection to the FS service.
1782 struct GNUNET_MQ_Handle *mq;
1785 * Parent download (used when downloading files
1788 struct GNUNET_FS_DownloadContext *parent;
1791 * Associated search (used when downloading files
1792 * based on search results), or NULL for none.
1794 struct GNUNET_FS_SearchResult *search;
1797 * Head of list of child downloads.
1799 struct GNUNET_FS_DownloadContext *child_head;
1802 * Tail of list of child downloads.
1804 struct GNUNET_FS_DownloadContext *child_tail;
1807 * Previous download belonging to the same parent.
1809 struct GNUNET_FS_DownloadContext *prev;
1812 * Next download belonging to the same parent.
1814 struct GNUNET_FS_DownloadContext *next;
1817 * Context kept for the client.
1822 * URI that identifies the file that we are downloading.
1824 struct GNUNET_FS_Uri *uri;
1827 * Known meta-data for the file (can be NULL).
1829 struct GNUNET_CONTAINER_MetaData *meta;
1832 * Error message, NULL if we're doing OK.
1837 * Random portion of filename we use for syncing state of this
1840 char *serialization;
1843 * Where are we writing the data (name of the
1844 * file, can be NULL!).
1849 * Where are we writing the data temporarily (name of the
1850 * file, can be NULL!); used if we do not have a permanent
1851 * name and we are a directory and we do a recursive download.
1853 char *temp_filename;
1856 * Our entry in the job queue.
1858 struct GNUNET_FS_QueueEntry *job_queue;
1861 * Tree encoder used for the reconstruction.
1863 struct GNUNET_FS_TreeEncoder *te;
1866 * File handle for reading data from an existing file
1867 * (to pass to tree encoder).
1869 struct GNUNET_DISK_FileHandle *rfh;
1872 * Map of active requests (those waiting for a response). The key
1873 * is the hash of the encryped block (aka query).
1875 struct GNUNET_CONTAINER_MultiHashMap *active;
1878 * Top-level download request.
1880 struct DownloadRequest *top_request;
1883 * Identity of the peer having the content, or all-zeros
1884 * if we don't know of such a peer.
1886 struct GNUNET_PeerIdentity target;
1889 * ID of a task that is using this struct and that must be cancelled
1890 * when the download is being stopped (if not
1891 * NULL). Used for the task that adds some
1892 * artificial delay when trying to reconnect to the FS service or
1893 * the task processing incrementally the data on disk, or the
1894 * task requesting blocks, etc.
1896 struct GNUNET_SCHEDULER_Task *task;
1899 * What is the first offset that we're interested
1905 * How many bytes starting from offset are desired?
1906 * This is NOT the overall length of the file!
1911 * How many bytes have we already received within
1912 * the specified range (DBlocks only).
1917 * What was the size of the file on disk that we're downloading
1918 * before we started? Used to detect if there is a point in
1919 * checking an existing block on disk for matching the desired
1920 * content. 0 if the file did not exist already.
1922 uint64_t old_file_size;
1925 * Time download was started.
1927 struct GNUNET_TIME_Absolute start_time;
1930 * How long to wait before we try to reconnect to FS service?
1932 struct GNUNET_TIME_Relative reconnect_backoff;
1935 * Desired level of anonymity.
1940 * The depth of the file-tree.
1942 unsigned int treedepth;
1945 * Options for the download.
1947 enum GNUNET_FS_DownloadOptions options;
1950 * Flag set upon transitive completion (includes child downloads).
1951 * This flag is only set to #GNUNET_YES for directories where all
1952 * child-downloads have also completed (and signalled completion).
1957 * Are we ready to issue requests (reconstructions are finished)?
1966 /* end of fs_api.h */