2 This file is part of GNUnet.
3 (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, 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 * Size of the individual blocks used for file-sharing.
40 #define DBLOCK_SIZE (32*1024)
43 * Pick a multiple of 2 here to achive 8-byte alignment! We also
44 * probably want DBlocks to have (roughly) the same size as IBlocks.
45 * With SHA-512, the optimal value is 32768 byte / 128 byte = 256 (128
46 * byte = 2 * 512 bits). DO NOT CHANGE!
48 #define CHK_PER_INODE 256
51 * Maximum size for a file to be considered for inlining in a
54 #define MAX_INLINE_SIZE 65536
57 * Name of the directory with top-level searches.
59 #define GNUNET_FS_SYNC_PATH_MASTER_SEARCH "search"
62 * Name of the directory with sub-searches (namespace-updates).
64 #define GNUNET_FS_SYNC_PATH_CHILD_SEARCH "search-child"
67 * Name of the directory with master downloads (not associated
68 * with search or part of another download).
70 #define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD "download"
73 * Name of the directory with downloads that are part of another
74 * download or a search.
76 #define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD "download-child"
79 * Name of the directory with publishing operations.
81 #define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH "publish"
84 * Name of the directory with files that are being published
86 #define GNUNET_FS_SYNC_PATH_FILE_INFO "publish-file"
89 * Name of the directory with unindex operations.
91 #define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX "unindex"
95 * @brief complete information needed
102 * Total size of the file in bytes. (network byte order (!))
104 uint64_t file_length;
107 * Query and key of the top GNUNET_EC_IBlock.
109 struct ContentHashKey chk;
115 * Information about a file and its location
116 * (peer claiming to share the file).
121 * Information about the shared file.
123 struct FileIdentifier fi;
126 * Identity of the peer sharing the file.
128 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
131 * Time when this location URI expires.
133 struct GNUNET_TIME_Absolute expirationTime;
136 * RSA signature over the GNUNET_EC_FileIdentifier,
137 * GNUNET_hash of the peer and expiration time.
139 struct GNUNET_CRYPTO_RsaSignature contentSignature;
149 * Content-hash-key (simple file).
154 * Signed key space (file in namespace).
159 * Keyword search key (query with keywords).
164 * Location (chk with identity of hosting peer).
170 * A Universal Resource Identifier (URI), opaque.
184 * Keywords start with a '+' if they are
185 * mandatory (in which case the '+' is NOT
186 * part of the keyword) and with a
187 * simple space if they are optional
188 * (in which case the space is ALSO not
189 * part of the actual keyword).
191 * Double-quotes to protect spaces and
192 * %-encoding are NOT used internally
193 * (only in URI-strings).
198 * Size of the keywords array.
200 unsigned int keywordCount;
206 * Hash of the public key for the namespace.
208 GNUNET_HashCode namespace;
211 * Human-readable identifier chosen for this
212 * entry in the namespace.
218 * Information needed to retrieve a file (content-hash-key
221 struct FileIdentifier chk;
224 * Information needed to retrieve a file including signed
225 * location (identity of a peer) of the content.
234 * Information for a file or directory that is
235 * about to be published.
237 struct GNUNET_FS_FileInformation
241 * Files in a directory are kept as a linked list.
243 struct GNUNET_FS_FileInformation *next;
246 * If this is a file in a directory, "dir" refers to
247 * the directory; otherwise NULL.
249 struct GNUNET_FS_FileInformation *dir;
252 * Handle to the master context.
254 struct GNUNET_FS_Handle *h;
257 * Pointer kept for the client.
262 * Metadata to use for the file.
264 struct GNUNET_CONTAINER_MetaData *meta;
267 * Keywords to use for KBlocks.
269 struct GNUNET_FS_Uri *keywords;
272 * CHK for this file or directory. NULL if
273 * we have not yet computed it.
275 struct GNUNET_FS_Uri *chk_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 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
390 * Is this struct for a file or directory?
395 * Are we done publishing this file?
403 * The job is now ready to run and should use the given client
404 * handle to communicate with the FS service.
407 * @param client handle to use for FS communication
409 typedef void (*GNUNET_FS_QueueStart) (void *cls,
410 struct GNUNET_CLIENT_Connection * client);
414 * The job must now stop to run and should destry the client handle as
415 * soon as possible (ideally prior to returning).
417 typedef void (*GNUNET_FS_QueueStop) (void *cls);
421 * Entry in the job queue.
423 struct GNUNET_FS_QueueEntry
426 * This is a linked list.
428 struct GNUNET_FS_QueueEntry *next;
431 * This is a linked list.
433 struct GNUNET_FS_QueueEntry *prev;
436 * Function to call when the job is started.
438 GNUNET_FS_QueueStart start;
441 * Function to call when the job needs to stop (or is done / dequeued).
443 GNUNET_FS_QueueStop stop;
446 * Closure for start and stop.
451 * Handle to FS primary context.
453 struct GNUNET_FS_Handle *h;
456 * Client handle, or NULL if job is not running.
458 struct GNUNET_CLIENT_Connection *client;
461 * Time the job was originally queued.
463 struct GNUNET_TIME_Absolute queue_time;
466 * Time the job was started last.
468 struct GNUNET_TIME_Absolute start_time;
471 * Total amount of time the job has been running (except for the
474 struct GNUNET_TIME_Relative run_time;
477 * How many blocks do the active downloads have?
482 * How often have we (re)started this download?
484 unsigned int start_times;
492 * Information we store for each search result.
494 struct GNUNET_FS_SearchResult
498 * Search context this result belongs to.
500 struct GNUNET_FS_SearchContext *sc;
503 * URI to which this search result refers to.
505 struct GNUNET_FS_Uri *uri;
508 * Metadata for the search result.
510 struct GNUNET_CONTAINER_MetaData *meta;
513 * Client info for this search result.
518 * ID of a job that is currently probing this results' availability
519 * (NULL if we are not currently probing).
521 struct GNUNET_FS_DownloadContext *probe_ctx;
524 * ID of an associated download based on this search result (or
527 struct GNUNET_FS_DownloadContext *download;
530 * If this search result triggered an update search, this field
531 * links to the update search.
533 struct GNUNET_FS_SearchContext *update_search;
536 * Name under which this search result is stored on disk.
541 * Bitmap that specifies precisely which keywords have been matched already.
543 uint8_t *keyword_bitmap;
546 * Key for the search result
551 * ID of the task that will clean up the probe_ctx should it not
552 * complete on time (and that will need to be cancelled if we clean
553 * up the search result before then).
555 GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
558 * When did the current probe become active?
560 struct GNUNET_TIME_Absolute probe_active_time;
563 * How much longer should we run the current probe before giving up?
565 struct GNUNET_TIME_Relative remaining_probe_time;
568 * Number of mandatory keywords for which we have NOT yet found the
569 * search result; when this value hits zero, the search result is
570 * given to the callback.
572 uint32_t mandatory_missing;
575 * Number of optional keywords under which this result was also
578 uint32_t optional_support;
581 * Number of availability tests that have succeeded for this result.
583 uint32_t availability_success;
586 * Number of availability trials that we have performed for this
589 uint32_t availability_trials;
595 * Add a job to the queue.
597 * @param h handle to the overall FS state
598 * @param start function to call to begin the job
599 * @param stop function to call to pause the job, or on dequeue (if the job was running)
600 * @param cls closure for start and stop
601 * @param blocks number of blocks this download has
602 * @return queue handle
604 struct GNUNET_FS_QueueEntry *
605 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, GNUNET_FS_QueueStart start,
606 GNUNET_FS_QueueStop stop, void *cls, unsigned int blocks);
610 * Dequeue a job from the queue.
611 * @param qh handle for the job
614 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
618 * Function that provides data by reading from a file.
620 * @param cls closure (points to the file information)
621 * @param offset offset to read from; it is possible
622 * that the caller might need to go backwards
624 * @param max maximum number of bytes that should be
625 * copied to buf; readers are not allowed
626 * to provide less data unless there is an error;
627 * a value of "0" will be used at the end to allow
628 * the reader to clean up its internal state
629 * @param buf where the reader should write the data
630 * @param emsg location for the reader to store an error message
631 * @return number of bytes written, usually "max", 0 on error
634 GNUNET_FS_data_reader_file_ (void *cls, uint64_t offset, size_t max, void *buf,
639 * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
641 * @param filename file to read
642 * @return closure to use
645 GNUNET_FS_make_file_reader_context_ (const char *filename);
650 * Function that provides data by copying from a buffer.
652 * @param cls closure (points to the buffer)
653 * @param offset offset to read from; it is possible
654 * that the caller might need to go backwards
656 * @param max maximum number of bytes that should be
657 * copied to buf; readers are not allowed
658 * to provide less data unless there is an error;
659 * a value of "0" will be used at the end to allow
660 * the reader to clean up its internal state
661 * @param buf where the reader should write the data
662 * @param emsg location for the reader to store an error message
663 * @return number of bytes written, usually "max", 0 on error
666 GNUNET_FS_data_reader_copy_ (void *cls, uint64_t offset, size_t max, void *buf,
670 * Notification of FS that a search probe has made progress.
671 * This function is used INSTEAD of the client's event handler
672 * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
674 * @param cls closure, always NULL (!), actual closure
675 * is in the client-context of the info struct
676 * @param info details about the event, specifying the event type
677 * and various bits about the event
678 * @return client-context (for the next progress call
679 * for this operation; should be set to NULL for
680 * SUSPEND and STOPPED events). The value returned
681 * will be passed to future callbacks in the respective
682 * field in the GNUNET_FS_ProgressInfo struct.
685 GNUNET_FS_search_probe_progress_ (void *cls,
686 const struct GNUNET_FS_ProgressInfo *info);
690 * Main function that performs the upload.
692 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
693 * @param tc task context
696 GNUNET_FS_publish_main_ (void *cls,
697 const struct GNUNET_SCHEDULER_TaskContext *tc);
701 * Function called once the hash of the file
702 * that is being unindexed has been computed.
704 * @param cls closure, unindex context
705 * @param file_id computed hash, NULL on error
708 GNUNET_FS_unindex_process_hash_ (void *cls, const GNUNET_HashCode * file_id);
712 * Fill in all of the generic fields for a publish event and call the
715 * @param pi structure to fill in
716 * @param pc overall publishing context
717 * @param p file information for the file being published
718 * @param offset where in the file are we so far
719 * @return value returned from callback
722 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
723 struct GNUNET_FS_PublishContext *pc,
724 const struct GNUNET_FS_FileInformation *p,
729 * Fill in all of the generic fields for a download event and call the
732 * @param pi structure to fill in
733 * @param dc overall download context
736 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
737 struct GNUNET_FS_DownloadContext *dc);
741 * Task that creates the initial (top-level) download
742 * request for the file.
744 * @param cls the 'struct GNUNET_FS_DownloadContext'
745 * @param tc scheduler context
748 GNUNET_FS_download_start_task_ (void *cls,
749 const struct GNUNET_SCHEDULER_TaskContext *tc);
754 * Fill in all of the generic fields for
755 * an unindex event and call the callback.
757 * @param pi structure to fill in
758 * @param uc overall unindex context
759 * @param offset where we are in the file (for progress)
762 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
763 struct GNUNET_FS_UnindexContext *uc,
767 * Fill in all of the generic fields for a search event and
770 * @param pi structure to fill in
771 * @param sc overall search context
772 * @return value returned by the callback
775 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
776 struct GNUNET_FS_SearchContext *sc);
780 * Connect to the datastore and remove the blocks.
782 * @param uc context for the unindex operation.
785 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
788 * Build the request and actually initiate the search using the
791 * @param sc search context
792 * @return GNUNET_OK on success, GNUNET_SYSERR on error
795 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
798 * Start the downloading process (by entering the queue).
800 * @param dc our download context
803 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
807 * Start download probes for the given search result.
809 * @param sr the search result
812 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
815 * Remove serialization/deserialization file from disk.
817 * @param h master context
818 * @param ext component of the path
819 * @param ent entity identifier
822 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, const char *ext,
827 * Remove serialization/deserialization directory from disk.
829 * @param h master context
830 * @param ext component of the path
831 * @param uni unique name of parent
834 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, const char *ext,
839 * Synchronize this file-information struct with its mirror
840 * on disk. Note that all internal FS-operations that change
841 * file information data should already call "sync" internally,
842 * so this function is likely not useful for clients.
844 * @param fi the struct to sync
847 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
850 * Synchronize this publishing struct with its mirror
851 * on disk. Note that all internal FS-operations that change
852 * publishing structs should already call "sync" internally,
853 * so this function is likely not useful for clients.
855 * @param pc the struct to sync
858 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
861 * Synchronize this unindex struct with its mirror
862 * on disk. Note that all internal FS-operations that change
863 * publishing structs should already call "sync" internally,
864 * so this function is likely not useful for clients.
866 * @param uc the struct to sync
869 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
872 * Synchronize this search struct with its mirror
873 * on disk. Note that all internal FS-operations that change
874 * publishing structs should already call "sync" internally,
875 * so this function is likely not useful for clients.
877 * @param sc the struct to sync
880 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
883 * Synchronize this search result with its mirror
884 * on disk. Note that all internal FS-operations that change
885 * publishing structs should already call "sync" internally,
886 * so this function is likely not useful for clients.
888 * @param sr the struct to sync
891 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
894 * Synchronize this download struct with its mirror
895 * on disk. Note that all internal FS-operations that change
896 * publishing structs should already call "sync" internally,
897 * so this function is likely not useful for clients.
899 * @param dc the struct to sync
902 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
905 * Create SUSPEND event for the given publish operation
906 * and then clean up our state (without stop signal).
908 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
911 GNUNET_FS_publish_signal_suspend_ (void *cls);
914 * Create SUSPEND event for the given search operation
915 * and then clean up our state (without stop signal).
917 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
920 GNUNET_FS_search_signal_suspend_ (void *cls);
923 * Create SUSPEND event for the given download operation
924 * and then clean up our state (without stop signal).
926 * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
929 GNUNET_FS_download_signal_suspend_ (void *cls);
932 * Create SUSPEND event for the given unindex operation
933 * and then clean up our state (without stop signal).
935 * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
938 GNUNET_FS_unindex_signal_suspend_ (void *cls);
941 * Function signature of the functions that can be called
942 * to trigger suspend signals and clean-up for top-level
947 typedef void (*SuspendSignalFunction) (void *cls);
950 * We track all of the top-level activities of FS
951 * so that we can signal 'suspend' on shutdown.
953 struct TopLevelActivity
956 * This is a doubly-linked list.
958 struct TopLevelActivity *next;
961 * This is a doubly-linked list.
963 struct TopLevelActivity *prev;
966 * Function to call for suspend-signalling and clean up.
968 SuspendSignalFunction ssf;
971 * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
978 * Create a top-level activity entry.
980 * @param h global fs handle
981 * @param ssf suspend signal function to use
982 * @param ssf_cls closure for ssf
983 * @return fresh top-level activity handle
985 struct TopLevelActivity *
986 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, SuspendSignalFunction ssf,
991 * Destroy a top-level activity entry.
993 * @param h global fs handle
994 * @param top top level activity entry
997 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top);
1002 * Master context for most FS operations.
1004 struct GNUNET_FS_Handle
1007 * Configuration to use.
1009 const struct GNUNET_CONFIGURATION_Handle *cfg;
1012 * Name of our client.
1017 * Function to call with updates on our progress.
1019 GNUNET_FS_ProgressCallback upcb;
1027 * Head of DLL of top-level activities.
1029 struct TopLevelActivity *top_head;
1032 * Tail of DLL of top-level activities.
1034 struct TopLevelActivity *top_tail;
1037 * Head of DLL of running jobs.
1039 struct GNUNET_FS_QueueEntry *running_head;
1042 * Tail of DLL of running jobs.
1044 struct GNUNET_FS_QueueEntry *running_tail;
1047 * Head of DLL of pending jobs.
1049 struct GNUNET_FS_QueueEntry *pending_head;
1052 * Tail of DLL of pending jobs.
1054 struct GNUNET_FS_QueueEntry *pending_tail;
1057 * Task that processes the jobs in the running and pending queues
1058 * (and moves jobs around as needed).
1060 GNUNET_SCHEDULER_TaskIdentifier queue_job;
1063 * Average time we take for a single request to be satisfied.
1064 * FIXME: not yet calcualted properly...
1066 struct GNUNET_TIME_Relative avg_block_latency;
1069 * How many actual downloads do we have running right now?
1071 unsigned int active_downloads;
1074 * How many blocks do the active downloads have?
1076 unsigned int active_blocks;
1081 enum GNUNET_FS_Flags flags;
1084 * Maximum number of parallel downloads.
1086 unsigned int max_parallel_downloads;
1089 * Maximum number of parallel requests.
1091 unsigned int max_parallel_requests;
1097 * Handle for controlling a publication process.
1099 struct GNUNET_FS_PublishContext
1102 * Handle to the global fs context.
1104 struct GNUNET_FS_Handle *h;
1107 * Our top-level activity entry (if we are top-level, otherwise NULL).
1109 struct TopLevelActivity *top;
1112 * File-structure that is being shared.
1114 struct GNUNET_FS_FileInformation *fi;
1117 * Namespace that we are publishing in, NULL if we have no namespace.
1119 struct GNUNET_FS_Namespace *namespace;
1122 * ID of the content in the namespace, NULL if we have no namespace.
1127 * ID for future updates, NULL if we have no namespace or no updates.
1132 * Filename used for serializing information about this operation
1133 * (should be determined using 'mktemp').
1135 char *serialization;
1138 * Our own client handle for the FS service; only briefly used when
1139 * we start to index a file, otherwise NULL.
1141 struct GNUNET_CLIENT_Connection *client;
1144 * Current position in the file-tree for the upload.
1146 struct GNUNET_FS_FileInformation *fi_pos;
1149 * Non-null if we are currently hashing a file.
1151 struct GNUNET_CRYPTO_FileHashContext *fhc;
1154 * Connection to the datastore service.
1156 struct GNUNET_DATASTORE_Handle *dsh;
1159 * Queue entry for reservation/unreservation.
1161 struct GNUNET_DATASTORE_QueueEntry *qre;
1164 * ID of the task performing the upload. NO_TASK if the upload has
1167 GNUNET_SCHEDULER_TaskIdentifier upload_task;
1170 * Storage space to reserve for the operation.
1172 uint64_t reserve_space;
1175 * Overall number of entries to reserve for the
1176 * publish operation.
1178 uint32_t reserve_entries;
1181 * Typically GNUNET_NO. Set to GNUNET_YES if "upload_task" is
1182 * GNUNET_SCHEDULER_NO_TASK and we're waiting for a response from
1183 * the datastore service (in which case this struct must not be
1184 * freed until we have that response). If someone tries to stop the
1185 * download for good during this period, "in_network_wait" is set to
1186 * GNUNET_SYSERR which will cause the struct to be destroyed right
1187 * after we have the reply (or timeout) from the datastore service.
1189 int in_network_wait;
1192 * Options for publishing.
1194 enum GNUNET_FS_PublishOptions options;
1197 * Space reservation ID with datastore service
1203 * Set to GNUNET_YES if all processing has completed.
1210 * Phases of unindex processing (state machine).
1215 * We're currently hashing the file.
1217 UNINDEX_STATE_HASHING = 0,
1220 * We're telling the datastore to delete
1221 * the respective entries.
1223 UNINDEX_STATE_DS_REMOVE = 1,
1226 * We're notifying the FS service about
1229 UNINDEX_STATE_FS_NOTIFY = 2,
1234 UNINDEX_STATE_COMPLETE = 3,
1237 * We've encountered a fatal error.
1239 UNINDEX_STATE_ERROR = 4
1244 * Handle for controlling an unindexing operation.
1246 struct GNUNET_FS_UnindexContext
1250 * Global FS context.
1252 struct GNUNET_FS_Handle *h;
1255 * Our top-level activity entry.
1257 struct TopLevelActivity *top;
1260 * Name of the file that we are unindexing.
1265 * Short name under which we are serializing the state of this operation.
1267 char *serialization;
1270 * Connection to the FS service, only valid during the
1271 * UNINDEX_STATE_FS_NOTIFY phase.
1273 struct GNUNET_CLIENT_Connection *client;
1276 * Connection to the datastore service, only valid during the
1277 * UNINDEX_STATE_DS_NOTIFY phase.
1279 struct GNUNET_DATASTORE_Handle *dsh;
1282 * Pointer kept for the client.
1287 * Merkle-ish tree encoder context.
1289 struct GNUNET_FS_TreeEncoder *tc;
1292 * Handle used to read the file.
1294 struct GNUNET_DISK_FileHandle *fh;
1297 * Error message, NULL on success.
1302 * Context for hashing of the file.
1304 struct GNUNET_CRYPTO_FileHashContext *fhc;
1307 * Overall size of the file.
1312 * When did we start?
1314 struct GNUNET_TIME_Absolute start_time;
1317 * Hash of the file's contents (once computed).
1319 GNUNET_HashCode file_id;
1322 * Current operatinonal phase.
1324 enum UnindexState state;
1330 * Information we keep for each keyword in
1333 struct SearchRequestEntry
1336 * Hash of the original keyword, also known as the
1337 * key (for decrypting the KBlock).
1339 GNUNET_HashCode key;
1342 * Hash of the public key, also known as the query.
1344 GNUNET_HashCode query;
1347 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1348 * was found under this keyword. Note that the entries will point
1349 * to the same locations as those in the master result map (in
1350 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1351 * The key for each entry is the XOR of the key and query in the CHK
1352 * URI (as a unique identifier for the search result).
1354 struct GNUNET_CONTAINER_MultiHashMap *results;
1357 * Is this keyword a mandatory keyword
1358 * (started with '+')?
1366 * Handle for controlling a search.
1368 struct GNUNET_FS_SearchContext
1371 * Handle to the global FS context.
1373 struct GNUNET_FS_Handle *h;
1376 * Our top-level activity entry (if we are top-level, otherwise NULL).
1378 struct TopLevelActivity *top;
1381 * List of keywords that we're looking for.
1383 struct GNUNET_FS_Uri *uri;
1386 * For update-searches, link to the search result that triggered
1387 * the update search; otherwise NULL.
1389 struct GNUNET_FS_SearchResult *psearch_result;
1392 * Connection to the FS service.
1394 struct GNUNET_CLIENT_Connection *client;
1397 * Pointer we keep for the client.
1402 * Name of the file on disk we use for persistence.
1404 char *serialization;
1407 * Error message (non-NULL if this operation failed).
1412 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1413 * was found in the search. The key for each entry is the XOR of
1414 * the key and query in the CHK URI (as a unique identifier for the
1417 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1420 * Per-keyword information for a keyword search. This array will
1421 * have exactly as many entries as there were keywords.
1423 struct SearchRequestEntry *requests;
1426 * When did we start?
1428 struct GNUNET_TIME_Absolute start_time;
1431 * ID of a task that is using this struct and that must be cancelled
1432 * when the search is being stopped (if not
1433 * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
1434 * artificial delay when trying to reconnect to the FS service.
1436 GNUNET_SCHEDULER_TaskIdentifier task;
1439 * How many of the entries in the search request
1440 * map have been passed to the service so far?
1442 unsigned int search_request_map_offset;
1445 * How many of the keywords in the KSK
1446 * map have been passed to the service so far?
1448 unsigned int keyword_offset;
1451 * Anonymity level for the search.
1456 * Number of mandatory keywords in this query.
1458 uint32_t mandatory_count;
1461 * Options for the search.
1463 enum GNUNET_FS_SearchOptions options;
1468 * FSM for possible states a block can go through. The typical
1469 * order of progression is linear through the states, alternatives
1470 * are documented in the comments.
1472 enum BlockRequestState
1475 * Initial state, block has only been allocated (since it is
1476 * relevant to the overall download request).
1481 * We've checked the block on the path down the tree, and the
1482 * content on disk did match the desired CHK, but not all
1483 * the way down, so at the bottom some blocks will still
1484 * need to be reconstructed).
1486 BRS_RECONSTRUCT_DOWN = 1,
1489 * We've calculated the CHK bottom-up based on the meta data.
1490 * This may work, but if it did we have to write the meta data to
1491 * disk at the end (and we still need to check against the
1494 BRS_RECONSTRUCT_META_UP = 2,
1497 * We've calculated the CHK bottom-up based on what we have on
1498 * disk, which may not be what the desired CHK is. If the
1499 * reconstructed CHKs match whatever comes from above, we're
1500 * done with the respective subtree.
1502 BRS_RECONSTRUCT_UP = 3,
1505 * We've determined the real, desired CHK for this block
1506 * (full tree reconstruction failed), request is now pending.
1507 * If the CHK that bubbled up through reconstruction did match
1508 * the top-level request, the state machine for the subtree
1509 * would have moved to BRS_DOWNLOAD_UP.
1514 * We've successfully downloaded this block, but the children
1515 * still need to be either downloaded or verified (download
1516 * request propagates down). If the download fails, the
1517 * state machine for this block may move to
1518 * BRS_DOWNLOAD_ERROR instead.
1520 BRS_DOWNLOAD_DOWN = 5,
1523 * This block and all of its children have been downloaded
1524 * successfully (full completion propagates up).
1526 BRS_DOWNLOAD_UP = 6,
1529 * We got a block back that matched the query but did not hash to
1530 * the key (malicious publisher or hash collision); this block
1531 * can never be downloaded (error propagates up).
1538 * Information about an active download request.
1540 struct DownloadRequest
1543 * While pending, we keep all download requests in a doubly-linked list.
1545 struct DownloadRequest *next;
1548 * While pending, we keep all download requests in a doubly-linked list.
1550 struct DownloadRequest *prev;
1553 * Parent in the CHK-tree.
1555 struct DownloadRequest *parent;
1558 * Array (!) of child-requests, or NULL for the bottom of the tree.
1560 struct DownloadRequest **children;
1563 * CHK for the request for this block (set during reconstruction
1564 * to what we have on disk, later to what we want to have).
1566 struct ContentHashKey chk;
1569 * Offset of the corresponding block. Specifically, first (!) byte of
1570 * the first DBLOCK in the subtree induced by block represented by
1576 * Number of entries in 'children' array.
1578 unsigned int num_children;
1581 * Depth of the corresponding block in the tree. 0==DBLOCKs.
1588 enum BlockRequestState state;
1591 * GNUNET_YES if this entry is in the pending list.
1599 * (recursively) free download request structure
1601 * @param dr request to free
1604 GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
1608 * Context for controlling a download.
1610 struct GNUNET_FS_DownloadContext
1614 * Global FS context.
1616 struct GNUNET_FS_Handle *h;
1619 * Our top-level activity entry (if we are top-level, otherwise NULL).
1621 struct TopLevelActivity *top;
1624 * Connection to the FS service.
1626 struct GNUNET_CLIENT_Connection *client;
1629 * Parent download (used when downloading files
1632 struct GNUNET_FS_DownloadContext *parent;
1635 * Associated search (used when downloading files
1636 * based on search results), or NULL for none.
1638 struct GNUNET_FS_SearchResult *search;
1641 * Head of list of child downloads.
1643 struct GNUNET_FS_DownloadContext *child_head;
1646 * Tail of list of child downloads.
1648 struct GNUNET_FS_DownloadContext *child_tail;
1651 * Previous download belonging to the same parent.
1653 struct GNUNET_FS_DownloadContext *prev;
1656 * Next download belonging to the same parent.
1658 struct GNUNET_FS_DownloadContext *next;
1661 * Context kept for the client.
1666 * URI that identifies the file that we are downloading.
1668 struct GNUNET_FS_Uri *uri;
1671 * Known meta-data for the file (can be NULL).
1673 struct GNUNET_CONTAINER_MetaData *meta;
1676 * Error message, NULL if we're doing OK.
1681 * Random portion of filename we use for syncing state of this
1684 char *serialization;
1687 * Where are we writing the data (name of the
1688 * file, can be NULL!).
1693 * Where are we writing the data temporarily (name of the
1694 * file, can be NULL!); used if we do not have a permanent
1695 * name and we are a directory and we do a recursive download.
1697 char *temp_filename;
1700 * Our entry in the job queue.
1702 struct GNUNET_FS_QueueEntry *job_queue;
1705 * Non-NULL if we are currently having a request for
1706 * transmission pending with the client handle.
1708 struct GNUNET_CLIENT_TransmitHandle *th;
1711 * Tree encoder used for the reconstruction.
1713 struct GNUNET_FS_TreeEncoder *te;
1716 * File handle for reading data from an existing file
1717 * (to pass to tree encoder).
1719 struct GNUNET_DISK_FileHandle *rfh;
1722 * Map of active requests (those waiting for a response). The key
1723 * is the hash of the encryped block (aka query).
1725 struct GNUNET_CONTAINER_MultiHashMap *active;
1728 * Head of linked list of pending requests.
1730 struct DownloadRequest *pending_head;
1733 * Head of linked list of pending requests.
1735 struct DownloadRequest *pending_tail;
1738 * Top-level download request.
1740 struct DownloadRequest *top_request;
1743 * Identity of the peer having the content, or all-zeros
1744 * if we don't know of such a peer.
1746 struct GNUNET_PeerIdentity target;
1749 * ID of a task that is using this struct and that must be cancelled
1750 * when the download is being stopped (if not
1751 * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
1752 * artificial delay when trying to reconnect to the FS service or
1753 * the task processing incrementally the data on disk, or the
1754 * task requesting blocks, etc.
1756 GNUNET_SCHEDULER_TaskIdentifier task;
1759 * What is the first offset that we're interested
1765 * How many bytes starting from offset are desired?
1766 * This is NOT the overall length of the file!
1771 * How many bytes have we already received within
1772 * the specified range (DBlocks only).
1777 * What was the size of the file on disk that we're downloading
1778 * before we started? Used to detect if there is a point in
1779 * checking an existing block on disk for matching the desired
1780 * content. 0 if the file did not exist already.
1782 uint64_t old_file_size;
1785 * Time download was started.
1787 struct GNUNET_TIME_Absolute start_time;
1790 * Desired level of anonymity.
1795 * The depth of the file-tree.
1797 unsigned int treedepth;
1800 * Options for the download.
1802 enum GNUNET_FS_DownloadOptions options;
1805 * Flag set upon transitive completion (includes child downloads).
1806 * This flag is only set to GNUNET_YES for directories where all
1807 * child-downloads have also completed (and signalled completion).
1812 * Have we started the receive continuation yet?
1820 * Information about an (updateable) node in the
1823 struct NamespaceUpdateNode
1826 * Identifier for this node.
1831 * Identifier of children of this node.
1836 * Metadata for this entry.
1838 struct GNUNET_CONTAINER_MetaData *md;
1841 * URI of this entry in the namespace.
1843 struct GNUNET_FS_Uri *uri;
1846 * Namespace update generation ID. Used to ensure
1847 * freshness of the tree_id.
1852 * TREE this entry belongs to (if nug is current).
1854 unsigned int tree_id;
1859 struct GNUNET_FS_Namespace
1863 * Handle to the FS service context.
1865 struct GNUNET_FS_Handle *h;
1868 * Array with information about nodes in the namespace.
1870 struct NamespaceUpdateNode **update_nodes;
1873 * Private key for the namespace.
1875 struct GNUNET_CRYPTO_RsaPrivateKey *key;
1878 * Hash map mapping identifiers of update nodes
1879 * to the update nodes (initialized on-demand).
1881 struct GNUNET_CONTAINER_MultiHashMap *update_map;
1884 * Name of the file with the private key.
1889 * Name of the namespace.
1894 * Size of the update nodes array.
1896 unsigned int update_node_count;
1899 * Reference counter.
1904 * Generator for unique nug numbers.
1906 unsigned int nug_gen;
1912 /* end of fs_api.h */