3 This file is part of GNUnet.
4 (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
6 GNUnet is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 3, or (at your
9 option) any later version.
11 GNUnet is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNUnet; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
24 * @brief definitions for the entire fs module
25 * @author Igor Wronsky, Christian Grothoff
30 #include "gnunet_constants.h"
31 #include "gnunet_datastore_service.h"
32 #include "gnunet_fs_service.h"
33 #include "gnunet_block_lib.h"
36 * Maximum size of the datastore queue for P2P operations.
38 #define MAX_DATASTORE_QUEUE 16
41 * Maximum number of blocks we keep in memory for migration.
43 #define MAX_MIGRATION_QUEUE 32
46 * How many peers do we select as possible
47 * targets per block obtained for migration?
49 #define MIGRATION_LIST_SIZE 4
52 * To how many peers do we forward each migration block ultimately?
53 * This number must be smaller or equal to MIGRATION_LIST_SIZE. Using
54 * a smaller value allows for variation in available bandwidth (for
55 * migration) between the peers.
57 #define MIGRATION_TARGET_COUNT 2
60 * Ratio for moving average delay calculation. The previous
61 * average goes in with a factor of (n-1) into the calculation.
64 #define RUNAVG_DELAY_N 16
67 * Size of the individual blocks used for file-sharing.
69 #define DBLOCK_SIZE (32*1024)
72 * Maximum legal size for a kblock.
74 #define MAX_KBLOCK_SIZE (60 * 1024)
77 * Maximum legal size for an sblock.
79 #define MAX_SBLOCK_SIZE (60 * 1024)
82 * Maximum legal size for an nblock.
84 #define MAX_NBLOCK_SIZE (60 * 1024)
87 * Pick a multiple of 2 here to achive 8-byte alignment!
88 * We also probably want DBlocks to have (roughly) the
89 * same size as IBlocks. With SHA-512, the optimal
90 * value is 32768 byte / 128 byte = 256
91 * (128 byte = 2 * 512 bits). DO NOT CHANGE!
93 #define CHK_PER_INODE 256
97 * Maximum size for a file to be considered for
98 * inlining in a directory.
100 #define MAX_INLINE_SIZE 65536
104 * Blocksize to use when hashing files
105 * for indexing (blocksize for IO, not for
106 * the DBlocks). Larger blocksizes can
107 * be more efficient but will be more disruptive
108 * as far as the scheduler is concerned.
110 #define HASHING_BLOCKSIZE (1024 * 1024)
113 * Number of bits we set per entry in the bloomfilter.
116 #define BLOOMFILTER_K 16
119 * Number of availability trials we perform per search result.
121 #define AVAILABILITY_TRIALS_MAX 8
124 * By how much (in ms) do we decrement the TTL
127 #define TTL_DECREMENT 5000
130 * Length of the P2P success tracker. Note that
131 * having a very long list can also hurt performance.
133 #define P2P_SUCCESS_LIST_SIZE 8
137 * Length of the CS-2-P success tracker. Note that
138 * having a very long list can also hurt performance.
140 #define CS2P_SUCCESS_LIST_SIZE 8
143 * How long are we willing to wait for the datastore to be ready to
144 * process a request for a query without priority?
146 #define BASIC_DATASTORE_REQUEST_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
150 * How long are we willing to wait for the core to be ready to
151 * transmit a reply to the target peer (if we can not transmit
152 * until then, we will discard the reply).
154 #define ACCEPTABLE_REPLY_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
158 * Bandwidth value of an (effectively) 0-priority query.
160 #define QUERY_BANDWIDTH_VALUE 1
163 * Bandwidth value of a 0-priority content (must be
164 * fairly high compared to query since content is
165 * typically significantly larger -- and more valueable
166 * since it can take many queries to get one piece of
169 #define CONTENT_BANDWIDTH_VALUE 800
172 * By which amount do we decrement the TTL for simple forwarding /
173 * indirection of the query; in milli-seconds. Set somewhat in
174 * accordance to your network latency (above the time it'll take you
175 * to send a packet and get a reply).
177 #define TTL_DECREMENT 5000
180 * Until which load do we consider the peer idle and do not
181 * charge at all? (should be larger than GNUNET_IDLE_LOAD_THRESHOLD used
182 * by the rest of the code)!
184 #define IDLE_LOAD_THRESHOLD ((100 + GNUNET_CONSTANTS_IDLE_LOAD_THRESHOLD) / 2)
187 * Name of the directory with top-level searches.
189 #define GNUNET_FS_SYNC_PATH_MASTER_SEARCH "search"
192 * Name of the directory with sub-searches (namespace-updates).
194 #define GNUNET_FS_SYNC_PATH_CHILD_SEARCH "search-child"
197 * Name of the directory with master downloads (not associated
198 * with search or part of another download).
200 #define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD "download"
203 * Name of the directory with downloads that are part of another
204 * download or a search.
206 #define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD "download-child"
209 * Name of the directory with publishing operations.
211 #define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH "publish"
214 * Name of the directory with files that are being published
216 #define GNUNET_FS_SYNC_PATH_FILE_INFO "publish-file"
219 * Name of the directory with unindex operations.
221 #define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX "unindex"
225 * @brief content hash key
227 struct ContentHashKey
230 * Hash of the original content, used for encryption.
235 * Hash of the encrypted content, used for querying.
237 GNUNET_HashCode query;
242 * @brief complete information needed
243 * to download a file.
245 struct FileIdentifier
249 * Total size of the file in bytes. (network byte order (!))
251 uint64_t file_length;
254 * Query and key of the top GNUNET_EC_IBlock.
256 struct ContentHashKey chk;
262 * Information about a file and its location
263 * (peer claiming to share the file).
268 * Information about the shared file.
270 struct FileIdentifier fi;
273 * Identity of the peer sharing the file.
275 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
278 * Time when this location URI expires.
280 struct GNUNET_TIME_Absolute expirationTime;
283 * RSA signature over the GNUNET_EC_FileIdentifier,
284 * GNUNET_hash of the peer and expiration time.
286 struct GNUNET_CRYPTO_RsaSignature contentSignature;
296 * Content-hash-key (simple file).
301 * Signed key space (file in namespace).
306 * Keyword search key (query with keywords).
311 * Location (chk with identity of hosting peer).
317 * A Universal Resource Identifier (URI), opaque.
331 * Keywords start with a '+' if they are
332 * mandatory (in which case the '+' is NOT
333 * part of the keyword) and with a
334 * simple space if they are optional
335 * (in which case the space is ALSO not
336 * part of the actual keyword).
338 * Double-quotes to protect spaces and
339 * %-encoding are NOT used internally
340 * (only in URI-strings).
345 * Size of the keywords array.
347 unsigned int keywordCount;
353 * Hash of the public key for the namespace.
355 GNUNET_HashCode namespace;
358 * Human-readable identifier chosen for this
359 * entry in the namespace.
365 * Information needed to retrieve a file (content-hash-key
368 struct FileIdentifier chk;
371 * Information needed to retrieve a file including signed
372 * location (identity of a peer) of the content.
381 * Information for a file or directory that is
382 * about to be published.
384 struct GNUNET_FS_FileInformation
388 * Files in a directory are kept as a linked list.
390 struct GNUNET_FS_FileInformation *next;
393 * If this is a file in a directory, "dir" refers to
394 * the directory; otherwise NULL.
396 struct GNUNET_FS_FileInformation *dir;
399 * Handle to the master context.
401 struct GNUNET_FS_Handle *h;
404 * Pointer kept for the client.
409 * Metadata to use for the file.
411 struct GNUNET_CONTAINER_MetaData *meta;
414 * Keywords to use for KBlocks.
416 struct GNUNET_FS_Uri *keywords;
419 * CHK for this file or directory. NULL if
420 * we have not yet computed it.
422 struct GNUNET_FS_Uri *chk_uri;
425 * At what time should the content expire?
427 struct GNUNET_TIME_Absolute expirationTime;
430 * At what time did we start this upload?
432 struct GNUNET_TIME_Absolute start_time;
435 * Under what filename is this struct serialized
436 * (for operational persistence). Should be determined
442 * Encoder being used to publish this file.
444 struct GNUNET_FS_TreeEncoder *te;
447 * Error message (non-NULL if this operation failed).
452 * Name of the file or directory (must be an absolute path).
457 * Data describing either the file or the directory.
468 * Function that can be used to read the data for the file.
470 GNUNET_FS_DataReader reader;
473 * Closure for reader.
478 * If this file is being indexed, this value is set to the hash
479 * over the entire file (when the indexing process is started).
480 * Otherwise this field is not used.
482 GNUNET_HashCode file_id;
485 * Size of the file (in bytes).
490 * Should the file be indexed or inserted?
495 * Is "file_id" already valid? Set to GNUNET_YES once the hash
496 * has been calculated.
501 * Has the service confirmed our INDEX_START request?
502 * GNUNET_YES if this step has been completed.
504 int index_start_confirmed;
509 * Data for a directory.
514 * Linked list of entries in the directory.
516 struct GNUNET_FS_FileInformation *entries;
519 * Size of the directory itself (in bytes); 0 if the
520 * size has not yet been calculated.
525 * Pointer to the data for the directory (or NULL if not
535 * Desired anonymity level.
540 * Desired priority (for keeping the content in the DB).
545 * Is this struct for a file or directory?
550 * Are we done publishing this file?
558 * The job is now ready to run and should use the given client
559 * handle to communicate with the FS service.
562 * @param client handle to use for FS communication
564 typedef void (*GNUNET_FS_QueueStart)(void *cls,
565 struct GNUNET_CLIENT_Connection *client);
569 * The job must now stop to run and should destry the client handle as
570 * soon as possible (ideally prior to returning).
572 typedef void (*GNUNET_FS_QueueStop)(void *cls);
576 * Entry in the job queue.
578 struct GNUNET_FS_QueueEntry
581 * This is a linked list.
583 struct GNUNET_FS_QueueEntry *next;
586 * This is a linked list.
588 struct GNUNET_FS_QueueEntry *prev;
591 * Function to call when the job is started.
593 GNUNET_FS_QueueStart start;
596 * Function to call when the job needs to stop (or is done / dequeued).
598 GNUNET_FS_QueueStop stop;
601 * Closure for start and stop.
606 * Handle to FS primary context.
608 struct GNUNET_FS_Handle *h;
611 * Client handle, or NULL if job is not running.
613 struct GNUNET_CLIENT_Connection *client;
616 * Time the job was originally queued.
618 struct GNUNET_TIME_Absolute queue_time;
621 * Time the job was started last.
623 struct GNUNET_TIME_Absolute start_time;
626 * Total amount of time the job has been running (except for the
629 struct GNUNET_TIME_Relative run_time;
632 * How many blocks do the active downloads have?
637 * How often have we (re)started this download?
639 unsigned int start_times;
647 * Information we store for each search result.
649 struct GNUNET_FS_SearchResult
653 * Search context this result belongs to.
655 struct GNUNET_FS_SearchContext *sc;
658 * URI to which this search result refers to.
660 struct GNUNET_FS_Uri *uri;
663 * Metadata for the search result.
665 struct GNUNET_CONTAINER_MetaData *meta;
668 * Client info for this search result.
673 * ID of a job that is currently probing this results' availability
674 * (NULL if we are not currently probing).
676 struct GNUNET_FS_DownloadContext *probe_ctx;
679 * ID of an associated download based on this search result (or
682 struct GNUNET_FS_DownloadContext *download;
685 * If this search result triggered an update search, this field
686 * links to the update search.
688 struct GNUNET_FS_SearchContext *update_search;
691 * Name under which this search result is stored on disk.
696 * Key for the search result
701 * ID of the task that will clean up the probe_ctx should it not
702 * complete on time (and that will need to be cancelled if we clean
703 * up the search result before then).
705 GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
708 * When did the current probe become active?
710 struct GNUNET_TIME_Absolute probe_active_time;
713 * How much longer should we run the current probe before giving up?
715 struct GNUNET_TIME_Relative remaining_probe_time;
718 * Number of mandatory keywords for which we have NOT yet found the
719 * search result; when this value hits zero, the search result is
720 * given to the callback.
722 uint32_t mandatory_missing;
725 * Number of optional keywords under which this result was also
728 uint32_t optional_support;
731 * Number of availability tests that have succeeded for this result.
733 uint32_t availability_success;
736 * Number of availability trials that we have performed for this
739 uint32_t availability_trials;
745 * Add a job to the queue.
747 * @param h handle to the overall FS state
748 * @param start function to call to begin the job
749 * @param stop function to call to pause the job, or on dequeue (if the job was running)
750 * @param cls closure for start and stop
751 * @param blocks number of blocks this download has
752 * @return queue handle
754 struct GNUNET_FS_QueueEntry *
755 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
756 GNUNET_FS_QueueStart start,
757 GNUNET_FS_QueueStop stop,
759 unsigned int blocks);
763 * Dequeue a job from the queue.
764 * @param qh handle for the job
767 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
771 * Function that provides data by reading from a file.
773 * @param cls closure (points to the file information)
774 * @param offset offset to read from; it is possible
775 * that the caller might need to go backwards
777 * @param max maximum number of bytes that should be
778 * copied to buf; readers are not allowed
779 * to provide less data unless there is an error;
780 * a value of "0" will be used at the end to allow
781 * the reader to clean up its internal state
782 * @param buf where the reader should write the data
783 * @param emsg location for the reader to store an error message
784 * @return number of bytes written, usually "max", 0 on error
787 GNUNET_FS_data_reader_file_(void *cls,
795 * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
797 * @param filename file to read
798 * @return closure to use
801 GNUNET_FS_make_file_reader_context_ (const char *filename);
806 * Function that provides data by copying from a buffer.
808 * @param cls closure (points to the buffer)
809 * @param offset offset to read from; it is possible
810 * that the caller might need to go backwards
812 * @param max maximum number of bytes that should be
813 * copied to buf; readers are not allowed
814 * to provide less data unless there is an error;
815 * a value of "0" will be used at the end to allow
816 * the reader to clean up its internal state
817 * @param buf where the reader should write the data
818 * @param emsg location for the reader to store an error message
819 * @return number of bytes written, usually "max", 0 on error
822 GNUNET_FS_data_reader_copy_(void *cls,
829 * Notification of FS that a search probe has made progress.
830 * This function is used INSTEAD of the client's event handler
831 * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
833 * @param cls closure, always NULL (!), actual closure
834 * is in the client-context of the info struct
835 * @param info details about the event, specifying the event type
836 * and various bits about the event
837 * @return client-context (for the next progress call
838 * for this operation; should be set to NULL for
839 * SUSPEND and STOPPED events). The value returned
840 * will be passed to future callbacks in the respective
841 * field in the GNUNET_FS_ProgressInfo struct.
844 GNUNET_FS_search_probe_progress_ (void *cls,
845 const struct GNUNET_FS_ProgressInfo *info);
849 * Main function that performs the upload.
851 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
852 * @param tc task context
855 GNUNET_FS_publish_main_ (void *cls,
856 const struct GNUNET_SCHEDULER_TaskContext *tc);
860 * Function called once the hash of the file
861 * that is being unindexed has been computed.
863 * @param cls closure, unindex context
864 * @param file_id computed hash, NULL on error
867 GNUNET_FS_unindex_process_hash_ (void *cls,
868 const GNUNET_HashCode *file_id);
872 * Fill in all of the generic fields for a publish event and call the
875 * @param pi structure to fill in
876 * @param sc overall publishing context
877 * @param p file information for the file being published
878 * @param offset where in the file are we so far
879 * @return value returned from callback
882 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
883 struct GNUNET_FS_PublishContext *sc,
884 const struct GNUNET_FS_FileInformation *p,
889 * Fill in all of the generic fields for a download event and call the
892 * @param pi structure to fill in
893 * @param dc overall download context
896 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
897 struct GNUNET_FS_DownloadContext *dc);
901 * Fill in all of the generic fields for
902 * an unindex event and call the callback.
904 * @param pi structure to fill in
905 * @param uc overall unindex context
906 * @param offset where we are in the file (for progress)
909 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
910 struct GNUNET_FS_UnindexContext *uc,
914 * Fill in all of the generic fields for a search event and
917 * @param pi structure to fill in
918 * @param sc overall search context
919 * @return value returned by the callback
922 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
923 struct GNUNET_FS_SearchContext *sc);
927 * Connect to the datastore and remove the blocks.
929 * @param uc context for the unindex operation.
932 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
935 * Build the request and actually initiate the search using the
938 * @param sc search context
939 * @return GNUNET_OK on success, GNUNET_SYSERR on error
942 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
945 * Start the downloading process (by entering the queue).
947 * @param dc our download context
950 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
954 * Start download probes for the given search result.
956 * @param sr the search result
959 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
962 * Remove serialization/deserialization file from disk.
964 * @param h master context
965 * @param ext component of the path
966 * @param ent entity identifier
969 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
975 * Remove serialization/deserialization directory from disk.
977 * @param h master context
978 * @param ext component of the path
979 * @param uni unique name of parent
982 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
988 * Synchronize this file-information struct with its mirror
989 * on disk. Note that all internal FS-operations that change
990 * file information data should already call "sync" internally,
991 * so this function is likely not useful for clients.
993 * @param fi the struct to sync
996 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
999 * Synchronize this publishing struct with its mirror
1000 * on disk. Note that all internal FS-operations that change
1001 * publishing structs should already call "sync" internally,
1002 * so this function is likely not useful for clients.
1004 * @param pc the struct to sync
1007 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
1010 * Synchronize this unindex struct with its mirror
1011 * on disk. Note that all internal FS-operations that change
1012 * publishing structs should already call "sync" internally,
1013 * so this function is likely not useful for clients.
1015 * @param uc the struct to sync
1018 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
1021 * Synchronize this search struct with its mirror
1022 * on disk. Note that all internal FS-operations that change
1023 * publishing structs should already call "sync" internally,
1024 * so this function is likely not useful for clients.
1026 * @param sc the struct to sync
1029 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
1032 * Synchronize this search result with its mirror
1033 * on disk. Note that all internal FS-operations that change
1034 * publishing structs should already call "sync" internally,
1035 * so this function is likely not useful for clients.
1037 * @param sr the struct to sync
1040 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
1043 * Synchronize this download struct with its mirror
1044 * on disk. Note that all internal FS-operations that change
1045 * publishing structs should already call "sync" internally,
1046 * so this function is likely not useful for clients.
1048 * @param dc the struct to sync
1051 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
1054 * Create SUSPEND event for the given publish operation
1055 * and then clean up our state (without stop signal).
1057 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
1060 GNUNET_FS_publish_signal_suspend_ (void *cls);
1063 * Create SUSPEND event for the given search operation
1064 * and then clean up our state (without stop signal).
1066 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
1069 GNUNET_FS_search_signal_suspend_ (void *cls);
1072 * Create SUSPEND event for the given download operation
1073 * and then clean up our state (without stop signal).
1075 * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
1078 GNUNET_FS_download_signal_suspend_ (void *cls);
1081 * Create SUSPEND event for the given unindex operation
1082 * and then clean up our state (without stop signal).
1084 * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
1087 GNUNET_FS_unindex_signal_suspend_ (void *cls);
1090 * Function signature of the functions that can be called
1091 * to trigger suspend signals and clean-up for top-level
1094 * @param cls closure
1096 typedef void (*SuspendSignalFunction)(void *cls);
1099 * We track all of the top-level activities of FS
1100 * so that we can signal 'suspend' on shutdown.
1102 struct TopLevelActivity
1105 * This is a doubly-linked list.
1107 struct TopLevelActivity *next;
1110 * This is a doubly-linked list.
1112 struct TopLevelActivity *prev;
1115 * Function to call for suspend-signalling and clean up.
1117 SuspendSignalFunction ssf;
1120 * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1127 * Create a top-level activity entry.
1129 * @param h global fs handle
1130 * @param ssf suspend signal function to use
1131 * @param ssf_cls closure for ssf
1132 * @return fresh top-level activity handle
1134 struct TopLevelActivity *
1135 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1136 SuspendSignalFunction ssf,
1141 * Destroy a top-level activity entry.
1143 * @param h global fs handle
1144 * @param top top level activity entry
1147 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
1148 struct TopLevelActivity *top);
1153 * Master context for most FS operations.
1155 struct GNUNET_FS_Handle
1160 struct GNUNET_SCHEDULER_Handle *sched;
1163 * Configuration to use.
1165 const struct GNUNET_CONFIGURATION_Handle *cfg;
1168 * Name of our client.
1173 * Function to call with updates on our progress.
1175 GNUNET_FS_ProgressCallback upcb;
1183 * Head of DLL of top-level activities.
1185 struct TopLevelActivity *top_head;
1188 * Tail of DLL of top-level activities.
1190 struct TopLevelActivity *top_tail;
1193 * Head of DLL of running jobs.
1195 struct GNUNET_FS_QueueEntry *running_head;
1198 * Tail of DLL of running jobs.
1200 struct GNUNET_FS_QueueEntry *running_tail;
1203 * Head of DLL of pending jobs.
1205 struct GNUNET_FS_QueueEntry *pending_head;
1208 * Tail of DLL of pending jobs.
1210 struct GNUNET_FS_QueueEntry *pending_tail;
1213 * Task that processes the jobs in the running and pending queues
1214 * (and moves jobs around as needed).
1216 GNUNET_SCHEDULER_TaskIdentifier queue_job;
1219 * Average time we take for a single request to be satisfied.
1220 * FIXME: not yet calcualted properly...
1222 struct GNUNET_TIME_Relative avg_block_latency;
1225 * How many actual downloads do we have running right now?
1227 unsigned int active_downloads;
1230 * How many blocks do the active downloads have?
1232 unsigned int active_blocks;
1237 enum GNUNET_FS_Flags flags;
1240 * Maximum number of parallel downloads.
1242 unsigned int max_parallel_downloads;
1245 * Maximum number of parallel requests.
1247 unsigned int max_parallel_requests;
1253 * Handle for controlling a publication process.
1255 struct GNUNET_FS_PublishContext
1258 * Handle to the global fs context.
1260 struct GNUNET_FS_Handle *h;
1263 * Our top-level activity entry (if we are top-level, otherwise NULL).
1265 struct TopLevelActivity *top;
1268 * File-structure that is being shared.
1270 struct GNUNET_FS_FileInformation *fi;
1273 * Namespace that we are publishing in, NULL if we have no namespace.
1275 struct GNUNET_FS_Namespace *namespace;
1278 * ID of the content in the namespace, NULL if we have no namespace.
1283 * ID for future updates, NULL if we have no namespace or no updates.
1288 * Filename used for serializing information about this operation
1289 * (should be determined using 'mktemp').
1291 char *serialization;
1294 * Our own client handle for the FS service; only briefly used when
1295 * we start to index a file, otherwise NULL.
1297 struct GNUNET_CLIENT_Connection *client;
1300 * Current position in the file-tree for the upload.
1302 struct GNUNET_FS_FileInformation *fi_pos;
1305 * Non-null if we are currently hashing a file.
1307 struct GNUNET_CRYPTO_FileHashContext *fhc;
1310 * Connection to the datastore service.
1312 struct GNUNET_DATASTORE_Handle *dsh;
1315 * Queue entry for reservation/unreservation.
1317 struct GNUNET_DATASTORE_QueueEntry *qre;
1320 * ID of the task performing the upload. NO_TASK if the upload has
1323 GNUNET_SCHEDULER_TaskIdentifier upload_task;
1326 * Storage space to reserve for the operation.
1328 uint64_t reserve_space;
1331 * Overall number of entries to reserve for the
1332 * publish operation.
1334 uint32_t reserve_entries;
1337 * Typically GNUNET_NO. Set to GNUNET_YES if "upload_task" is
1338 * GNUNET_SCHEDULER_NO_TASK and we're waiting for a response from
1339 * the datastore service (in which case this struct must not be
1340 * freed until we have that response). If someone tries to stop the
1341 * download for good during this period, "in_network_wait" is set to
1342 * GNUNET_SYSERR which will cause the struct to be destroyed right
1343 * after we have the reply (or timeout) from the datastore service.
1345 int in_network_wait;
1348 * Options for publishing.
1350 enum GNUNET_FS_PublishOptions options;
1353 * Space reservation ID with datastore service
1359 * Set to GNUNET_YES if all processing has completed.
1366 * Phases of unindex processing (state machine).
1371 * We're currently hashing the file.
1373 UNINDEX_STATE_HASHING = 0,
1376 * We're telling the datastore to delete
1377 * the respective entries.
1379 UNINDEX_STATE_DS_REMOVE = 1,
1382 * We're notifying the FS service about
1385 UNINDEX_STATE_FS_NOTIFY = 2,
1390 UNINDEX_STATE_COMPLETE = 3,
1393 * We've encountered a fatal error.
1395 UNINDEX_STATE_ERROR = 4
1401 * Handle for controlling an unindexing operation.
1403 struct GNUNET_FS_UnindexContext
1407 * Global FS context.
1409 struct GNUNET_FS_Handle *h;
1412 * Our top-level activity entry.
1414 struct TopLevelActivity *top;
1417 * Name of the file that we are unindexing.
1422 * Short name under which we are serializing the state of this operation.
1424 char *serialization;
1427 * Connection to the FS service, only valid during the
1428 * UNINDEX_STATE_FS_NOTIFY phase.
1430 struct GNUNET_CLIENT_Connection *client;
1433 * Connection to the datastore service, only valid during the
1434 * UNINDEX_STATE_DS_NOTIFY phase.
1436 struct GNUNET_DATASTORE_Handle *dsh;
1439 * Pointer kept for the client.
1444 * Merkle-ish tree encoder context.
1446 struct GNUNET_FS_TreeEncoder *tc;
1449 * Handle used to read the file.
1451 struct GNUNET_DISK_FileHandle *fh;
1454 * Error message, NULL on success.
1459 * Context for hashing of the file.
1461 struct GNUNET_CRYPTO_FileHashContext *fhc;
1464 * Overall size of the file.
1469 * When did we start?
1471 struct GNUNET_TIME_Absolute start_time;
1474 * Hash of the file's contents (once computed).
1476 GNUNET_HashCode file_id;
1479 * Current operatinonal phase.
1481 enum UnindexState state;
1487 * Information we keep for each keyword in
1490 struct SearchRequestEntry
1493 * Hash of the original keyword, also known as the
1494 * key (for decrypting the KBlock).
1496 GNUNET_HashCode key;
1499 * Hash of the public key, also known as the query.
1501 GNUNET_HashCode query;
1504 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1505 * was found under this keyword. Note that the entries will point
1506 * to the same locations as those in the master result map (in
1507 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1508 * The key for each entry is the XOR of the key and query in the CHK
1509 * URI (as a unique identifier for the search result).
1511 struct GNUNET_CONTAINER_MultiHashMap *results;
1514 * Is this keyword a mandatory keyword
1515 * (started with '+')?
1523 * Handle for controlling a search.
1525 struct GNUNET_FS_SearchContext
1528 * Handle to the global FS context.
1530 struct GNUNET_FS_Handle *h;
1533 * Our top-level activity entry (if we are top-level, otherwise NULL).
1535 struct TopLevelActivity *top;
1538 * List of keywords that we're looking for.
1540 struct GNUNET_FS_Uri *uri;
1543 * For update-searches, link to the search result that triggered
1544 * the update search; otherwise NULL.
1546 struct GNUNET_FS_SearchResult *psearch_result;
1549 * Connection to the FS service.
1551 struct GNUNET_CLIENT_Connection *client;
1554 * Pointer we keep for the client.
1559 * Name of the file on disk we use for persistence.
1561 char *serialization;
1564 * Error message (non-NULL if this operation failed).
1569 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1570 * was found in the search. The key for each entry is the XOR of
1571 * the key and query in the CHK URI (as a unique identifier for the
1574 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1577 * Per-keyword information for a keyword search. This array will
1578 * have exactly as many entries as there were keywords.
1580 struct SearchRequestEntry *requests;
1583 * When did we start?
1585 struct GNUNET_TIME_Absolute start_time;
1588 * ID of a task that is using this struct and that must be cancelled
1589 * when the search is being stopped (if not
1590 * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
1591 * artificial delay when trying to reconnect to the FS service.
1593 GNUNET_SCHEDULER_TaskIdentifier task;
1596 * Anonymity level for the search.
1601 * Number of mandatory keywords in this query.
1603 uint32_t mandatory_count;
1606 * Options for the search.
1608 enum GNUNET_FS_SearchOptions options;
1613 * Information about an active download request.
1615 struct DownloadRequest
1618 * While pending, we keep all download requests in a linked list.
1620 struct DownloadRequest *next;
1623 * CHK for the request.
1625 struct ContentHashKey chk;
1628 * Offset of the corresponding block.
1633 * Depth of the corresponding block in the tree.
1638 * Set if this request is currently in the linked list of pending
1639 * requests. Needed in case we get a response for a request that we
1640 * have not yet send (i.e. due to two blocks with identical
1641 * content); in this case, we would need to remove the block from
1642 * the pending list (and need a fast way to check if the block is on
1651 * Context for controlling a download.
1653 struct GNUNET_FS_DownloadContext
1657 * Global FS context.
1659 struct GNUNET_FS_Handle *h;
1662 * Our top-level activity entry (if we are top-level, otherwise NULL).
1664 struct TopLevelActivity *top;
1667 * Connection to the FS service.
1669 struct GNUNET_CLIENT_Connection *client;
1672 * Parent download (used when downloading files
1675 struct GNUNET_FS_DownloadContext *parent;
1678 * Associated search (used when downloading files
1679 * based on search results), or NULL for none.
1681 struct GNUNET_FS_SearchResult *search;
1684 * Head of list of child downloads.
1686 struct GNUNET_FS_DownloadContext *child_head;
1689 * Tail of list of child downloads.
1691 struct GNUNET_FS_DownloadContext *child_tail;
1694 * Previous download belonging to the same parent.
1696 struct GNUNET_FS_DownloadContext *prev;
1699 * Next download belonging to the same parent.
1701 struct GNUNET_FS_DownloadContext *next;
1704 * Context kept for the client.
1709 * URI that identifies the file that
1710 * we are downloading.
1712 struct GNUNET_FS_Uri *uri;
1715 * Known meta-data for the file (can be NULL).
1717 struct GNUNET_CONTAINER_MetaData *meta;
1720 * Error message, NULL if we're doing OK.
1725 * Random portion of filename we use for syncing state of this
1728 char *serialization;
1731 * Where are we writing the data (name of the
1732 * file, can be NULL!).
1737 * Where are we writing the data temporarily (name of the
1738 * file, can be NULL!); used if we do not have a permanent
1739 * name and we are a directory and we do a recursive download.
1741 char *temp_filename;
1744 * Map of active requests (those waiting
1745 * for a response). The key is the hash
1746 * of the encryped block (aka query).
1748 struct GNUNET_CONTAINER_MultiHashMap *active;
1751 * Linked list of pending requests.
1753 struct DownloadRequest *pending;
1756 * Non-NULL if we are currently having a request for
1757 * transmission pending with the client handle.
1759 struct GNUNET_CLIENT_TransmitHandle *th;
1762 * Our entry in the job queue.
1764 struct GNUNET_FS_QueueEntry *job_queue;
1767 * Identity of the peer having the content, or all-zeros
1768 * if we don't know of such a peer.
1770 struct GNUNET_PeerIdentity target;
1773 * ID of a task that is using this struct
1774 * and that must be cancelled when the download
1775 * is being stopped (if not GNUNET_SCHEDULER_NO_TASK).
1776 * Used for the task that adds some artificial
1777 * delay when trying to reconnect to the FS
1780 GNUNET_SCHEDULER_TaskIdentifier task;
1783 * What was the size of the file on disk that we're downloading
1784 * before we started? Used to detect if there is a point in
1785 * checking an existing block on disk for matching the desired
1786 * content. 0 if the file did not exist already.
1788 uint64_t old_file_size;
1791 * What is the first offset that we're interested
1797 * How many bytes starting from offset are desired?
1798 * This is NOT the overall length of the file!
1803 * How many bytes have we already received within
1804 * the specified range (DBlocks only).
1809 * Time download was started.
1811 struct GNUNET_TIME_Absolute start_time;
1814 * Desired level of anonymity.
1819 * The depth of the file-tree.
1821 unsigned int treedepth;
1824 * Options for the download.
1826 enum GNUNET_FS_DownloadOptions options;
1829 * Flag set upon transitive completion (includes child downloads).
1830 * This flag is only set to GNUNET_YES for directories where all
1831 * child-downloads have also completed (and signalled completion).
1836 * Have we tried (and failed) to find matching full
1837 * data from the meta data yet?
1839 int tried_full_data;
1844 * Information about an (updateable) node in the
1847 struct NamespaceUpdateNode
1850 * Identifier for this node.
1855 * Identifier of children of this node.
1860 * Metadata for this entry.
1862 struct GNUNET_CONTAINER_MetaData *md;
1865 * URI of this entry in the namespace.
1867 struct GNUNET_FS_Uri *uri;
1870 * Namespace update generation ID. Used to ensure
1871 * freshness of the scc_id.
1876 * SCC this entry belongs to (if nug is current).
1878 unsigned int scc_id;
1883 struct GNUNET_FS_Namespace
1887 * Handle to the FS service context.
1889 struct GNUNET_FS_Handle *h;
1892 * Array with information about nodes in the namespace.
1894 struct NamespaceUpdateNode **update_nodes;
1897 * Private key for the namespace.
1899 struct GNUNET_CRYPTO_RsaPrivateKey *key;
1902 * Hash map mapping identifiers of update nodes
1903 * to the update nodes (initialized on-demand).
1905 struct GNUNET_CONTAINER_MultiHashMap *update_map;
1908 * Name of the file with the private key.
1913 * Name of the namespace.
1918 * Size of the update nodes array.
1920 unsigned int update_node_count;
1923 * Reference counter.
1928 * Generator for unique nug numbers.
1930 unsigned int nug_gen;
1935 * Message sent from a GNUnet (fs) publishing activity to the
1936 * gnunet-fs-service to initiate indexing of a file. The service is
1937 * supposed to check if the specified file is available and has the
1938 * same cryptographic hash. It should then respond with either a
1939 * confirmation or a denial.
1941 * On OSes where this works, it is considered acceptable if the
1942 * service only checks that the path, device and inode match (it can
1943 * then be assumed that the hash will also match without actually
1944 * computing it; this is an optimization that should be safe given
1945 * that the client is not our adversary).
1947 struct IndexStartMessage
1951 * Message type will be GNUNET_MESSAGE_TYPE_FS_INDEX_START.
1953 struct GNUNET_MessageHeader header;
1958 uint32_t reserved GNUNET_PACKED;
1961 * ID of device containing the file, as seen by the client. This
1962 * device ID is obtained using a call like "statvfs" (and converting
1963 * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
1964 * OS does not support this, in which case the service must do a
1965 * full hash recomputation.
1967 uint64_t device GNUNET_PACKED;
1970 * Inode of the file on the given device, as seen by the client
1971 * ("st_ino" field from "struct stat"). Use 0 if the OS does not
1972 * support this, in which case the service must do a full hash
1975 uint64_t inode GNUNET_PACKED;
1978 * Hash of the file that we would like to index.
1980 GNUNET_HashCode file_id;
1982 /* this is followed by a 0-terminated
1983 filename of a file with the hash
1984 "file_id" as seen by the client */
1990 * Message send by FS service in response to a request
1991 * asking for a list of all indexed files.
1993 struct IndexInfoMessage
1996 * Message type will be
1997 * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
1999 struct GNUNET_MessageHeader header;
2004 uint32_t reserved GNUNET_PACKED;
2007 * Hash of the indexed file.
2009 GNUNET_HashCode file_id;
2011 /* this is followed by a 0-terminated
2012 filename of a file with the hash
2013 "file_id" as seen by the client */
2019 * Message sent from a GNUnet (fs) unindexing activity to the
2020 * gnunet-service-fs to indicate that a file will be unindexed. The
2021 * service is supposed to remove the file from the list of indexed
2022 * files and response with a confirmation message (even if the file
2023 * was already not on the list).
2025 struct UnindexMessage
2029 * Message type will be
2030 * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
2032 struct GNUNET_MessageHeader header;
2037 uint32_t reserved GNUNET_PACKED;
2040 * Hash of the file that we will unindex.
2042 GNUNET_HashCode file_id;
2048 * Message sent from a GNUnet (fs) search activity to the
2049 * gnunet-service-fs to start a search.
2051 struct SearchMessage
2055 * Message type will be
2056 * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
2058 struct GNUNET_MessageHeader header;
2061 * Bitmask with options. Zero for no options, one for loopback-only.
2062 * Other bits are currently not defined.
2064 int32_t options GNUNET_PACKED;
2067 * Type of the content that we're looking for.
2069 uint32_t type GNUNET_PACKED;
2072 * Desired anonymity level, big-endian.
2074 uint32_t anonymity_level GNUNET_PACKED;
2077 * If the request is for a DBLOCK or IBLOCK, this is the identity of
2078 * the peer that is known to have a response. Set to all-zeros if
2079 * such a target is not known (note that even if OUR anonymity
2080 * level is >0 we may happen to know the responder's identity;
2081 * nevertheless, we should probably not use it for a DHT-lookup
2082 * or similar blunt actions in order to avoid exposing ourselves).
2084 * If the request is for an SBLOCK, this is the identity of the
2085 * pseudonym to which the SBLOCK belongs.
2087 * If the request is for a KBLOCK, "target" must be all zeros.
2089 GNUNET_HashCode target;
2092 * Hash of the keyword (aka query) for KBLOCKs; Hash of
2093 * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
2094 * and hash of the identifier XORed with the target for
2095 * SBLOCKS (aka query).
2097 GNUNET_HashCode query;
2099 /* this is followed by the hash codes of already-known
2100 results (which should hence be excluded from what
2101 the service returns); naturally, this only applies
2102 to queries that can have multiple results, such as
2103 those for KBLOCKS (KSK) and SBLOCKS (SKS) */
2108 * Only the (mandatory) query is included.
2110 #define GET_MESSAGE_BIT_QUERY_ONLY 0
2113 * The peer identity of a peer waiting for the
2114 * reply is included (used if the response
2115 * should be transmitted to someone other than
2116 * the sender of the GET).
2118 #define GET_MESSAGE_BIT_RETURN_TO 1
2121 * The hash of the public key of the target
2122 * namespace is included (for SKS queries).
2124 #define GET_MESSAGE_BIT_SKS_NAMESPACE 2
2127 * The peer identity of a peer that had claimed to have the content
2128 * previously is included (can be used if responder-anonymity is not
2129 * desired; note that the precursor presumably lacked a direct
2130 * connection to the specified peer; still, the receiver is in no way
2131 * required to limit forwarding only to the specified peer, it should
2132 * only prefer it somewhat if possible).
2134 #define GET_MESSAGE_BIT_TRANSMIT_TO 4
2138 * Message sent between peers asking for FS-content.
2144 * Message type will be GNUNET_MESSAGE_TYPE_FS_GET.
2146 struct GNUNET_MessageHeader header;
2149 * Type of the query (block type).
2151 uint32_t type GNUNET_PACKED;
2154 * How important is this request (network byte order)
2156 uint32_t priority GNUNET_PACKED;
2159 * Relative time to live in MILLISECONDS (network byte order)
2161 int32_t ttl GNUNET_PACKED;
2164 * The content hash should be mutated using this value
2165 * before checking against the bloomfilter (used to
2166 * get many different filters for the same hash codes).
2167 * The number should be in big-endian format when used
2170 int32_t filter_mutator GNUNET_PACKED;
2173 * Which of the optional hash codes are present at the end of the
2174 * message? See GET_MESSAGE_BIT_xx constants. For each bit that is
2175 * set, an additional GNUNET_HashCode with the respective content
2176 * (in order of the bits) will be appended to the end of the GET
2179 uint32_t hash_bitmap GNUNET_PACKED;
2182 * Hashcodes of the file(s) we're looking for.
2183 * Details depend on the query type.
2185 GNUNET_HashCode query GNUNET_PACKED;
2187 /* this is followed by hash codes
2188 as specified in the "hash_bitmap";
2189 after that, an optional bloomfilter
2190 (with bits set for replies that should
2191 be suppressed) can be present */
2196 * Response from FS service with a result for a previous FS search.
2197 * Note that queries for DBLOCKS and IBLOCKS that have received a
2198 * single response are considered done. This message is transmitted
2199 * between peers as well as between the service and a client.
2205 * Message type will be GNUNET_MESSAGE_TYPE_FS_PUT.
2207 struct GNUNET_MessageHeader header;
2210 * Type of the block (in big endian). Should never be zero.
2212 uint32_t type GNUNET_PACKED;
2215 * When does this result expire?
2217 struct GNUNET_TIME_AbsoluteNBO expiration;
2219 /* this is followed by the actual encrypted content */