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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
23 * @brief shared definitions for the FS library
24 * @author Igor Wronsky, Christian Grothoff
29 #include "gnunet_constants.h"
30 #include "gnunet_datastore_service.h"
31 #include "gnunet_dht_service.h"
32 #include "gnunet_fs_service.h"
33 #include "gnunet_block_lib.h"
38 * Pick a multiple of 2 here to achive 8-byte alignment! We also
39 * probably want DBlocks to have (roughly) the same size as IBlocks.
40 * With SHA-512, the optimal value is 32768 byte / 128 byte = 256 (128
41 * byte = 2 * 512 bits). DO NOT CHANGE!
43 #define CHK_PER_INODE 256
46 * Maximum size for a file to be considered for inlining in a
49 #define MAX_INLINE_SIZE 65536
52 * Name of the directory with top-level searches.
54 #define GNUNET_FS_SYNC_PATH_MASTER_SEARCH "search"
57 * Name of the directory with sub-searches (namespace-updates).
59 #define GNUNET_FS_SYNC_PATH_CHILD_SEARCH "search-child"
62 * Name of the directory with master downloads (not associated
63 * with search or part of another download).
65 #define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD "download"
68 * Name of the directory with downloads that are part of another
69 * download or a search.
71 #define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD "download-child"
74 * Name of the directory with publishing operations.
76 #define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH "publish"
79 * Name of the directory with files that are being published
81 #define GNUNET_FS_SYNC_PATH_FILE_INFO "publish-file"
84 * Name of the directory with unindex operations.
86 #define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX "unindex"
90 * @brief complete information needed
97 * Total size of the file in bytes. (network byte order (!))
102 * Query and key of the top GNUNET_EC_IBlock.
104 struct ContentHashKey chk;
110 * Information about a file and its location
111 * (peer claiming to share the file).
116 * Information about the shared file.
118 struct FileIdentifier fi;
121 * Identity of the peer sharing the file.
123 struct GNUNET_PeerIdentity peer;
126 * Time when this location URI expires.
128 struct GNUNET_TIME_Absolute expirationTime;
131 * Signature over the GNUNET_EC_FileIdentifier,
132 * peer identity and expiration time.
134 struct GNUNET_CRYPTO_EddsaSignature contentSignature;
141 enum GNUNET_FS_UriType
144 * Content-hash-key (simple file).
149 * Signed key space (file in namespace).
154 * Keyword search key (query with keywords).
159 * Location (chk with identity of hosting peer).
166 * A Universal Resource Identifier (URI), opaque.
173 enum GNUNET_FS_UriType type;
180 * Keywords start with a '+' if they are mandatory (in which
181 * case the '+' is NOT part of the keyword) and with a simple
182 * space if they are optional (in which case the space is ALSO
183 * not part of the actual keyword).
185 * Double-quotes to protect spaces and %-encoding are NOT used
186 * internally (only in URI-strings).
191 * Size of the keywords array.
193 unsigned int keywordCount;
199 * Identifier of the namespace.
201 struct GNUNET_CRYPTO_EcdsaPublicKey ns;
204 * Human-readable identifier chosen for this entry in the
212 * Information needed to retrieve a file (content-hash-key
215 struct FileIdentifier chk;
218 * Information needed to retrieve a file including signed
219 * location (identity of a peer) of the content.
228 * Information for a file or directory that is
229 * about to be published.
231 struct GNUNET_FS_FileInformation
235 * Files in a directory are kept as a linked list.
237 struct GNUNET_FS_FileInformation *next;
240 * If this is a file in a directory, "dir" refers to
241 * the directory; otherwise NULL.
243 struct GNUNET_FS_FileInformation *dir;
246 * Handle to the master context.
248 struct GNUNET_FS_Handle *h;
251 * Pointer kept for the client.
256 * Metadata to use for the file.
258 struct GNUNET_CONTAINER_MetaData *meta;
261 * Keywords to use for KBlocks.
263 struct GNUNET_FS_Uri *keywords;
266 * CHK for this file or directory. NULL if
267 * we have not yet computed it.
269 struct GNUNET_FS_Uri *chk_uri;
272 * SKS URI for this file or directory. NULL if
273 * we have not yet computed it.
275 struct GNUNET_FS_Uri *sks_uri;
278 * Block options for the file.
280 struct GNUNET_FS_BlockOptions bo;
283 * At what time did we start this upload?
285 struct GNUNET_TIME_Absolute start_time;
288 * Under what filename is this struct serialized
289 * (for operational persistence). Should be determined
295 * Encoder being used to publish this file.
297 struct GNUNET_FS_TreeEncoder *te;
300 * Error message (non-NULL if this operation failed).
305 * Name of the file or directory (must be an absolute path).
310 * Data describing either the file or the directory.
322 * Function that can be used to read the data for the file.
324 GNUNET_FS_DataReader reader;
327 * Closure for reader.
332 * If this file is being indexed, this value is set to the hash
333 * over the entire file (when the indexing process is started).
334 * Otherwise this field is not used.
336 struct GNUNET_HashCode file_id;
339 * Size of the file (in bytes).
344 * Should the file be indexed or inserted?
349 * Is "file_id" already valid? Set to #GNUNET_YES once the hash
350 * has been calculated.
355 * Has the service confirmed our INDEX_START request?
356 * #GNUNET_YES if this step has been completed.
358 int index_start_confirmed;
363 * Data for a directory.
369 * Linked list of entries in the directory.
371 struct GNUNET_FS_FileInformation *entries;
374 * Size of the directory itself (in bytes); 0 if the
375 * size has not yet been calculated.
380 * Pointer to the data for the directory (or NULL if not
386 * How much of the directory have we published (relative to @e contents_size).
388 uint64_t contents_completed;
391 * Sum of all of the sizes of all of the files in the directory.
393 uint64_t contents_size;
400 * Is this struct for a file or directory?
405 * Are we done publishing this file?
413 * Priorities for the queue.
415 enum GNUNET_FS_QueuePriority
418 * This is a probe (low priority).
420 GNUNET_FS_QUEUE_PRIORITY_PROBE,
425 GNUNET_FS_QUEUE_PRIORITY_NORMAL
430 * Entry in the job queue.
432 struct GNUNET_FS_QueueEntry
435 * This is a linked list.
437 struct GNUNET_FS_QueueEntry *next;
440 * This is a linked list.
442 struct GNUNET_FS_QueueEntry *prev;
445 * Function to call when the job is started.
447 GNUNET_SCHEDULER_TaskCallback start;
450 * Function to call when the job needs to stop (or is done / dequeued).
452 GNUNET_SCHEDULER_TaskCallback stop;
455 * Closure for start and stop.
460 * Handle to FS primary context.
462 struct GNUNET_FS_Handle *h;
465 * Message queue handle, or NULL if job is not running.
467 struct GNUNET_MQ_Handle *mq;
470 * Time the job was originally queued.
472 struct GNUNET_TIME_Absolute queue_time;
475 * Time the job was started last.
477 struct GNUNET_TIME_Absolute start_time;
480 * Total amount of time the job has been running (except for the
483 struct GNUNET_TIME_Relative run_time;
486 * How many blocks do the active downloads have?
491 * How important is this download?
493 enum GNUNET_FS_QueuePriority priority;
496 * How often have we (re)started this download?
498 unsigned int start_times;
501 * #GNUNET_YES if the job is active now.
509 * Information we store for each search result.
511 struct GNUNET_FS_SearchResult
515 * File-sharing context this result belongs to.
517 struct GNUNET_FS_Handle *h;
520 * Kept in a DLL while probing.
522 struct GNUNET_FS_SearchResult *next;
525 * Kept in a DLL while probing.
527 struct GNUNET_FS_SearchResult *prev;
530 * Search context this result belongs to; can be NULL
531 * for probes that come from a directory result.
533 struct GNUNET_FS_SearchContext *sc;
536 * URI to which this search result refers to.
538 struct GNUNET_FS_Uri *uri;
541 * Metadata for the search result.
543 struct GNUNET_CONTAINER_MetaData *meta;
546 * Client info for this search result.
551 * ID of a job that is currently probing this results' availability
552 * (NULL if we are not currently probing).
554 struct GNUNET_FS_DownloadContext *probe_ctx;
557 * ID of an associated download based on this search result (or
560 struct GNUNET_FS_DownloadContext *download;
563 * If this search result triggered an update search, this field
564 * links to the update search.
566 struct GNUNET_FS_SearchContext *update_search;
569 * Name under which this search result is stored on disk.
574 * Bitmap that specifies precisely which keywords have been matched already.
576 uint8_t *keyword_bitmap;
579 * Key for the search result based on the URI.
581 struct GNUNET_HashCode key;
584 * ID of the task that will clean up the probe_ctx should it not
585 * complete on time (and that will need to be cancelled if we clean
586 * up the search result before then).
588 struct GNUNET_SCHEDULER_Task * probe_cancel_task;
591 * When did the current probe become active?
593 struct GNUNET_TIME_Absolute probe_active_time;
596 * How much longer should we run the current probe before giving up?
598 struct GNUNET_TIME_Relative remaining_probe_time;
601 * Anonymity level to use for probes using this search result.
606 * Number of mandatory keywords for which we have NOT yet found the
607 * search result; when this value hits zero, the search result is
608 * given to the callback.
610 uint32_t mandatory_missing;
613 * Number of optional keywords under which this result was also
616 uint32_t optional_support;
619 * Number of availability tests that have succeeded for this result.
621 uint32_t availability_success;
624 * Number of availability trials that we have performed for this
627 uint32_t availability_trials;
633 * Add a job to the queue.
635 * @param h handle to the overall FS state
636 * @param start function to call to begin the job
637 * @param stop function to call to pause the job, or on dequeue (if the job was running)
638 * @param cls closure for start and stop
639 * @param blocks number of blocks this download has
640 * @param priority how important is this download
641 * @return queue handle
643 struct GNUNET_FS_QueueEntry *
644 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
645 GNUNET_SCHEDULER_TaskCallback start,
646 GNUNET_SCHEDULER_TaskCallback stop,
649 enum GNUNET_FS_QueuePriority priority);
653 * Dequeue a job from the queue.
655 * @param qe handle for the job
658 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe);
662 * Function that provides data by reading from a file.
664 * @param cls closure (points to the file information)
665 * @param offset offset to read from; it is possible
666 * that the caller might need to go backwards
668 * @param max maximum number of bytes that should be
669 * copied to @a buf; readers are not allowed
670 * to provide less data unless there is an error;
671 * a value of "0" will be used at the end to allow
672 * the reader to clean up its internal state
673 * @param buf where the reader should write the data
674 * @param emsg location for the reader to store an error message
675 * @return number of bytes written, usually "max", 0 on error
678 GNUNET_FS_data_reader_file_ (void *cls,
686 * Create the closure for the #GNUNET_FS_data_reader_file_() callback.
688 * @param filename file to read
689 * @return closure to use
692 GNUNET_FS_make_file_reader_context_ (const char *filename);
697 * Function that provides data by copying from a buffer.
699 * @param cls closure (points to the buffer)
700 * @param offset offset to read from; it is possible
701 * that the caller might need to go backwards
703 * @param max maximum number of bytes that should be
704 * copied to @a buf; readers are not allowed
705 * to provide less data unless there is an error;
706 * a value of "0" will be used at the end to allow
707 * the reader to clean up its internal state
708 * @param buf where the reader should write the data
709 * @param emsg location for the reader to store an error message
710 * @return number of bytes written, usually @a max, 0 on error
713 GNUNET_FS_data_reader_copy_ (void *cls,
721 * Notification of FS that a search probe has made progress.
722 * This function is used INSTEAD of the client's event handler
723 * for downloads where the #GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
725 * @param cls closure, always NULL (!), actual closure
726 * is in the client-context of the info struct
727 * @param info details about the event, specifying the event type
728 * and various bits about the event
729 * @return client-context (for the next progress call
730 * for this operation; should be set to NULL for
731 * SUSPEND and STOPPED events). The value returned
732 * will be passed to future callbacks in the respective
733 * field in the `struct GNUNET_FS_ProgressInfo`.
736 GNUNET_FS_search_probe_progress_ (void *cls,
737 const struct GNUNET_FS_ProgressInfo *info);
741 * Main function that performs the upload.
743 * @param cls `struct GNUNET_FS_PublishContext` identifies the upload
746 GNUNET_FS_publish_main_ (void *cls);
750 * Function called once the hash of the file
751 * that is being unindexed has been computed.
753 * @param cls closure, unindex context
754 * @param file_id computed hash, NULL on error
757 GNUNET_FS_unindex_process_hash_ (void *cls,
758 const struct GNUNET_HashCode *file_id);
762 * Extract the keywords for KBlock removal
764 * @param uc context for the unindex operation.
767 GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc);
771 * If necessary, connect to the datastore and remove the KBlocks.
773 * @param uc context for the unindex operation.
776 GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc);
780 * Fill in all of the generic fields for a publish event and call the
783 * @param pi structure to fill in
784 * @param pc overall publishing context
785 * @param p file information for the file being published
786 * @param offset where in the file are we so far
787 * @return value returned from callback
790 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
791 struct GNUNET_FS_PublishContext *pc,
792 const struct GNUNET_FS_FileInformation *p,
797 * Fill in all of the generic fields for a download event and call the
800 * @param pi structure to fill in
801 * @param dc overall download context
804 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
805 struct GNUNET_FS_DownloadContext *dc);
809 * Task that creates the initial (top-level) download
810 * request for the file.
812 * @param cls the 'struct GNUNET_FS_DownloadContext'
815 GNUNET_FS_download_start_task_ (void *cls);
820 * Fill in all of the generic fields for
821 * an unindex event and call the callback.
823 * @param pi structure to fill in
824 * @param uc overall unindex context
825 * @param offset where we are in the file (for progress)
828 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
829 struct GNUNET_FS_UnindexContext *uc,
833 * Fill in all of the generic fields for a search event and
836 * @param pi structure to fill in
837 * @param h file-sharing handle
838 * @param sc overall search context
839 * @return value returned by the callback
842 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
843 struct GNUNET_FS_Handle *h,
844 struct GNUNET_FS_SearchContext *sc);
848 * Connect to the datastore and remove the blocks.
850 * @param uc context for the unindex operation.
853 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
856 * Build the request and actually initiate the search using the
859 * @param sc search context
860 * @return GNUNET_OK on success, GNUNET_SYSERR on error
863 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
866 * Start the downloading process (by entering the queue).
868 * @param dc our download context
871 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
875 * Start download probes for the given search result.
877 * @param sr the search result
880 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
884 * Remove serialization/deserialization file from disk.
886 * @param h master context
887 * @param ext component of the path
888 * @param ent entity identifier
891 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
897 * Remove serialization/deserialization directory from disk.
899 * @param h master context
900 * @param ext component of the path
901 * @param uni unique name of parent
904 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
910 * Synchronize this file-information struct with its mirror
911 * on disk. Note that all internal FS-operations that change
912 * file information data should already call "sync" internally,
913 * so this function is likely not useful for clients.
915 * @param fi the struct to sync
918 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
922 * Synchronize this publishing struct with its mirror
923 * on disk. Note that all internal FS-operations that change
924 * publishing structs should already call "sync" internally,
925 * so this function is likely not useful for clients.
927 * @param pc the struct to sync
930 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
934 * Synchronize this unindex struct with its mirror
935 * on disk. Note that all internal FS-operations that change
936 * publishing structs should already call "sync" internally,
937 * so this function is likely not useful for clients.
939 * @param uc the struct to sync
942 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
946 * Synchronize this search struct with its mirror
947 * on disk. Note that all internal FS-operations that change
948 * publishing structs should already call "sync" internally,
949 * so this function is likely not useful for clients.
951 * @param sc the struct to sync
954 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
958 * Synchronize this search result with its mirror
959 * on disk. Note that all internal FS-operations that change
960 * publishing structs should already call "sync" internally,
961 * so this function is likely not useful for clients.
963 * @param sr the struct to sync
966 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
970 * Synchronize this download struct with its mirror
971 * on disk. Note that all internal FS-operations that change
972 * publishing structs should already call "sync" internally,
973 * so this function is likely not useful for clients.
975 * @param dc the struct to sync
978 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
982 * Create SUSPEND event for the given publish operation
983 * and then clean up our state (without stop signal).
985 * @param cls the `struct GNUNET_FS_PublishContext` to signal for
988 GNUNET_FS_publish_signal_suspend_ (void *cls);
992 * Create SUSPEND event for the given search operation
993 * and then clean up our state (without stop signal).
995 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
998 GNUNET_FS_search_signal_suspend_ (void *cls);
1002 * Create SUSPEND event for the given download operation
1003 * and then clean up our state (without stop signal).
1005 * @param cls the `struct GNUNET_FS_DownloadContext` to signal for
1008 GNUNET_FS_download_signal_suspend_ (void *cls);
1012 * Create SUSPEND event for the given unindex operation
1013 * and then clean up our state (without stop signal).
1015 * @param cls the `struct GNUNET_FS_UnindexContext` to signal for
1018 GNUNET_FS_unindex_signal_suspend_ (void *cls);
1022 * Function signature of the functions that can be called
1023 * to trigger suspend signals and clean-up for top-level
1026 * @param cls closure
1028 typedef void (*SuspendSignalFunction) (void *cls);
1031 * We track all of the top-level activities of FS
1032 * so that we can signal 'suspend' on shutdown.
1034 struct TopLevelActivity
1037 * This is a doubly-linked list.
1039 struct TopLevelActivity *next;
1042 * This is a doubly-linked list.
1044 struct TopLevelActivity *prev;
1047 * Function to call for suspend-signalling and clean up.
1049 SuspendSignalFunction ssf;
1052 * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1059 * Create a top-level activity entry.
1061 * @param h global fs handle
1062 * @param ssf suspend signal function to use
1063 * @param ssf_cls closure for @a ssf
1064 * @return fresh top-level activity handle
1066 struct TopLevelActivity *
1067 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1068 SuspendSignalFunction ssf,
1073 * Destroy a top-level activity entry.
1075 * @param h global fs handle
1076 * @param top top level activity entry
1079 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
1080 struct TopLevelActivity *top);
1085 * Master context for most FS operations.
1087 struct GNUNET_FS_Handle
1090 * Configuration to use.
1092 const struct GNUNET_CONFIGURATION_Handle *cfg;
1095 * Name of our client.
1100 * Function to call with updates on our progress.
1102 GNUNET_FS_ProgressCallback upcb;
1110 * Head of DLL of top-level activities.
1112 struct TopLevelActivity *top_head;
1115 * Tail of DLL of top-level activities.
1117 struct TopLevelActivity *top_tail;
1120 * Head of DLL of running jobs.
1122 struct GNUNET_FS_QueueEntry *running_head;
1125 * Tail of DLL of running jobs.
1127 struct GNUNET_FS_QueueEntry *running_tail;
1130 * Head of DLL of pending jobs.
1132 struct GNUNET_FS_QueueEntry *pending_head;
1135 * Tail of DLL of pending jobs.
1137 struct GNUNET_FS_QueueEntry *pending_tail;
1140 * Head of active probes.
1142 struct GNUNET_FS_SearchResult *probes_head;
1145 * Tail of active probes.
1147 struct GNUNET_FS_SearchResult *probes_tail;
1150 * Task that processes the jobs in the running and pending queues
1151 * (and moves jobs around as needed).
1153 struct GNUNET_SCHEDULER_Task * queue_job;
1156 * Task we use to report periodically to the application that
1157 * certain search probes (from @e probes_head) are still running.
1159 struct GNUNET_SCHEDULER_Task * probe_ping_task;
1162 * Average time we take for a single request to be satisfied.
1163 * FIXME: not yet calcualted properly...
1165 struct GNUNET_TIME_Relative avg_block_latency;
1168 * How many actual downloads do we have running right now?
1170 unsigned int active_downloads;
1173 * How many blocks do the active downloads have?
1175 unsigned int active_blocks;
1180 enum GNUNET_FS_Flags flags;
1183 * Maximum number of parallel downloads.
1185 unsigned int max_parallel_downloads;
1188 * Maximum number of parallel requests.
1190 unsigned int max_parallel_requests;
1196 * Handle for controlling a publication process.
1198 struct GNUNET_FS_PublishContext
1201 * Handle to the global fs context.
1203 struct GNUNET_FS_Handle *h;
1206 * Our top-level activity entry (if we are top-level, otherwise NULL).
1208 struct TopLevelActivity *top;
1211 * File-structure that is being shared.
1213 struct GNUNET_FS_FileInformation *fi;
1216 * Namespace that we are publishing in, NULL if we have no namespace.
1218 struct GNUNET_CRYPTO_EcdsaPrivateKey *ns;
1221 * ID of the content in the namespace, NULL if we have no namespace.
1226 * ID for future updates, NULL if we have no namespace or no updates.
1231 * Filename used for serializing information about this operation
1232 * (should be determined using 'mktemp').
1234 char *serialization;
1237 * Our own message queue for the FS service; only briefly used when
1238 * we start to index a file, otherwise NULL.
1240 struct GNUNET_MQ_Handle *mq;
1243 * Current position in the file-tree for the upload.
1245 struct GNUNET_FS_FileInformation *fi_pos;
1248 * Non-null if we are currently hashing a file.
1250 struct GNUNET_CRYPTO_FileHashContext *fhc;
1253 * Connection to the datastore service.
1255 struct GNUNET_DATASTORE_Handle *dsh;
1258 * Queue entry for reservation/unreservation.
1260 struct GNUNET_DATASTORE_QueueEntry *qre;
1263 * Context for SKS publishing operation that is part of this publishing operation
1264 * (NULL if not active).
1266 struct GNUNET_FS_PublishSksContext *sks_pc;
1269 * Context for KSK publishing operation that is part of this publishing operation
1270 * (NULL if not active).
1272 struct GNUNET_FS_PublishKskContext *ksk_pc;
1275 * ID of the task performing the upload. NO_TASK if the upload has
1278 struct GNUNET_SCHEDULER_Task * upload_task;
1281 * Storage space to reserve for the operation.
1283 uint64_t reserve_space;
1286 * Overall number of entries to reserve for the
1287 * publish operation.
1289 uint32_t reserve_entries;
1292 * Options for publishing.
1294 enum GNUNET_FS_PublishOptions options;
1297 * Space reservation ID with datastore service
1303 * Set to #GNUNET_YES if we were able to publish any block.
1304 * (and thus unindexing on error might make sense).
1309 * Set to #GNUNET_YES if all processing has completed.
1314 * Flag set to #GNUNET_YES if the next callback from
1315 * #GNUNET_FS_file_information_inspect should be skipped because it
1316 * is for the directory which was already processed with the parent.
1318 int skip_next_fi_callback;
1323 * Phases of unindex processing (state machine).
1328 * We're currently hashing the file.
1330 UNINDEX_STATE_HASHING = 0,
1333 * We're telling the datastore to delete
1334 * the respective DBlocks and IBlocks.
1336 UNINDEX_STATE_DS_REMOVE = 1,
1339 * Find out which keywords apply.
1341 UNINDEX_STATE_EXTRACT_KEYWORDS = 2,
1344 * We're telling the datastore to remove KBlocks.
1346 UNINDEX_STATE_DS_REMOVE_KBLOCKS = 3,
1349 * We're notifying the FS service about
1352 UNINDEX_STATE_FS_NOTIFY = 4,
1357 UNINDEX_STATE_COMPLETE = 5,
1360 * We've encountered a fatal error.
1362 UNINDEX_STATE_ERROR = 6
1367 * Handle for controlling an unindexing operation.
1369 struct GNUNET_FS_UnindexContext
1373 * The content hash key of the last block we processed, will in the
1374 * end be set to the CHK from the URI. Used to remove the KBlocks.
1376 struct ContentHashKey chk;
1379 * Global FS context.
1381 struct GNUNET_FS_Handle *h;
1384 * Our top-level activity entry.
1386 struct TopLevelActivity *top;
1389 * Directory scanner to find keywords (KBlock removal).
1391 struct GNUNET_FS_DirScanner *dscan;
1394 * Keywords found (telling us which KBlocks to remove).
1396 struct GNUNET_FS_Uri *ksk_uri;
1399 * Current offset in KSK removal.
1401 uint32_t ksk_offset;
1404 * Name of the file that we are unindexing.
1409 * Short name under which we are serializing the state of this operation.
1411 char *serialization;
1414 * Connection to the FS service, only valid during the
1415 * #UNINDEX_STATE_FS_NOTIFY phase.
1417 struct GNUNET_MQ_Handle *mq;
1420 * Connection to the datastore service, only valid during the
1421 * UNINDEX_STATE_DS_NOTIFY phase.
1423 struct GNUNET_DATASTORE_Handle *dsh;
1426 * Pointer kept for the client.
1431 * Merkle-ish tree encoder context.
1433 struct GNUNET_FS_TreeEncoder *tc;
1436 * Handle used to read the file.
1438 struct GNUNET_DISK_FileHandle *fh;
1441 * Handle to datastore 'get_key' operation issued for
1442 * obtaining KBlocks.
1444 struct GNUNET_DATASTORE_QueueEntry *dqe;
1447 * Current key for decrypting UBLocks from 'get_key' operation.
1449 struct GNUNET_HashCode ukey;
1452 * Current query of 'get_key' operation.
1454 struct GNUNET_HashCode uquery;
1457 * Error message, NULL on success.
1462 * Context for hashing of the file.
1464 struct GNUNET_CRYPTO_FileHashContext *fhc;
1467 * Overall size of the file.
1472 * When did we start?
1474 struct GNUNET_TIME_Absolute start_time;
1477 * Hash of the file's contents (once computed).
1479 struct GNUNET_HashCode file_id;
1482 * Current operatinonal phase.
1484 enum UnindexState state;
1490 * Information we keep for each keyword in a keyword search.
1492 struct SearchRequestEntry
1496 * Hash of the public key, also known as the query.
1498 struct GNUNET_HashCode uquery;
1501 * Derived public key, hashes to 'uquery'.
1503 struct GNUNET_CRYPTO_EcdsaPublicKey dpub;
1506 * The original keyword, used to derive the
1507 * key (for decrypting the UBlock).
1512 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1513 * was found under this keyword. Note that the entries will point
1514 * to the same locations as those in the master result map (in
1515 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1516 * The key for each entry is the XOR of the key and query in the CHK
1517 * URI (as a unique identifier for the search result).
1519 struct GNUNET_CONTAINER_MultiHashMap *results;
1522 * Is this keyword a mandatory keyword
1523 * (started with '+')?
1531 * Handle for controlling a search.
1533 struct GNUNET_FS_SearchContext
1536 * Handle to the global FS context.
1538 struct GNUNET_FS_Handle *h;
1541 * Our top-level activity entry (if we are top-level, otherwise NULL).
1543 struct TopLevelActivity *top;
1546 * List of keywords that we're looking for.
1548 struct GNUNET_FS_Uri *uri;
1551 * For update-searches, link to the search result that triggered
1552 * the update search; otherwise NULL.
1554 struct GNUNET_FS_SearchResult *psearch_result;
1557 * Connection to the FS service.
1559 struct GNUNET_MQ_Handle *mq;
1562 * Pointer we keep for the client.
1567 * Name of the file on disk we use for persistence.
1569 char *serialization;
1572 * Error message (non-NULL if this operation failed).
1577 * Map that contains a `struct GNUNET_FS_SearchResult` for each result that
1578 * was found in the search. The key for each entry is the XOR of
1579 * the key and query in the CHK URI (as a unique identifier for the
1582 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1585 * Per-keyword information for a keyword search. This array will
1586 * have exactly as many entries as there were keywords.
1588 struct SearchRequestEntry *requests;
1591 * When did we start?
1593 struct GNUNET_TIME_Absolute start_time;
1596 * How long to wait before we try to reconnect to FS service?
1598 struct GNUNET_TIME_Relative reconnect_backoff;
1601 * ID of a task that is using this struct and that must be cancelled
1602 * when the search is being stopped (if not
1603 * NULL). Used for the task that adds some
1604 * artificial delay when trying to reconnect to the FS service.
1606 struct GNUNET_SCHEDULER_Task *task;
1609 * Anonymity level for the search.
1614 * Number of mandatory keywords in this query.
1616 uint32_t mandatory_count;
1619 * Options for the search.
1621 enum GNUNET_FS_SearchOptions options;
1626 * FSM for possible states a block can go through. The typical
1627 * order of progression is linear through the states, alternatives
1628 * are documented in the comments.
1630 enum BlockRequestState
1633 * Initial state, block has only been allocated (since it is
1634 * relevant to the overall download request).
1639 * We've checked the block on the path down the tree, and the
1640 * content on disk did match the desired CHK, but not all
1641 * the way down, so at the bottom some blocks will still
1642 * need to be reconstructed).
1644 BRS_RECONSTRUCT_DOWN = 1,
1647 * We've calculated the CHK bottom-up based on the meta data.
1648 * This may work, but if it did we have to write the meta data to
1649 * disk at the end (and we still need to check against the
1652 BRS_RECONSTRUCT_META_UP = 2,
1655 * We've calculated the CHK bottom-up based on what we have on
1656 * disk, which may not be what the desired CHK is. If the
1657 * reconstructed CHKs match whatever comes from above, we're
1658 * done with the respective subtree.
1660 BRS_RECONSTRUCT_UP = 3,
1663 * We've determined the real, desired CHK for this block
1664 * (full tree reconstruction failed), request is now pending.
1665 * If the CHK that bubbled up through reconstruction did match
1666 * the top-level request, the state machine for the subtree
1667 * would have moved to BRS_DOWNLOAD_UP.
1672 * We've successfully downloaded this block, but the children
1673 * still need to be either downloaded or verified (download
1674 * request propagates down). If the download fails, the
1675 * state machine for this block may move to
1676 * BRS_DOWNLOAD_ERROR instead.
1678 BRS_DOWNLOAD_DOWN = 5,
1681 * This block and all of its children have been downloaded
1682 * successfully (full completion propagates up).
1684 BRS_DOWNLOAD_UP = 6,
1687 * We got a block back that matched the query but did not hash to
1688 * the key (malicious publisher or hash collision); this block
1689 * can never be downloaded (error propagates up).
1696 * Information about an active download request.
1698 struct DownloadRequest
1702 * Parent in the CHK-tree.
1704 struct DownloadRequest *parent;
1707 * Array (!) of child-requests, or NULL for the bottom of the tree.
1709 struct DownloadRequest **children;
1712 * CHK for the request for this block (set during reconstruction
1713 * to what we have on disk, later to what we want to have).
1715 struct ContentHashKey chk;
1718 * Offset of the corresponding block. Specifically, first (!) byte of
1719 * the first DBLOCK in the subtree induced by block represented by
1725 * Number of entries in @e children array.
1727 unsigned int num_children;
1730 * Depth of the corresponding block in the tree. 0==DBLOCKs.
1735 * Offset of the CHK for this block in the parent block
1737 unsigned int chk_idx;
1742 enum BlockRequestState state;
1748 * (recursively) free download request structure
1750 * @param dr request to free
1753 GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
1757 * Stop the ping task for this search result.
1759 * @param sr result to start pinging for.
1762 GNUNET_FS_stop_probe_ping_task_ (struct GNUNET_FS_SearchResult *sr);
1766 * Context for controlling a download.
1768 struct GNUNET_FS_DownloadContext
1772 * Global FS context.
1774 struct GNUNET_FS_Handle *h;
1777 * Our top-level activity entry (if we are top-level, otherwise NULL).
1779 struct TopLevelActivity *top;
1782 * Connection to the FS service.
1784 struct GNUNET_MQ_Handle *mq;
1787 * Parent download (used when downloading files
1790 struct GNUNET_FS_DownloadContext *parent;
1793 * Associated search (used when downloading files
1794 * based on search results), or NULL for none.
1796 struct GNUNET_FS_SearchResult *search;
1799 * Head of list of child downloads.
1801 struct GNUNET_FS_DownloadContext *child_head;
1804 * Tail of list of child downloads.
1806 struct GNUNET_FS_DownloadContext *child_tail;
1809 * Previous download belonging to the same parent.
1811 struct GNUNET_FS_DownloadContext *prev;
1814 * Next download belonging to the same parent.
1816 struct GNUNET_FS_DownloadContext *next;
1819 * Context kept for the client.
1824 * URI that identifies the file that we are downloading.
1826 struct GNUNET_FS_Uri *uri;
1829 * Known meta-data for the file (can be NULL).
1831 struct GNUNET_CONTAINER_MetaData *meta;
1834 * Error message, NULL if we're doing OK.
1839 * Random portion of filename we use for syncing state of this
1842 char *serialization;
1845 * Where are we writing the data (name of the
1846 * file, can be NULL!).
1851 * Where are we writing the data temporarily (name of the
1852 * file, can be NULL!); used if we do not have a permanent
1853 * name and we are a directory and we do a recursive download.
1855 char *temp_filename;
1858 * Our entry in the job queue.
1860 struct GNUNET_FS_QueueEntry *job_queue;
1863 * Tree encoder used for the reconstruction.
1865 struct GNUNET_FS_TreeEncoder *te;
1868 * File handle for reading data from an existing file
1869 * (to pass to tree encoder).
1871 struct GNUNET_DISK_FileHandle *rfh;
1874 * Map of active requests (those waiting for a response). The key
1875 * is the hash of the encryped block (aka query).
1877 struct GNUNET_CONTAINER_MultiHashMap *active;
1880 * Top-level download request.
1882 struct DownloadRequest *top_request;
1885 * Identity of the peer having the content, or all-zeros
1886 * if we don't know of such a peer.
1888 struct GNUNET_PeerIdentity target;
1891 * ID of a task that is using this struct and that must be cancelled
1892 * when the download is being stopped (if not
1893 * NULL). Used for the task that adds some
1894 * artificial delay when trying to reconnect to the FS service or
1895 * the task processing incrementally the data on disk, or the
1896 * task requesting blocks, etc.
1898 struct GNUNET_SCHEDULER_Task *task;
1901 * What is the first offset that we're interested
1907 * How many bytes starting from offset are desired?
1908 * This is NOT the overall length of the file!
1913 * How many bytes have we already received within
1914 * the specified range (DBlocks only).
1919 * What was the size of the file on disk that we're downloading
1920 * before we started? Used to detect if there is a point in
1921 * checking an existing block on disk for matching the desired
1922 * content. 0 if the file did not exist already.
1924 uint64_t old_file_size;
1927 * Time download was started.
1929 struct GNUNET_TIME_Absolute start_time;
1932 * How long to wait before we try to reconnect to FS service?
1934 struct GNUNET_TIME_Relative reconnect_backoff;
1937 * Desired level of anonymity.
1942 * The depth of the file-tree.
1944 unsigned int treedepth;
1947 * Options for the download.
1949 enum GNUNET_FS_DownloadOptions options;
1952 * Flag set upon transitive completion (includes child downloads).
1953 * This flag is only set to #GNUNET_YES for directories where all
1954 * child-downloads have also completed (and signalled completion).
1959 * Are we ready to issue requests (reconstructions are finished)?
1968 /* end of fs_api.h */