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_dht_service.h"
33 #include "gnunet_fs_service.h"
34 #include "gnunet_block_lib.h"
38 * Maximum size of the datastore queue for P2P operations.
40 #define MAX_DATASTORE_QUEUE 16
43 * Maximum number of blocks we keep in memory for migration.
45 #define MAX_MIGRATION_QUEUE 32
48 * How many peers do we select as possible
49 * targets per block obtained for migration?
51 #define MIGRATION_LIST_SIZE 4
54 * To how many peers do we forward each migration block ultimately?
55 * This number must be smaller or equal to MIGRATION_LIST_SIZE. Using
56 * a smaller value allows for variation in available bandwidth (for
57 * migration) between the peers.
59 #define MIGRATION_TARGET_COUNT 2
62 * Ratio for moving average delay calculation. The previous
63 * average goes in with a factor of (n-1) into the calculation.
66 #define RUNAVG_DELAY_N 16
69 * Size of the individual blocks used for file-sharing.
71 #define DBLOCK_SIZE (32*1024)
74 * Maximum legal size for a kblock.
76 #define MAX_KBLOCK_SIZE (60 * 1024)
79 * Maximum legal size for an sblock.
81 #define MAX_SBLOCK_SIZE (60 * 1024)
84 * Maximum legal size for an nblock.
86 #define MAX_NBLOCK_SIZE (60 * 1024)
89 * Pick a multiple of 2 here to achive 8-byte alignment!
90 * We also probably want DBlocks to have (roughly) the
91 * same size as IBlocks. With SHA-512, the optimal
92 * value is 32768 byte / 128 byte = 256
93 * (128 byte = 2 * 512 bits). DO NOT CHANGE!
95 #define CHK_PER_INODE 256
99 * Maximum size for a file to be considered for
100 * inlining in a directory.
102 #define MAX_INLINE_SIZE 65536
106 * Blocksize to use when hashing files
107 * for indexing (blocksize for IO, not for
108 * the DBlocks). Larger blocksizes can
109 * be more efficient but will be more disruptive
110 * as far as the scheduler is concerned.
112 #define HASHING_BLOCKSIZE (1024 * 1024)
115 * Number of bits we set per entry in the bloomfilter.
118 #define BLOOMFILTER_K GNUNET_DHT_GET_BLOOMFILTER_K
121 * Number of availability trials we perform per search result.
123 #define AVAILABILITY_TRIALS_MAX 8
126 * Length of the P2P success tracker. Note that
127 * having a very long list can also hurt performance.
129 #define P2P_SUCCESS_LIST_SIZE 8
133 * Length of the CS-2-P success tracker. Note that
134 * having a very long list can also hurt performance.
136 #define CS2P_SUCCESS_LIST_SIZE 8
139 * How long are we willing to wait for the datastore to be ready to
140 * process a request for a query without priority?
142 #define BASIC_DATASTORE_REQUEST_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
146 * How long are we willing to wait for the core to be ready to
147 * transmit a reply to the target peer (if we can not transmit
148 * until then, we will discard the reply).
150 #define ACCEPTABLE_REPLY_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
154 * Bandwidth value of an (effectively) 0-priority query.
156 #define QUERY_BANDWIDTH_VALUE 1
159 * Bandwidth value of a 0-priority content (must be
160 * fairly high compared to query since content is
161 * typically significantly larger -- and more valueable
162 * since it can take many queries to get one piece of
165 #define CONTENT_BANDWIDTH_VALUE 800
168 * By which amount do we decrement the TTL for simple forwarding /
169 * indirection of the query; in milli-seconds. Set somewhat in
170 * accordance to your network latency (above the time it'll take you
171 * to send a packet and get a reply).
173 #define TTL_DECREMENT 5000
176 * Until which load do we consider the peer idle and do not
177 * charge at all? (should be larger than GNUNET_IDLE_LOAD_THRESHOLD used
178 * by the rest of the code)!
180 #define IDLE_LOAD_THRESHOLD ((100 + GNUNET_CONSTANTS_IDLE_LOAD_THRESHOLD) / 2)
183 * Name of the directory with top-level searches.
185 #define GNUNET_FS_SYNC_PATH_MASTER_SEARCH "search"
188 * Name of the directory with sub-searches (namespace-updates).
190 #define GNUNET_FS_SYNC_PATH_CHILD_SEARCH "search-child"
193 * Name of the directory with master downloads (not associated
194 * with search or part of another download).
196 #define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD "download"
199 * Name of the directory with downloads that are part of another
200 * download or a search.
202 #define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD "download-child"
205 * Name of the directory with publishing operations.
207 #define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH "publish"
210 * Name of the directory with files that are being published
212 #define GNUNET_FS_SYNC_PATH_FILE_INFO "publish-file"
215 * Name of the directory with unindex operations.
217 #define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX "unindex"
221 * @brief content hash key
223 struct ContentHashKey
226 * Hash of the original content, used for encryption.
231 * Hash of the encrypted content, used for querying.
233 GNUNET_HashCode query;
238 * @brief complete information needed
239 * to download a file.
241 struct FileIdentifier
245 * Total size of the file in bytes. (network byte order (!))
247 uint64_t file_length;
250 * Query and key of the top GNUNET_EC_IBlock.
252 struct ContentHashKey chk;
258 * Information about a file and its location
259 * (peer claiming to share the file).
264 * Information about the shared file.
266 struct FileIdentifier fi;
269 * Identity of the peer sharing the file.
271 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
274 * Time when this location URI expires.
276 struct GNUNET_TIME_Absolute expirationTime;
279 * RSA signature over the GNUNET_EC_FileIdentifier,
280 * GNUNET_hash of the peer and expiration time.
282 struct GNUNET_CRYPTO_RsaSignature contentSignature;
292 * Content-hash-key (simple file).
297 * Signed key space (file in namespace).
302 * Keyword search key (query with keywords).
307 * Location (chk with identity of hosting peer).
313 * A Universal Resource Identifier (URI), opaque.
327 * Keywords start with a '+' if they are
328 * mandatory (in which case the '+' is NOT
329 * part of the keyword) and with a
330 * simple space if they are optional
331 * (in which case the space is ALSO not
332 * part of the actual keyword).
334 * Double-quotes to protect spaces and
335 * %-encoding are NOT used internally
336 * (only in URI-strings).
341 * Size of the keywords array.
343 unsigned int keywordCount;
349 * Hash of the public key for the namespace.
351 GNUNET_HashCode namespace;
354 * Human-readable identifier chosen for this
355 * entry in the namespace.
361 * Information needed to retrieve a file (content-hash-key
364 struct FileIdentifier chk;
367 * Information needed to retrieve a file including signed
368 * location (identity of a peer) of the content.
377 * Information for a file or directory that is
378 * about to be published.
380 struct GNUNET_FS_FileInformation
384 * Files in a directory are kept as a linked list.
386 struct GNUNET_FS_FileInformation *next;
389 * If this is a file in a directory, "dir" refers to
390 * the directory; otherwise NULL.
392 struct GNUNET_FS_FileInformation *dir;
395 * Handle to the master context.
397 struct GNUNET_FS_Handle *h;
400 * Pointer kept for the client.
405 * Metadata to use for the file.
407 struct GNUNET_CONTAINER_MetaData *meta;
410 * Keywords to use for KBlocks.
412 struct GNUNET_FS_Uri *keywords;
415 * CHK for this file or directory. NULL if
416 * we have not yet computed it.
418 struct GNUNET_FS_Uri *chk_uri;
421 * At what time should the content expire?
423 struct GNUNET_TIME_Absolute expirationTime;
426 * At what time did we start this upload?
428 struct GNUNET_TIME_Absolute start_time;
431 * Under what filename is this struct serialized
432 * (for operational persistence). Should be determined
438 * Encoder being used to publish this file.
440 struct GNUNET_FS_TreeEncoder *te;
443 * Error message (non-NULL if this operation failed).
448 * Name of the file or directory (must be an absolute path).
453 * Data describing either the file or the directory.
464 * Function that can be used to read the data for the file.
466 GNUNET_FS_DataReader reader;
469 * Closure for reader.
474 * If this file is being indexed, this value is set to the hash
475 * over the entire file (when the indexing process is started).
476 * Otherwise this field is not used.
478 GNUNET_HashCode file_id;
481 * Size of the file (in bytes).
486 * Should the file be indexed or inserted?
491 * Is "file_id" already valid? Set to GNUNET_YES once the hash
492 * has been calculated.
497 * Has the service confirmed our INDEX_START request?
498 * GNUNET_YES if this step has been completed.
500 int index_start_confirmed;
505 * Data for a directory.
510 * Linked list of entries in the directory.
512 struct GNUNET_FS_FileInformation *entries;
515 * Size of the directory itself (in bytes); 0 if the
516 * size has not yet been calculated.
521 * Pointer to the data for the directory (or NULL if not
531 * Desired anonymity level.
536 * Desired priority (for keeping the content in the DB).
541 * Is this struct for a file or directory?
546 * Are we done publishing this file?
554 * The job is now ready to run and should use the given client
555 * handle to communicate with the FS service.
558 * @param client handle to use for FS communication
560 typedef void (*GNUNET_FS_QueueStart)(void *cls,
561 struct GNUNET_CLIENT_Connection *client);
565 * The job must now stop to run and should destry the client handle as
566 * soon as possible (ideally prior to returning).
568 typedef void (*GNUNET_FS_QueueStop)(void *cls);
572 * Entry in the job queue.
574 struct GNUNET_FS_QueueEntry
577 * This is a linked list.
579 struct GNUNET_FS_QueueEntry *next;
582 * This is a linked list.
584 struct GNUNET_FS_QueueEntry *prev;
587 * Function to call when the job is started.
589 GNUNET_FS_QueueStart start;
592 * Function to call when the job needs to stop (or is done / dequeued).
594 GNUNET_FS_QueueStop stop;
597 * Closure for start and stop.
602 * Handle to FS primary context.
604 struct GNUNET_FS_Handle *h;
607 * Client handle, or NULL if job is not running.
609 struct GNUNET_CLIENT_Connection *client;
612 * Time the job was originally queued.
614 struct GNUNET_TIME_Absolute queue_time;
617 * Time the job was started last.
619 struct GNUNET_TIME_Absolute start_time;
622 * Total amount of time the job has been running (except for the
625 struct GNUNET_TIME_Relative run_time;
628 * How many blocks do the active downloads have?
633 * How often have we (re)started this download?
635 unsigned int start_times;
643 * Information we store for each search result.
645 struct GNUNET_FS_SearchResult
649 * Search context this result belongs to.
651 struct GNUNET_FS_SearchContext *sc;
654 * URI to which this search result refers to.
656 struct GNUNET_FS_Uri *uri;
659 * Metadata for the search result.
661 struct GNUNET_CONTAINER_MetaData *meta;
664 * Client info for this search result.
669 * ID of a job that is currently probing this results' availability
670 * (NULL if we are not currently probing).
672 struct GNUNET_FS_DownloadContext *probe_ctx;
675 * ID of an associated download based on this search result (or
678 struct GNUNET_FS_DownloadContext *download;
681 * If this search result triggered an update search, this field
682 * links to the update search.
684 struct GNUNET_FS_SearchContext *update_search;
687 * Name under which this search result is stored on disk.
692 * Key for the search result
697 * ID of the task that will clean up the probe_ctx should it not
698 * complete on time (and that will need to be cancelled if we clean
699 * up the search result before then).
701 GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
704 * When did the current probe become active?
706 struct GNUNET_TIME_Absolute probe_active_time;
709 * How much longer should we run the current probe before giving up?
711 struct GNUNET_TIME_Relative remaining_probe_time;
714 * Number of mandatory keywords for which we have NOT yet found the
715 * search result; when this value hits zero, the search result is
716 * given to the callback.
718 uint32_t mandatory_missing;
721 * Number of optional keywords under which this result was also
724 uint32_t optional_support;
727 * Number of availability tests that have succeeded for this result.
729 uint32_t availability_success;
732 * Number of availability trials that we have performed for this
735 uint32_t availability_trials;
741 * Add a job to the queue.
743 * @param h handle to the overall FS state
744 * @param start function to call to begin the job
745 * @param stop function to call to pause the job, or on dequeue (if the job was running)
746 * @param cls closure for start and stop
747 * @param blocks number of blocks this download has
748 * @return queue handle
750 struct GNUNET_FS_QueueEntry *
751 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
752 GNUNET_FS_QueueStart start,
753 GNUNET_FS_QueueStop stop,
755 unsigned int blocks);
759 * Dequeue a job from the queue.
760 * @param qh handle for the job
763 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
767 * Function that provides data by reading from a file.
769 * @param cls closure (points to the file information)
770 * @param offset offset to read from; it is possible
771 * that the caller might need to go backwards
773 * @param max maximum number of bytes that should be
774 * copied to buf; readers are not allowed
775 * to provide less data unless there is an error;
776 * a value of "0" will be used at the end to allow
777 * the reader to clean up its internal state
778 * @param buf where the reader should write the data
779 * @param emsg location for the reader to store an error message
780 * @return number of bytes written, usually "max", 0 on error
783 GNUNET_FS_data_reader_file_(void *cls,
791 * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
793 * @param filename file to read
794 * @return closure to use
797 GNUNET_FS_make_file_reader_context_ (const char *filename);
802 * Function that provides data by copying from a buffer.
804 * @param cls closure (points to the buffer)
805 * @param offset offset to read from; it is possible
806 * that the caller might need to go backwards
808 * @param max maximum number of bytes that should be
809 * copied to buf; readers are not allowed
810 * to provide less data unless there is an error;
811 * a value of "0" will be used at the end to allow
812 * the reader to clean up its internal state
813 * @param buf where the reader should write the data
814 * @param emsg location for the reader to store an error message
815 * @return number of bytes written, usually "max", 0 on error
818 GNUNET_FS_data_reader_copy_(void *cls,
825 * Notification of FS that a search probe has made progress.
826 * This function is used INSTEAD of the client's event handler
827 * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
829 * @param cls closure, always NULL (!), actual closure
830 * is in the client-context of the info struct
831 * @param info details about the event, specifying the event type
832 * and various bits about the event
833 * @return client-context (for the next progress call
834 * for this operation; should be set to NULL for
835 * SUSPEND and STOPPED events). The value returned
836 * will be passed to future callbacks in the respective
837 * field in the GNUNET_FS_ProgressInfo struct.
840 GNUNET_FS_search_probe_progress_ (void *cls,
841 const struct GNUNET_FS_ProgressInfo *info);
845 * Main function that performs the upload.
847 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
848 * @param tc task context
851 GNUNET_FS_publish_main_ (void *cls,
852 const struct GNUNET_SCHEDULER_TaskContext *tc);
856 * Function called once the hash of the file
857 * that is being unindexed has been computed.
859 * @param cls closure, unindex context
860 * @param file_id computed hash, NULL on error
863 GNUNET_FS_unindex_process_hash_ (void *cls,
864 const GNUNET_HashCode *file_id);
868 * Fill in all of the generic fields for a publish event and call the
871 * @param pi structure to fill in
872 * @param sc overall publishing context
873 * @param p file information for the file being published
874 * @param offset where in the file are we so far
875 * @return value returned from callback
878 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
879 struct GNUNET_FS_PublishContext *sc,
880 const struct GNUNET_FS_FileInformation *p,
885 * Fill in all of the generic fields for a download event and call the
888 * @param pi structure to fill in
889 * @param dc overall download context
892 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
893 struct GNUNET_FS_DownloadContext *dc);
897 * Fill in all of the generic fields for
898 * an unindex event and call the callback.
900 * @param pi structure to fill in
901 * @param uc overall unindex context
902 * @param offset where we are in the file (for progress)
905 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
906 struct GNUNET_FS_UnindexContext *uc,
910 * Fill in all of the generic fields for a search event and
913 * @param pi structure to fill in
914 * @param sc overall search context
915 * @return value returned by the callback
918 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
919 struct GNUNET_FS_SearchContext *sc);
923 * Connect to the datastore and remove the blocks.
925 * @param uc context for the unindex operation.
928 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
931 * Build the request and actually initiate the search using the
934 * @param sc search context
935 * @return GNUNET_OK on success, GNUNET_SYSERR on error
938 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
941 * Start the downloading process (by entering the queue).
943 * @param dc our download context
946 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
950 * Start download probes for the given search result.
952 * @param sr the search result
955 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
958 * Remove serialization/deserialization file from disk.
960 * @param h master context
961 * @param ext component of the path
962 * @param ent entity identifier
965 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
971 * Remove serialization/deserialization directory from disk.
973 * @param h master context
974 * @param ext component of the path
975 * @param uni unique name of parent
978 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
984 * Synchronize this file-information struct with its mirror
985 * on disk. Note that all internal FS-operations that change
986 * file information data should already call "sync" internally,
987 * so this function is likely not useful for clients.
989 * @param fi the struct to sync
992 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
995 * Synchronize this publishing struct with its mirror
996 * on disk. Note that all internal FS-operations that change
997 * publishing structs should already call "sync" internally,
998 * so this function is likely not useful for clients.
1000 * @param pc the struct to sync
1003 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
1006 * Synchronize this unindex struct with its mirror
1007 * on disk. Note that all internal FS-operations that change
1008 * publishing structs should already call "sync" internally,
1009 * so this function is likely not useful for clients.
1011 * @param uc the struct to sync
1014 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
1017 * Synchronize this search struct with its mirror
1018 * on disk. Note that all internal FS-operations that change
1019 * publishing structs should already call "sync" internally,
1020 * so this function is likely not useful for clients.
1022 * @param sc the struct to sync
1025 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
1028 * Synchronize this search result with its mirror
1029 * on disk. Note that all internal FS-operations that change
1030 * publishing structs should already call "sync" internally,
1031 * so this function is likely not useful for clients.
1033 * @param sr the struct to sync
1036 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
1039 * Synchronize this download struct with its mirror
1040 * on disk. Note that all internal FS-operations that change
1041 * publishing structs should already call "sync" internally,
1042 * so this function is likely not useful for clients.
1044 * @param dc the struct to sync
1047 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
1050 * Create SUSPEND event for the given publish operation
1051 * and then clean up our state (without stop signal).
1053 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
1056 GNUNET_FS_publish_signal_suspend_ (void *cls);
1059 * Create SUSPEND event for the given search operation
1060 * and then clean up our state (without stop signal).
1062 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
1065 GNUNET_FS_search_signal_suspend_ (void *cls);
1068 * Create SUSPEND event for the given download operation
1069 * and then clean up our state (without stop signal).
1071 * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
1074 GNUNET_FS_download_signal_suspend_ (void *cls);
1077 * Create SUSPEND event for the given unindex operation
1078 * and then clean up our state (without stop signal).
1080 * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
1083 GNUNET_FS_unindex_signal_suspend_ (void *cls);
1086 * Function signature of the functions that can be called
1087 * to trigger suspend signals and clean-up for top-level
1090 * @param cls closure
1092 typedef void (*SuspendSignalFunction)(void *cls);
1095 * We track all of the top-level activities of FS
1096 * so that we can signal 'suspend' on shutdown.
1098 struct TopLevelActivity
1101 * This is a doubly-linked list.
1103 struct TopLevelActivity *next;
1106 * This is a doubly-linked list.
1108 struct TopLevelActivity *prev;
1111 * Function to call for suspend-signalling and clean up.
1113 SuspendSignalFunction ssf;
1116 * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1123 * Create a top-level activity entry.
1125 * @param h global fs handle
1126 * @param ssf suspend signal function to use
1127 * @param ssf_cls closure for ssf
1128 * @return fresh top-level activity handle
1130 struct TopLevelActivity *
1131 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1132 SuspendSignalFunction ssf,
1137 * Destroy a top-level activity entry.
1139 * @param h global fs handle
1140 * @param top top level activity entry
1143 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
1144 struct TopLevelActivity *top);
1149 * Master context for most FS operations.
1151 struct GNUNET_FS_Handle
1156 struct GNUNET_SCHEDULER_Handle *sched;
1159 * Configuration to use.
1161 const struct GNUNET_CONFIGURATION_Handle *cfg;
1164 * Name of our client.
1169 * Function to call with updates on our progress.
1171 GNUNET_FS_ProgressCallback upcb;
1179 * Head of DLL of top-level activities.
1181 struct TopLevelActivity *top_head;
1184 * Tail of DLL of top-level activities.
1186 struct TopLevelActivity *top_tail;
1189 * Head of DLL of running jobs.
1191 struct GNUNET_FS_QueueEntry *running_head;
1194 * Tail of DLL of running jobs.
1196 struct GNUNET_FS_QueueEntry *running_tail;
1199 * Head of DLL of pending jobs.
1201 struct GNUNET_FS_QueueEntry *pending_head;
1204 * Tail of DLL of pending jobs.
1206 struct GNUNET_FS_QueueEntry *pending_tail;
1209 * Task that processes the jobs in the running and pending queues
1210 * (and moves jobs around as needed).
1212 GNUNET_SCHEDULER_TaskIdentifier queue_job;
1215 * Average time we take for a single request to be satisfied.
1216 * FIXME: not yet calcualted properly...
1218 struct GNUNET_TIME_Relative avg_block_latency;
1221 * How many actual downloads do we have running right now?
1223 unsigned int active_downloads;
1226 * How many blocks do the active downloads have?
1228 unsigned int active_blocks;
1233 enum GNUNET_FS_Flags flags;
1236 * Maximum number of parallel downloads.
1238 unsigned int max_parallel_downloads;
1241 * Maximum number of parallel requests.
1243 unsigned int max_parallel_requests;
1249 * Handle for controlling a publication process.
1251 struct GNUNET_FS_PublishContext
1254 * Handle to the global fs context.
1256 struct GNUNET_FS_Handle *h;
1259 * Our top-level activity entry (if we are top-level, otherwise NULL).
1261 struct TopLevelActivity *top;
1264 * File-structure that is being shared.
1266 struct GNUNET_FS_FileInformation *fi;
1269 * Namespace that we are publishing in, NULL if we have no namespace.
1271 struct GNUNET_FS_Namespace *namespace;
1274 * ID of the content in the namespace, NULL if we have no namespace.
1279 * ID for future updates, NULL if we have no namespace or no updates.
1284 * Filename used for serializing information about this operation
1285 * (should be determined using 'mktemp').
1287 char *serialization;
1290 * Our own client handle for the FS service; only briefly used when
1291 * we start to index a file, otherwise NULL.
1293 struct GNUNET_CLIENT_Connection *client;
1296 * Current position in the file-tree for the upload.
1298 struct GNUNET_FS_FileInformation *fi_pos;
1301 * Non-null if we are currently hashing a file.
1303 struct GNUNET_CRYPTO_FileHashContext *fhc;
1306 * Connection to the datastore service.
1308 struct GNUNET_DATASTORE_Handle *dsh;
1311 * Queue entry for reservation/unreservation.
1313 struct GNUNET_DATASTORE_QueueEntry *qre;
1316 * ID of the task performing the upload. NO_TASK if the upload has
1319 GNUNET_SCHEDULER_TaskIdentifier upload_task;
1322 * Storage space to reserve for the operation.
1324 uint64_t reserve_space;
1327 * Overall number of entries to reserve for the
1328 * publish operation.
1330 uint32_t reserve_entries;
1333 * Typically GNUNET_NO. Set to GNUNET_YES if "upload_task" is
1334 * GNUNET_SCHEDULER_NO_TASK and we're waiting for a response from
1335 * the datastore service (in which case this struct must not be
1336 * freed until we have that response). If someone tries to stop the
1337 * download for good during this period, "in_network_wait" is set to
1338 * GNUNET_SYSERR which will cause the struct to be destroyed right
1339 * after we have the reply (or timeout) from the datastore service.
1341 int in_network_wait;
1344 * Options for publishing.
1346 enum GNUNET_FS_PublishOptions options;
1349 * Space reservation ID with datastore service
1355 * Set to GNUNET_YES if all processing has completed.
1362 * Phases of unindex processing (state machine).
1367 * We're currently hashing the file.
1369 UNINDEX_STATE_HASHING = 0,
1372 * We're telling the datastore to delete
1373 * the respective entries.
1375 UNINDEX_STATE_DS_REMOVE = 1,
1378 * We're notifying the FS service about
1381 UNINDEX_STATE_FS_NOTIFY = 2,
1386 UNINDEX_STATE_COMPLETE = 3,
1389 * We've encountered a fatal error.
1391 UNINDEX_STATE_ERROR = 4
1397 * Handle for controlling an unindexing operation.
1399 struct GNUNET_FS_UnindexContext
1403 * Global FS context.
1405 struct GNUNET_FS_Handle *h;
1408 * Our top-level activity entry.
1410 struct TopLevelActivity *top;
1413 * Name of the file that we are unindexing.
1418 * Short name under which we are serializing the state of this operation.
1420 char *serialization;
1423 * Connection to the FS service, only valid during the
1424 * UNINDEX_STATE_FS_NOTIFY phase.
1426 struct GNUNET_CLIENT_Connection *client;
1429 * Connection to the datastore service, only valid during the
1430 * UNINDEX_STATE_DS_NOTIFY phase.
1432 struct GNUNET_DATASTORE_Handle *dsh;
1435 * Pointer kept for the client.
1440 * Merkle-ish tree encoder context.
1442 struct GNUNET_FS_TreeEncoder *tc;
1445 * Handle used to read the file.
1447 struct GNUNET_DISK_FileHandle *fh;
1450 * Error message, NULL on success.
1455 * Context for hashing of the file.
1457 struct GNUNET_CRYPTO_FileHashContext *fhc;
1460 * Overall size of the file.
1465 * When did we start?
1467 struct GNUNET_TIME_Absolute start_time;
1470 * Hash of the file's contents (once computed).
1472 GNUNET_HashCode file_id;
1475 * Current operatinonal phase.
1477 enum UnindexState state;
1483 * Information we keep for each keyword in
1486 struct SearchRequestEntry
1489 * Hash of the original keyword, also known as the
1490 * key (for decrypting the KBlock).
1492 GNUNET_HashCode key;
1495 * Hash of the public key, also known as the query.
1497 GNUNET_HashCode query;
1500 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1501 * was found under this keyword. Note that the entries will point
1502 * to the same locations as those in the master result map (in
1503 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1504 * The key for each entry is the XOR of the key and query in the CHK
1505 * URI (as a unique identifier for the search result).
1507 struct GNUNET_CONTAINER_MultiHashMap *results;
1510 * Is this keyword a mandatory keyword
1511 * (started with '+')?
1519 * Handle for controlling a search.
1521 struct GNUNET_FS_SearchContext
1524 * Handle to the global FS context.
1526 struct GNUNET_FS_Handle *h;
1529 * Our top-level activity entry (if we are top-level, otherwise NULL).
1531 struct TopLevelActivity *top;
1534 * List of keywords that we're looking for.
1536 struct GNUNET_FS_Uri *uri;
1539 * For update-searches, link to the search result that triggered
1540 * the update search; otherwise NULL.
1542 struct GNUNET_FS_SearchResult *psearch_result;
1545 * Connection to the FS service.
1547 struct GNUNET_CLIENT_Connection *client;
1550 * Pointer we keep for the client.
1555 * Name of the file on disk we use for persistence.
1557 char *serialization;
1560 * Error message (non-NULL if this operation failed).
1565 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1566 * was found in the search. The key for each entry is the XOR of
1567 * the key and query in the CHK URI (as a unique identifier for the
1570 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1573 * Per-keyword information for a keyword search. This array will
1574 * have exactly as many entries as there were keywords.
1576 struct SearchRequestEntry *requests;
1579 * When did we start?
1581 struct GNUNET_TIME_Absolute start_time;
1584 * ID of a task that is using this struct and that must be cancelled
1585 * when the search is being stopped (if not
1586 * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
1587 * artificial delay when trying to reconnect to the FS service.
1589 GNUNET_SCHEDULER_TaskIdentifier task;
1592 * Anonymity level for the search.
1597 * Number of mandatory keywords in this query.
1599 uint32_t mandatory_count;
1602 * Options for the search.
1604 enum GNUNET_FS_SearchOptions options;
1609 * Information about an active download request.
1611 struct DownloadRequest
1614 * While pending, we keep all download requests in a linked list.
1616 struct DownloadRequest *next;
1619 * CHK for the request.
1621 struct ContentHashKey chk;
1624 * Offset of the corresponding block.
1629 * Depth of the corresponding block in the tree.
1634 * Set if this request is currently in the linked list of pending
1635 * requests. Needed in case we get a response for a request that we
1636 * have not yet send (i.e. due to two blocks with identical
1637 * content); in this case, we would need to remove the block from
1638 * the pending list (and need a fast way to check if the block is on
1647 * Context for controlling a download.
1649 struct GNUNET_FS_DownloadContext
1653 * Global FS context.
1655 struct GNUNET_FS_Handle *h;
1658 * Our top-level activity entry (if we are top-level, otherwise NULL).
1660 struct TopLevelActivity *top;
1663 * Connection to the FS service.
1665 struct GNUNET_CLIENT_Connection *client;
1668 * Parent download (used when downloading files
1671 struct GNUNET_FS_DownloadContext *parent;
1674 * Associated search (used when downloading files
1675 * based on search results), or NULL for none.
1677 struct GNUNET_FS_SearchResult *search;
1680 * Head of list of child downloads.
1682 struct GNUNET_FS_DownloadContext *child_head;
1685 * Tail of list of child downloads.
1687 struct GNUNET_FS_DownloadContext *child_tail;
1690 * Previous download belonging to the same parent.
1692 struct GNUNET_FS_DownloadContext *prev;
1695 * Next download belonging to the same parent.
1697 struct GNUNET_FS_DownloadContext *next;
1700 * Context kept for the client.
1705 * URI that identifies the file that
1706 * we are downloading.
1708 struct GNUNET_FS_Uri *uri;
1711 * Known meta-data for the file (can be NULL).
1713 struct GNUNET_CONTAINER_MetaData *meta;
1716 * Error message, NULL if we're doing OK.
1721 * Random portion of filename we use for syncing state of this
1724 char *serialization;
1727 * Where are we writing the data (name of the
1728 * file, can be NULL!).
1733 * Where are we writing the data temporarily (name of the
1734 * file, can be NULL!); used if we do not have a permanent
1735 * name and we are a directory and we do a recursive download.
1737 char *temp_filename;
1740 * Map of active requests (those waiting
1741 * for a response). The key is the hash
1742 * of the encryped block (aka query).
1744 struct GNUNET_CONTAINER_MultiHashMap *active;
1747 * Linked list of pending requests.
1749 struct DownloadRequest *pending;
1752 * Non-NULL if we are currently having a request for
1753 * transmission pending with the client handle.
1755 struct GNUNET_CLIENT_TransmitHandle *th;
1758 * Our entry in the job queue.
1760 struct GNUNET_FS_QueueEntry *job_queue;
1763 * Identity of the peer having the content, or all-zeros
1764 * if we don't know of such a peer.
1766 struct GNUNET_PeerIdentity target;
1769 * ID of a task that is using this struct
1770 * and that must be cancelled when the download
1771 * is being stopped (if not GNUNET_SCHEDULER_NO_TASK).
1772 * Used for the task that adds some artificial
1773 * delay when trying to reconnect to the FS
1776 GNUNET_SCHEDULER_TaskIdentifier task;
1779 * What was the size of the file on disk that we're downloading
1780 * before we started? Used to detect if there is a point in
1781 * checking an existing block on disk for matching the desired
1782 * content. 0 if the file did not exist already.
1784 uint64_t old_file_size;
1787 * What is the first offset that we're interested
1793 * How many bytes starting from offset are desired?
1794 * This is NOT the overall length of the file!
1799 * How many bytes have we already received within
1800 * the specified range (DBlocks only).
1805 * Time download was started.
1807 struct GNUNET_TIME_Absolute start_time;
1810 * Desired level of anonymity.
1815 * The depth of the file-tree.
1817 unsigned int treedepth;
1820 * Options for the download.
1822 enum GNUNET_FS_DownloadOptions options;
1825 * Flag set upon transitive completion (includes child downloads).
1826 * This flag is only set to GNUNET_YES for directories where all
1827 * child-downloads have also completed (and signalled completion).
1832 * Have we tried (and failed) to find matching full
1833 * data from the meta data yet?
1835 int tried_full_data;
1840 * Information about an (updateable) node in the
1843 struct NamespaceUpdateNode
1846 * Identifier for this node.
1851 * Identifier of children of this node.
1856 * Metadata for this entry.
1858 struct GNUNET_CONTAINER_MetaData *md;
1861 * URI of this entry in the namespace.
1863 struct GNUNET_FS_Uri *uri;
1866 * Namespace update generation ID. Used to ensure
1867 * freshness of the scc_id.
1872 * SCC this entry belongs to (if nug is current).
1874 unsigned int scc_id;
1879 struct GNUNET_FS_Namespace
1883 * Handle to the FS service context.
1885 struct GNUNET_FS_Handle *h;
1888 * Array with information about nodes in the namespace.
1890 struct NamespaceUpdateNode **update_nodes;
1893 * Private key for the namespace.
1895 struct GNUNET_CRYPTO_RsaPrivateKey *key;
1898 * Hash map mapping identifiers of update nodes
1899 * to the update nodes (initialized on-demand).
1901 struct GNUNET_CONTAINER_MultiHashMap *update_map;
1904 * Name of the file with the private key.
1909 * Name of the namespace.
1914 * Size of the update nodes array.
1916 unsigned int update_node_count;
1919 * Reference counter.
1924 * Generator for unique nug numbers.
1926 unsigned int nug_gen;
1931 * Message sent from a GNUnet (fs) publishing activity to the
1932 * gnunet-fs-service to initiate indexing of a file. The service is
1933 * supposed to check if the specified file is available and has the
1934 * same cryptographic hash. It should then respond with either a
1935 * confirmation or a denial.
1937 * On OSes where this works, it is considered acceptable if the
1938 * service only checks that the path, device and inode match (it can
1939 * then be assumed that the hash will also match without actually
1940 * computing it; this is an optimization that should be safe given
1941 * that the client is not our adversary).
1943 struct IndexStartMessage
1947 * Message type will be GNUNET_MESSAGE_TYPE_FS_INDEX_START.
1949 struct GNUNET_MessageHeader header;
1954 uint32_t reserved GNUNET_PACKED;
1957 * ID of device containing the file, as seen by the client. This
1958 * device ID is obtained using a call like "statvfs" (and converting
1959 * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
1960 * OS does not support this, in which case the service must do a
1961 * full hash recomputation.
1963 uint64_t device GNUNET_PACKED;
1966 * Inode of the file on the given device, as seen by the client
1967 * ("st_ino" field from "struct stat"). Use 0 if the OS does not
1968 * support this, in which case the service must do a full hash
1971 uint64_t inode GNUNET_PACKED;
1974 * Hash of the file that we would like to index.
1976 GNUNET_HashCode file_id;
1978 /* this is followed by a 0-terminated
1979 filename of a file with the hash
1980 "file_id" as seen by the client */
1986 * Message send by FS service in response to a request
1987 * asking for a list of all indexed files.
1989 struct IndexInfoMessage
1992 * Message type will be
1993 * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
1995 struct GNUNET_MessageHeader header;
2000 uint32_t reserved GNUNET_PACKED;
2003 * Hash of the indexed file.
2005 GNUNET_HashCode file_id;
2007 /* this is followed by a 0-terminated
2008 filename of a file with the hash
2009 "file_id" as seen by the client */
2015 * Message sent from a GNUnet (fs) unindexing activity to the
2016 * gnunet-service-fs to indicate that a file will be unindexed. The
2017 * service is supposed to remove the file from the list of indexed
2018 * files and response with a confirmation message (even if the file
2019 * was already not on the list).
2021 struct UnindexMessage
2025 * Message type will be
2026 * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
2028 struct GNUNET_MessageHeader header;
2033 uint32_t reserved GNUNET_PACKED;
2036 * Hash of the file that we will unindex.
2038 GNUNET_HashCode file_id;
2044 * Message sent from a GNUnet (fs) search activity to the
2045 * gnunet-service-fs to start a search.
2047 struct SearchMessage
2051 * Message type will be
2052 * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
2054 struct GNUNET_MessageHeader header;
2057 * Bitmask with options. Zero for no options, one for loopback-only.
2058 * Other bits are currently not defined.
2060 int32_t options GNUNET_PACKED;
2063 * Type of the content that we're looking for.
2065 uint32_t type GNUNET_PACKED;
2068 * Desired anonymity level, big-endian.
2070 uint32_t anonymity_level GNUNET_PACKED;
2073 * If the request is for a DBLOCK or IBLOCK, this is the identity of
2074 * the peer that is known to have a response. Set to all-zeros if
2075 * such a target is not known (note that even if OUR anonymity
2076 * level is >0 we may happen to know the responder's identity;
2077 * nevertheless, we should probably not use it for a DHT-lookup
2078 * or similar blunt actions in order to avoid exposing ourselves).
2080 * If the request is for an SBLOCK, this is the identity of the
2081 * pseudonym to which the SBLOCK belongs.
2083 * If the request is for a KBLOCK, "target" must be all zeros.
2085 GNUNET_HashCode target;
2088 * Hash of the keyword (aka query) for KBLOCKs; Hash of
2089 * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
2090 * and hash of the identifier XORed with the target for
2091 * SBLOCKS (aka query).
2093 GNUNET_HashCode query;
2095 /* this is followed by the hash codes of already-known
2096 results (which should hence be excluded from what
2097 the service returns); naturally, this only applies
2098 to queries that can have multiple results, such as
2099 those for KBLOCKS (KSK) and SBLOCKS (SKS) */
2104 * Only the (mandatory) query is included.
2106 #define GET_MESSAGE_BIT_QUERY_ONLY 0
2109 * The peer identity of a peer waiting for the
2110 * reply is included (used if the response
2111 * should be transmitted to someone other than
2112 * the sender of the GET).
2114 #define GET_MESSAGE_BIT_RETURN_TO 1
2117 * The hash of the public key of the target
2118 * namespace is included (for SKS queries).
2120 #define GET_MESSAGE_BIT_SKS_NAMESPACE 2
2123 * The peer identity of a peer that had claimed to have the content
2124 * previously is included (can be used if responder-anonymity is not
2125 * desired; note that the precursor presumably lacked a direct
2126 * connection to the specified peer; still, the receiver is in no way
2127 * required to limit forwarding only to the specified peer, it should
2128 * only prefer it somewhat if possible).
2130 #define GET_MESSAGE_BIT_TRANSMIT_TO 4
2134 * Message sent between peers asking for FS-content.
2140 * Message type will be GNUNET_MESSAGE_TYPE_FS_GET.
2142 struct GNUNET_MessageHeader header;
2145 * Type of the query (block type).
2147 uint32_t type GNUNET_PACKED;
2150 * How important is this request (network byte order)
2152 uint32_t priority GNUNET_PACKED;
2155 * Relative time to live in MILLISECONDS (network byte order)
2157 int32_t ttl GNUNET_PACKED;
2160 * The content hash should be mutated using this value
2161 * before checking against the bloomfilter (used to
2162 * get many different filters for the same hash codes).
2163 * The number should be in big-endian format when used
2166 int32_t filter_mutator GNUNET_PACKED;
2169 * Which of the optional hash codes are present at the end of the
2170 * message? See GET_MESSAGE_BIT_xx constants. For each bit that is
2171 * set, an additional GNUNET_HashCode with the respective content
2172 * (in order of the bits) will be appended to the end of the GET
2175 uint32_t hash_bitmap GNUNET_PACKED;
2178 * Hashcodes of the file(s) we're looking for.
2179 * Details depend on the query type.
2181 GNUNET_HashCode query GNUNET_PACKED;
2183 /* this is followed by hash codes
2184 as specified in the "hash_bitmap";
2185 after that, an optional bloomfilter
2186 (with bits set for replies that should
2187 be suppressed) can be present */
2192 * Response from FS service with a result for a previous FS search.
2193 * Note that queries for DBLOCKS and IBLOCKS that have received a
2194 * single response are considered done. This message is transmitted
2195 * between peers as well as between the service and a client.
2201 * Message type will be GNUNET_MESSAGE_TYPE_FS_PUT.
2203 struct GNUNET_MessageHeader header;
2206 * Type of the block (in big endian). Should never be zero.
2208 uint32_t type GNUNET_PACKED;
2211 * When does this result expire?
2213 struct GNUNET_TIME_AbsoluteNBO expiration;
2215 /* this is followed by the actual encrypted content */
2221 * Message send by a peer that wants to be excluded
2222 * from migration for a while.
2224 struct MigrationStopMessage
2227 * Message type will be
2228 * GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP.
2230 struct GNUNET_MessageHeader header;
2235 uint32_t reserved GNUNET_PACKED;
2238 * How long should the block last?
2240 struct GNUNET_TIME_RelativeNBO duration;