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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
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 * The job is now ready to run and should use the given client
414 * handle to communicate with the FS service.
417 * @param client handle to use for FS communication
420 (*GNUNET_FS_QueueStart) (void *cls,
421 struct GNUNET_CLIENT_Connection *client);
425 * The job must now stop to run and should destry the client handle as
426 * soon as possible (ideally prior to returning).
429 (*GNUNET_FS_QueueStop) (void *cls);
434 * Priorities for the queue.
436 enum GNUNET_FS_QueuePriority
439 * This is a probe (low priority).
441 GNUNET_FS_QUEUE_PRIORITY_PROBE,
446 GNUNET_FS_QUEUE_PRIORITY_NORMAL
451 * Entry in the job queue.
453 struct GNUNET_FS_QueueEntry
456 * This is a linked list.
458 struct GNUNET_FS_QueueEntry *next;
461 * This is a linked list.
463 struct GNUNET_FS_QueueEntry *prev;
466 * Function to call when the job is started.
468 GNUNET_FS_QueueStart start;
471 * Function to call when the job needs to stop (or is done / dequeued).
473 GNUNET_FS_QueueStop stop;
476 * Closure for start and stop.
481 * Handle to FS primary context.
483 struct GNUNET_FS_Handle *h;
486 * Client handle, or NULL if job is not running.
488 struct GNUNET_CLIENT_Connection *client;
491 * Time the job was originally queued.
493 struct GNUNET_TIME_Absolute queue_time;
496 * Time the job was started last.
498 struct GNUNET_TIME_Absolute start_time;
501 * Total amount of time the job has been running (except for the
504 struct GNUNET_TIME_Relative run_time;
507 * How many blocks do the active downloads have?
512 * How important is this download?
514 enum GNUNET_FS_QueuePriority priority;
517 * How often have we (re)started this download?
519 unsigned int start_times;
525 * Information we store for each search result.
527 struct GNUNET_FS_SearchResult
531 * File-sharing context this result belongs to.
533 struct GNUNET_FS_Handle *h;
536 * Kept in a DLL while probing.
538 struct GNUNET_FS_SearchResult *next;
541 * Kept in a DLL while probing.
543 struct GNUNET_FS_SearchResult *prev;
546 * Search context this result belongs to; can be NULL
547 * for probes that come from a directory result.
549 struct GNUNET_FS_SearchContext *sc;
552 * URI to which this search result refers to.
554 struct GNUNET_FS_Uri *uri;
557 * Metadata for the search result.
559 struct GNUNET_CONTAINER_MetaData *meta;
562 * Client info for this search result.
567 * ID of a job that is currently probing this results' availability
568 * (NULL if we are not currently probing).
570 struct GNUNET_FS_DownloadContext *probe_ctx;
573 * ID of an associated download based on this search result (or
576 struct GNUNET_FS_DownloadContext *download;
579 * If this search result triggered an update search, this field
580 * links to the update search.
582 struct GNUNET_FS_SearchContext *update_search;
585 * Name under which this search result is stored on disk.
590 * Bitmap that specifies precisely which keywords have been matched already.
592 uint8_t *keyword_bitmap;
595 * Key for the search result based on the URI.
597 struct GNUNET_HashCode key;
600 * ID of the task that will clean up the probe_ctx should it not
601 * complete on time (and that will need to be cancelled if we clean
602 * up the search result before then).
604 struct GNUNET_SCHEDULER_Task * probe_cancel_task;
607 * When did the current probe become active?
609 struct GNUNET_TIME_Absolute probe_active_time;
612 * How much longer should we run the current probe before giving up?
614 struct GNUNET_TIME_Relative remaining_probe_time;
617 * Anonymity level to use for probes using this search result.
622 * Number of mandatory keywords for which we have NOT yet found the
623 * search result; when this value hits zero, the search result is
624 * given to the callback.
626 uint32_t mandatory_missing;
629 * Number of optional keywords under which this result was also
632 uint32_t optional_support;
635 * Number of availability tests that have succeeded for this result.
637 uint32_t availability_success;
640 * Number of availability trials that we have performed for this
643 uint32_t availability_trials;
649 * Add a job to the queue.
651 * @param h handle to the overall FS state
652 * @param start function to call to begin the job
653 * @param stop function to call to pause the job, or on dequeue (if the job was running)
654 * @param cls closure for start and stop
655 * @param blocks number of blocks this download has
656 * @param priority how important is this download
657 * @return queue handle
659 struct GNUNET_FS_QueueEntry *
660 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
661 GNUNET_FS_QueueStart start,
662 GNUNET_FS_QueueStop stop,
665 enum GNUNET_FS_QueuePriority priority);
669 * Dequeue a job from the queue.
671 * @param qe handle for the job
674 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe);
678 * Function that provides data by reading from a file.
680 * @param cls closure (points to the file information)
681 * @param offset offset to read from; it is possible
682 * that the caller might need to go backwards
684 * @param max maximum number of bytes that should be
685 * copied to @a buf; readers are not allowed
686 * to provide less data unless there is an error;
687 * a value of "0" will be used at the end to allow
688 * the reader to clean up its internal state
689 * @param buf where the reader should write the data
690 * @param emsg location for the reader to store an error message
691 * @return number of bytes written, usually "max", 0 on error
694 GNUNET_FS_data_reader_file_ (void *cls,
702 * Create the closure for the #GNUNET_FS_data_reader_file_() callback.
704 * @param filename file to read
705 * @return closure to use
708 GNUNET_FS_make_file_reader_context_ (const char *filename);
713 * Function that provides data by copying from a buffer.
715 * @param cls closure (points to the buffer)
716 * @param offset offset to read from; it is possible
717 * that the caller might need to go backwards
719 * @param max maximum number of bytes that should be
720 * copied to @a buf; readers are not allowed
721 * to provide less data unless there is an error;
722 * a value of "0" will be used at the end to allow
723 * the reader to clean up its internal state
724 * @param buf where the reader should write the data
725 * @param emsg location for the reader to store an error message
726 * @return number of bytes written, usually @a max, 0 on error
729 GNUNET_FS_data_reader_copy_ (void *cls,
737 * Notification of FS that a search probe has made progress.
738 * This function is used INSTEAD of the client's event handler
739 * for downloads where the #GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
741 * @param cls closure, always NULL (!), actual closure
742 * is in the client-context of the info struct
743 * @param info details about the event, specifying the event type
744 * and various bits about the event
745 * @return client-context (for the next progress call
746 * for this operation; should be set to NULL for
747 * SUSPEND and STOPPED events). The value returned
748 * will be passed to future callbacks in the respective
749 * field in the `struct GNUNET_FS_ProgressInfo`.
752 GNUNET_FS_search_probe_progress_ (void *cls,
753 const struct GNUNET_FS_ProgressInfo *info);
757 * Main function that performs the upload.
759 * @param cls `struct GNUNET_FS_PublishContext` identifies the upload
762 GNUNET_FS_publish_main_ (void *cls);
766 * Function called once the hash of the file
767 * that is being unindexed has been computed.
769 * @param cls closure, unindex context
770 * @param file_id computed hash, NULL on error
773 GNUNET_FS_unindex_process_hash_ (void *cls,
774 const struct GNUNET_HashCode *file_id);
778 * Extract the keywords for KBlock removal
780 * @param uc context for the unindex operation.
783 GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc);
787 * If necessary, connect to the datastore and remove the KBlocks.
789 * @param uc context for the unindex operation.
792 GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc);
796 * Fill in all of the generic fields for a publish event and call the
799 * @param pi structure to fill in
800 * @param pc overall publishing context
801 * @param p file information for the file being published
802 * @param offset where in the file are we so far
803 * @return value returned from callback
806 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
807 struct GNUNET_FS_PublishContext *pc,
808 const struct GNUNET_FS_FileInformation *p,
813 * Fill in all of the generic fields for a download event and call the
816 * @param pi structure to fill in
817 * @param dc overall download context
820 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
821 struct GNUNET_FS_DownloadContext *dc);
825 * Task that creates the initial (top-level) download
826 * request for the file.
828 * @param cls the 'struct GNUNET_FS_DownloadContext'
831 GNUNET_FS_download_start_task_ (void *cls);
836 * Fill in all of the generic fields for
837 * an unindex event and call the callback.
839 * @param pi structure to fill in
840 * @param uc overall unindex context
841 * @param offset where we are in the file (for progress)
844 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
845 struct GNUNET_FS_UnindexContext *uc,
849 * Fill in all of the generic fields for a search event and
852 * @param pi structure to fill in
853 * @param h file-sharing handle
854 * @param sc overall search context
855 * @return value returned by the callback
858 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
859 struct GNUNET_FS_Handle *h,
860 struct GNUNET_FS_SearchContext *sc);
864 * Connect to the datastore and remove the blocks.
866 * @param uc context for the unindex operation.
869 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
872 * Build the request and actually initiate the search using the
875 * @param sc search context
876 * @return GNUNET_OK on success, GNUNET_SYSERR on error
879 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
882 * Start the downloading process (by entering the queue).
884 * @param dc our download context
887 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
891 * Start download probes for the given search result.
893 * @param sr the search result
896 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
900 * Remove serialization/deserialization file from disk.
902 * @param h master context
903 * @param ext component of the path
904 * @param ent entity identifier
907 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
913 * Remove serialization/deserialization directory from disk.
915 * @param h master context
916 * @param ext component of the path
917 * @param uni unique name of parent
920 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
926 * Synchronize this file-information struct with its mirror
927 * on disk. Note that all internal FS-operations that change
928 * file information data should already call "sync" internally,
929 * so this function is likely not useful for clients.
931 * @param fi the struct to sync
934 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
938 * Synchronize this publishing struct with its mirror
939 * on disk. Note that all internal FS-operations that change
940 * publishing structs should already call "sync" internally,
941 * so this function is likely not useful for clients.
943 * @param pc the struct to sync
946 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
950 * Synchronize this unindex struct with its mirror
951 * on disk. Note that all internal FS-operations that change
952 * publishing structs should already call "sync" internally,
953 * so this function is likely not useful for clients.
955 * @param uc the struct to sync
958 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
962 * Synchronize this search struct with its mirror
963 * on disk. Note that all internal FS-operations that change
964 * publishing structs should already call "sync" internally,
965 * so this function is likely not useful for clients.
967 * @param sc the struct to sync
970 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
974 * Synchronize this search result with its mirror
975 * on disk. Note that all internal FS-operations that change
976 * publishing structs should already call "sync" internally,
977 * so this function is likely not useful for clients.
979 * @param sr the struct to sync
982 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
986 * Synchronize this download struct with its mirror
987 * on disk. Note that all internal FS-operations that change
988 * publishing structs should already call "sync" internally,
989 * so this function is likely not useful for clients.
991 * @param dc the struct to sync
994 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
998 * Create SUSPEND event for the given publish operation
999 * and then clean up our state (without stop signal).
1001 * @param cls the `struct GNUNET_FS_PublishContext` to signal for
1004 GNUNET_FS_publish_signal_suspend_ (void *cls);
1008 * Create SUSPEND event for the given search operation
1009 * and then clean up our state (without stop signal).
1011 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
1014 GNUNET_FS_search_signal_suspend_ (void *cls);
1018 * Create SUSPEND event for the given download operation
1019 * and then clean up our state (without stop signal).
1021 * @param cls the `struct GNUNET_FS_DownloadContext` to signal for
1024 GNUNET_FS_download_signal_suspend_ (void *cls);
1028 * Create SUSPEND event for the given unindex operation
1029 * and then clean up our state (without stop signal).
1031 * @param cls the `struct GNUNET_FS_UnindexContext` to signal for
1034 GNUNET_FS_unindex_signal_suspend_ (void *cls);
1038 * Function signature of the functions that can be called
1039 * to trigger suspend signals and clean-up for top-level
1042 * @param cls closure
1044 typedef void (*SuspendSignalFunction) (void *cls);
1047 * We track all of the top-level activities of FS
1048 * so that we can signal 'suspend' on shutdown.
1050 struct TopLevelActivity
1053 * This is a doubly-linked list.
1055 struct TopLevelActivity *next;
1058 * This is a doubly-linked list.
1060 struct TopLevelActivity *prev;
1063 * Function to call for suspend-signalling and clean up.
1065 SuspendSignalFunction ssf;
1068 * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1075 * Create a top-level activity entry.
1077 * @param h global fs handle
1078 * @param ssf suspend signal function to use
1079 * @param ssf_cls closure for @a ssf
1080 * @return fresh top-level activity handle
1082 struct TopLevelActivity *
1083 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1084 SuspendSignalFunction ssf,
1089 * Destroy a top-level activity entry.
1091 * @param h global fs handle
1092 * @param top top level activity entry
1095 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
1096 struct TopLevelActivity *top);
1101 * Master context for most FS operations.
1103 struct GNUNET_FS_Handle
1106 * Configuration to use.
1108 const struct GNUNET_CONFIGURATION_Handle *cfg;
1111 * Name of our client.
1116 * Function to call with updates on our progress.
1118 GNUNET_FS_ProgressCallback upcb;
1126 * Head of DLL of top-level activities.
1128 struct TopLevelActivity *top_head;
1131 * Tail of DLL of top-level activities.
1133 struct TopLevelActivity *top_tail;
1136 * Head of DLL of running jobs.
1138 struct GNUNET_FS_QueueEntry *running_head;
1141 * Tail of DLL of running jobs.
1143 struct GNUNET_FS_QueueEntry *running_tail;
1146 * Head of DLL of pending jobs.
1148 struct GNUNET_FS_QueueEntry *pending_head;
1151 * Tail of DLL of pending jobs.
1153 struct GNUNET_FS_QueueEntry *pending_tail;
1156 * Head of active probes.
1158 struct GNUNET_FS_SearchResult *probes_head;
1161 * Tail of active probes.
1163 struct GNUNET_FS_SearchResult *probes_tail;
1166 * Task that processes the jobs in the running and pending queues
1167 * (and moves jobs around as needed).
1169 struct GNUNET_SCHEDULER_Task * queue_job;
1172 * Task we use to report periodically to the application that
1173 * certain search probes (from @e probes_head) are still running.
1175 struct GNUNET_SCHEDULER_Task * probe_ping_task;
1178 * Average time we take for a single request to be satisfied.
1179 * FIXME: not yet calcualted properly...
1181 struct GNUNET_TIME_Relative avg_block_latency;
1184 * How many actual downloads do we have running right now?
1186 unsigned int active_downloads;
1189 * How many blocks do the active downloads have?
1191 unsigned int active_blocks;
1196 enum GNUNET_FS_Flags flags;
1199 * Maximum number of parallel downloads.
1201 unsigned int max_parallel_downloads;
1204 * Maximum number of parallel requests.
1206 unsigned int max_parallel_requests;
1212 * Handle for controlling a publication process.
1214 struct GNUNET_FS_PublishContext
1217 * Handle to the global fs context.
1219 struct GNUNET_FS_Handle *h;
1222 * Connection to FS service (only used for LOC URI signing).
1224 struct GNUNET_CLIENT_Handle *fs_client;
1227 * Our top-level activity entry (if we are top-level, otherwise NULL).
1229 struct TopLevelActivity *top;
1232 * File-structure that is being shared.
1234 struct GNUNET_FS_FileInformation *fi;
1237 * Namespace that we are publishing in, NULL if we have no namespace.
1239 struct GNUNET_CRYPTO_EcdsaPrivateKey *ns;
1242 * ID of the content in the namespace, NULL if we have no namespace.
1247 * ID for future updates, NULL if we have no namespace or no updates.
1252 * Filename used for serializing information about this operation
1253 * (should be determined using 'mktemp').
1255 char *serialization;
1258 * Our own client handle for the FS service; only briefly used when
1259 * we start to index a file, otherwise NULL.
1261 struct GNUNET_CLIENT_Connection *client;
1264 * Current position in the file-tree for the upload.
1266 struct GNUNET_FS_FileInformation *fi_pos;
1269 * Non-null if we are currently hashing a file.
1271 struct GNUNET_CRYPTO_FileHashContext *fhc;
1274 * Connection to the datastore service.
1276 struct GNUNET_DATASTORE_Handle *dsh;
1279 * Queue entry for reservation/unreservation.
1281 struct GNUNET_DATASTORE_QueueEntry *qre;
1284 * Context for SKS publishing operation that is part of this publishing operation
1285 * (NULL if not active).
1287 struct GNUNET_FS_PublishSksContext *sks_pc;
1290 * Context for KSK publishing operation that is part of this publishing operation
1291 * (NULL if not active).
1293 struct GNUNET_FS_PublishKskContext *ksk_pc;
1296 * ID of the task performing the upload. NO_TASK if the upload has
1299 struct GNUNET_SCHEDULER_Task * upload_task;
1302 * Storage space to reserve for the operation.
1304 uint64_t reserve_space;
1307 * Overall number of entries to reserve for the
1308 * publish operation.
1310 uint32_t reserve_entries;
1313 * Options for publishing.
1315 enum GNUNET_FS_PublishOptions options;
1318 * Space reservation ID with datastore service
1324 * Set to #GNUNET_YES if we were able to publish any block.
1325 * (and thus unindexing on error might make sense).
1330 * Set to #GNUNET_YES if all processing has completed.
1335 * Flag set to #GNUNET_YES if the next callback from
1336 * #GNUNET_FS_file_information_inspect should be skipped because it
1337 * is for the directory which was already processed with the parent.
1339 int skip_next_fi_callback;
1344 * Phases of unindex processing (state machine).
1349 * We're currently hashing the file.
1351 UNINDEX_STATE_HASHING = 0,
1354 * We're telling the datastore to delete
1355 * the respective DBlocks and IBlocks.
1357 UNINDEX_STATE_DS_REMOVE = 1,
1360 * Find out which keywords apply.
1362 UNINDEX_STATE_EXTRACT_KEYWORDS = 2,
1365 * We're telling the datastore to remove KBlocks.
1367 UNINDEX_STATE_DS_REMOVE_KBLOCKS = 3,
1370 * We're notifying the FS service about
1373 UNINDEX_STATE_FS_NOTIFY = 4,
1378 UNINDEX_STATE_COMPLETE = 5,
1381 * We've encountered a fatal error.
1383 UNINDEX_STATE_ERROR = 6
1388 * Handle for controlling an unindexing operation.
1390 struct GNUNET_FS_UnindexContext
1394 * The content hash key of the last block we processed, will in the
1395 * end be set to the CHK from the URI. Used to remove the KBlocks.
1397 struct ContentHashKey chk;
1400 * Global FS context.
1402 struct GNUNET_FS_Handle *h;
1405 * Our top-level activity entry.
1407 struct TopLevelActivity *top;
1410 * Directory scanner to find keywords (KBlock removal).
1412 struct GNUNET_FS_DirScanner *dscan;
1415 * Keywords found (telling us which KBlocks to remove).
1417 struct GNUNET_FS_Uri *ksk_uri;
1420 * Current offset in KSK removal.
1422 uint32_t ksk_offset;
1425 * Name of the file that we are unindexing.
1430 * Short name under which we are serializing the state of this operation.
1432 char *serialization;
1435 * Connection to the FS service, only valid during the
1436 * #UNINDEX_STATE_FS_NOTIFY phase.
1438 struct GNUNET_CLIENT_Connection *client;
1441 * Connection to the datastore service, only valid during the
1442 * UNINDEX_STATE_DS_NOTIFY phase.
1444 struct GNUNET_DATASTORE_Handle *dsh;
1447 * Pointer kept for the client.
1452 * Merkle-ish tree encoder context.
1454 struct GNUNET_FS_TreeEncoder *tc;
1457 * Handle used to read the file.
1459 struct GNUNET_DISK_FileHandle *fh;
1462 * Handle to datastore 'get_key' operation issued for
1463 * obtaining KBlocks.
1465 struct GNUNET_DATASTORE_QueueEntry *dqe;
1468 * Current key for decrypting UBLocks from 'get_key' operation.
1470 struct GNUNET_HashCode ukey;
1473 * Current query of 'get_key' operation.
1475 struct GNUNET_HashCode uquery;
1478 * Error message, NULL on success.
1483 * Context for hashing of the file.
1485 struct GNUNET_CRYPTO_FileHashContext *fhc;
1488 * Which values have we seen already?
1490 struct GNUNET_CONTAINER_MultiHashMap *seen_dh;
1493 * Overall size of the file.
1498 * Random offset given to #GNUNET_DATASTORE_get_key.
1503 * When did we start?
1505 struct GNUNET_TIME_Absolute start_time;
1508 * Hash of the file's contents (once computed).
1510 struct GNUNET_HashCode file_id;
1513 * Current operatinonal phase.
1515 enum UnindexState state;
1521 * Information we keep for each keyword in a keyword search.
1523 struct SearchRequestEntry
1527 * Hash of the public key, also known as the query.
1529 struct GNUNET_HashCode uquery;
1532 * Derived public key, hashes to 'uquery'.
1534 struct GNUNET_CRYPTO_EcdsaPublicKey dpub;
1537 * The original keyword, used to derive the
1538 * key (for decrypting the UBlock).
1543 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1544 * was found under this keyword. Note that the entries will point
1545 * to the same locations as those in the master result map (in
1546 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1547 * The key for each entry is the XOR of the key and query in the CHK
1548 * URI (as a unique identifier for the search result).
1550 struct GNUNET_CONTAINER_MultiHashMap *results;
1553 * Is this keyword a mandatory keyword
1554 * (started with '+')?
1562 * Handle for controlling a search.
1564 struct GNUNET_FS_SearchContext
1567 * Handle to the global FS context.
1569 struct GNUNET_FS_Handle *h;
1572 * Our top-level activity entry (if we are top-level, otherwise NULL).
1574 struct TopLevelActivity *top;
1577 * List of keywords that we're looking for.
1579 struct GNUNET_FS_Uri *uri;
1582 * For update-searches, link to the search result that triggered
1583 * the update search; otherwise NULL.
1585 struct GNUNET_FS_SearchResult *psearch_result;
1588 * Connection to the FS service.
1590 struct GNUNET_CLIENT_Connection *client;
1593 * Pointer we keep for the client.
1598 * Name of the file on disk we use for persistence.
1600 char *serialization;
1603 * Error message (non-NULL if this operation failed).
1608 * Map that contains a `struct GNUNET_FS_SearchResult` for each result that
1609 * was found in the search. The key for each entry is the XOR of
1610 * the key and query in the CHK URI (as a unique identifier for the
1613 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1616 * Per-keyword information for a keyword search. This array will
1617 * have exactly as many entries as there were keywords.
1619 struct SearchRequestEntry *requests;
1622 * When did we start?
1624 struct GNUNET_TIME_Absolute start_time;
1627 * How long to wait before we try to reconnect to FS service?
1629 struct GNUNET_TIME_Relative reconnect_backoff;
1632 * ID of a task that is using this struct and that must be cancelled
1633 * when the search is being stopped (if not
1634 * NULL). Used for the task that adds some
1635 * artificial delay when trying to reconnect to the FS service.
1637 struct GNUNET_SCHEDULER_Task *task;
1640 * How many of the entries in the search request
1641 * map have been passed to the service so far?
1643 unsigned int search_request_map_offset;
1646 * How many of the keywords in the KSK
1647 * map have been passed to the service so far?
1649 unsigned int keyword_offset;
1652 * Anonymity level for the search.
1657 * Number of mandatory keywords in this query.
1659 uint32_t mandatory_count;
1662 * Options for the search.
1664 enum GNUNET_FS_SearchOptions options;
1669 * FSM for possible states a block can go through. The typical
1670 * order of progression is linear through the states, alternatives
1671 * are documented in the comments.
1673 enum BlockRequestState
1676 * Initial state, block has only been allocated (since it is
1677 * relevant to the overall download request).
1682 * We've checked the block on the path down the tree, and the
1683 * content on disk did match the desired CHK, but not all
1684 * the way down, so at the bottom some blocks will still
1685 * need to be reconstructed).
1687 BRS_RECONSTRUCT_DOWN = 1,
1690 * We've calculated the CHK bottom-up based on the meta data.
1691 * This may work, but if it did we have to write the meta data to
1692 * disk at the end (and we still need to check against the
1695 BRS_RECONSTRUCT_META_UP = 2,
1698 * We've calculated the CHK bottom-up based on what we have on
1699 * disk, which may not be what the desired CHK is. If the
1700 * reconstructed CHKs match whatever comes from above, we're
1701 * done with the respective subtree.
1703 BRS_RECONSTRUCT_UP = 3,
1706 * We've determined the real, desired CHK for this block
1707 * (full tree reconstruction failed), request is now pending.
1708 * If the CHK that bubbled up through reconstruction did match
1709 * the top-level request, the state machine for the subtree
1710 * would have moved to BRS_DOWNLOAD_UP.
1715 * We've successfully downloaded this block, but the children
1716 * still need to be either downloaded or verified (download
1717 * request propagates down). If the download fails, the
1718 * state machine for this block may move to
1719 * BRS_DOWNLOAD_ERROR instead.
1721 BRS_DOWNLOAD_DOWN = 5,
1724 * This block and all of its children have been downloaded
1725 * successfully (full completion propagates up).
1727 BRS_DOWNLOAD_UP = 6,
1730 * We got a block back that matched the query but did not hash to
1731 * the key (malicious publisher or hash collision); this block
1732 * can never be downloaded (error propagates up).
1739 * Information about an active download request.
1741 struct DownloadRequest
1744 * While pending, we keep all download requests in a doubly-linked list.
1746 struct DownloadRequest *next;
1749 * While pending, we keep all download requests in a doubly-linked list.
1751 struct DownloadRequest *prev;
1754 * Parent in the CHK-tree.
1756 struct DownloadRequest *parent;
1759 * Array (!) of child-requests, or NULL for the bottom of the tree.
1761 struct DownloadRequest **children;
1764 * CHK for the request for this block (set during reconstruction
1765 * to what we have on disk, later to what we want to have).
1767 struct ContentHashKey chk;
1770 * Offset of the corresponding block. Specifically, first (!) byte of
1771 * the first DBLOCK in the subtree induced by block represented by
1777 * Number of entries in 'children' array.
1779 unsigned int num_children;
1782 * Depth of the corresponding block in the tree. 0==DBLOCKs.
1787 * Offset of the CHK for this block in the parent block
1789 unsigned int chk_idx;
1794 enum BlockRequestState state;
1797 * #GNUNET_YES if this entry is in the pending list.
1805 * (recursively) free download request structure
1807 * @param dr request to free
1810 GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
1814 * Stop the ping task for this search result.
1816 * @param sr result to start pinging for.
1819 GNUNET_FS_stop_probe_ping_task_ (struct GNUNET_FS_SearchResult *sr);
1823 * Context for controlling a download.
1825 struct GNUNET_FS_DownloadContext
1829 * Global FS context.
1831 struct GNUNET_FS_Handle *h;
1834 * Our top-level activity entry (if we are top-level, otherwise NULL).
1836 struct TopLevelActivity *top;
1839 * Connection to the FS service.
1841 struct GNUNET_CLIENT_Connection *client;
1844 * Parent download (used when downloading files
1847 struct GNUNET_FS_DownloadContext *parent;
1850 * Associated search (used when downloading files
1851 * based on search results), or NULL for none.
1853 struct GNUNET_FS_SearchResult *search;
1856 * Head of list of child downloads.
1858 struct GNUNET_FS_DownloadContext *child_head;
1861 * Tail of list of child downloads.
1863 struct GNUNET_FS_DownloadContext *child_tail;
1866 * Previous download belonging to the same parent.
1868 struct GNUNET_FS_DownloadContext *prev;
1871 * Next download belonging to the same parent.
1873 struct GNUNET_FS_DownloadContext *next;
1876 * Context kept for the client.
1881 * URI that identifies the file that we are downloading.
1883 struct GNUNET_FS_Uri *uri;
1886 * Known meta-data for the file (can be NULL).
1888 struct GNUNET_CONTAINER_MetaData *meta;
1891 * Error message, NULL if we're doing OK.
1896 * Random portion of filename we use for syncing state of this
1899 char *serialization;
1902 * Where are we writing the data (name of the
1903 * file, can be NULL!).
1908 * Where are we writing the data temporarily (name of the
1909 * file, can be NULL!); used if we do not have a permanent
1910 * name and we are a directory and we do a recursive download.
1912 char *temp_filename;
1915 * Our entry in the job queue.
1917 struct GNUNET_FS_QueueEntry *job_queue;
1920 * Non-NULL if we are currently having a request for
1921 * transmission pending with the client handle.
1923 struct GNUNET_CLIENT_TransmitHandle *th;
1926 * Tree encoder used for the reconstruction.
1928 struct GNUNET_FS_TreeEncoder *te;
1931 * File handle for reading data from an existing file
1932 * (to pass to tree encoder).
1934 struct GNUNET_DISK_FileHandle *rfh;
1937 * Map of active requests (those waiting for a response). The key
1938 * is the hash of the encryped block (aka query).
1940 struct GNUNET_CONTAINER_MultiHashMap *active;
1943 * Head of linked list of pending requests.
1945 struct DownloadRequest *pending_head;
1948 * Head of linked list of pending requests.
1950 struct DownloadRequest *pending_tail;
1953 * Top-level download request.
1955 struct DownloadRequest *top_request;
1958 * Identity of the peer having the content, or all-zeros
1959 * if we don't know of such a peer.
1961 struct GNUNET_PeerIdentity target;
1964 * ID of a task that is using this struct and that must be cancelled
1965 * when the download is being stopped (if not
1966 * NULL). Used for the task that adds some
1967 * artificial delay when trying to reconnect to the FS service or
1968 * the task processing incrementally the data on disk, or the
1969 * task requesting blocks, etc.
1971 struct GNUNET_SCHEDULER_Task *task;
1974 * What is the first offset that we're interested
1980 * How many bytes starting from offset are desired?
1981 * This is NOT the overall length of the file!
1986 * How many bytes have we already received within
1987 * the specified range (DBlocks only).
1992 * What was the size of the file on disk that we're downloading
1993 * before we started? Used to detect if there is a point in
1994 * checking an existing block on disk for matching the desired
1995 * content. 0 if the file did not exist already.
1997 uint64_t old_file_size;
2000 * Time download was started.
2002 struct GNUNET_TIME_Absolute start_time;
2005 * How long to wait before we try to reconnect to FS service?
2007 struct GNUNET_TIME_Relative reconnect_backoff;
2010 * Desired level of anonymity.
2015 * The depth of the file-tree.
2017 unsigned int treedepth;
2020 * Options for the download.
2022 enum GNUNET_FS_DownloadOptions options;
2025 * Flag set upon transitive completion (includes child downloads).
2026 * This flag is only set to #GNUNET_YES for directories where all
2027 * child-downloads have also completed (and signalled completion).
2032 * Have we started the receive continuation yet?
2037 * Are we ready to issue requests (reconstructions are finished)?
2046 /* end of fs_api.h */