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_EccPublicKeyBinaryEncoded 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_EccSignature contentSignature;
146 enum GNUNET_FS_UriType
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).
171 * A Universal Resource Identifier (URI), opaque.
178 enum GNUNET_FS_UriType type;
185 * Keywords start with a '+' if they are
186 * mandatory (in which case the '+' is NOT
187 * part of the keyword) and with a
188 * simple space if they are optional
189 * (in which case the space is ALSO not
190 * part of the actual keyword).
192 * Double-quotes to protect spaces and
193 * %-encoding are NOT used internally
194 * (only in URI-strings).
199 * Size of the keywords array.
201 unsigned int keywordCount;
207 * Hash of the public key for the namespace.
209 struct GNUNET_HashCode ns;
212 * Human-readable identifier chosen for this
213 * entry in the namespace.
219 * Information needed to retrieve a file (content-hash-key
222 struct FileIdentifier chk;
225 * Information needed to retrieve a file including signed
226 * location (identity of a peer) of the content.
235 * Information for a file or directory that is
236 * about to be published.
238 struct GNUNET_FS_FileInformation
242 * Files in a directory are kept as a linked list.
244 struct GNUNET_FS_FileInformation *next;
247 * If this is a file in a directory, "dir" refers to
248 * the directory; otherwise NULL.
250 struct GNUNET_FS_FileInformation *dir;
253 * Handle to the master context.
255 struct GNUNET_FS_Handle *h;
258 * Pointer kept for the client.
263 * Metadata to use for the file.
265 struct GNUNET_CONTAINER_MetaData *meta;
268 * Keywords to use for KBlocks.
270 struct GNUNET_FS_Uri *keywords;
273 * CHK for this file or directory. NULL if
274 * we have not yet computed it.
276 struct GNUNET_FS_Uri *chk_uri;
279 * Block options for the file.
281 struct GNUNET_FS_BlockOptions bo;
284 * At what time did we start this upload?
286 struct GNUNET_TIME_Absolute start_time;
289 * Under what filename is this struct serialized
290 * (for operational persistence). Should be determined
296 * Encoder being used to publish this file.
298 struct GNUNET_FS_TreeEncoder *te;
301 * Error message (non-NULL if this operation failed).
306 * Name of the file or directory (must be an absolute path).
311 * Data describing either the file or the directory.
323 * Function that can be used to read the data for the file.
325 GNUNET_FS_DataReader reader;
328 * Closure for reader.
333 * If this file is being indexed, this value is set to the hash
334 * over the entire file (when the indexing process is started).
335 * Otherwise this field is not used.
337 struct GNUNET_HashCode file_id;
340 * Size of the file (in bytes).
345 * Should the file be indexed or inserted?
350 * Is "file_id" already valid? Set to GNUNET_YES once the hash
351 * has been calculated.
356 * Has the service confirmed our INDEX_START request?
357 * GNUNET_YES if this step has been completed.
359 int index_start_confirmed;
364 * Data for a directory.
370 * Linked list of entries in the directory.
372 struct GNUNET_FS_FileInformation *entries;
375 * Size of the directory itself (in bytes); 0 if the
376 * size has not yet been calculated.
381 * Pointer to the data for the directory (or NULL if not
391 * Is this struct for a file or directory?
396 * Are we done publishing this file?
404 * The job is now ready to run and should use the given client
405 * handle to communicate with the FS service.
408 * @param client handle to use for FS communication
410 typedef void (*GNUNET_FS_QueueStart) (void *cls,
411 struct GNUNET_CLIENT_Connection * client);
415 * The job must now stop to run and should destry the client handle as
416 * soon as possible (ideally prior to returning).
418 typedef void (*GNUNET_FS_QueueStop) (void *cls);
423 * Priorities for the queue.
425 enum GNUNET_FS_QueuePriority
428 * This is a probe (low priority).
430 GNUNET_FS_QUEUE_PRIORITY_PROBE,
435 GNUNET_FS_QUEUE_PRIORITY_NORMAL
440 * Entry in the job queue.
442 struct GNUNET_FS_QueueEntry
445 * This is a linked list.
447 struct GNUNET_FS_QueueEntry *next;
450 * This is a linked list.
452 struct GNUNET_FS_QueueEntry *prev;
455 * Function to call when the job is started.
457 GNUNET_FS_QueueStart start;
460 * Function to call when the job needs to stop (or is done / dequeued).
462 GNUNET_FS_QueueStop stop;
465 * Closure for start and stop.
470 * Handle to FS primary context.
472 struct GNUNET_FS_Handle *h;
475 * Client handle, or NULL if job is not running.
477 struct GNUNET_CLIENT_Connection *client;
480 * Time the job was originally queued.
482 struct GNUNET_TIME_Absolute queue_time;
485 * Time the job was started last.
487 struct GNUNET_TIME_Absolute start_time;
490 * Total amount of time the job has been running (except for the
493 struct GNUNET_TIME_Relative run_time;
496 * How many blocks do the active downloads have?
501 * How important is this download?
503 enum GNUNET_FS_QueuePriority priority;
506 * How often have we (re)started this download?
508 unsigned int start_times;
516 * Information we store for each search result.
518 struct GNUNET_FS_SearchResult
522 * Search context this result belongs to.
524 struct GNUNET_FS_SearchContext *sc;
527 * URI to which this search result refers to.
529 struct GNUNET_FS_Uri *uri;
532 * Metadata for the search result.
534 struct GNUNET_CONTAINER_MetaData *meta;
537 * Client info for this search result.
542 * ID of a job that is currently probing this results' availability
543 * (NULL if we are not currently probing).
545 struct GNUNET_FS_DownloadContext *probe_ctx;
548 * ID of an associated download based on this search result (or
551 struct GNUNET_FS_DownloadContext *download;
554 * If this search result triggered an update search, this field
555 * links to the update search.
557 struct GNUNET_FS_SearchContext *update_search;
560 * Name under which this search result is stored on disk.
565 * Bitmap that specifies precisely which keywords have been matched already.
567 uint8_t *keyword_bitmap;
570 * Key for the search result
572 struct GNUNET_HashCode key;
575 * ID of the task that will clean up the probe_ctx should it not
576 * complete on time (and that will need to be cancelled if we clean
577 * up the search result before then).
579 GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
582 * Task we use to report periodically to the application that the
583 * probe is still running.
585 GNUNET_SCHEDULER_TaskIdentifier probe_ping_task;
588 * When did the current probe become active?
590 struct GNUNET_TIME_Absolute probe_active_time;
593 * How much longer should we run the current probe before giving up?
595 struct GNUNET_TIME_Relative remaining_probe_time;
598 * Number of mandatory keywords for which we have NOT yet found the
599 * search result; when this value hits zero, the search result is
600 * given to the callback.
602 uint32_t mandatory_missing;
605 * Number of optional keywords under which this result was also
608 uint32_t optional_support;
611 * Number of availability tests that have succeeded for this result.
613 uint32_t availability_success;
616 * Number of availability trials that we have performed for this
619 uint32_t availability_trials;
625 * Add a job to the queue.
627 * @param h handle to the overall FS state
628 * @param start function to call to begin the job
629 * @param stop function to call to pause the job, or on dequeue (if the job was running)
630 * @param cls closure for start and stop
631 * @param blocks number of blocks this download has
632 * @param priority how important is this download
633 * @return queue handle
635 struct GNUNET_FS_QueueEntry *
636 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, GNUNET_FS_QueueStart start,
637 GNUNET_FS_QueueStop stop, void *cls, unsigned int blocks,
638 enum GNUNET_FS_QueuePriority priority);
642 * Dequeue a job from the queue.
644 * @param qe handle for the job
647 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe);
651 * Function that provides data by reading from a file.
653 * @param cls closure (points to the file information)
654 * @param offset offset to read from; it is possible
655 * that the caller might need to go backwards
657 * @param max maximum number of bytes that should be
658 * copied to buf; readers are not allowed
659 * to provide less data unless there is an error;
660 * a value of "0" will be used at the end to allow
661 * the reader to clean up its internal state
662 * @param buf where the reader should write the data
663 * @param emsg location for the reader to store an error message
664 * @return number of bytes written, usually "max", 0 on error
667 GNUNET_FS_data_reader_file_ (void *cls, uint64_t offset, size_t max, void *buf,
672 * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
674 * @param filename file to read
675 * @return closure to use
678 GNUNET_FS_make_file_reader_context_ (const char *filename);
683 * Function that provides data by copying from a buffer.
685 * @param cls closure (points to the buffer)
686 * @param offset offset to read from; it is possible
687 * that the caller might need to go backwards
689 * @param max maximum number of bytes that should be
690 * copied to buf; readers are not allowed
691 * to provide less data unless there is an error;
692 * a value of "0" will be used at the end to allow
693 * the reader to clean up its internal state
694 * @param buf where the reader should write the data
695 * @param emsg location for the reader to store an error message
696 * @return number of bytes written, usually "max", 0 on error
699 GNUNET_FS_data_reader_copy_ (void *cls, uint64_t offset, size_t max, void *buf,
703 * Notification of FS that a search probe has made progress.
704 * This function is used INSTEAD of the client's event handler
705 * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
707 * @param cls closure, always NULL (!), actual closure
708 * is in the client-context of the info struct
709 * @param info details about the event, specifying the event type
710 * and various bits about the event
711 * @return client-context (for the next progress call
712 * for this operation; should be set to NULL for
713 * SUSPEND and STOPPED events). The value returned
714 * will be passed to future callbacks in the respective
715 * field in the GNUNET_FS_ProgressInfo struct.
718 GNUNET_FS_search_probe_progress_ (void *cls,
719 const struct GNUNET_FS_ProgressInfo *info);
723 * Main function that performs the upload.
725 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
726 * @param tc task context
729 GNUNET_FS_publish_main_ (void *cls,
730 const struct GNUNET_SCHEDULER_TaskContext *tc);
734 * Function called once the hash of the file
735 * that is being unindexed has been computed.
737 * @param cls closure, unindex context
738 * @param file_id computed hash, NULL on error
741 GNUNET_FS_unindex_process_hash_ (void *cls, const struct GNUNET_HashCode * file_id);
745 * Extract the keywords for KBlock removal
747 * @param uc context for the unindex operation.
750 GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc);
754 * If necessary, connect to the datastore and remove the KBlocks.
756 * @param uc context for the unindex operation.
759 GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc);
763 * Fill in all of the generic fields for a publish event and call the
766 * @param pi structure to fill in
767 * @param pc overall publishing context
768 * @param p file information for the file being published
769 * @param offset where in the file are we so far
770 * @return value returned from callback
773 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
774 struct GNUNET_FS_PublishContext *pc,
775 const struct GNUNET_FS_FileInformation *p,
780 * Fill in all of the generic fields for a download event and call the
783 * @param pi structure to fill in
784 * @param dc overall download context
787 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
788 struct GNUNET_FS_DownloadContext *dc);
792 * Task that creates the initial (top-level) download
793 * request for the file.
795 * @param cls the 'struct GNUNET_FS_DownloadContext'
796 * @param tc scheduler context
799 GNUNET_FS_download_start_task_ (void *cls,
800 const struct GNUNET_SCHEDULER_TaskContext *tc);
805 * Fill in all of the generic fields for
806 * an unindex event and call the callback.
808 * @param pi structure to fill in
809 * @param uc overall unindex context
810 * @param offset where we are in the file (for progress)
813 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
814 struct GNUNET_FS_UnindexContext *uc,
818 * Fill in all of the generic fields for a search event and
821 * @param pi structure to fill in
822 * @param sc overall search context
823 * @return value returned by the callback
826 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
827 struct GNUNET_FS_SearchContext *sc);
831 * Connect to the datastore and remove the blocks.
833 * @param uc context for the unindex operation.
836 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
839 * Build the request and actually initiate the search using the
842 * @param sc search context
843 * @return GNUNET_OK on success, GNUNET_SYSERR on error
846 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
849 * Start the downloading process (by entering the queue).
851 * @param dc our download context
854 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
858 * Start download probes for the given search result.
860 * @param sr the search result
863 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
866 * Remove serialization/deserialization file from disk.
868 * @param h master context
869 * @param ext component of the path
870 * @param ent entity identifier
873 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, const char *ext,
878 * Remove serialization/deserialization directory from disk.
880 * @param h master context
881 * @param ext component of the path
882 * @param uni unique name of parent
885 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, const char *ext,
890 * Synchronize this file-information struct with its mirror
891 * on disk. Note that all internal FS-operations that change
892 * file information data should already call "sync" internally,
893 * so this function is likely not useful for clients.
895 * @param fi the struct to sync
898 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
901 * Synchronize this publishing struct with its mirror
902 * on disk. Note that all internal FS-operations that change
903 * publishing structs should already call "sync" internally,
904 * so this function is likely not useful for clients.
906 * @param pc the struct to sync
909 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
912 * Synchronize this unindex struct with its mirror
913 * on disk. Note that all internal FS-operations that change
914 * publishing structs should already call "sync" internally,
915 * so this function is likely not useful for clients.
917 * @param uc the struct to sync
920 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
923 * Synchronize this search struct with its mirror
924 * on disk. Note that all internal FS-operations that change
925 * publishing structs should already call "sync" internally,
926 * so this function is likely not useful for clients.
928 * @param sc the struct to sync
931 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
934 * Synchronize this search result 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 sr the struct to sync
942 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
945 * Synchronize this download struct with its mirror
946 * on disk. Note that all internal FS-operations that change
947 * publishing structs should already call "sync" internally,
948 * so this function is likely not useful for clients.
950 * @param dc the struct to sync
953 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
956 * Create SUSPEND event for the given publish operation
957 * and then clean up our state (without stop signal).
959 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
962 GNUNET_FS_publish_signal_suspend_ (void *cls);
965 * Create SUSPEND event for the given search operation
966 * and then clean up our state (without stop signal).
968 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
971 GNUNET_FS_search_signal_suspend_ (void *cls);
974 * Create SUSPEND event for the given download operation
975 * and then clean up our state (without stop signal).
977 * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
980 GNUNET_FS_download_signal_suspend_ (void *cls);
983 * Create SUSPEND event for the given unindex operation
984 * and then clean up our state (without stop signal).
986 * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
989 GNUNET_FS_unindex_signal_suspend_ (void *cls);
992 * Function signature of the functions that can be called
993 * to trigger suspend signals and clean-up for top-level
998 typedef void (*SuspendSignalFunction) (void *cls);
1001 * We track all of the top-level activities of FS
1002 * so that we can signal 'suspend' on shutdown.
1004 struct TopLevelActivity
1007 * This is a doubly-linked list.
1009 struct TopLevelActivity *next;
1012 * This is a doubly-linked list.
1014 struct TopLevelActivity *prev;
1017 * Function to call for suspend-signalling and clean up.
1019 SuspendSignalFunction ssf;
1022 * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1029 * Create a top-level activity entry.
1031 * @param h global fs handle
1032 * @param ssf suspend signal function to use
1033 * @param ssf_cls closure for ssf
1034 * @return fresh top-level activity handle
1036 struct TopLevelActivity *
1037 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, SuspendSignalFunction ssf,
1042 * Destroy a top-level activity entry.
1044 * @param h global fs handle
1045 * @param top top level activity entry
1048 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top);
1053 * Master context for most FS operations.
1055 struct GNUNET_FS_Handle
1058 * Configuration to use.
1060 const struct GNUNET_CONFIGURATION_Handle *cfg;
1063 * Name of our client.
1068 * Function to call with updates on our progress.
1070 GNUNET_FS_ProgressCallback upcb;
1078 * Head of DLL of top-level activities.
1080 struct TopLevelActivity *top_head;
1083 * Tail of DLL of top-level activities.
1085 struct TopLevelActivity *top_tail;
1088 * Head of DLL of running jobs.
1090 struct GNUNET_FS_QueueEntry *running_head;
1093 * Tail of DLL of running jobs.
1095 struct GNUNET_FS_QueueEntry *running_tail;
1098 * Head of DLL of pending jobs.
1100 struct GNUNET_FS_QueueEntry *pending_head;
1103 * Tail of DLL of pending jobs.
1105 struct GNUNET_FS_QueueEntry *pending_tail;
1108 * Task that processes the jobs in the running and pending queues
1109 * (and moves jobs around as needed).
1111 GNUNET_SCHEDULER_TaskIdentifier queue_job;
1114 * Average time we take for a single request to be satisfied.
1115 * FIXME: not yet calcualted properly...
1117 struct GNUNET_TIME_Relative avg_block_latency;
1120 * How many actual downloads do we have running right now?
1122 unsigned int active_downloads;
1125 * How many blocks do the active downloads have?
1127 unsigned int active_blocks;
1132 enum GNUNET_FS_Flags flags;
1135 * Maximum number of parallel downloads.
1137 unsigned int max_parallel_downloads;
1140 * Maximum number of parallel requests.
1142 unsigned int max_parallel_requests;
1148 * Handle for controlling a publication process.
1150 struct GNUNET_FS_PublishContext
1153 * Handle to the global fs context.
1155 struct GNUNET_FS_Handle *h;
1158 * Our top-level activity entry (if we are top-level, otherwise NULL).
1160 struct TopLevelActivity *top;
1163 * File-structure that is being shared.
1165 struct GNUNET_FS_FileInformation *fi;
1168 * Namespace that we are publishing in, NULL if we have no namespace.
1170 struct GNUNET_FS_Namespace *ns;
1173 * ID of the content in the namespace, NULL if we have no namespace.
1178 * ID for future updates, NULL if we have no namespace or no updates.
1183 * Filename used for serializing information about this operation
1184 * (should be determined using 'mktemp').
1186 char *serialization;
1189 * Our own client handle for the FS service; only briefly used when
1190 * we start to index a file, otherwise NULL.
1192 struct GNUNET_CLIENT_Connection *client;
1195 * Current position in the file-tree for the upload.
1197 struct GNUNET_FS_FileInformation *fi_pos;
1200 * Non-null if we are currently hashing a file.
1202 struct GNUNET_CRYPTO_FileHashContext *fhc;
1205 * Connection to the datastore service.
1207 struct GNUNET_DATASTORE_Handle *dsh;
1210 * Queue entry for reservation/unreservation.
1212 struct GNUNET_DATASTORE_QueueEntry *qre;
1215 * Context for SKS publishing operation that is part of this publishing operation
1216 * (NULL if not active).
1218 struct GNUNET_FS_PublishSksContext *sks_pc;
1221 * Context for KSK publishing operation that is part of this publishing operation
1222 * (NULL if not active).
1224 struct GNUNET_FS_PublishKskContext *ksk_pc;
1227 * ID of the task performing the upload. NO_TASK if the upload has
1230 GNUNET_SCHEDULER_TaskIdentifier upload_task;
1233 * Storage space to reserve for the operation.
1235 uint64_t reserve_space;
1238 * Overall number of entries to reserve for the
1239 * publish operation.
1241 uint32_t reserve_entries;
1244 * Options for publishing.
1246 enum GNUNET_FS_PublishOptions options;
1249 * Space reservation ID with datastore service
1255 * Set to GNUNET_YES if all processing has completed.
1260 * Flag set to GNUNET_YES if the next callback from
1261 * GNUNET_FS_file_information_inspect should be skipped because it
1262 * is for the directory which was already processed with the parent.
1264 int skip_next_fi_callback;
1269 * Phases of unindex processing (state machine).
1274 * We're currently hashing the file.
1276 UNINDEX_STATE_HASHING = 0,
1279 * We're telling the datastore to delete
1280 * the respective DBlocks and IBlocks.
1282 UNINDEX_STATE_DS_REMOVE = 1,
1285 * Find out which keywords apply.
1287 UNINDEX_STATE_EXTRACT_KEYWORDS = 2,
1290 * We're telling the datastore to remove KBlocks.
1292 UNINDEX_STATE_DS_REMOVE_KBLOCKS = 3,
1295 * We're notifying the FS service about
1298 UNINDEX_STATE_FS_NOTIFY = 4,
1303 UNINDEX_STATE_COMPLETE = 5,
1306 * We've encountered a fatal error.
1308 UNINDEX_STATE_ERROR = 6
1313 * Handle for controlling an unindexing operation.
1315 struct GNUNET_FS_UnindexContext
1319 * The content hash key of the last block we processed, will in the
1320 * end be set to the CHK from the URI. Used to remove the KBlocks.
1322 struct ContentHashKey chk;
1325 * Global FS context.
1327 struct GNUNET_FS_Handle *h;
1330 * Our top-level activity entry.
1332 struct TopLevelActivity *top;
1335 * Directory scanner to find keywords (KBlock removal).
1337 struct GNUNET_FS_DirScanner *dscan;
1340 * Keywords found (telling us which KBlocks to remove).
1342 struct GNUNET_FS_Uri *ksk_uri;
1345 * Current offset in KSK removal.
1347 uint32_t ksk_offset;
1350 * Name of the file that we are unindexing.
1355 * Short name under which we are serializing the state of this operation.
1357 char *serialization;
1360 * Connection to the FS service, only valid during the
1361 * UNINDEX_STATE_FS_NOTIFY phase.
1363 struct GNUNET_CLIENT_Connection *client;
1366 * Connection to the datastore service, only valid during the
1367 * UNINDEX_STATE_DS_NOTIFY phase.
1369 struct GNUNET_DATASTORE_Handle *dsh;
1372 * Pointer kept for the client.
1377 * Merkle-ish tree encoder context.
1379 struct GNUNET_FS_TreeEncoder *tc;
1382 * Handle used to read the file.
1384 struct GNUNET_DISK_FileHandle *fh;
1387 * Handle to datastore 'get_key' operation issued for
1388 * obtaining KBlocks.
1390 struct GNUNET_DATASTORE_QueueEntry *dqe;
1393 * Current key for decrypting KBLocks from 'get_key' operation.
1395 struct GNUNET_HashCode key;
1398 * Current query of 'get_key' operation.
1400 struct GNUNET_HashCode query;
1403 * First content UID, 0 for none.
1408 * Error message, NULL on success.
1413 * Context for hashing of the file.
1415 struct GNUNET_CRYPTO_FileHashContext *fhc;
1418 * Overall size of the file.
1423 * Random offset given to 'GNUNET_DATASTORE_get_key'.
1428 * When did we start?
1430 struct GNUNET_TIME_Absolute start_time;
1433 * Hash of the file's contents (once computed).
1435 struct GNUNET_HashCode file_id;
1438 * Current operatinonal phase.
1440 enum UnindexState state;
1446 * Information we keep for each keyword in
1449 struct SearchRequestEntry
1452 * Hash of the original keyword, also known as the
1453 * key (for decrypting the KBlock).
1455 struct GNUNET_HashCode key;
1458 * Hash of the public key, also known as the query.
1460 struct GNUNET_HashCode query;
1463 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1464 * was found under this keyword. Note that the entries will point
1465 * to the same locations as those in the master result map (in
1466 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1467 * The key for each entry is the XOR of the key and query in the CHK
1468 * URI (as a unique identifier for the search result).
1470 struct GNUNET_CONTAINER_MultiHashMap *results;
1473 * Is this keyword a mandatory keyword
1474 * (started with '+')?
1482 * Handle for controlling a search.
1484 struct GNUNET_FS_SearchContext
1487 * Handle to the global FS context.
1489 struct GNUNET_FS_Handle *h;
1492 * Our top-level activity entry (if we are top-level, otherwise NULL).
1494 struct TopLevelActivity *top;
1497 * List of keywords that we're looking for.
1499 struct GNUNET_FS_Uri *uri;
1502 * For update-searches, link to the search result that triggered
1503 * the update search; otherwise NULL.
1505 struct GNUNET_FS_SearchResult *psearch_result;
1508 * Connection to the FS service.
1510 struct GNUNET_CLIENT_Connection *client;
1513 * Pointer we keep for the client.
1518 * Name of the file on disk we use for persistence.
1520 char *serialization;
1523 * Error message (non-NULL if this operation failed).
1528 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1529 * was found in the search. The key for each entry is the XOR of
1530 * the key and query in the CHK URI (as a unique identifier for the
1533 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1536 * Per-keyword information for a keyword search. This array will
1537 * have exactly as many entries as there were keywords.
1539 struct SearchRequestEntry *requests;
1542 * When did we start?
1544 struct GNUNET_TIME_Absolute start_time;
1547 * How long to wait before we try to reconnect to FS service?
1549 struct GNUNET_TIME_Relative reconnect_backoff;
1552 * ID of a task that is using this struct and that must be cancelled
1553 * when the search is being stopped (if not
1554 * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
1555 * artificial delay when trying to reconnect to the FS service.
1557 GNUNET_SCHEDULER_TaskIdentifier task;
1560 * How many of the entries in the search request
1561 * map have been passed to the service so far?
1563 unsigned int search_request_map_offset;
1566 * How many of the keywords in the KSK
1567 * map have been passed to the service so far?
1569 unsigned int keyword_offset;
1572 * Anonymity level for the search.
1577 * Number of mandatory keywords in this query.
1579 uint32_t mandatory_count;
1582 * Options for the search.
1584 enum GNUNET_FS_SearchOptions options;
1589 * FSM for possible states a block can go through. The typical
1590 * order of progression is linear through the states, alternatives
1591 * are documented in the comments.
1593 enum BlockRequestState
1596 * Initial state, block has only been allocated (since it is
1597 * relevant to the overall download request).
1602 * We've checked the block on the path down the tree, and the
1603 * content on disk did match the desired CHK, but not all
1604 * the way down, so at the bottom some blocks will still
1605 * need to be reconstructed).
1607 BRS_RECONSTRUCT_DOWN = 1,
1610 * We've calculated the CHK bottom-up based on the meta data.
1611 * This may work, but if it did we have to write the meta data to
1612 * disk at the end (and we still need to check against the
1615 BRS_RECONSTRUCT_META_UP = 2,
1618 * We've calculated the CHK bottom-up based on what we have on
1619 * disk, which may not be what the desired CHK is. If the
1620 * reconstructed CHKs match whatever comes from above, we're
1621 * done with the respective subtree.
1623 BRS_RECONSTRUCT_UP = 3,
1626 * We've determined the real, desired CHK for this block
1627 * (full tree reconstruction failed), request is now pending.
1628 * If the CHK that bubbled up through reconstruction did match
1629 * the top-level request, the state machine for the subtree
1630 * would have moved to BRS_DOWNLOAD_UP.
1635 * We've successfully downloaded this block, but the children
1636 * still need to be either downloaded or verified (download
1637 * request propagates down). If the download fails, the
1638 * state machine for this block may move to
1639 * BRS_DOWNLOAD_ERROR instead.
1641 BRS_DOWNLOAD_DOWN = 5,
1644 * This block and all of its children have been downloaded
1645 * successfully (full completion propagates up).
1647 BRS_DOWNLOAD_UP = 6,
1650 * We got a block back that matched the query but did not hash to
1651 * the key (malicious publisher or hash collision); this block
1652 * can never be downloaded (error propagates up).
1659 * Information about an active download request.
1661 struct DownloadRequest
1664 * While pending, we keep all download requests in a doubly-linked list.
1666 struct DownloadRequest *next;
1669 * While pending, we keep all download requests in a doubly-linked list.
1671 struct DownloadRequest *prev;
1674 * Parent in the CHK-tree.
1676 struct DownloadRequest *parent;
1679 * Array (!) of child-requests, or NULL for the bottom of the tree.
1681 struct DownloadRequest **children;
1684 * CHK for the request for this block (set during reconstruction
1685 * to what we have on disk, later to what we want to have).
1687 struct ContentHashKey chk;
1690 * Offset of the corresponding block. Specifically, first (!) byte of
1691 * the first DBLOCK in the subtree induced by block represented by
1697 * Number of entries in 'children' array.
1699 unsigned int num_children;
1702 * Depth of the corresponding block in the tree. 0==DBLOCKs.
1707 * Offset of the CHK for this block in the parent block
1709 unsigned int chk_idx;
1714 enum BlockRequestState state;
1717 * GNUNET_YES if this entry is in the pending list.
1725 * (recursively) free download request structure
1727 * @param dr request to free
1730 GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
1734 * Context for controlling a download.
1736 struct GNUNET_FS_DownloadContext
1740 * Global FS context.
1742 struct GNUNET_FS_Handle *h;
1745 * Our top-level activity entry (if we are top-level, otherwise NULL).
1747 struct TopLevelActivity *top;
1750 * Connection to the FS service.
1752 struct GNUNET_CLIENT_Connection *client;
1755 * Parent download (used when downloading files
1758 struct GNUNET_FS_DownloadContext *parent;
1761 * Associated search (used when downloading files
1762 * based on search results), or NULL for none.
1764 struct GNUNET_FS_SearchResult *search;
1767 * Head of list of child downloads.
1769 struct GNUNET_FS_DownloadContext *child_head;
1772 * Tail of list of child downloads.
1774 struct GNUNET_FS_DownloadContext *child_tail;
1777 * Previous download belonging to the same parent.
1779 struct GNUNET_FS_DownloadContext *prev;
1782 * Next download belonging to the same parent.
1784 struct GNUNET_FS_DownloadContext *next;
1787 * Context kept for the client.
1792 * URI that identifies the file that we are downloading.
1794 struct GNUNET_FS_Uri *uri;
1797 * Known meta-data for the file (can be NULL).
1799 struct GNUNET_CONTAINER_MetaData *meta;
1802 * Error message, NULL if we're doing OK.
1807 * Random portion of filename we use for syncing state of this
1810 char *serialization;
1813 * Where are we writing the data (name of the
1814 * file, can be NULL!).
1819 * Where are we writing the data temporarily (name of the
1820 * file, can be NULL!); used if we do not have a permanent
1821 * name and we are a directory and we do a recursive download.
1823 char *temp_filename;
1826 * Our entry in the job queue.
1828 struct GNUNET_FS_QueueEntry *job_queue;
1831 * Non-NULL if we are currently having a request for
1832 * transmission pending with the client handle.
1834 struct GNUNET_CLIENT_TransmitHandle *th;
1837 * Tree encoder used for the reconstruction.
1839 struct GNUNET_FS_TreeEncoder *te;
1842 * File handle for reading data from an existing file
1843 * (to pass to tree encoder).
1845 struct GNUNET_DISK_FileHandle *rfh;
1848 * Map of active requests (those waiting for a response). The key
1849 * is the hash of the encryped block (aka query).
1851 struct GNUNET_CONTAINER_MultiHashMap *active;
1854 * Head of linked list of pending requests.
1856 struct DownloadRequest *pending_head;
1859 * Head of linked list of pending requests.
1861 struct DownloadRequest *pending_tail;
1864 * Top-level download request.
1866 struct DownloadRequest *top_request;
1869 * Identity of the peer having the content, or all-zeros
1870 * if we don't know of such a peer.
1872 struct GNUNET_PeerIdentity target;
1875 * ID of a task that is using this struct and that must be cancelled
1876 * when the download is being stopped (if not
1877 * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
1878 * artificial delay when trying to reconnect to the FS service or
1879 * the task processing incrementally the data on disk, or the
1880 * task requesting blocks, etc.
1882 GNUNET_SCHEDULER_TaskIdentifier task;
1885 * What is the first offset that we're interested
1891 * How many bytes starting from offset are desired?
1892 * This is NOT the overall length of the file!
1897 * How many bytes have we already received within
1898 * the specified range (DBlocks only).
1903 * What was the size of the file on disk that we're downloading
1904 * before we started? Used to detect if there is a point in
1905 * checking an existing block on disk for matching the desired
1906 * content. 0 if the file did not exist already.
1908 uint64_t old_file_size;
1911 * Time download was started.
1913 struct GNUNET_TIME_Absolute start_time;
1916 * How long to wait before we try to reconnect to FS service?
1918 struct GNUNET_TIME_Relative reconnect_backoff;
1921 * Desired level of anonymity.
1926 * The depth of the file-tree.
1928 unsigned int treedepth;
1931 * Options for the download.
1933 enum GNUNET_FS_DownloadOptions options;
1936 * Flag set upon transitive completion (includes child downloads).
1937 * This flag is only set to GNUNET_YES for directories where all
1938 * child-downloads have also completed (and signalled completion).
1943 * Have we started the receive continuation yet?
1948 * Are we ready to issue requests (reconstructions are finished)?
1956 * Information about an (updateable) node in the
1959 struct NamespaceUpdateNode
1962 * Identifier for this node.
1967 * Identifier of children of this node.
1972 * Metadata for this entry.
1974 struct GNUNET_CONTAINER_MetaData *md;
1977 * URI of this entry in the namespace.
1979 struct GNUNET_FS_Uri *uri;
1982 * Namespace update generation ID. Used to ensure
1983 * freshness of the tree_id.
1988 * TREE this entry belongs to (if nug is current).
1990 unsigned int tree_id;
1995 struct GNUNET_FS_Namespace
1999 * Handle to the FS service context.
2001 struct GNUNET_FS_Handle *h;
2004 * Array with information about nodes in the namespace.
2006 struct NamespaceUpdateNode **update_nodes;
2009 * Private key for the namespace.
2011 struct GNUNET_CRYPTO_RsaPrivateKey *key;
2014 * Hash map mapping identifiers of update nodes
2015 * to the update nodes (initialized on-demand).
2017 struct GNUNET_CONTAINER_MultiHashMap *update_map;
2020 * Name of the file with the private key.
2025 * Name of the namespace.
2030 * Size of the update nodes array.
2032 unsigned int update_node_count;
2035 * Reference counter.
2040 * Generator for unique nug numbers.
2042 unsigned int nug_gen;
2047 /* end of fs_api.h */