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 2, 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 definitions for the entire fs module
24 * @author Igor Wronsky, Christian Grothoff
29 #include "gnunet_constants.h"
30 #include "gnunet_datastore_service.h"
31 #include "gnunet_fs_service.h"
32 #include "gnunet_block_lib.h"
35 * Maximum size of the datastore queue for P2P operations.
37 #define MAX_DATASTORE_QUEUE 16
40 * Size of the individual blocks used for file-sharing.
42 #define DBLOCK_SIZE (32*1024)
45 * Maximum legal size for a kblock.
47 #define MAX_KBLOCK_SIZE (60 * 1024)
50 * Maximum legal size for an sblock.
52 #define MAX_SBLOCK_SIZE (60 * 1024)
55 * Maximum legal size for an nblock.
57 #define MAX_NBLOCK_SIZE (60 * 1024)
60 * Pick a multiple of 2 here to achive 8-byte alignment!
61 * We also probably want DBlocks to have (roughly) the
62 * same size as IBlocks. With SHA-512, the optimal
63 * value is 32768 byte / 128 byte = 256
64 * (128 byte = 2 * 512 bits). DO NOT CHANGE!
66 #define CHK_PER_INODE 256
70 * Maximum size for a file to be considered for
71 * inlining in a directory.
73 #define MAX_INLINE_SIZE 65536
77 * Blocksize to use when hashing files
78 * for indexing (blocksize for IO, not for
79 * the DBlocks). Larger blocksizes can
80 * be more efficient but will be more disruptive
81 * as far as the scheduler is concerned.
83 #define HASHING_BLOCKSIZE (1024 * 1024)
86 * Number of bits we set per entry in the bloomfilter.
89 #define BLOOMFILTER_K 16
92 * Number of availability trials we perform per search result.
94 #define AVAILABILITY_TRIALS_MAX 8
97 * By how much (in ms) do we decrement the TTL
100 #define TTL_DECREMENT 5000
103 * Length of the P2P success tracker. Note that
104 * having a very long list can also hurt performance.
106 #define P2P_SUCCESS_LIST_SIZE 8
110 * Length of the CS-2-P success tracker. Note that
111 * having a very long list can also hurt performance.
113 #define CS2P_SUCCESS_LIST_SIZE 8
116 * How long are we willing to wait for the datastore to be ready to
117 * process a request for a query without priority?
119 #define BASIC_DATASTORE_REQUEST_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
123 * How long are we willing to wait for the core to be ready to
124 * transmit a reply to the target peer (if we can not transmit
125 * until then, we will discard the reply).
127 #define ACCEPTABLE_REPLY_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
131 * Bandwidth value of an (effectively) 0-priority query.
133 #define QUERY_BANDWIDTH_VALUE 0.001
136 * Bandwidth value of a 0-priority content (must be
137 * fairly high compared to query since content is
138 * typically significantly larger -- and more valueable
139 * since it can take many queries to get one piece of
142 #define CONTENT_BANDWIDTH_VALUE 0.8
145 * By which amount do we decrement the TTL for simple forwarding /
146 * indirection of the query; in milli-seconds. Set somewhat in
147 * accordance to your network latency (above the time it'll take you
148 * to send a packet and get a reply).
150 #define TTL_DECREMENT 5000
153 * Until which load do we consider the peer idle and do not
154 * charge at all? (should be larger than GNUNET_IDLE_LOAD_THRESHOLD used
155 * by the rest of the code)!
157 #define IDLE_LOAD_THRESHOLD ((100 + GNUNET_CONSTANTS_IDLE_LOAD_THRESHOLD) / 2)
160 * Name of the directory with top-level searches.
162 #define GNUNET_FS_SYNC_PATH_MASTER_SEARCH "search"
165 * Name of the directory with sub-searches (namespace-updates).
167 #define GNUNET_FS_SYNC_PATH_CHILD_SEARCH "search-child"
170 * Name of the directory with master downloads (not associated
171 * with search or part of another download).
173 #define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD "download"
176 * Name of the directory with downloads that are part of another
177 * download or a search.
179 #define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD "download-child"
182 * Name of the directory with publishing operations.
184 #define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH "publish"
187 * Name of the directory with files that are being published
189 #define GNUNET_FS_SYNC_PATH_FILE_INFO "publish-file"
192 * Name of the directory with unindex operations.
194 #define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX "unindex"
198 * @brief content hash key
200 struct ContentHashKey
203 * Hash of the original content, used for encryption.
208 * Hash of the encrypted content, used for querying.
210 GNUNET_HashCode query;
215 * @brief complete information needed
216 * to download a file.
218 struct FileIdentifier
222 * Total size of the file in bytes. (network byte order (!))
224 uint64_t file_length;
227 * Query and key of the top GNUNET_EC_IBlock.
229 struct ContentHashKey chk;
235 * Information about a file and its location
236 * (peer claiming to share the file).
241 * Information about the shared file.
243 struct FileIdentifier fi;
246 * Identity of the peer sharing the file.
248 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
251 * Time when this location URI expires.
253 struct GNUNET_TIME_Absolute expirationTime;
256 * RSA signature over the GNUNET_EC_FileIdentifier,
257 * GNUNET_hash of the peer and expiration time.
259 struct GNUNET_CRYPTO_RsaSignature contentSignature;
269 * Content-hash-key (simple file).
274 * Signed key space (file in namespace).
279 * Keyword search key (query with keywords).
284 * Location (chk with identity of hosting peer).
290 * A Universal Resource Identifier (URI), opaque.
304 * Keywords start with a '+' if they are
305 * mandatory (in which case the '+' is NOT
306 * part of the keyword) and with a
307 * simple space if they are optional
308 * (in which case the space is ALSO not
309 * part of the actual keyword).
311 * Double-quotes to protect spaces and
312 * %-encoding are NOT used internally
313 * (only in URI-strings).
318 * Size of the keywords array.
320 unsigned int keywordCount;
326 * Hash of the public key for the namespace.
328 GNUNET_HashCode namespace;
331 * Human-readable identifier chosen for this
332 * entry in the namespace.
338 * Information needed to retrieve a file (content-hash-key
341 struct FileIdentifier chk;
344 * Information needed to retrieve a file including signed
345 * location (identity of a peer) of the content.
354 * Information for a file or directory that is
355 * about to be published.
357 struct GNUNET_FS_FileInformation
361 * Files in a directory are kept as a linked list.
363 struct GNUNET_FS_FileInformation *next;
366 * If this is a file in a directory, "dir" refers to
367 * the directory; otherwise NULL.
369 struct GNUNET_FS_FileInformation *dir;
372 * Handle to the master context.
374 struct GNUNET_FS_Handle *h;
377 * Pointer kept for the client.
382 * Metadata to use for the file.
384 struct GNUNET_CONTAINER_MetaData *meta;
387 * Keywords to use for KBlocks.
389 struct GNUNET_FS_Uri *keywords;
392 * CHK for this file or directory. NULL if
393 * we have not yet computed it.
395 struct GNUNET_FS_Uri *chk_uri;
398 * At what time should the content expire?
400 struct GNUNET_TIME_Absolute expirationTime;
403 * At what time did we start this upload?
405 struct GNUNET_TIME_Absolute start_time;
408 * Under what filename is this struct serialized
409 * (for operational persistence). Should be determined
415 * Encoder being used to publish this file.
417 struct GNUNET_FS_TreeEncoder *te;
420 * Error message (non-NULL if this operation failed).
425 * Name of the file or directory (must be an absolute path).
430 * Data describing either the file or the directory.
441 * Function that can be used to read the data for the file.
443 GNUNET_FS_DataReader reader;
446 * Closure for reader.
451 * If this file is being indexed, this value is set to the hash
452 * over the entire file (when the indexing process is started).
453 * Otherwise this field is not used.
455 GNUNET_HashCode file_id;
458 * Size of the file (in bytes).
463 * Should the file be indexed or inserted?
468 * Is "file_id" already valid? Set to GNUNET_YES once the hash
469 * has been calculated.
474 * Has the service confirmed our INDEX_START request?
475 * GNUNET_YES if this step has been completed.
477 int index_start_confirmed;
482 * Data for a directory.
487 * Linked list of entries in the directory.
489 struct GNUNET_FS_FileInformation *entries;
492 * Size of the directory itself (in bytes); 0 if the
493 * size has not yet been calculated.
498 * Pointer to the data for the directory (or NULL if not
508 * Desired anonymity level.
513 * Desired priority (for keeping the content in the DB).
518 * Is this struct for a file or directory?
523 * Are we done publishing this file?
531 * The job is now ready to run and should use the given client
532 * handle to communicate with the FS service.
535 * @param client handle to use for FS communication
537 typedef void (*GNUNET_FS_QueueStart)(void *cls,
538 struct GNUNET_CLIENT_Connection *client);
542 * The job must now stop to run and should destry the client handle as
543 * soon as possible (ideally prior to returning).
545 typedef void (*GNUNET_FS_QueueStop)(void *cls);
549 * Entry in the job queue.
551 struct GNUNET_FS_QueueEntry
554 * This is a linked list.
556 struct GNUNET_FS_QueueEntry *next;
559 * This is a linked list.
561 struct GNUNET_FS_QueueEntry *prev;
564 * Function to call when the job is started.
566 GNUNET_FS_QueueStart start;
569 * Function to call when the job needs to stop (or is done / dequeued).
571 GNUNET_FS_QueueStop stop;
574 * Closure for start and stop.
579 * Handle to FS primary context.
581 struct GNUNET_FS_Handle *h;
584 * Client handle, or NULL if job is not running.
586 struct GNUNET_CLIENT_Connection *client;
589 * Time the job was originally queued.
591 struct GNUNET_TIME_Absolute queue_time;
594 * Time the job was started last.
596 struct GNUNET_TIME_Absolute start_time;
599 * Total amount of time the job has been running (except for the
602 struct GNUNET_TIME_Relative run_time;
605 * How many blocks do the active downloads have?
610 * How often have we (re)started this download?
612 unsigned int start_times;
620 * Information we store for each search result.
622 struct GNUNET_FS_SearchResult
626 * Search context this result belongs to.
628 struct GNUNET_FS_SearchContext *sc;
631 * URI to which this search result refers to.
633 struct GNUNET_FS_Uri *uri;
636 * Metadata for the search result.
638 struct GNUNET_CONTAINER_MetaData *meta;
641 * Client info for this search result.
646 * ID of a job that is currently probing this results' availability
647 * (NULL if we are not currently probing).
649 struct GNUNET_FS_DownloadContext *probe_ctx;
652 * ID of an associated download based on this search result (or
655 struct GNUNET_FS_DownloadContext *download;
658 * If this search result triggered an update search, this field
659 * links to the update search.
661 struct GNUNET_FS_SearchContext *update_search;
664 * Name under which this search result is stored on disk.
669 * Key for the search result
674 * ID of the task that will clean up the probe_ctx should it not
675 * complete on time (and that will need to be cancelled if we clean
676 * up the search result before then).
678 GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
681 * When did the current probe become active?
683 struct GNUNET_TIME_Absolute probe_active_time;
686 * How much longer should we run the current probe before giving up?
688 struct GNUNET_TIME_Relative remaining_probe_time;
691 * Number of mandatory keywords for which we have NOT yet found the
692 * search result; when this value hits zero, the search result is
693 * given to the callback.
695 uint32_t mandatory_missing;
698 * Number of optional keywords under which this result was also
701 uint32_t optional_support;
704 * Number of availability tests that have succeeded for this result.
706 uint32_t availability_success;
709 * Number of availability trials that we have performed for this
712 uint32_t availability_trials;
718 * Add a job to the queue.
720 * @param h handle to the overall FS state
721 * @param start function to call to begin the job
722 * @param stop function to call to pause the job, or on dequeue (if the job was running)
723 * @param cls closure for start and stop
724 * @param blocks number of blocks this download has
725 * @return queue handle
727 struct GNUNET_FS_QueueEntry *
728 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
729 GNUNET_FS_QueueStart start,
730 GNUNET_FS_QueueStop stop,
732 unsigned int blocks);
736 * Dequeue a job from the queue.
737 * @param qh handle for the job
740 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
744 * Function that provides data by reading from a file.
746 * @param cls closure (points to the file information)
747 * @param offset offset to read from; it is possible
748 * that the caller might need to go backwards
750 * @param max maximum number of bytes that should be
751 * copied to buf; readers are not allowed
752 * to provide less data unless there is an error;
753 * a value of "0" will be used at the end to allow
754 * the reader to clean up its internal state
755 * @param buf where the reader should write the data
756 * @param emsg location for the reader to store an error message
757 * @return number of bytes written, usually "max", 0 on error
760 GNUNET_FS_data_reader_file_(void *cls,
768 * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
770 * @param filename file to read
771 * @return closure to use
774 GNUNET_FS_make_file_reader_context_ (const char *filename);
779 * Function that provides data by copying from a buffer.
781 * @param cls closure (points to the buffer)
782 * @param offset offset to read from; it is possible
783 * that the caller might need to go backwards
785 * @param max maximum number of bytes that should be
786 * copied to buf; readers are not allowed
787 * to provide less data unless there is an error;
788 * a value of "0" will be used at the end to allow
789 * the reader to clean up its internal state
790 * @param buf where the reader should write the data
791 * @param emsg location for the reader to store an error message
792 * @return number of bytes written, usually "max", 0 on error
795 GNUNET_FS_data_reader_copy_(void *cls,
802 * Notification of FS that a search probe has made progress.
803 * This function is used INSTEAD of the client's event handler
804 * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
806 * @param cls closure, always NULL (!), actual closure
807 * is in the client-context of the info struct
808 * @param info details about the event, specifying the event type
809 * and various bits about the event
810 * @return client-context (for the next progress call
811 * for this operation; should be set to NULL for
812 * SUSPEND and STOPPED events). The value returned
813 * will be passed to future callbacks in the respective
814 * field in the GNUNET_FS_ProgressInfo struct.
817 GNUNET_FS_search_probe_progress_ (void *cls,
818 const struct GNUNET_FS_ProgressInfo *info);
822 * Main function that performs the upload.
824 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
825 * @param tc task context
828 GNUNET_FS_publish_main_ (void *cls,
829 const struct GNUNET_SCHEDULER_TaskContext *tc);
833 * Function called once the hash of the file
834 * that is being unindexed has been computed.
836 * @param cls closure, unindex context
837 * @param file_id computed hash, NULL on error
840 GNUNET_FS_unindex_process_hash_ (void *cls,
841 const GNUNET_HashCode *file_id);
845 * Fill in all of the generic fields for a publish event and call the
848 * @param pi structure to fill in
849 * @param sc overall publishing context
850 * @param p file information for the file being published
851 * @param offset where in the file are we so far
852 * @return value returned from callback
855 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
856 struct GNUNET_FS_PublishContext *sc,
857 const struct GNUNET_FS_FileInformation *p,
862 * Fill in all of the generic fields for a download event and call the
865 * @param pi structure to fill in
866 * @param dc overall download context
869 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
870 struct GNUNET_FS_DownloadContext *dc);
874 * Fill in all of the generic fields for
875 * an unindex event and call the callback.
877 * @param pi structure to fill in
878 * @param uc overall unindex context
879 * @param offset where we are in the file (for progress)
882 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
883 struct GNUNET_FS_UnindexContext *uc,
887 * Fill in all of the generic fields for a search event and
890 * @param pi structure to fill in
891 * @param sc overall search context
892 * @return value returned by the callback
895 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
896 struct GNUNET_FS_SearchContext *sc);
900 * Connect to the datastore and remove the blocks.
902 * @param uc context for the unindex operation.
905 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
908 * Build the request and actually initiate the search using the
911 * @param sc search context
912 * @return GNUNET_OK on success, GNUNET_SYSERR on error
915 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
918 * Start the downloading process (by entering the queue).
920 * @param dc our download context
923 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
927 * Start download probes for the given search result.
929 * @param sr the search result
932 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
935 * Remove serialization/deserialization file from disk.
937 * @param h master context
938 * @param ext component of the path
939 * @param ent entity identifier
942 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
948 * Remove serialization/deserialization directory from disk.
950 * @param h master context
951 * @param ext component of the path
952 * @param uni unique name of parent
955 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
961 * Synchronize this file-information struct with its mirror
962 * on disk. Note that all internal FS-operations that change
963 * file information data should already call "sync" internally,
964 * so this function is likely not useful for clients.
966 * @param fi the struct to sync
969 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
972 * Synchronize this publishing struct with its mirror
973 * on disk. Note that all internal FS-operations that change
974 * publishing structs should already call "sync" internally,
975 * so this function is likely not useful for clients.
977 * @param pc the struct to sync
980 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
983 * Synchronize this unindex struct with its mirror
984 * on disk. Note that all internal FS-operations that change
985 * publishing structs should already call "sync" internally,
986 * so this function is likely not useful for clients.
988 * @param uc the struct to sync
991 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
994 * Synchronize this search struct with its mirror
995 * on disk. Note that all internal FS-operations that change
996 * publishing structs should already call "sync" internally,
997 * so this function is likely not useful for clients.
999 * @param sc the struct to sync
1002 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
1005 * Synchronize this search result with its mirror
1006 * on disk. Note that all internal FS-operations that change
1007 * publishing structs should already call "sync" internally,
1008 * so this function is likely not useful for clients.
1010 * @param sr the struct to sync
1013 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
1016 * Synchronize this download struct with its mirror
1017 * on disk. Note that all internal FS-operations that change
1018 * publishing structs should already call "sync" internally,
1019 * so this function is likely not useful for clients.
1021 * @param dc the struct to sync
1024 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
1027 * Create SUSPEND event for the given publish operation
1028 * and then clean up our state (without stop signal).
1030 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
1033 GNUNET_FS_publish_signal_suspend_ (void *cls);
1036 * Create SUSPEND event for the given search operation
1037 * and then clean up our state (without stop signal).
1039 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
1042 GNUNET_FS_search_signal_suspend_ (void *cls);
1045 * Create SUSPEND event for the given download operation
1046 * and then clean up our state (without stop signal).
1048 * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
1051 GNUNET_FS_download_signal_suspend_ (void *cls);
1054 * Create SUSPEND event for the given unindex operation
1055 * and then clean up our state (without stop signal).
1057 * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
1060 GNUNET_FS_unindex_signal_suspend_ (void *cls);
1063 * Function signature of the functions that can be called
1064 * to trigger suspend signals and clean-up for top-level
1067 * @param cls closure
1069 typedef void (*SuspendSignalFunction)(void *cls);
1072 * We track all of the top-level activities of FS
1073 * so that we can signal 'suspend' on shutdown.
1075 struct TopLevelActivity
1078 * This is a doubly-linked list.
1080 struct TopLevelActivity *next;
1083 * This is a doubly-linked list.
1085 struct TopLevelActivity *prev;
1088 * Function to call for suspend-signalling and clean up.
1090 SuspendSignalFunction ssf;
1093 * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1100 * Create a top-level activity entry.
1102 * @param h global fs handle
1103 * @param ssf suspend signal function to use
1104 * @param ssf_cls closure for ssf
1105 * @return fresh top-level activity handle
1107 struct TopLevelActivity *
1108 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1109 SuspendSignalFunction ssf,
1114 * Destroy a top-level activity entry.
1116 * @param h global fs handle
1117 * @param top top level activity entry
1120 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
1121 struct TopLevelActivity *top);
1126 * Master context for most FS operations.
1128 struct GNUNET_FS_Handle
1133 struct GNUNET_SCHEDULER_Handle *sched;
1136 * Configuration to use.
1138 const struct GNUNET_CONFIGURATION_Handle *cfg;
1141 * Name of our client.
1146 * Function to call with updates on our progress.
1148 GNUNET_FS_ProgressCallback upcb;
1156 * Head of DLL of top-level activities.
1158 struct TopLevelActivity *top_head;
1161 * Tail of DLL of top-level activities.
1163 struct TopLevelActivity *top_tail;
1166 * Head of DLL of running jobs.
1168 struct GNUNET_FS_QueueEntry *running_head;
1171 * Tail of DLL of running jobs.
1173 struct GNUNET_FS_QueueEntry *running_tail;
1176 * Head of DLL of pending jobs.
1178 struct GNUNET_FS_QueueEntry *pending_head;
1181 * Tail of DLL of pending jobs.
1183 struct GNUNET_FS_QueueEntry *pending_tail;
1186 * Task that processes the jobs in the running and pending queues
1187 * (and moves jobs around as needed).
1189 GNUNET_SCHEDULER_TaskIdentifier queue_job;
1192 * Average time we take for a single request to be satisfied.
1193 * FIXME: not yet calcualted properly...
1195 struct GNUNET_TIME_Relative avg_block_latency;
1198 * How many actual downloads do we have running right now?
1200 unsigned int active_downloads;
1203 * How many blocks do the active downloads have?
1205 unsigned int active_blocks;
1210 enum GNUNET_FS_Flags flags;
1213 * Maximum number of parallel downloads.
1215 unsigned int max_parallel_downloads;
1218 * Maximum number of parallel requests.
1220 unsigned int max_parallel_requests;
1226 * Handle for controlling a publication process.
1228 struct GNUNET_FS_PublishContext
1231 * Handle to the global fs context.
1233 struct GNUNET_FS_Handle *h;
1236 * Our top-level activity entry (if we are top-level, otherwise NULL).
1238 struct TopLevelActivity *top;
1241 * File-structure that is being shared.
1243 struct GNUNET_FS_FileInformation *fi;
1246 * Namespace that we are publishing in, NULL if we have no namespace.
1248 struct GNUNET_FS_Namespace *namespace;
1251 * ID of the content in the namespace, NULL if we have no namespace.
1256 * ID for future updates, NULL if we have no namespace or no updates.
1261 * Filename used for serializing information about this operation
1262 * (should be determined using 'mktemp').
1264 char *serialization;
1267 * Our own client handle for the FS service; only briefly used when
1268 * we start to index a file, otherwise NULL.
1270 struct GNUNET_CLIENT_Connection *client;
1273 * Current position in the file-tree for the upload.
1275 struct GNUNET_FS_FileInformation *fi_pos;
1278 * Connection to the datastore service.
1280 struct GNUNET_DATASTORE_Handle *dsh;
1283 * ID of the task performing the upload. NO_TASK if the upload has
1286 GNUNET_SCHEDULER_TaskIdentifier upload_task;
1289 * Typically GNUNET_NO. Set to GNUNET_YES if "upload_task" is
1290 * GNUNET_SCHEDULER_NO_TASK and we're waiting for a response from
1291 * the datastore service (in which case this struct must not be
1292 * freed until we have that response). If someone tries to stop the
1293 * download for good during this period, "in_network_wait" is set to
1294 * GNUNET_SYSERR which will cause the struct to be destroyed right
1295 * after we have the reply (or timeout) from the datastore service.
1297 int in_network_wait;
1300 * Options for publishing.
1302 enum GNUNET_FS_PublishOptions options;
1305 * Space reservation ID with datastore service
1311 * Set to GNUNET_YES if all processing has completed.
1318 * Phases of unindex processing (state machine).
1323 * We're currently hashing the file.
1325 UNINDEX_STATE_HASHING = 0,
1328 * We're notifying the FS service about
1331 UNINDEX_STATE_FS_NOTIFY = 1,
1334 * We're telling the datastore to delete
1335 * the respective entries.
1337 UNINDEX_STATE_DS_REMOVE = 2,
1342 UNINDEX_STATE_COMPLETE = 3,
1345 * We've encountered a fatal error.
1347 UNINDEX_STATE_ERROR = 4
1353 * Handle for controlling an unindexing operation.
1355 struct GNUNET_FS_UnindexContext
1359 * Global FS context.
1361 struct GNUNET_FS_Handle *h;
1364 * Our top-level activity entry.
1366 struct TopLevelActivity *top;
1369 * Name of the file that we are unindexing.
1374 * Short name under which we are serializing the state of this operation.
1376 char *serialization;
1379 * Connection to the FS service, only valid during the
1380 * UNINDEX_STATE_FS_NOTIFY phase.
1382 struct GNUNET_CLIENT_Connection *client;
1385 * Connection to the datastore service, only valid during the
1386 * UNINDEX_STATE_DS_NOTIFY phase.
1388 struct GNUNET_DATASTORE_Handle *dsh;
1391 * Pointer kept for the client.
1396 * Merkle-ish tree encoder context.
1398 struct GNUNET_FS_TreeEncoder *tc;
1401 * Handle used to read the file.
1403 struct GNUNET_DISK_FileHandle *fh;
1406 * Error message, NULL on success.
1411 * Context for hashing of the file.
1413 struct GNUNET_CRYPTO_FileHashContext *fhc;
1416 * Overall size of the file.
1421 * When did we start?
1423 struct GNUNET_TIME_Absolute start_time;
1426 * Hash of the file's contents (once computed).
1428 GNUNET_HashCode file_id;
1431 * Current operatinonal phase.
1433 enum UnindexState state;
1439 * Information we keep for each keyword in
1442 struct SearchRequestEntry
1445 * Hash of the original keyword, also known as the
1446 * key (for decrypting the KBlock).
1448 GNUNET_HashCode key;
1451 * Hash of the public key, also known as the query.
1453 GNUNET_HashCode query;
1456 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1457 * was found under this keyword. Note that the entries will point
1458 * to the same locations as those in the master result map (in
1459 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1460 * The key for each entry is the XOR of the key and query in the CHK
1461 * URI (as a unique identifier for the search result).
1463 struct GNUNET_CONTAINER_MultiHashMap *results;
1466 * Is this keyword a mandatory keyword
1467 * (started with '+')?
1475 * Handle for controlling a search.
1477 struct GNUNET_FS_SearchContext
1480 * Handle to the global FS context.
1482 struct GNUNET_FS_Handle *h;
1485 * Our top-level activity entry (if we are top-level, otherwise NULL).
1487 struct TopLevelActivity *top;
1490 * List of keywords that we're looking for.
1492 struct GNUNET_FS_Uri *uri;
1495 * For update-searches, link to the search result that triggered
1496 * the update search; otherwise NULL.
1498 struct GNUNET_FS_SearchResult *psearch_result;
1501 * Connection to the FS service.
1503 struct GNUNET_CLIENT_Connection *client;
1506 * Pointer we keep for the client.
1511 * Name of the file on disk we use for persistence.
1513 char *serialization;
1516 * Error message (non-NULL if this operation failed).
1521 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1522 * was found in the search. The key for each entry is the XOR of
1523 * the key and query in the CHK URI (as a unique identifier for the
1526 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1529 * Per-keyword information for a keyword search. This array will
1530 * have exactly as many entries as there were keywords.
1532 struct SearchRequestEntry *requests;
1535 * When did we start?
1537 struct GNUNET_TIME_Absolute start_time;
1540 * ID of a task that is using this struct and that must be cancelled
1541 * when the search is being stopped (if not
1542 * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
1543 * artificial delay when trying to reconnect to the FS service.
1545 GNUNET_SCHEDULER_TaskIdentifier task;
1548 * Anonymity level for the search.
1553 * Number of mandatory keywords in this query.
1555 uint32_t mandatory_count;
1558 * Options for the search.
1560 enum GNUNET_FS_SearchOptions options;
1565 * Information about an active download request.
1567 struct DownloadRequest
1570 * While pending, we keep all download requests in a linked list.
1572 struct DownloadRequest *next;
1575 * CHK for the request.
1577 struct ContentHashKey chk;
1580 * Offset of the corresponding block.
1585 * Depth of the corresponding block in the tree.
1590 * Set if this request is currently in the linked list of pending
1591 * requests. Needed in case we get a response for a request that we
1592 * have not yet send (i.e. due to two blocks with identical
1593 * content); in this case, we would need to remove the block from
1594 * the pending list (and need a fast way to check if the block is on
1603 * Context for controlling a download.
1605 struct GNUNET_FS_DownloadContext
1609 * Global FS context.
1611 struct GNUNET_FS_Handle *h;
1614 * Our top-level activity entry (if we are top-level, otherwise NULL).
1616 struct TopLevelActivity *top;
1619 * Connection to the FS service.
1621 struct GNUNET_CLIENT_Connection *client;
1624 * Parent download (used when downloading files
1627 struct GNUNET_FS_DownloadContext *parent;
1630 * Associated search (used when downloading files
1631 * based on search results), or NULL for none.
1633 struct GNUNET_FS_SearchResult *search;
1636 * Head of list of child downloads.
1638 struct GNUNET_FS_DownloadContext *child_head;
1641 * Tail of list of child downloads.
1643 struct GNUNET_FS_DownloadContext *child_tail;
1646 * Previous download belonging to the same parent.
1648 struct GNUNET_FS_DownloadContext *prev;
1651 * Next download belonging to the same parent.
1653 struct GNUNET_FS_DownloadContext *next;
1656 * Context kept for the client.
1661 * URI that identifies the file that
1662 * we are downloading.
1664 struct GNUNET_FS_Uri *uri;
1667 * Known meta-data for the file (can be NULL).
1669 struct GNUNET_CONTAINER_MetaData *meta;
1672 * Error message, NULL if we're doing OK.
1677 * Random portion of filename we use for syncing state of this
1680 char *serialization;
1683 * Where are we writing the data (name of the
1684 * file, can be NULL!).
1689 * Where are we writing the data temporarily (name of the
1690 * file, can be NULL!); used if we do not have a permanent
1691 * name and we are a directory and we do a recursive download.
1693 char *temp_filename;
1696 * Map of active requests (those waiting
1697 * for a response). The key is the hash
1698 * of the encryped block (aka query).
1700 struct GNUNET_CONTAINER_MultiHashMap *active;
1703 * Linked list of pending requests.
1705 struct DownloadRequest *pending;
1708 * Non-NULL if we are currently having a request for
1709 * transmission pending with the client handle.
1711 struct GNUNET_CLIENT_TransmitHandle *th;
1714 * Our entry in the job queue.
1716 struct GNUNET_FS_QueueEntry *job_queue;
1719 * Identity of the peer having the content, or all-zeros
1720 * if we don't know of such a peer.
1722 struct GNUNET_PeerIdentity target;
1725 * ID of a task that is using this struct
1726 * and that must be cancelled when the download
1727 * is being stopped (if not GNUNET_SCHEDULER_NO_TASK).
1728 * Used for the task that adds some artificial
1729 * delay when trying to reconnect to the FS
1732 GNUNET_SCHEDULER_TaskIdentifier task;
1735 * What was the size of the file on disk that we're downloading
1736 * before we started? Used to detect if there is a point in
1737 * checking an existing block on disk for matching the desired
1738 * content. 0 if the file did not exist already.
1740 uint64_t old_file_size;
1743 * What is the first offset that we're interested
1749 * How many bytes starting from offset are desired?
1750 * This is NOT the overall length of the file!
1755 * How many bytes have we already received within
1756 * the specified range (DBlocks only).
1761 * Time download was started.
1763 struct GNUNET_TIME_Absolute start_time;
1766 * Desired level of anonymity.
1771 * The depth of the file-tree.
1773 unsigned int treedepth;
1776 * Options for the download.
1778 enum GNUNET_FS_DownloadOptions options;
1781 * Flag set upon transitive completion (includes child downloads).
1782 * This flag is only set to GNUNET_YES for directories where all
1783 * child-downloads have also completed (and signalled completion).
1789 struct GNUNET_FS_Namespace
1793 * Private key for the namespace.
1795 struct GNUNET_CRYPTO_RsaPrivateKey *key;
1798 * Name of the file with the private key.
1803 * Name of the namespace.
1808 * Reference counter.
1815 * Message sent from a GNUnet (fs) publishing activity to the
1816 * gnunet-fs-service to initiate indexing of a file. The service is
1817 * supposed to check if the specified file is available and has the
1818 * same cryptographic hash. It should then respond with either a
1819 * confirmation or a denial.
1821 * On OSes where this works, it is considered acceptable if the
1822 * service only checks that the path, device and inode match (it can
1823 * then be assumed that the hash will also match without actually
1824 * computing it; this is an optimization that should be safe given
1825 * that the client is not our adversary).
1827 struct IndexStartMessage
1831 * Message type will be GNUNET_MESSAGE_TYPE_FS_INDEX_START.
1833 struct GNUNET_MessageHeader header;
1836 * ID of device containing the file, as seen by the client. This
1837 * device ID is obtained using a call like "statvfs" (and converting
1838 * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
1839 * OS does not support this, in which case the service must do a
1840 * full hash recomputation.
1842 uint32_t device GNUNET_PACKED;
1845 * Inode of the file on the given device, as seen by the client
1846 * ("st_ino" field from "struct stat"). Use 0 if the OS does not
1847 * support this, in which case the service must do a full hash
1850 uint64_t inode GNUNET_PACKED;
1853 * Hash of the file that we would like to index.
1855 GNUNET_HashCode file_id;
1857 /* this is followed by a 0-terminated
1858 filename of a file with the hash
1859 "file_id" as seen by the client */
1865 * Message send by FS service in response to a request
1866 * asking for a list of all indexed files.
1868 struct IndexInfoMessage
1871 * Message type will be
1872 * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
1874 struct GNUNET_MessageHeader header;
1879 uint32_t reserved GNUNET_PACKED;
1882 * Hash of the indexed file.
1884 GNUNET_HashCode file_id;
1886 /* this is followed by a 0-terminated
1887 filename of a file with the hash
1888 "file_id" as seen by the client */
1894 * Message sent from a GNUnet (fs) unindexing activity to the
1895 * gnunet-service-fs to indicate that a file will be unindexed. The
1896 * service is supposed to remove the file from the list of indexed
1897 * files and response with a confirmation message (even if the file
1898 * was already not on the list).
1900 struct UnindexMessage
1904 * Message type will be
1905 * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
1907 struct GNUNET_MessageHeader header;
1912 uint32_t reserved GNUNET_PACKED;
1915 * Hash of the file that we will unindex.
1917 GNUNET_HashCode file_id;
1923 * Message sent from a GNUnet (fs) search activity to the
1924 * gnunet-service-fs to start a search.
1926 struct SearchMessage
1930 * Message type will be
1931 * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
1933 struct GNUNET_MessageHeader header;
1936 * Bitmask with options. Zero for no options, one for loopback-only.
1937 * Other bits are currently not defined.
1939 int32_t options GNUNET_PACKED;
1942 * Type of the content that we're looking for.
1944 uint32_t type GNUNET_PACKED;
1947 * Desired anonymity level, big-endian.
1949 uint32_t anonymity_level GNUNET_PACKED;
1952 * If the request is for a DBLOCK or IBLOCK, this is the identity of
1953 * the peer that is known to have a response. Set to all-zeros if
1954 * such a target is not known (note that even if OUR anonymity
1955 * level is >0 we may happen to know the responder's identity;
1956 * nevertheless, we should probably not use it for a DHT-lookup
1957 * or similar blunt actions in order to avoid exposing ourselves).
1959 * If the request is for an SBLOCK, this is the identity of the
1960 * pseudonym to which the SBLOCK belongs.
1962 * If the request is for a KBLOCK, "target" must be all zeros.
1964 GNUNET_HashCode target;
1967 * Hash of the keyword (aka query) for KBLOCKs; Hash of
1968 * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
1969 * and hash of the identifier XORed with the target for
1970 * SBLOCKS (aka query).
1972 GNUNET_HashCode query;
1974 /* this is followed by the hash codes of already-known
1975 results (which should hence be excluded from what
1976 the service returns); naturally, this only applies
1977 to queries that can have multiple results, such as
1978 those for KBLOCKS (KSK) and SBLOCKS (SKS) */
1983 * Only the (mandatory) query is included.
1985 #define GET_MESSAGE_BIT_QUERY_ONLY 0
1988 * The peer identity of a peer waiting for the
1989 * reply is included (used if the response
1990 * should be transmitted to someone other than
1991 * the sender of the GET).
1993 #define GET_MESSAGE_BIT_RETURN_TO 1
1996 * The hash of the public key of the target
1997 * namespace is included (for SKS queries).
1999 #define GET_MESSAGE_BIT_SKS_NAMESPACE 2
2002 * The peer identity of a peer that had claimed to have the content
2003 * previously is included (can be used if responder-anonymity is not
2004 * desired; note that the precursor presumably lacked a direct
2005 * connection to the specified peer; still, the receiver is in no way
2006 * required to limit forwarding only to the specified peer, it should
2007 * only prefer it somewhat if possible).
2009 #define GET_MESSAGE_BIT_TRANSMIT_TO 4
2013 * Message sent between peers asking for FS-content.
2019 * Message type will be GNUNET_MESSAGE_TYPE_FS_GET.
2021 struct GNUNET_MessageHeader header;
2024 * Type of the query (block type).
2026 uint32_t type GNUNET_PACKED;
2029 * How important is this request (network byte order)
2031 uint32_t priority GNUNET_PACKED;
2034 * Relative time to live in MILLISECONDS (network byte order)
2036 int32_t ttl GNUNET_PACKED;
2039 * The content hash should be mutated using this value
2040 * before checking against the bloomfilter (used to
2041 * get many different filters for the same hash codes).
2042 * The number should be in big-endian format when used
2045 int32_t filter_mutator GNUNET_PACKED;
2048 * Which of the optional hash codes are present at the end of the
2049 * message? See GET_MESSAGE_BIT_xx constants. For each bit that is
2050 * set, an additional GNUNET_HashCode with the respective content
2051 * (in order of the bits) will be appended to the end of the GET
2054 uint32_t hash_bitmap GNUNET_PACKED;
2057 * Hashcodes of the file(s) we're looking for.
2058 * Details depend on the query type.
2060 GNUNET_HashCode query GNUNET_PACKED;
2062 /* this is followed by hash codes
2063 as specified in the "hash_bitmap";
2064 after that, an optional bloomfilter
2065 (with bits set for replies that should
2066 be suppressed) can be present */
2071 * Response from FS service with a result for a previous FS search.
2072 * Note that queries for DBLOCKS and IBLOCKS that have received a
2073 * single response are considered done. This message is transmitted
2074 * between peers as well as between the service and a client.
2080 * Message type will be GNUNET_MESSAGE_TYPE_FS_PUT.
2082 struct GNUNET_MessageHeader header;
2085 * Type of the block (in big endian). Should never be zero.
2087 uint32_t type GNUNET_PACKED;
2090 * When does this result expire?
2092 struct GNUNET_TIME_AbsoluteNBO expiration;
2094 /* this is followed by the actual encrypted content */