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 * Identifier of the namespace.
209 struct GNUNET_FS_PseudonymIdentifier 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;
514 * Information we store for each search result.
516 struct GNUNET_FS_SearchResult
520 * File-sharing context this result belongs to.
522 struct GNUNET_FS_Handle *h;
525 * Search context this result belongs to; can be NULL
526 * for probes that come from a directory result.
528 struct GNUNET_FS_SearchContext *sc;
531 * URI to which this search result refers to.
533 struct GNUNET_FS_Uri *uri;
536 * Metadata for the search result.
538 struct GNUNET_CONTAINER_MetaData *meta;
541 * Client info for this search result.
546 * ID of a job that is currently probing this results' availability
547 * (NULL if we are not currently probing).
549 struct GNUNET_FS_DownloadContext *probe_ctx;
552 * ID of an associated download based on this search result (or
555 struct GNUNET_FS_DownloadContext *download;
558 * If this search result triggered an update search, this field
559 * links to the update search.
561 struct GNUNET_FS_SearchContext *update_search;
564 * Name under which this search result is stored on disk.
569 * Bitmap that specifies precisely which keywords have been matched already.
571 uint8_t *keyword_bitmap;
574 * Key for the search result
576 struct GNUNET_HashCode key;
579 * ID of the task that will clean up the probe_ctx should it not
580 * complete on time (and that will need to be cancelled if we clean
581 * up the search result before then).
583 GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
586 * Task we use to report periodically to the application that the
587 * probe is still running.
589 GNUNET_SCHEDULER_TaskIdentifier probe_ping_task;
592 * When did the current probe become active?
594 struct GNUNET_TIME_Absolute probe_active_time;
597 * How much longer should we run the current probe before giving up?
599 struct GNUNET_TIME_Relative remaining_probe_time;
602 * Number of mandatory keywords for which we have NOT yet found the
603 * search result; when this value hits zero, the search result is
604 * given to the callback.
606 uint32_t mandatory_missing;
609 * Number of optional keywords under which this result was also
612 uint32_t optional_support;
615 * Number of availability tests that have succeeded for this result.
617 uint32_t availability_success;
620 * Number of availability trials that we have performed for this
623 uint32_t availability_trials;
629 * Add a job to the queue.
631 * @param h handle to the overall FS state
632 * @param start function to call to begin the job
633 * @param stop function to call to pause the job, or on dequeue (if the job was running)
634 * @param cls closure for start and stop
635 * @param blocks number of blocks this download has
636 * @param priority how important is this download
637 * @return queue handle
639 struct GNUNET_FS_QueueEntry *
640 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, GNUNET_FS_QueueStart start,
641 GNUNET_FS_QueueStop stop, void *cls, unsigned int blocks,
642 enum GNUNET_FS_QueuePriority priority);
646 * Dequeue a job from the queue.
648 * @param qe handle for the job
651 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe);
655 * Function that provides data by reading from a file.
657 * @param cls closure (points to the file information)
658 * @param offset offset to read from; it is possible
659 * that the caller might need to go backwards
661 * @param max maximum number of bytes that should be
662 * copied to buf; readers are not allowed
663 * to provide less data unless there is an error;
664 * a value of "0" will be used at the end to allow
665 * the reader to clean up its internal state
666 * @param buf where the reader should write the data
667 * @param emsg location for the reader to store an error message
668 * @return number of bytes written, usually "max", 0 on error
671 GNUNET_FS_data_reader_file_ (void *cls, uint64_t offset, size_t max, void *buf,
676 * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
678 * @param filename file to read
679 * @return closure to use
682 GNUNET_FS_make_file_reader_context_ (const char *filename);
687 * Function that provides data by copying from a buffer.
689 * @param cls closure (points to the buffer)
690 * @param offset offset to read from; it is possible
691 * that the caller might need to go backwards
693 * @param max maximum number of bytes that should be
694 * copied to buf; readers are not allowed
695 * to provide less data unless there is an error;
696 * a value of "0" will be used at the end to allow
697 * the reader to clean up its internal state
698 * @param buf where the reader should write the data
699 * @param emsg location for the reader to store an error message
700 * @return number of bytes written, usually "max", 0 on error
703 GNUNET_FS_data_reader_copy_ (void *cls, uint64_t offset, size_t max, void *buf,
707 * Notification of FS that a search probe has made progress.
708 * This function is used INSTEAD of the client's event handler
709 * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
711 * @param cls closure, always NULL (!), actual closure
712 * is in the client-context of the info struct
713 * @param info details about the event, specifying the event type
714 * and various bits about the event
715 * @return client-context (for the next progress call
716 * for this operation; should be set to NULL for
717 * SUSPEND and STOPPED events). The value returned
718 * will be passed to future callbacks in the respective
719 * field in the GNUNET_FS_ProgressInfo struct.
722 GNUNET_FS_search_probe_progress_ (void *cls,
723 const struct GNUNET_FS_ProgressInfo *info);
727 * Main function that performs the upload.
729 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
730 * @param tc task context
733 GNUNET_FS_publish_main_ (void *cls,
734 const struct GNUNET_SCHEDULER_TaskContext *tc);
738 * Function called once the hash of the file
739 * that is being unindexed has been computed.
741 * @param cls closure, unindex context
742 * @param file_id computed hash, NULL on error
745 GNUNET_FS_unindex_process_hash_ (void *cls, const struct GNUNET_HashCode * file_id);
749 * Extract the keywords for KBlock removal
751 * @param uc context for the unindex operation.
754 GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc);
758 * If necessary, connect to the datastore and remove the KBlocks.
760 * @param uc context for the unindex operation.
763 GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc);
767 * Fill in all of the generic fields for a publish event and call the
770 * @param pi structure to fill in
771 * @param pc overall publishing context
772 * @param p file information for the file being published
773 * @param offset where in the file are we so far
774 * @return value returned from callback
777 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
778 struct GNUNET_FS_PublishContext *pc,
779 const struct GNUNET_FS_FileInformation *p,
784 * Fill in all of the generic fields for a download event and call the
787 * @param pi structure to fill in
788 * @param dc overall download context
791 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
792 struct GNUNET_FS_DownloadContext *dc);
796 * Task that creates the initial (top-level) download
797 * request for the file.
799 * @param cls the 'struct GNUNET_FS_DownloadContext'
800 * @param tc scheduler context
803 GNUNET_FS_download_start_task_ (void *cls,
804 const struct GNUNET_SCHEDULER_TaskContext *tc);
809 * Fill in all of the generic fields for
810 * an unindex event and call the callback.
812 * @param pi structure to fill in
813 * @param uc overall unindex context
814 * @param offset where we are in the file (for progress)
817 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
818 struct GNUNET_FS_UnindexContext *uc,
822 * Fill in all of the generic fields for a search event and
825 * @param pi structure to fill in
826 * @param h file-sharing handle
827 * @param sc overall search context
828 * @return value returned by the callback
831 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
832 struct GNUNET_FS_Handle *h,
833 struct GNUNET_FS_SearchContext *sc);
837 * Connect to the datastore and remove the blocks.
839 * @param uc context for the unindex operation.
842 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
845 * Build the request and actually initiate the search using the
848 * @param sc search context
849 * @return GNUNET_OK on success, GNUNET_SYSERR on error
852 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
855 * Start the downloading process (by entering the queue).
857 * @param dc our download context
860 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
864 * Start download probes for the given search result.
866 * @param sr the search result
869 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
872 * Remove serialization/deserialization file from disk.
874 * @param h master context
875 * @param ext component of the path
876 * @param ent entity identifier
879 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, const char *ext,
884 * Remove serialization/deserialization directory from disk.
886 * @param h master context
887 * @param ext component of the path
888 * @param uni unique name of parent
891 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, const char *ext,
896 * Synchronize this file-information struct with its mirror
897 * on disk. Note that all internal FS-operations that change
898 * file information data should already call "sync" internally,
899 * so this function is likely not useful for clients.
901 * @param fi the struct to sync
904 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
907 * Synchronize this publishing struct with its mirror
908 * on disk. Note that all internal FS-operations that change
909 * publishing structs should already call "sync" internally,
910 * so this function is likely not useful for clients.
912 * @param pc the struct to sync
915 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
918 * Synchronize this unindex struct with its mirror
919 * on disk. Note that all internal FS-operations that change
920 * publishing structs should already call "sync" internally,
921 * so this function is likely not useful for clients.
923 * @param uc the struct to sync
926 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
929 * Synchronize this search struct with its mirror
930 * on disk. Note that all internal FS-operations that change
931 * publishing structs should already call "sync" internally,
932 * so this function is likely not useful for clients.
934 * @param sc the struct to sync
937 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
940 * Synchronize this search result with its mirror
941 * on disk. Note that all internal FS-operations that change
942 * publishing structs should already call "sync" internally,
943 * so this function is likely not useful for clients.
945 * @param sr the struct to sync
948 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
951 * Synchronize this download struct with its mirror
952 * on disk. Note that all internal FS-operations that change
953 * publishing structs should already call "sync" internally,
954 * so this function is likely not useful for clients.
956 * @param dc the struct to sync
959 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
962 * Create SUSPEND event for the given publish operation
963 * and then clean up our state (without stop signal).
965 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
968 GNUNET_FS_publish_signal_suspend_ (void *cls);
971 * Create SUSPEND event for the given search operation
972 * and then clean up our state (without stop signal).
974 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
977 GNUNET_FS_search_signal_suspend_ (void *cls);
980 * Create SUSPEND event for the given download operation
981 * and then clean up our state (without stop signal).
983 * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
986 GNUNET_FS_download_signal_suspend_ (void *cls);
989 * Create SUSPEND event for the given unindex operation
990 * and then clean up our state (without stop signal).
992 * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
995 GNUNET_FS_unindex_signal_suspend_ (void *cls);
998 * Function signature of the functions that can be called
999 * to trigger suspend signals and clean-up for top-level
1002 * @param cls closure
1004 typedef void (*SuspendSignalFunction) (void *cls);
1007 * We track all of the top-level activities of FS
1008 * so that we can signal 'suspend' on shutdown.
1010 struct TopLevelActivity
1013 * This is a doubly-linked list.
1015 struct TopLevelActivity *next;
1018 * This is a doubly-linked list.
1020 struct TopLevelActivity *prev;
1023 * Function to call for suspend-signalling and clean up.
1025 SuspendSignalFunction ssf;
1028 * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1035 * Create a top-level activity entry.
1037 * @param h global fs handle
1038 * @param ssf suspend signal function to use
1039 * @param ssf_cls closure for ssf
1040 * @return fresh top-level activity handle
1042 struct TopLevelActivity *
1043 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, SuspendSignalFunction ssf,
1048 * Destroy a top-level activity entry.
1050 * @param h global fs handle
1051 * @param top top level activity entry
1054 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top);
1059 * Master context for most FS operations.
1061 struct GNUNET_FS_Handle
1064 * Configuration to use.
1066 const struct GNUNET_CONFIGURATION_Handle *cfg;
1069 * Name of our client.
1074 * Function to call with updates on our progress.
1076 GNUNET_FS_ProgressCallback upcb;
1084 * Head of DLL of top-level activities.
1086 struct TopLevelActivity *top_head;
1089 * Tail of DLL of top-level activities.
1091 struct TopLevelActivity *top_tail;
1094 * Head of DLL of running jobs.
1096 struct GNUNET_FS_QueueEntry *running_head;
1099 * Tail of DLL of running jobs.
1101 struct GNUNET_FS_QueueEntry *running_tail;
1104 * Head of DLL of pending jobs.
1106 struct GNUNET_FS_QueueEntry *pending_head;
1109 * Tail of DLL of pending jobs.
1111 struct GNUNET_FS_QueueEntry *pending_tail;
1114 * Task that processes the jobs in the running and pending queues
1115 * (and moves jobs around as needed).
1117 GNUNET_SCHEDULER_TaskIdentifier queue_job;
1120 * Average time we take for a single request to be satisfied.
1121 * FIXME: not yet calcualted properly...
1123 struct GNUNET_TIME_Relative avg_block_latency;
1126 * How many actual downloads do we have running right now?
1128 unsigned int active_downloads;
1131 * How many blocks do the active downloads have?
1133 unsigned int active_blocks;
1138 enum GNUNET_FS_Flags flags;
1141 * Maximum number of parallel downloads.
1143 unsigned int max_parallel_downloads;
1146 * Maximum number of parallel requests.
1148 unsigned int max_parallel_requests;
1154 * Handle for controlling a publication process.
1156 struct GNUNET_FS_PublishContext
1159 * Handle to the global fs context.
1161 struct GNUNET_FS_Handle *h;
1164 * Our top-level activity entry (if we are top-level, otherwise NULL).
1166 struct TopLevelActivity *top;
1169 * File-structure that is being shared.
1171 struct GNUNET_FS_FileInformation *fi;
1174 * Namespace that we are publishing in, NULL if we have no namespace.
1176 struct GNUNET_FS_Namespace *ns;
1179 * ID of the content in the namespace, NULL if we have no namespace.
1184 * ID for future updates, NULL if we have no namespace or no updates.
1189 * Filename used for serializing information about this operation
1190 * (should be determined using 'mktemp').
1192 char *serialization;
1195 * Our own client handle for the FS service; only briefly used when
1196 * we start to index a file, otherwise NULL.
1198 struct GNUNET_CLIENT_Connection *client;
1201 * Current position in the file-tree for the upload.
1203 struct GNUNET_FS_FileInformation *fi_pos;
1206 * Non-null if we are currently hashing a file.
1208 struct GNUNET_CRYPTO_FileHashContext *fhc;
1211 * Connection to the datastore service.
1213 struct GNUNET_DATASTORE_Handle *dsh;
1216 * Queue entry for reservation/unreservation.
1218 struct GNUNET_DATASTORE_QueueEntry *qre;
1221 * Context for SKS publishing operation that is part of this publishing operation
1222 * (NULL if not active).
1224 struct GNUNET_FS_PublishSksContext *sks_pc;
1227 * Context for KSK publishing operation that is part of this publishing operation
1228 * (NULL if not active).
1230 struct GNUNET_FS_PublishKskContext *ksk_pc;
1233 * ID of the task performing the upload. NO_TASK if the upload has
1236 GNUNET_SCHEDULER_TaskIdentifier upload_task;
1239 * Storage space to reserve for the operation.
1241 uint64_t reserve_space;
1244 * Overall number of entries to reserve for the
1245 * publish operation.
1247 uint32_t reserve_entries;
1250 * Options for publishing.
1252 enum GNUNET_FS_PublishOptions options;
1255 * Space reservation ID with datastore service
1261 * Set to GNUNET_YES if all processing has completed.
1266 * Flag set to GNUNET_YES if the next callback from
1267 * GNUNET_FS_file_information_inspect should be skipped because it
1268 * is for the directory which was already processed with the parent.
1270 int skip_next_fi_callback;
1275 * Phases of unindex processing (state machine).
1280 * We're currently hashing the file.
1282 UNINDEX_STATE_HASHING = 0,
1285 * We're telling the datastore to delete
1286 * the respective DBlocks and IBlocks.
1288 UNINDEX_STATE_DS_REMOVE = 1,
1291 * Find out which keywords apply.
1293 UNINDEX_STATE_EXTRACT_KEYWORDS = 2,
1296 * We're telling the datastore to remove KBlocks.
1298 UNINDEX_STATE_DS_REMOVE_KBLOCKS = 3,
1301 * We're notifying the FS service about
1304 UNINDEX_STATE_FS_NOTIFY = 4,
1309 UNINDEX_STATE_COMPLETE = 5,
1312 * We've encountered a fatal error.
1314 UNINDEX_STATE_ERROR = 6
1319 * Handle for controlling an unindexing operation.
1321 struct GNUNET_FS_UnindexContext
1325 * The content hash key of the last block we processed, will in the
1326 * end be set to the CHK from the URI. Used to remove the KBlocks.
1328 struct ContentHashKey chk;
1331 * Global FS context.
1333 struct GNUNET_FS_Handle *h;
1336 * Our top-level activity entry.
1338 struct TopLevelActivity *top;
1341 * Directory scanner to find keywords (KBlock removal).
1343 struct GNUNET_FS_DirScanner *dscan;
1346 * Keywords found (telling us which KBlocks to remove).
1348 struct GNUNET_FS_Uri *ksk_uri;
1351 * Current offset in KSK removal.
1353 uint32_t ksk_offset;
1356 * Name of the file that we are unindexing.
1361 * Short name under which we are serializing the state of this operation.
1363 char *serialization;
1366 * Connection to the FS service, only valid during the
1367 * UNINDEX_STATE_FS_NOTIFY phase.
1369 struct GNUNET_CLIENT_Connection *client;
1372 * Connection to the datastore service, only valid during the
1373 * UNINDEX_STATE_DS_NOTIFY phase.
1375 struct GNUNET_DATASTORE_Handle *dsh;
1378 * Pointer kept for the client.
1383 * Merkle-ish tree encoder context.
1385 struct GNUNET_FS_TreeEncoder *tc;
1388 * Handle used to read the file.
1390 struct GNUNET_DISK_FileHandle *fh;
1393 * Handle to datastore 'get_key' operation issued for
1394 * obtaining KBlocks.
1396 struct GNUNET_DATASTORE_QueueEntry *dqe;
1399 * Current key for decrypting UBLocks from 'get_key' operation.
1401 struct GNUNET_HashCode ukey;
1404 * Current query of 'get_key' operation.
1406 struct GNUNET_HashCode uquery;
1409 * First content UID, 0 for none.
1414 * Error message, NULL on success.
1419 * Context for hashing of the file.
1421 struct GNUNET_CRYPTO_FileHashContext *fhc;
1424 * Overall size of the file.
1429 * Random offset given to 'GNUNET_DATASTORE_get_key'.
1434 * When did we start?
1436 struct GNUNET_TIME_Absolute start_time;
1439 * Hash of the file's contents (once computed).
1441 struct GNUNET_HashCode file_id;
1444 * Current operatinonal phase.
1446 enum UnindexState state;
1452 * Information we keep for each keyword in
1455 struct SearchRequestEntry
1458 * Hash of the original keyword, used to derive the
1459 * key (for decrypting the KBlock).
1461 struct GNUNET_HashCode ukey;
1464 * Hash of the public key, also known as the query.
1466 struct GNUNET_HashCode uquery;
1469 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1470 * was found under this keyword. Note that the entries will point
1471 * to the same locations as those in the master result map (in
1472 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1473 * The key for each entry is the XOR of the key and query in the CHK
1474 * URI (as a unique identifier for the search result).
1476 struct GNUNET_CONTAINER_MultiHashMap *results;
1479 * Is this keyword a mandatory keyword
1480 * (started with '+')?
1488 * Handle for controlling a search.
1490 struct GNUNET_FS_SearchContext
1493 * Handle to the global FS context.
1495 struct GNUNET_FS_Handle *h;
1498 * Our top-level activity entry (if we are top-level, otherwise NULL).
1500 struct TopLevelActivity *top;
1503 * List of keywords that we're looking for.
1505 struct GNUNET_FS_Uri *uri;
1508 * For update-searches, link to the search result that triggered
1509 * the update search; otherwise NULL.
1511 struct GNUNET_FS_SearchResult *psearch_result;
1514 * Connection to the FS service.
1516 struct GNUNET_CLIENT_Connection *client;
1519 * Pointer we keep for the client.
1524 * Name of the file on disk we use for persistence.
1526 char *serialization;
1529 * Error message (non-NULL if this operation failed).
1534 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1535 * was found in the search. The key for each entry is the XOR of
1536 * the key and query in the CHK URI (as a unique identifier for the
1539 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1542 * Per-keyword information for a keyword search. This array will
1543 * have exactly as many entries as there were keywords.
1545 struct SearchRequestEntry *requests;
1548 * When did we start?
1550 struct GNUNET_TIME_Absolute start_time;
1553 * How long to wait before we try to reconnect to FS service?
1555 struct GNUNET_TIME_Relative reconnect_backoff;
1558 * ID of a task that is using this struct and that must be cancelled
1559 * when the search is being stopped (if not
1560 * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
1561 * artificial delay when trying to reconnect to the FS service.
1563 GNUNET_SCHEDULER_TaskIdentifier task;
1566 * How many of the entries in the search request
1567 * map have been passed to the service so far?
1569 unsigned int search_request_map_offset;
1572 * How many of the keywords in the KSK
1573 * map have been passed to the service so far?
1575 unsigned int keyword_offset;
1578 * Anonymity level for the search.
1583 * Number of mandatory keywords in this query.
1585 uint32_t mandatory_count;
1588 * Options for the search.
1590 enum GNUNET_FS_SearchOptions options;
1595 * FSM for possible states a block can go through. The typical
1596 * order of progression is linear through the states, alternatives
1597 * are documented in the comments.
1599 enum BlockRequestState
1602 * Initial state, block has only been allocated (since it is
1603 * relevant to the overall download request).
1608 * We've checked the block on the path down the tree, and the
1609 * content on disk did match the desired CHK, but not all
1610 * the way down, so at the bottom some blocks will still
1611 * need to be reconstructed).
1613 BRS_RECONSTRUCT_DOWN = 1,
1616 * We've calculated the CHK bottom-up based on the meta data.
1617 * This may work, but if it did we have to write the meta data to
1618 * disk at the end (and we still need to check against the
1621 BRS_RECONSTRUCT_META_UP = 2,
1624 * We've calculated the CHK bottom-up based on what we have on
1625 * disk, which may not be what the desired CHK is. If the
1626 * reconstructed CHKs match whatever comes from above, we're
1627 * done with the respective subtree.
1629 BRS_RECONSTRUCT_UP = 3,
1632 * We've determined the real, desired CHK for this block
1633 * (full tree reconstruction failed), request is now pending.
1634 * If the CHK that bubbled up through reconstruction did match
1635 * the top-level request, the state machine for the subtree
1636 * would have moved to BRS_DOWNLOAD_UP.
1641 * We've successfully downloaded this block, but the children
1642 * still need to be either downloaded or verified (download
1643 * request propagates down). If the download fails, the
1644 * state machine for this block may move to
1645 * BRS_DOWNLOAD_ERROR instead.
1647 BRS_DOWNLOAD_DOWN = 5,
1650 * This block and all of its children have been downloaded
1651 * successfully (full completion propagates up).
1653 BRS_DOWNLOAD_UP = 6,
1656 * We got a block back that matched the query but did not hash to
1657 * the key (malicious publisher or hash collision); this block
1658 * can never be downloaded (error propagates up).
1665 * Information about an active download request.
1667 struct DownloadRequest
1670 * While pending, we keep all download requests in a doubly-linked list.
1672 struct DownloadRequest *next;
1675 * While pending, we keep all download requests in a doubly-linked list.
1677 struct DownloadRequest *prev;
1680 * Parent in the CHK-tree.
1682 struct DownloadRequest *parent;
1685 * Array (!) of child-requests, or NULL for the bottom of the tree.
1687 struct DownloadRequest **children;
1690 * CHK for the request for this block (set during reconstruction
1691 * to what we have on disk, later to what we want to have).
1693 struct ContentHashKey chk;
1696 * Offset of the corresponding block. Specifically, first (!) byte of
1697 * the first DBLOCK in the subtree induced by block represented by
1703 * Number of entries in 'children' array.
1705 unsigned int num_children;
1708 * Depth of the corresponding block in the tree. 0==DBLOCKs.
1713 * Offset of the CHK for this block in the parent block
1715 unsigned int chk_idx;
1720 enum BlockRequestState state;
1723 * GNUNET_YES if this entry is in the pending list.
1731 * (recursively) free download request structure
1733 * @param dr request to free
1736 GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
1740 * Context for controlling a download.
1742 struct GNUNET_FS_DownloadContext
1746 * Global FS context.
1748 struct GNUNET_FS_Handle *h;
1751 * Our top-level activity entry (if we are top-level, otherwise NULL).
1753 struct TopLevelActivity *top;
1756 * Connection to the FS service.
1758 struct GNUNET_CLIENT_Connection *client;
1761 * Parent download (used when downloading files
1764 struct GNUNET_FS_DownloadContext *parent;
1767 * Associated search (used when downloading files
1768 * based on search results), or NULL for none.
1770 struct GNUNET_FS_SearchResult *search;
1773 * Head of list of child downloads.
1775 struct GNUNET_FS_DownloadContext *child_head;
1778 * Tail of list of child downloads.
1780 struct GNUNET_FS_DownloadContext *child_tail;
1783 * Previous download belonging to the same parent.
1785 struct GNUNET_FS_DownloadContext *prev;
1788 * Next download belonging to the same parent.
1790 struct GNUNET_FS_DownloadContext *next;
1793 * Context kept for the client.
1798 * URI that identifies the file that we are downloading.
1800 struct GNUNET_FS_Uri *uri;
1803 * Known meta-data for the file (can be NULL).
1805 struct GNUNET_CONTAINER_MetaData *meta;
1808 * Error message, NULL if we're doing OK.
1813 * Random portion of filename we use for syncing state of this
1816 char *serialization;
1819 * Where are we writing the data (name of the
1820 * file, can be NULL!).
1825 * Where are we writing the data temporarily (name of the
1826 * file, can be NULL!); used if we do not have a permanent
1827 * name and we are a directory and we do a recursive download.
1829 char *temp_filename;
1832 * Our entry in the job queue.
1834 struct GNUNET_FS_QueueEntry *job_queue;
1837 * Non-NULL if we are currently having a request for
1838 * transmission pending with the client handle.
1840 struct GNUNET_CLIENT_TransmitHandle *th;
1843 * Tree encoder used for the reconstruction.
1845 struct GNUNET_FS_TreeEncoder *te;
1848 * File handle for reading data from an existing file
1849 * (to pass to tree encoder).
1851 struct GNUNET_DISK_FileHandle *rfh;
1854 * Map of active requests (those waiting for a response). The key
1855 * is the hash of the encryped block (aka query).
1857 struct GNUNET_CONTAINER_MultiHashMap *active;
1860 * Head of linked list of pending requests.
1862 struct DownloadRequest *pending_head;
1865 * Head of linked list of pending requests.
1867 struct DownloadRequest *pending_tail;
1870 * Top-level download request.
1872 struct DownloadRequest *top_request;
1875 * Identity of the peer having the content, or all-zeros
1876 * if we don't know of such a peer.
1878 struct GNUNET_PeerIdentity target;
1881 * ID of a task that is using this struct and that must be cancelled
1882 * when the download is being stopped (if not
1883 * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
1884 * artificial delay when trying to reconnect to the FS service or
1885 * the task processing incrementally the data on disk, or the
1886 * task requesting blocks, etc.
1888 GNUNET_SCHEDULER_TaskIdentifier task;
1891 * What is the first offset that we're interested
1897 * How many bytes starting from offset are desired?
1898 * This is NOT the overall length of the file!
1903 * How many bytes have we already received within
1904 * the specified range (DBlocks only).
1909 * What was the size of the file on disk that we're downloading
1910 * before we started? Used to detect if there is a point in
1911 * checking an existing block on disk for matching the desired
1912 * content. 0 if the file did not exist already.
1914 uint64_t old_file_size;
1917 * Time download was started.
1919 struct GNUNET_TIME_Absolute start_time;
1922 * How long to wait before we try to reconnect to FS service?
1924 struct GNUNET_TIME_Relative reconnect_backoff;
1927 * Desired level of anonymity.
1932 * The depth of the file-tree.
1934 unsigned int treedepth;
1937 * Options for the download.
1939 enum GNUNET_FS_DownloadOptions options;
1942 * Flag set upon transitive completion (includes child downloads).
1943 * This flag is only set to GNUNET_YES for directories where all
1944 * child-downloads have also completed (and signalled completion).
1949 * Have we started the receive continuation yet?
1954 * Are we ready to issue requests (reconstructions are finished)?
1962 * Information about an (updateable) node in the
1965 struct NamespaceUpdateNode
1968 * Identifier for this node.
1973 * Identifier of children of this node.
1978 * Metadata for this entry.
1980 struct GNUNET_CONTAINER_MetaData *md;
1983 * URI of this entry in the namespace.
1985 struct GNUNET_FS_Uri *uri;
1988 * Namespace update generation ID. Used to ensure
1989 * freshness of the tree_id.
1994 * TREE this entry belongs to (if nug is current).
1996 unsigned int tree_id;
2002 * Handle to one of our namespaces.
2004 struct GNUNET_FS_Namespace
2008 * Handle to the FS service context.
2010 struct GNUNET_FS_Handle *h;
2013 * Array with information about nodes in the namespace.
2015 struct NamespaceUpdateNode **update_nodes;
2018 * Private key for the namespace.
2020 struct GNUNET_FS_PseudonymHandle *key;
2023 * Hash map mapping identifiers of update nodes
2024 * to the update nodes (initialized on-demand).
2026 struct GNUNET_CONTAINER_MultiHashMap *update_map;
2029 * Name of the file with the private key.
2034 * Name of the namespace.
2039 * Size of the update nodes array.
2041 unsigned int update_node_count;
2044 * Reference counter.
2049 * Generator for unique nug numbers.
2051 unsigned int nug_gen;
2056 /* end of fs_api.h */