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 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.
18 * @brief shared definitions for the FS library
19 * @author Igor Wronsky, Christian Grothoff
24 #include "gnunet_constants.h"
25 #include "gnunet_datastore_service.h"
26 #include "gnunet_dht_service.h"
27 #include "gnunet_fs_service.h"
28 #include "gnunet_block_lib.h"
33 * Pick a multiple of 2 here to achive 8-byte alignment! We also
34 * probably want DBlocks to have (roughly) the same size as IBlocks.
35 * With SHA-512, the optimal value is 32768 byte / 128 byte = 256 (128
36 * byte = 2 * 512 bits). DO NOT CHANGE!
38 #define CHK_PER_INODE 256
41 * Maximum size for a file to be considered for inlining in a
44 #define MAX_INLINE_SIZE 65536
47 * Name of the directory with top-level searches.
49 #define GNUNET_FS_SYNC_PATH_MASTER_SEARCH "search"
52 * Name of the directory with sub-searches (namespace-updates).
54 #define GNUNET_FS_SYNC_PATH_CHILD_SEARCH "search-child"
57 * Name of the directory with master downloads (not associated
58 * with search or part of another download).
60 #define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD "download"
63 * Name of the directory with downloads that are part of another
64 * download or a search.
66 #define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD "download-child"
69 * Name of the directory with publishing operations.
71 #define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH "publish"
74 * Name of the directory with files that are being published
76 #define GNUNET_FS_SYNC_PATH_FILE_INFO "publish-file"
79 * Name of the directory with unindex operations.
81 #define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX "unindex"
85 * @brief complete information needed
92 * Total size of the file in bytes. (network byte order (!))
97 * Query and key of the top GNUNET_EC_IBlock.
99 struct ContentHashKey chk;
105 * Information about a file and its location
106 * (peer claiming to share the file).
111 * Information about the shared file.
113 struct FileIdentifier fi;
116 * Identity of the peer sharing the file.
118 struct GNUNET_PeerIdentity peer;
121 * Time when this location URI expires.
123 struct GNUNET_TIME_Absolute expirationTime;
126 * Signature over the GNUNET_EC_FileIdentifier,
127 * peer identity and expiration time.
129 struct GNUNET_CRYPTO_EddsaSignature contentSignature;
136 enum GNUNET_FS_UriType
139 * Content-hash-key (simple file).
144 * Signed key space (file in namespace).
149 * Keyword search key (query with keywords).
154 * Location (chk with identity of hosting peer).
161 * A Universal Resource Identifier (URI), opaque.
168 enum GNUNET_FS_UriType type;
175 * Keywords start with a '+' if they are mandatory (in which
176 * case the '+' is NOT part of the keyword) and with a simple
177 * space if they are optional (in which case the space is ALSO
178 * not part of the actual keyword).
180 * Double-quotes to protect spaces and %-encoding are NOT used
181 * internally (only in URI-strings).
186 * Size of the keywords array.
188 unsigned int keywordCount;
194 * Identifier of the namespace.
196 struct GNUNET_CRYPTO_EcdsaPublicKey ns;
199 * Human-readable identifier chosen for this entry in the
207 * Information needed to retrieve a file (content-hash-key
210 struct FileIdentifier chk;
213 * Information needed to retrieve a file including signed
214 * location (identity of a peer) of the content.
223 * Information for a file or directory that is
224 * about to be published.
226 struct GNUNET_FS_FileInformation
230 * Files in a directory are kept as a linked list.
232 struct GNUNET_FS_FileInformation *next;
235 * If this is a file in a directory, "dir" refers to
236 * the directory; otherwise NULL.
238 struct GNUNET_FS_FileInformation *dir;
241 * Handle to the master context.
243 struct GNUNET_FS_Handle *h;
246 * Pointer kept for the client.
251 * Metadata to use for the file.
253 struct GNUNET_CONTAINER_MetaData *meta;
256 * Keywords to use for KBlocks.
258 struct GNUNET_FS_Uri *keywords;
261 * CHK for this file or directory. NULL if
262 * we have not yet computed it.
264 struct GNUNET_FS_Uri *chk_uri;
267 * SKS URI for this file or directory. NULL if
268 * we have not yet computed it.
270 struct GNUNET_FS_Uri *sks_uri;
273 * Block options for the file.
275 struct GNUNET_FS_BlockOptions bo;
278 * At what time did we start this upload?
280 struct GNUNET_TIME_Absolute start_time;
283 * Under what filename is this struct serialized
284 * (for operational persistence). Should be determined
290 * Encoder being used to publish this file.
292 struct GNUNET_FS_TreeEncoder *te;
295 * Error message (non-NULL if this operation failed).
300 * Name of the file or directory (must be an absolute path).
305 * Data describing either the file or the directory.
317 * Function that can be used to read the data for the file.
319 GNUNET_FS_DataReader reader;
322 * Closure for reader.
327 * If this file is being indexed, this value is set to the hash
328 * over the entire file (when the indexing process is started).
329 * Otherwise this field is not used.
331 struct GNUNET_HashCode file_id;
334 * Size of the file (in bytes).
339 * Should the file be indexed or inserted?
344 * Is "file_id" already valid? Set to #GNUNET_YES once the hash
345 * has been calculated.
350 * Has the service confirmed our INDEX_START request?
351 * #GNUNET_YES if this step has been completed.
353 int index_start_confirmed;
358 * Data for a directory.
364 * Linked list of entries in the directory.
366 struct GNUNET_FS_FileInformation *entries;
369 * Size of the directory itself (in bytes); 0 if the
370 * size has not yet been calculated.
375 * Pointer to the data for the directory (or NULL if not
381 * How much of the directory have we published (relative to @e contents_size).
383 uint64_t contents_completed;
386 * Sum of all of the sizes of all of the files in the directory.
388 uint64_t contents_size;
395 * Is this struct for a file or directory?
400 * Are we done publishing this file?
408 * Priorities for the queue.
410 enum GNUNET_FS_QueuePriority
413 * This is a probe (low priority).
415 GNUNET_FS_QUEUE_PRIORITY_PROBE,
420 GNUNET_FS_QUEUE_PRIORITY_NORMAL
425 * Entry in the job queue.
427 struct GNUNET_FS_QueueEntry
430 * This is a linked list.
432 struct GNUNET_FS_QueueEntry *next;
435 * This is a linked list.
437 struct GNUNET_FS_QueueEntry *prev;
440 * Function to call when the job is started.
442 GNUNET_SCHEDULER_TaskCallback start;
445 * Function to call when the job needs to stop (or is done / dequeued).
447 GNUNET_SCHEDULER_TaskCallback stop;
450 * Closure for start and stop.
455 * Handle to FS primary context.
457 struct GNUNET_FS_Handle *h;
460 * Message queue handle, or NULL if job is not running.
462 struct GNUNET_MQ_Handle *mq;
465 * Time the job was originally queued.
467 struct GNUNET_TIME_Absolute queue_time;
470 * Time the job was started last.
472 struct GNUNET_TIME_Absolute start_time;
475 * Total amount of time the job has been running (except for the
478 struct GNUNET_TIME_Relative run_time;
481 * How many blocks do the active downloads have?
486 * How important is this download?
488 enum GNUNET_FS_QueuePriority priority;
491 * How often have we (re)started this download?
493 unsigned int start_times;
496 * #GNUNET_YES if the job is active now.
504 * Information we store for each search result.
506 struct GNUNET_FS_SearchResult
510 * File-sharing context this result belongs to.
512 struct GNUNET_FS_Handle *h;
515 * Kept in a DLL while probing.
517 struct GNUNET_FS_SearchResult *next;
520 * Kept in a DLL while probing.
522 struct GNUNET_FS_SearchResult *prev;
525 * Search context this result belongs to; can be NULL
526 * for probes that come from a directory result.
528 struct GNUNET_FS_SearchContext *sc;
531 * URI to which this search result refers to.
533 struct GNUNET_FS_Uri *uri;
536 * Metadata for the search result.
538 struct GNUNET_CONTAINER_MetaData *meta;
541 * Client info for this search result.
546 * ID of a job that is currently probing this results' availability
547 * (NULL if we are not currently probing).
549 struct GNUNET_FS_DownloadContext *probe_ctx;
552 * ID of an associated download based on this search result (or
555 struct GNUNET_FS_DownloadContext *download;
558 * If this search result triggered an update search, this field
559 * links to the update search.
561 struct GNUNET_FS_SearchContext *update_search;
564 * Name under which this search result is stored on disk.
569 * Bitmap that specifies precisely which keywords have been matched already.
571 uint8_t *keyword_bitmap;
574 * Key for the search result based on the URI.
576 struct GNUNET_HashCode key;
579 * ID of the task that will clean up the probe_ctx should it not
580 * complete on time (and that will need to be cancelled if we clean
581 * up the search result before then).
583 struct GNUNET_SCHEDULER_Task * probe_cancel_task;
586 * When did the current probe become active?
588 struct GNUNET_TIME_Absolute probe_active_time;
591 * How much longer should we run the current probe before giving up?
593 struct GNUNET_TIME_Relative remaining_probe_time;
596 * Anonymity level to use for probes using this search result.
601 * Number of mandatory keywords for which we have NOT yet found the
602 * search result; when this value hits zero, the search result is
603 * given to the callback.
605 uint32_t mandatory_missing;
608 * Number of optional keywords under which this result was also
611 uint32_t optional_support;
614 * Number of availability tests that have succeeded for this result.
616 uint32_t availability_success;
619 * Number of availability trials that we have performed for this
622 uint32_t availability_trials;
628 * Add a job to the queue.
630 * @param h handle to the overall FS state
631 * @param start function to call to begin the job
632 * @param stop function to call to pause the job, or on dequeue (if the job was running)
633 * @param cls closure for start and stop
634 * @param blocks number of blocks this download has
635 * @param priority how important is this download
636 * @return queue handle
638 struct GNUNET_FS_QueueEntry *
639 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
640 GNUNET_SCHEDULER_TaskCallback start,
641 GNUNET_SCHEDULER_TaskCallback stop,
644 enum GNUNET_FS_QueuePriority priority);
648 * Dequeue a job from the queue.
650 * @param qe handle for the job
653 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe);
657 * Function that provides data by reading from a file.
659 * @param cls closure (points to the file information)
660 * @param offset offset to read from; it is possible
661 * that the caller might need to go backwards
663 * @param max maximum number of bytes that should be
664 * copied to @a buf; readers are not allowed
665 * to provide less data unless there is an error;
666 * a value of "0" will be used at the end to allow
667 * the reader to clean up its internal state
668 * @param buf where the reader should write the data
669 * @param emsg location for the reader to store an error message
670 * @return number of bytes written, usually "max", 0 on error
673 GNUNET_FS_data_reader_file_ (void *cls,
681 * Create the closure for the #GNUNET_FS_data_reader_file_() callback.
683 * @param filename file to read
684 * @return closure to use
687 GNUNET_FS_make_file_reader_context_ (const char *filename);
692 * Function that provides data by copying from a buffer.
694 * @param cls closure (points to the buffer)
695 * @param offset offset to read from; it is possible
696 * that the caller might need to go backwards
698 * @param max maximum number of bytes that should be
699 * copied to @a buf; readers are not allowed
700 * to provide less data unless there is an error;
701 * a value of "0" will be used at the end to allow
702 * the reader to clean up its internal state
703 * @param buf where the reader should write the data
704 * @param emsg location for the reader to store an error message
705 * @return number of bytes written, usually @a max, 0 on error
708 GNUNET_FS_data_reader_copy_ (void *cls,
716 * Notification of FS that a search probe has made progress.
717 * This function is used INSTEAD of the client's event handler
718 * for downloads where the #GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
720 * @param cls closure, always NULL (!), actual closure
721 * is in the client-context of the info struct
722 * @param info details about the event, specifying the event type
723 * and various bits about the event
724 * @return client-context (for the next progress call
725 * for this operation; should be set to NULL for
726 * SUSPEND and STOPPED events). The value returned
727 * will be passed to future callbacks in the respective
728 * field in the `struct GNUNET_FS_ProgressInfo`.
731 GNUNET_FS_search_probe_progress_ (void *cls,
732 const struct GNUNET_FS_ProgressInfo *info);
736 * Main function that performs the upload.
738 * @param cls `struct GNUNET_FS_PublishContext` identifies the upload
741 GNUNET_FS_publish_main_ (void *cls);
745 * Function called once the hash of the file
746 * that is being unindexed has been computed.
748 * @param cls closure, unindex context
749 * @param file_id computed hash, NULL on error
752 GNUNET_FS_unindex_process_hash_ (void *cls,
753 const struct GNUNET_HashCode *file_id);
757 * Extract the keywords for KBlock removal
759 * @param uc context for the unindex operation.
762 GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc);
766 * If necessary, connect to the datastore and remove the KBlocks.
768 * @param uc context for the unindex operation.
771 GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc);
775 * Fill in all of the generic fields for a publish event and call the
778 * @param pi structure to fill in
779 * @param pc overall publishing context
780 * @param p file information for the file being published
781 * @param offset where in the file are we so far
782 * @return value returned from callback
785 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
786 struct GNUNET_FS_PublishContext *pc,
787 const struct GNUNET_FS_FileInformation *p,
792 * Fill in all of the generic fields for a download event and call the
795 * @param pi structure to fill in
796 * @param dc overall download context
799 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
800 struct GNUNET_FS_DownloadContext *dc);
804 * Task that creates the initial (top-level) download
805 * request for the file.
807 * @param cls the 'struct GNUNET_FS_DownloadContext'
810 GNUNET_FS_download_start_task_ (void *cls);
815 * Fill in all of the generic fields for
816 * an unindex event and call the callback.
818 * @param pi structure to fill in
819 * @param uc overall unindex context
820 * @param offset where we are in the file (for progress)
823 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
824 struct GNUNET_FS_UnindexContext *uc,
828 * Fill in all of the generic fields for a search event and
831 * @param pi structure to fill in
832 * @param h file-sharing handle
833 * @param sc overall search context
834 * @return value returned by the callback
837 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
838 struct GNUNET_FS_Handle *h,
839 struct GNUNET_FS_SearchContext *sc);
843 * Connect to the datastore and remove the blocks.
845 * @param uc context for the unindex operation.
848 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
851 * Build the request and actually initiate the search using the
854 * @param sc search context
855 * @return GNUNET_OK on success, GNUNET_SYSERR on error
858 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
861 * Start the downloading process (by entering the queue).
863 * @param dc our download context
866 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
870 * Start download probes for the given search result.
872 * @param sr the search result
875 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
879 * Remove serialization/deserialization file from disk.
881 * @param h master context
882 * @param ext component of the path
883 * @param ent entity identifier
886 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
892 * Remove serialization/deserialization directory from disk.
894 * @param h master context
895 * @param ext component of the path
896 * @param uni unique name of parent
899 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
905 * Synchronize this file-information struct with its mirror
906 * on disk. Note that all internal FS-operations that change
907 * file information data should already call "sync" internally,
908 * so this function is likely not useful for clients.
910 * @param fi the struct to sync
913 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
917 * Synchronize this publishing struct with its mirror
918 * on disk. Note that all internal FS-operations that change
919 * publishing structs should already call "sync" internally,
920 * so this function is likely not useful for clients.
922 * @param pc the struct to sync
925 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
929 * Synchronize this unindex struct with its mirror
930 * on disk. Note that all internal FS-operations that change
931 * publishing structs should already call "sync" internally,
932 * so this function is likely not useful for clients.
934 * @param uc the struct to sync
937 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
941 * Synchronize this search struct with its mirror
942 * on disk. Note that all internal FS-operations that change
943 * publishing structs should already call "sync" internally,
944 * so this function is likely not useful for clients.
946 * @param sc the struct to sync
949 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
953 * Synchronize this search result with its mirror
954 * on disk. Note that all internal FS-operations that change
955 * publishing structs should already call "sync" internally,
956 * so this function is likely not useful for clients.
958 * @param sr the struct to sync
961 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
965 * Synchronize this download struct with its mirror
966 * on disk. Note that all internal FS-operations that change
967 * publishing structs should already call "sync" internally,
968 * so this function is likely not useful for clients.
970 * @param dc the struct to sync
973 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
977 * Create SUSPEND event for the given publish operation
978 * and then clean up our state (without stop signal).
980 * @param cls the `struct GNUNET_FS_PublishContext` to signal for
983 GNUNET_FS_publish_signal_suspend_ (void *cls);
987 * Create SUSPEND event for the given search operation
988 * and then clean up our state (without stop signal).
990 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
993 GNUNET_FS_search_signal_suspend_ (void *cls);
997 * Create SUSPEND event for the given download operation
998 * and then clean up our state (without stop signal).
1000 * @param cls the `struct GNUNET_FS_DownloadContext` to signal for
1003 GNUNET_FS_download_signal_suspend_ (void *cls);
1007 * Create SUSPEND event for the given unindex operation
1008 * and then clean up our state (without stop signal).
1010 * @param cls the `struct GNUNET_FS_UnindexContext` to signal for
1013 GNUNET_FS_unindex_signal_suspend_ (void *cls);
1017 * Function signature of the functions that can be called
1018 * to trigger suspend signals and clean-up for top-level
1021 * @param cls closure
1023 typedef void (*SuspendSignalFunction) (void *cls);
1026 * We track all of the top-level activities of FS
1027 * so that we can signal 'suspend' on shutdown.
1029 struct TopLevelActivity
1032 * This is a doubly-linked list.
1034 struct TopLevelActivity *next;
1037 * This is a doubly-linked list.
1039 struct TopLevelActivity *prev;
1042 * Function to call for suspend-signalling and clean up.
1044 SuspendSignalFunction ssf;
1047 * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1054 * Create a top-level activity entry.
1056 * @param h global fs handle
1057 * @param ssf suspend signal function to use
1058 * @param ssf_cls closure for @a ssf
1059 * @return fresh top-level activity handle
1061 struct TopLevelActivity *
1062 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1063 SuspendSignalFunction ssf,
1068 * Destroy a top-level activity entry.
1070 * @param h global fs handle
1071 * @param top top level activity entry
1074 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
1075 struct TopLevelActivity *top);
1080 * Master context for most FS operations.
1082 struct GNUNET_FS_Handle
1085 * Configuration to use.
1087 const struct GNUNET_CONFIGURATION_Handle *cfg;
1090 * Name of our client.
1095 * Function to call with updates on our progress.
1097 GNUNET_FS_ProgressCallback upcb;
1105 * Head of DLL of top-level activities.
1107 struct TopLevelActivity *top_head;
1110 * Tail of DLL of top-level activities.
1112 struct TopLevelActivity *top_tail;
1115 * Head of DLL of running jobs.
1117 struct GNUNET_FS_QueueEntry *running_head;
1120 * Tail of DLL of running jobs.
1122 struct GNUNET_FS_QueueEntry *running_tail;
1125 * Head of DLL of pending jobs.
1127 struct GNUNET_FS_QueueEntry *pending_head;
1130 * Tail of DLL of pending jobs.
1132 struct GNUNET_FS_QueueEntry *pending_tail;
1135 * Head of active probes.
1137 struct GNUNET_FS_SearchResult *probes_head;
1140 * Tail of active probes.
1142 struct GNUNET_FS_SearchResult *probes_tail;
1145 * Task that processes the jobs in the running and pending queues
1146 * (and moves jobs around as needed).
1148 struct GNUNET_SCHEDULER_Task * queue_job;
1151 * Task we use to report periodically to the application that
1152 * certain search probes (from @e probes_head) are still running.
1154 struct GNUNET_SCHEDULER_Task * probe_ping_task;
1157 * Average time we take for a single request to be satisfied.
1158 * FIXME: not yet calcualted properly...
1160 struct GNUNET_TIME_Relative avg_block_latency;
1163 * How many actual downloads do we have running right now?
1165 unsigned int active_downloads;
1168 * How many blocks do the active downloads have?
1170 unsigned int active_blocks;
1175 enum GNUNET_FS_Flags flags;
1178 * Maximum number of parallel downloads.
1180 unsigned int max_parallel_downloads;
1183 * Maximum number of parallel requests.
1185 unsigned int max_parallel_requests;
1191 * Handle for controlling a publication process.
1193 struct GNUNET_FS_PublishContext
1196 * Handle to the global fs context.
1198 struct GNUNET_FS_Handle *h;
1201 * Our top-level activity entry (if we are top-level, otherwise NULL).
1203 struct TopLevelActivity *top;
1206 * File-structure that is being shared.
1208 struct GNUNET_FS_FileInformation *fi;
1211 * Namespace that we are publishing in, NULL if we have no namespace.
1213 struct GNUNET_CRYPTO_EcdsaPrivateKey *ns;
1216 * ID of the content in the namespace, NULL if we have no namespace.
1221 * ID for future updates, NULL if we have no namespace or no updates.
1226 * Filename used for serializing information about this operation
1227 * (should be determined using 'mktemp').
1229 char *serialization;
1232 * Our own message queue for the FS service; only briefly used when
1233 * we start to index a file, otherwise NULL.
1235 struct GNUNET_MQ_Handle *mq;
1238 * Current position in the file-tree for the upload.
1240 struct GNUNET_FS_FileInformation *fi_pos;
1243 * Non-null if we are currently hashing a file.
1245 struct GNUNET_CRYPTO_FileHashContext *fhc;
1248 * Connection to the datastore service.
1250 struct GNUNET_DATASTORE_Handle *dsh;
1253 * Queue entry for reservation/unreservation.
1255 struct GNUNET_DATASTORE_QueueEntry *qre;
1258 * Context for SKS publishing operation that is part of this publishing operation
1259 * (NULL if not active).
1261 struct GNUNET_FS_PublishSksContext *sks_pc;
1264 * Context for KSK publishing operation that is part of this publishing operation
1265 * (NULL if not active).
1267 struct GNUNET_FS_PublishKskContext *ksk_pc;
1270 * ID of the task performing the upload. NO_TASK if the upload has
1273 struct GNUNET_SCHEDULER_Task * upload_task;
1276 * Storage space to reserve for the operation.
1278 uint64_t reserve_space;
1281 * Overall number of entries to reserve for the
1282 * publish operation.
1284 uint32_t reserve_entries;
1287 * Options for publishing.
1289 enum GNUNET_FS_PublishOptions options;
1292 * Space reservation ID with datastore service
1298 * Set to #GNUNET_YES if we were able to publish any block.
1299 * (and thus unindexing on error might make sense).
1304 * Set to #GNUNET_YES if all processing has completed.
1309 * Flag set to #GNUNET_YES if the next callback from
1310 * #GNUNET_FS_file_information_inspect should be skipped because it
1311 * is for the directory which was already processed with the parent.
1313 int skip_next_fi_callback;
1318 * Phases of unindex processing (state machine).
1323 * We're currently hashing the file.
1325 UNINDEX_STATE_HASHING = 0,
1328 * We're telling the datastore to delete
1329 * the respective DBlocks and IBlocks.
1331 UNINDEX_STATE_DS_REMOVE = 1,
1334 * Find out which keywords apply.
1336 UNINDEX_STATE_EXTRACT_KEYWORDS = 2,
1339 * We're telling the datastore to remove KBlocks.
1341 UNINDEX_STATE_DS_REMOVE_KBLOCKS = 3,
1344 * We're notifying the FS service about
1347 UNINDEX_STATE_FS_NOTIFY = 4,
1352 UNINDEX_STATE_COMPLETE = 5,
1355 * We've encountered a fatal error.
1357 UNINDEX_STATE_ERROR = 6
1362 * Handle for controlling an unindexing operation.
1364 struct GNUNET_FS_UnindexContext
1368 * The content hash key of the last block we processed, will in the
1369 * end be set to the CHK from the URI. Used to remove the KBlocks.
1371 struct ContentHashKey chk;
1374 * Global FS context.
1376 struct GNUNET_FS_Handle *h;
1379 * Our top-level activity entry.
1381 struct TopLevelActivity *top;
1384 * Directory scanner to find keywords (KBlock removal).
1386 struct GNUNET_FS_DirScanner *dscan;
1389 * Keywords found (telling us which KBlocks to remove).
1391 struct GNUNET_FS_Uri *ksk_uri;
1394 * Current offset in KSK removal.
1396 uint32_t ksk_offset;
1399 * Name of the file that we are unindexing.
1404 * Short name under which we are serializing the state of this operation.
1406 char *serialization;
1409 * Connection to the FS service, only valid during the
1410 * #UNINDEX_STATE_FS_NOTIFY phase.
1412 struct GNUNET_MQ_Handle *mq;
1415 * Connection to the datastore service, only valid during the
1416 * UNINDEX_STATE_DS_NOTIFY phase.
1418 struct GNUNET_DATASTORE_Handle *dsh;
1421 * Pointer kept for the client.
1426 * Merkle-ish tree encoder context.
1428 struct GNUNET_FS_TreeEncoder *tc;
1431 * Handle used to read the file.
1433 struct GNUNET_DISK_FileHandle *fh;
1436 * Handle to datastore 'get_key' operation issued for
1437 * obtaining KBlocks.
1439 struct GNUNET_DATASTORE_QueueEntry *dqe;
1442 * Current key for decrypting UBLocks from 'get_key' operation.
1444 struct GNUNET_HashCode ukey;
1447 * Current query of 'get_key' operation.
1449 struct GNUNET_HashCode uquery;
1452 * Error message, NULL on success.
1457 * Context for hashing of the file.
1459 struct GNUNET_CRYPTO_FileHashContext *fhc;
1462 * Overall size of the file.
1467 * When did we start?
1469 struct GNUNET_TIME_Absolute start_time;
1472 * Hash of the file's contents (once computed).
1474 struct GNUNET_HashCode file_id;
1477 * Current operatinonal phase.
1479 enum UnindexState state;
1485 * Information we keep for each keyword in a keyword search.
1487 struct SearchRequestEntry
1491 * Hash of the public key, also known as the query.
1493 struct GNUNET_HashCode uquery;
1496 * Derived public key, hashes to 'uquery'.
1498 struct GNUNET_CRYPTO_EcdsaPublicKey dpub;
1501 * The original keyword, used to derive the
1502 * key (for decrypting the UBlock).
1507 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1508 * was found under this keyword. Note that the entries will point
1509 * to the same locations as those in the master result map (in
1510 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1511 * The key for each entry is the XOR of the key and query in the CHK
1512 * URI (as a unique identifier for the search result).
1514 struct GNUNET_CONTAINER_MultiHashMap *results;
1517 * Is this keyword a mandatory keyword
1518 * (started with '+')?
1526 * Handle for controlling a search.
1528 struct GNUNET_FS_SearchContext
1531 * Handle to the global FS context.
1533 struct GNUNET_FS_Handle *h;
1536 * Our top-level activity entry (if we are top-level, otherwise NULL).
1538 struct TopLevelActivity *top;
1541 * List of keywords that we're looking for.
1543 struct GNUNET_FS_Uri *uri;
1546 * For update-searches, link to the search result that triggered
1547 * the update search; otherwise NULL.
1549 struct GNUNET_FS_SearchResult *psearch_result;
1552 * Connection to the FS service.
1554 struct GNUNET_MQ_Handle *mq;
1557 * Pointer we keep for the client.
1562 * Name of the file on disk we use for persistence.
1564 char *serialization;
1567 * Error message (non-NULL if this operation failed).
1572 * Map that contains a `struct GNUNET_FS_SearchResult` for each result that
1573 * was found in the search. The key for each entry is the XOR of
1574 * the key and query in the CHK URI (as a unique identifier for the
1577 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1580 * Per-keyword information for a keyword search. This array will
1581 * have exactly as many entries as there were keywords.
1583 struct SearchRequestEntry *requests;
1586 * When did we start?
1588 struct GNUNET_TIME_Absolute start_time;
1591 * How long to wait before we try to reconnect to FS service?
1593 struct GNUNET_TIME_Relative reconnect_backoff;
1596 * ID of a task that is using this struct and that must be cancelled
1597 * when the search is being stopped (if not
1598 * NULL). Used for the task that adds some
1599 * artificial delay when trying to reconnect to the FS service.
1601 struct GNUNET_SCHEDULER_Task *task;
1604 * Anonymity level for the search.
1609 * Number of mandatory keywords in this query.
1611 uint32_t mandatory_count;
1614 * Options for the search.
1616 enum GNUNET_FS_SearchOptions options;
1621 * FSM for possible states a block can go through. The typical
1622 * order of progression is linear through the states, alternatives
1623 * are documented in the comments.
1625 enum BlockRequestState
1628 * Initial state, block has only been allocated (since it is
1629 * relevant to the overall download request).
1634 * We've checked the block on the path down the tree, and the
1635 * content on disk did match the desired CHK, but not all
1636 * the way down, so at the bottom some blocks will still
1637 * need to be reconstructed).
1639 BRS_RECONSTRUCT_DOWN = 1,
1642 * We've calculated the CHK bottom-up based on the meta data.
1643 * This may work, but if it did we have to write the meta data to
1644 * disk at the end (and we still need to check against the
1647 BRS_RECONSTRUCT_META_UP = 2,
1650 * We've calculated the CHK bottom-up based on what we have on
1651 * disk, which may not be what the desired CHK is. If the
1652 * reconstructed CHKs match whatever comes from above, we're
1653 * done with the respective subtree.
1655 BRS_RECONSTRUCT_UP = 3,
1658 * We've determined the real, desired CHK for this block
1659 * (full tree reconstruction failed), request is now pending.
1660 * If the CHK that bubbled up through reconstruction did match
1661 * the top-level request, the state machine for the subtree
1662 * would have moved to BRS_DOWNLOAD_UP.
1667 * We've successfully downloaded this block, but the children
1668 * still need to be either downloaded or verified (download
1669 * request propagates down). If the download fails, the
1670 * state machine for this block may move to
1671 * BRS_DOWNLOAD_ERROR instead.
1673 BRS_DOWNLOAD_DOWN = 5,
1676 * This block and all of its children have been downloaded
1677 * successfully (full completion propagates up).
1679 BRS_DOWNLOAD_UP = 6,
1682 * We got a block back that matched the query but did not hash to
1683 * the key (malicious publisher or hash collision); this block
1684 * can never be downloaded (error propagates up).
1691 * Information about an active download request.
1693 struct DownloadRequest
1697 * Parent in the CHK-tree.
1699 struct DownloadRequest *parent;
1702 * Array (!) of child-requests, or NULL for the bottom of the tree.
1704 struct DownloadRequest **children;
1707 * CHK for the request for this block (set during reconstruction
1708 * to what we have on disk, later to what we want to have).
1710 struct ContentHashKey chk;
1713 * Offset of the corresponding block. Specifically, first (!) byte of
1714 * the first DBLOCK in the subtree induced by block represented by
1720 * Number of entries in @e children array.
1722 unsigned int num_children;
1725 * Depth of the corresponding block in the tree. 0==DBLOCKs.
1730 * Offset of the CHK for this block in the parent block
1732 unsigned int chk_idx;
1737 enum BlockRequestState state;
1743 * (recursively) free download request structure
1745 * @param dr request to free
1748 GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
1752 * Stop the ping task for this search result.
1754 * @param sr result to start pinging for.
1757 GNUNET_FS_stop_probe_ping_task_ (struct GNUNET_FS_SearchResult *sr);
1761 * Context for controlling a download.
1763 struct GNUNET_FS_DownloadContext
1767 * Global FS context.
1769 struct GNUNET_FS_Handle *h;
1772 * Our top-level activity entry (if we are top-level, otherwise NULL).
1774 struct TopLevelActivity *top;
1777 * Connection to the FS service.
1779 struct GNUNET_MQ_Handle *mq;
1782 * Parent download (used when downloading files
1785 struct GNUNET_FS_DownloadContext *parent;
1788 * Associated search (used when downloading files
1789 * based on search results), or NULL for none.
1791 struct GNUNET_FS_SearchResult *search;
1794 * Head of list of child downloads.
1796 struct GNUNET_FS_DownloadContext *child_head;
1799 * Tail of list of child downloads.
1801 struct GNUNET_FS_DownloadContext *child_tail;
1804 * Previous download belonging to the same parent.
1806 struct GNUNET_FS_DownloadContext *prev;
1809 * Next download belonging to the same parent.
1811 struct GNUNET_FS_DownloadContext *next;
1814 * Context kept for the client.
1819 * URI that identifies the file that we are downloading.
1821 struct GNUNET_FS_Uri *uri;
1824 * Known meta-data for the file (can be NULL).
1826 struct GNUNET_CONTAINER_MetaData *meta;
1829 * Error message, NULL if we're doing OK.
1834 * Random portion of filename we use for syncing state of this
1837 char *serialization;
1840 * Where are we writing the data (name of the
1841 * file, can be NULL!).
1846 * Where are we writing the data temporarily (name of the
1847 * file, can be NULL!); used if we do not have a permanent
1848 * name and we are a directory and we do a recursive download.
1850 char *temp_filename;
1853 * Our entry in the job queue.
1855 struct GNUNET_FS_QueueEntry *job_queue;
1858 * Tree encoder used for the reconstruction.
1860 struct GNUNET_FS_TreeEncoder *te;
1863 * File handle for reading data from an existing file
1864 * (to pass to tree encoder).
1866 struct GNUNET_DISK_FileHandle *rfh;
1869 * Map of active requests (those waiting for a response). The key
1870 * is the hash of the encryped block (aka query).
1872 struct GNUNET_CONTAINER_MultiHashMap *active;
1875 * Top-level download request.
1877 struct DownloadRequest *top_request;
1880 * Identity of the peer having the content, or all-zeros
1881 * if we don't know of such a peer.
1883 struct GNUNET_PeerIdentity target;
1886 * ID of a task that is using this struct and that must be cancelled
1887 * when the download is being stopped (if not
1888 * NULL). Used for the task that adds some
1889 * artificial delay when trying to reconnect to the FS service or
1890 * the task processing incrementally the data on disk, or the
1891 * task requesting blocks, etc.
1893 struct GNUNET_SCHEDULER_Task *task;
1896 * What is the first offset that we're interested
1902 * How many bytes starting from offset are desired?
1903 * This is NOT the overall length of the file!
1908 * How many bytes have we already received within
1909 * the specified range (DBlocks only).
1914 * What was the size of the file on disk that we're downloading
1915 * before we started? Used to detect if there is a point in
1916 * checking an existing block on disk for matching the desired
1917 * content. 0 if the file did not exist already.
1919 uint64_t old_file_size;
1922 * Time download was started.
1924 struct GNUNET_TIME_Absolute start_time;
1927 * How long to wait before we try to reconnect to FS service?
1929 struct GNUNET_TIME_Relative reconnect_backoff;
1932 * Desired level of anonymity.
1937 * The depth of the file-tree.
1939 unsigned int treedepth;
1942 * Options for the download.
1944 enum GNUNET_FS_DownloadOptions options;
1947 * Flag set upon transitive completion (includes child downloads).
1948 * This flag is only set to #GNUNET_YES for directories where all
1949 * child-downloads have also completed (and signalled completion).
1954 * Are we ready to issue requests (reconstructions are finished)?
1963 /* end of fs_api.h */