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 * Maximum number of blocks we keep in memory for migration.
42 #define MAX_MIGRATION_QUEUE 32
45 * Size of the individual blocks used for file-sharing.
47 #define DBLOCK_SIZE (32*1024)
50 * Maximum legal size for a kblock.
52 #define MAX_KBLOCK_SIZE (60 * 1024)
55 * Maximum legal size for an sblock.
57 #define MAX_SBLOCK_SIZE (60 * 1024)
60 * Maximum legal size for an nblock.
62 #define MAX_NBLOCK_SIZE (60 * 1024)
65 * Pick a multiple of 2 here to achive 8-byte alignment!
66 * We also probably want DBlocks to have (roughly) the
67 * same size as IBlocks. With SHA-512, the optimal
68 * value is 32768 byte / 128 byte = 256
69 * (128 byte = 2 * 512 bits). DO NOT CHANGE!
71 #define CHK_PER_INODE 256
75 * Maximum size for a file to be considered for
76 * inlining in a directory.
78 #define MAX_INLINE_SIZE 65536
82 * Blocksize to use when hashing files
83 * for indexing (blocksize for IO, not for
84 * the DBlocks). Larger blocksizes can
85 * be more efficient but will be more disruptive
86 * as far as the scheduler is concerned.
88 #define HASHING_BLOCKSIZE (1024 * 1024)
91 * Number of bits we set per entry in the bloomfilter.
94 #define BLOOMFILTER_K 16
97 * Number of availability trials we perform per search result.
99 #define AVAILABILITY_TRIALS_MAX 8
102 * By how much (in ms) do we decrement the TTL
105 #define TTL_DECREMENT 5000
108 * Length of the P2P success tracker. Note that
109 * having a very long list can also hurt performance.
111 #define P2P_SUCCESS_LIST_SIZE 8
115 * Length of the CS-2-P success tracker. Note that
116 * having a very long list can also hurt performance.
118 #define CS2P_SUCCESS_LIST_SIZE 8
121 * How long are we willing to wait for the datastore to be ready to
122 * process a request for a query without priority?
124 #define BASIC_DATASTORE_REQUEST_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
128 * How long are we willing to wait for the core to be ready to
129 * transmit a reply to the target peer (if we can not transmit
130 * until then, we will discard the reply).
132 #define ACCEPTABLE_REPLY_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
136 * Bandwidth value of an (effectively) 0-priority query.
138 #define QUERY_BANDWIDTH_VALUE 0.001
141 * Bandwidth value of a 0-priority content (must be
142 * fairly high compared to query since content is
143 * typically significantly larger -- and more valueable
144 * since it can take many queries to get one piece of
147 #define CONTENT_BANDWIDTH_VALUE 0.8
150 * By which amount do we decrement the TTL for simple forwarding /
151 * indirection of the query; in milli-seconds. Set somewhat in
152 * accordance to your network latency (above the time it'll take you
153 * to send a packet and get a reply).
155 #define TTL_DECREMENT 5000
158 * Until which load do we consider the peer idle and do not
159 * charge at all? (should be larger than GNUNET_IDLE_LOAD_THRESHOLD used
160 * by the rest of the code)!
162 #define IDLE_LOAD_THRESHOLD ((100 + GNUNET_CONSTANTS_IDLE_LOAD_THRESHOLD) / 2)
165 * Name of the directory with top-level searches.
167 #define GNUNET_FS_SYNC_PATH_MASTER_SEARCH "search"
170 * Name of the directory with sub-searches (namespace-updates).
172 #define GNUNET_FS_SYNC_PATH_CHILD_SEARCH "search-child"
175 * Name of the directory with master downloads (not associated
176 * with search or part of another download).
178 #define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD "download"
181 * Name of the directory with downloads that are part of another
182 * download or a search.
184 #define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD "download-child"
187 * Name of the directory with publishing operations.
189 #define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH "publish"
192 * Name of the directory with files that are being published
194 #define GNUNET_FS_SYNC_PATH_FILE_INFO "publish-file"
197 * Name of the directory with unindex operations.
199 #define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX "unindex"
203 * @brief content hash key
205 struct ContentHashKey
208 * Hash of the original content, used for encryption.
213 * Hash of the encrypted content, used for querying.
215 GNUNET_HashCode query;
220 * @brief complete information needed
221 * to download a file.
223 struct FileIdentifier
227 * Total size of the file in bytes. (network byte order (!))
229 uint64_t file_length;
232 * Query and key of the top GNUNET_EC_IBlock.
234 struct ContentHashKey chk;
240 * Information about a file and its location
241 * (peer claiming to share the file).
246 * Information about the shared file.
248 struct FileIdentifier fi;
251 * Identity of the peer sharing the file.
253 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
256 * Time when this location URI expires.
258 struct GNUNET_TIME_Absolute expirationTime;
261 * RSA signature over the GNUNET_EC_FileIdentifier,
262 * GNUNET_hash of the peer and expiration time.
264 struct GNUNET_CRYPTO_RsaSignature contentSignature;
274 * Content-hash-key (simple file).
279 * Signed key space (file in namespace).
284 * Keyword search key (query with keywords).
289 * Location (chk with identity of hosting peer).
295 * A Universal Resource Identifier (URI), opaque.
309 * Keywords start with a '+' if they are
310 * mandatory (in which case the '+' is NOT
311 * part of the keyword) and with a
312 * simple space if they are optional
313 * (in which case the space is ALSO not
314 * part of the actual keyword).
316 * Double-quotes to protect spaces and
317 * %-encoding are NOT used internally
318 * (only in URI-strings).
323 * Size of the keywords array.
325 unsigned int keywordCount;
331 * Hash of the public key for the namespace.
333 GNUNET_HashCode namespace;
336 * Human-readable identifier chosen for this
337 * entry in the namespace.
343 * Information needed to retrieve a file (content-hash-key
346 struct FileIdentifier chk;
349 * Information needed to retrieve a file including signed
350 * location (identity of a peer) of the content.
359 * Information for a file or directory that is
360 * about to be published.
362 struct GNUNET_FS_FileInformation
366 * Files in a directory are kept as a linked list.
368 struct GNUNET_FS_FileInformation *next;
371 * If this is a file in a directory, "dir" refers to
372 * the directory; otherwise NULL.
374 struct GNUNET_FS_FileInformation *dir;
377 * Handle to the master context.
379 struct GNUNET_FS_Handle *h;
382 * Pointer kept for the client.
387 * Metadata to use for the file.
389 struct GNUNET_CONTAINER_MetaData *meta;
392 * Keywords to use for KBlocks.
394 struct GNUNET_FS_Uri *keywords;
397 * CHK for this file or directory. NULL if
398 * we have not yet computed it.
400 struct GNUNET_FS_Uri *chk_uri;
403 * At what time should the content expire?
405 struct GNUNET_TIME_Absolute expirationTime;
408 * At what time did we start this upload?
410 struct GNUNET_TIME_Absolute start_time;
413 * Under what filename is this struct serialized
414 * (for operational persistence). Should be determined
420 * Encoder being used to publish this file.
422 struct GNUNET_FS_TreeEncoder *te;
425 * Error message (non-NULL if this operation failed).
430 * Name of the file or directory (must be an absolute path).
435 * Data describing either the file or the directory.
446 * Function that can be used to read the data for the file.
448 GNUNET_FS_DataReader reader;
451 * Closure for reader.
456 * If this file is being indexed, this value is set to the hash
457 * over the entire file (when the indexing process is started).
458 * Otherwise this field is not used.
460 GNUNET_HashCode file_id;
463 * Size of the file (in bytes).
468 * Should the file be indexed or inserted?
473 * Is "file_id" already valid? Set to GNUNET_YES once the hash
474 * has been calculated.
479 * Has the service confirmed our INDEX_START request?
480 * GNUNET_YES if this step has been completed.
482 int index_start_confirmed;
487 * Data for a directory.
492 * Linked list of entries in the directory.
494 struct GNUNET_FS_FileInformation *entries;
497 * Size of the directory itself (in bytes); 0 if the
498 * size has not yet been calculated.
503 * Pointer to the data for the directory (or NULL if not
513 * Desired anonymity level.
518 * Desired priority (for keeping the content in the DB).
523 * Is this struct for a file or directory?
528 * Are we done publishing this file?
536 * The job is now ready to run and should use the given client
537 * handle to communicate with the FS service.
540 * @param client handle to use for FS communication
542 typedef void (*GNUNET_FS_QueueStart)(void *cls,
543 struct GNUNET_CLIENT_Connection *client);
547 * The job must now stop to run and should destry the client handle as
548 * soon as possible (ideally prior to returning).
550 typedef void (*GNUNET_FS_QueueStop)(void *cls);
554 * Entry in the job queue.
556 struct GNUNET_FS_QueueEntry
559 * This is a linked list.
561 struct GNUNET_FS_QueueEntry *next;
564 * This is a linked list.
566 struct GNUNET_FS_QueueEntry *prev;
569 * Function to call when the job is started.
571 GNUNET_FS_QueueStart start;
574 * Function to call when the job needs to stop (or is done / dequeued).
576 GNUNET_FS_QueueStop stop;
579 * Closure for start and stop.
584 * Handle to FS primary context.
586 struct GNUNET_FS_Handle *h;
589 * Client handle, or NULL if job is not running.
591 struct GNUNET_CLIENT_Connection *client;
594 * Time the job was originally queued.
596 struct GNUNET_TIME_Absolute queue_time;
599 * Time the job was started last.
601 struct GNUNET_TIME_Absolute start_time;
604 * Total amount of time the job has been running (except for the
607 struct GNUNET_TIME_Relative run_time;
610 * How many blocks do the active downloads have?
615 * How often have we (re)started this download?
617 unsigned int start_times;
625 * Information we store for each search result.
627 struct GNUNET_FS_SearchResult
631 * Search context this result belongs to.
633 struct GNUNET_FS_SearchContext *sc;
636 * URI to which this search result refers to.
638 struct GNUNET_FS_Uri *uri;
641 * Metadata for the search result.
643 struct GNUNET_CONTAINER_MetaData *meta;
646 * Client info for this search result.
651 * ID of a job that is currently probing this results' availability
652 * (NULL if we are not currently probing).
654 struct GNUNET_FS_DownloadContext *probe_ctx;
657 * ID of an associated download based on this search result (or
660 struct GNUNET_FS_DownloadContext *download;
663 * If this search result triggered an update search, this field
664 * links to the update search.
666 struct GNUNET_FS_SearchContext *update_search;
669 * Name under which this search result is stored on disk.
674 * Key for the search result
679 * ID of the task that will clean up the probe_ctx should it not
680 * complete on time (and that will need to be cancelled if we clean
681 * up the search result before then).
683 GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
686 * When did the current probe become active?
688 struct GNUNET_TIME_Absolute probe_active_time;
691 * How much longer should we run the current probe before giving up?
693 struct GNUNET_TIME_Relative remaining_probe_time;
696 * Number of mandatory keywords for which we have NOT yet found the
697 * search result; when this value hits zero, the search result is
698 * given to the callback.
700 uint32_t mandatory_missing;
703 * Number of optional keywords under which this result was also
706 uint32_t optional_support;
709 * Number of availability tests that have succeeded for this result.
711 uint32_t availability_success;
714 * Number of availability trials that we have performed for this
717 uint32_t availability_trials;
723 * Add a job to the queue.
725 * @param h handle to the overall FS state
726 * @param start function to call to begin the job
727 * @param stop function to call to pause the job, or on dequeue (if the job was running)
728 * @param cls closure for start and stop
729 * @param blocks number of blocks this download has
730 * @return queue handle
732 struct GNUNET_FS_QueueEntry *
733 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
734 GNUNET_FS_QueueStart start,
735 GNUNET_FS_QueueStop stop,
737 unsigned int blocks);
741 * Dequeue a job from the queue.
742 * @param qh handle for the job
745 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
749 * Function that provides data by reading from a file.
751 * @param cls closure (points to the file information)
752 * @param offset offset to read from; it is possible
753 * that the caller might need to go backwards
755 * @param max maximum number of bytes that should be
756 * copied to buf; readers are not allowed
757 * to provide less data unless there is an error;
758 * a value of "0" will be used at the end to allow
759 * the reader to clean up its internal state
760 * @param buf where the reader should write the data
761 * @param emsg location for the reader to store an error message
762 * @return number of bytes written, usually "max", 0 on error
765 GNUNET_FS_data_reader_file_(void *cls,
773 * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
775 * @param filename file to read
776 * @return closure to use
779 GNUNET_FS_make_file_reader_context_ (const char *filename);
784 * Function that provides data by copying from a buffer.
786 * @param cls closure (points to the buffer)
787 * @param offset offset to read from; it is possible
788 * that the caller might need to go backwards
790 * @param max maximum number of bytes that should be
791 * copied to buf; readers are not allowed
792 * to provide less data unless there is an error;
793 * a value of "0" will be used at the end to allow
794 * the reader to clean up its internal state
795 * @param buf where the reader should write the data
796 * @param emsg location for the reader to store an error message
797 * @return number of bytes written, usually "max", 0 on error
800 GNUNET_FS_data_reader_copy_(void *cls,
807 * Notification of FS that a search probe has made progress.
808 * This function is used INSTEAD of the client's event handler
809 * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
811 * @param cls closure, always NULL (!), actual closure
812 * is in the client-context of the info struct
813 * @param info details about the event, specifying the event type
814 * and various bits about the event
815 * @return client-context (for the next progress call
816 * for this operation; should be set to NULL for
817 * SUSPEND and STOPPED events). The value returned
818 * will be passed to future callbacks in the respective
819 * field in the GNUNET_FS_ProgressInfo struct.
822 GNUNET_FS_search_probe_progress_ (void *cls,
823 const struct GNUNET_FS_ProgressInfo *info);
827 * Main function that performs the upload.
829 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
830 * @param tc task context
833 GNUNET_FS_publish_main_ (void *cls,
834 const struct GNUNET_SCHEDULER_TaskContext *tc);
838 * Function called once the hash of the file
839 * that is being unindexed has been computed.
841 * @param cls closure, unindex context
842 * @param file_id computed hash, NULL on error
845 GNUNET_FS_unindex_process_hash_ (void *cls,
846 const GNUNET_HashCode *file_id);
850 * Fill in all of the generic fields for a publish event and call the
853 * @param pi structure to fill in
854 * @param sc overall publishing context
855 * @param p file information for the file being published
856 * @param offset where in the file are we so far
857 * @return value returned from callback
860 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
861 struct GNUNET_FS_PublishContext *sc,
862 const struct GNUNET_FS_FileInformation *p,
867 * Fill in all of the generic fields for a download event and call the
870 * @param pi structure to fill in
871 * @param dc overall download context
874 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
875 struct GNUNET_FS_DownloadContext *dc);
879 * Fill in all of the generic fields for
880 * an unindex event and call the callback.
882 * @param pi structure to fill in
883 * @param uc overall unindex context
884 * @param offset where we are in the file (for progress)
887 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
888 struct GNUNET_FS_UnindexContext *uc,
892 * Fill in all of the generic fields for a search event and
895 * @param pi structure to fill in
896 * @param sc overall search context
897 * @return value returned by the callback
900 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
901 struct GNUNET_FS_SearchContext *sc);
905 * Connect to the datastore and remove the blocks.
907 * @param uc context for the unindex operation.
910 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
913 * Build the request and actually initiate the search using the
916 * @param sc search context
917 * @return GNUNET_OK on success, GNUNET_SYSERR on error
920 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
923 * Start the downloading process (by entering the queue).
925 * @param dc our download context
928 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
932 * Start download probes for the given search result.
934 * @param sr the search result
937 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
940 * Remove serialization/deserialization file from disk.
942 * @param h master context
943 * @param ext component of the path
944 * @param ent entity identifier
947 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
953 * Remove serialization/deserialization directory from disk.
955 * @param h master context
956 * @param ext component of the path
957 * @param uni unique name of parent
960 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
966 * Synchronize this file-information struct with its mirror
967 * on disk. Note that all internal FS-operations that change
968 * file information data should already call "sync" internally,
969 * so this function is likely not useful for clients.
971 * @param fi the struct to sync
974 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
977 * Synchronize this publishing struct with its mirror
978 * on disk. Note that all internal FS-operations that change
979 * publishing structs should already call "sync" internally,
980 * so this function is likely not useful for clients.
982 * @param pc the struct to sync
985 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
988 * Synchronize this unindex struct with its mirror
989 * on disk. Note that all internal FS-operations that change
990 * publishing structs should already call "sync" internally,
991 * so this function is likely not useful for clients.
993 * @param uc the struct to sync
996 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
999 * Synchronize this search 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 sc the struct to sync
1007 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
1010 * Synchronize this search result 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 sr the struct to sync
1018 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
1021 * Synchronize this download 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 dc the struct to sync
1029 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
1032 * Create SUSPEND event for the given publish operation
1033 * and then clean up our state (without stop signal).
1035 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
1038 GNUNET_FS_publish_signal_suspend_ (void *cls);
1041 * Create SUSPEND event for the given search operation
1042 * and then clean up our state (without stop signal).
1044 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
1047 GNUNET_FS_search_signal_suspend_ (void *cls);
1050 * Create SUSPEND event for the given download operation
1051 * and then clean up our state (without stop signal).
1053 * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
1056 GNUNET_FS_download_signal_suspend_ (void *cls);
1059 * Create SUSPEND event for the given unindex operation
1060 * and then clean up our state (without stop signal).
1062 * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
1065 GNUNET_FS_unindex_signal_suspend_ (void *cls);
1068 * Function signature of the functions that can be called
1069 * to trigger suspend signals and clean-up for top-level
1072 * @param cls closure
1074 typedef void (*SuspendSignalFunction)(void *cls);
1077 * We track all of the top-level activities of FS
1078 * so that we can signal 'suspend' on shutdown.
1080 struct TopLevelActivity
1083 * This is a doubly-linked list.
1085 struct TopLevelActivity *next;
1088 * This is a doubly-linked list.
1090 struct TopLevelActivity *prev;
1093 * Function to call for suspend-signalling and clean up.
1095 SuspendSignalFunction ssf;
1098 * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1105 * Create a top-level activity entry.
1107 * @param h global fs handle
1108 * @param ssf suspend signal function to use
1109 * @param ssf_cls closure for ssf
1110 * @return fresh top-level activity handle
1112 struct TopLevelActivity *
1113 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1114 SuspendSignalFunction ssf,
1119 * Destroy a top-level activity entry.
1121 * @param h global fs handle
1122 * @param top top level activity entry
1125 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
1126 struct TopLevelActivity *top);
1131 * Master context for most FS operations.
1133 struct GNUNET_FS_Handle
1138 struct GNUNET_SCHEDULER_Handle *sched;
1141 * Configuration to use.
1143 const struct GNUNET_CONFIGURATION_Handle *cfg;
1146 * Name of our client.
1151 * Function to call with updates on our progress.
1153 GNUNET_FS_ProgressCallback upcb;
1161 * Head of DLL of top-level activities.
1163 struct TopLevelActivity *top_head;
1166 * Tail of DLL of top-level activities.
1168 struct TopLevelActivity *top_tail;
1171 * Head of DLL of running jobs.
1173 struct GNUNET_FS_QueueEntry *running_head;
1176 * Tail of DLL of running jobs.
1178 struct GNUNET_FS_QueueEntry *running_tail;
1181 * Head of DLL of pending jobs.
1183 struct GNUNET_FS_QueueEntry *pending_head;
1186 * Tail of DLL of pending jobs.
1188 struct GNUNET_FS_QueueEntry *pending_tail;
1191 * Task that processes the jobs in the running and pending queues
1192 * (and moves jobs around as needed).
1194 GNUNET_SCHEDULER_TaskIdentifier queue_job;
1197 * Average time we take for a single request to be satisfied.
1198 * FIXME: not yet calcualted properly...
1200 struct GNUNET_TIME_Relative avg_block_latency;
1203 * How many actual downloads do we have running right now?
1205 unsigned int active_downloads;
1208 * How many blocks do the active downloads have?
1210 unsigned int active_blocks;
1215 enum GNUNET_FS_Flags flags;
1218 * Maximum number of parallel downloads.
1220 unsigned int max_parallel_downloads;
1223 * Maximum number of parallel requests.
1225 unsigned int max_parallel_requests;
1231 * Handle for controlling a publication process.
1233 struct GNUNET_FS_PublishContext
1236 * Handle to the global fs context.
1238 struct GNUNET_FS_Handle *h;
1241 * Our top-level activity entry (if we are top-level, otherwise NULL).
1243 struct TopLevelActivity *top;
1246 * File-structure that is being shared.
1248 struct GNUNET_FS_FileInformation *fi;
1251 * Namespace that we are publishing in, NULL if we have no namespace.
1253 struct GNUNET_FS_Namespace *namespace;
1256 * ID of the content in the namespace, NULL if we have no namespace.
1261 * ID for future updates, NULL if we have no namespace or no updates.
1266 * Filename used for serializing information about this operation
1267 * (should be determined using 'mktemp').
1269 char *serialization;
1272 * Our own client handle for the FS service; only briefly used when
1273 * we start to index a file, otherwise NULL.
1275 struct GNUNET_CLIENT_Connection *client;
1278 * Current position in the file-tree for the upload.
1280 struct GNUNET_FS_FileInformation *fi_pos;
1283 * Connection to the datastore service.
1285 struct GNUNET_DATASTORE_Handle *dsh;
1288 * ID of the task performing the upload. NO_TASK if the upload has
1291 GNUNET_SCHEDULER_TaskIdentifier upload_task;
1294 * Typically GNUNET_NO. Set to GNUNET_YES if "upload_task" is
1295 * GNUNET_SCHEDULER_NO_TASK and we're waiting for a response from
1296 * the datastore service (in which case this struct must not be
1297 * freed until we have that response). If someone tries to stop the
1298 * download for good during this period, "in_network_wait" is set to
1299 * GNUNET_SYSERR which will cause the struct to be destroyed right
1300 * after we have the reply (or timeout) from the datastore service.
1302 int in_network_wait;
1305 * Options for publishing.
1307 enum GNUNET_FS_PublishOptions options;
1310 * Space reservation ID with datastore service
1316 * Set to GNUNET_YES if all processing has completed.
1323 * Phases of unindex processing (state machine).
1328 * We're currently hashing the file.
1330 UNINDEX_STATE_HASHING = 0,
1333 * We're notifying the FS service about
1336 UNINDEX_STATE_FS_NOTIFY = 1,
1339 * We're telling the datastore to delete
1340 * the respective entries.
1342 UNINDEX_STATE_DS_REMOVE = 2,
1347 UNINDEX_STATE_COMPLETE = 3,
1350 * We've encountered a fatal error.
1352 UNINDEX_STATE_ERROR = 4
1358 * Handle for controlling an unindexing operation.
1360 struct GNUNET_FS_UnindexContext
1364 * Global FS context.
1366 struct GNUNET_FS_Handle *h;
1369 * Our top-level activity entry.
1371 struct TopLevelActivity *top;
1374 * Name of the file that we are unindexing.
1379 * Short name under which we are serializing the state of this operation.
1381 char *serialization;
1384 * Connection to the FS service, only valid during the
1385 * UNINDEX_STATE_FS_NOTIFY phase.
1387 struct GNUNET_CLIENT_Connection *client;
1390 * Connection to the datastore service, only valid during the
1391 * UNINDEX_STATE_DS_NOTIFY phase.
1393 struct GNUNET_DATASTORE_Handle *dsh;
1396 * Pointer kept for the client.
1401 * Merkle-ish tree encoder context.
1403 struct GNUNET_FS_TreeEncoder *tc;
1406 * Handle used to read the file.
1408 struct GNUNET_DISK_FileHandle *fh;
1411 * Error message, NULL on success.
1416 * Context for hashing of the file.
1418 struct GNUNET_CRYPTO_FileHashContext *fhc;
1421 * Overall size of the file.
1426 * When did we start?
1428 struct GNUNET_TIME_Absolute start_time;
1431 * Hash of the file's contents (once computed).
1433 GNUNET_HashCode file_id;
1436 * Current operatinonal phase.
1438 enum UnindexState state;
1444 * Information we keep for each keyword in
1447 struct SearchRequestEntry
1450 * Hash of the original keyword, also known as the
1451 * key (for decrypting the KBlock).
1453 GNUNET_HashCode key;
1456 * Hash of the public key, also known as the query.
1458 GNUNET_HashCode query;
1461 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1462 * was found under this keyword. Note that the entries will point
1463 * to the same locations as those in the master result map (in
1464 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1465 * The key for each entry is the XOR of the key and query in the CHK
1466 * URI (as a unique identifier for the search result).
1468 struct GNUNET_CONTAINER_MultiHashMap *results;
1471 * Is this keyword a mandatory keyword
1472 * (started with '+')?
1480 * Handle for controlling a search.
1482 struct GNUNET_FS_SearchContext
1485 * Handle to the global FS context.
1487 struct GNUNET_FS_Handle *h;
1490 * Our top-level activity entry (if we are top-level, otherwise NULL).
1492 struct TopLevelActivity *top;
1495 * List of keywords that we're looking for.
1497 struct GNUNET_FS_Uri *uri;
1500 * For update-searches, link to the search result that triggered
1501 * the update search; otherwise NULL.
1503 struct GNUNET_FS_SearchResult *psearch_result;
1506 * Connection to the FS service.
1508 struct GNUNET_CLIENT_Connection *client;
1511 * Pointer we keep for the client.
1516 * Name of the file on disk we use for persistence.
1518 char *serialization;
1521 * Error message (non-NULL if this operation failed).
1526 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1527 * was found in the search. The key for each entry is the XOR of
1528 * the key and query in the CHK URI (as a unique identifier for the
1531 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1534 * Per-keyword information for a keyword search. This array will
1535 * have exactly as many entries as there were keywords.
1537 struct SearchRequestEntry *requests;
1540 * When did we start?
1542 struct GNUNET_TIME_Absolute start_time;
1545 * ID of a task that is using this struct and that must be cancelled
1546 * when the search is being stopped (if not
1547 * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
1548 * artificial delay when trying to reconnect to the FS service.
1550 GNUNET_SCHEDULER_TaskIdentifier task;
1553 * Anonymity level for the search.
1558 * Number of mandatory keywords in this query.
1560 uint32_t mandatory_count;
1563 * Options for the search.
1565 enum GNUNET_FS_SearchOptions options;
1570 * Information about an active download request.
1572 struct DownloadRequest
1575 * While pending, we keep all download requests in a linked list.
1577 struct DownloadRequest *next;
1580 * CHK for the request.
1582 struct ContentHashKey chk;
1585 * Offset of the corresponding block.
1590 * Depth of the corresponding block in the tree.
1595 * Set if this request is currently in the linked list of pending
1596 * requests. Needed in case we get a response for a request that we
1597 * have not yet send (i.e. due to two blocks with identical
1598 * content); in this case, we would need to remove the block from
1599 * the pending list (and need a fast way to check if the block is on
1608 * Context for controlling a download.
1610 struct GNUNET_FS_DownloadContext
1614 * Global FS context.
1616 struct GNUNET_FS_Handle *h;
1619 * Our top-level activity entry (if we are top-level, otherwise NULL).
1621 struct TopLevelActivity *top;
1624 * Connection to the FS service.
1626 struct GNUNET_CLIENT_Connection *client;
1629 * Parent download (used when downloading files
1632 struct GNUNET_FS_DownloadContext *parent;
1635 * Associated search (used when downloading files
1636 * based on search results), or NULL for none.
1638 struct GNUNET_FS_SearchResult *search;
1641 * Head of list of child downloads.
1643 struct GNUNET_FS_DownloadContext *child_head;
1646 * Tail of list of child downloads.
1648 struct GNUNET_FS_DownloadContext *child_tail;
1651 * Previous download belonging to the same parent.
1653 struct GNUNET_FS_DownloadContext *prev;
1656 * Next download belonging to the same parent.
1658 struct GNUNET_FS_DownloadContext *next;
1661 * Context kept for the client.
1666 * URI that identifies the file that
1667 * we are downloading.
1669 struct GNUNET_FS_Uri *uri;
1672 * Known meta-data for the file (can be NULL).
1674 struct GNUNET_CONTAINER_MetaData *meta;
1677 * Error message, NULL if we're doing OK.
1682 * Random portion of filename we use for syncing state of this
1685 char *serialization;
1688 * Where are we writing the data (name of the
1689 * file, can be NULL!).
1694 * Where are we writing the data temporarily (name of the
1695 * file, can be NULL!); used if we do not have a permanent
1696 * name and we are a directory and we do a recursive download.
1698 char *temp_filename;
1701 * Map of active requests (those waiting
1702 * for a response). The key is the hash
1703 * of the encryped block (aka query).
1705 struct GNUNET_CONTAINER_MultiHashMap *active;
1708 * Linked list of pending requests.
1710 struct DownloadRequest *pending;
1713 * Non-NULL if we are currently having a request for
1714 * transmission pending with the client handle.
1716 struct GNUNET_CLIENT_TransmitHandle *th;
1719 * Our entry in the job queue.
1721 struct GNUNET_FS_QueueEntry *job_queue;
1724 * Identity of the peer having the content, or all-zeros
1725 * if we don't know of such a peer.
1727 struct GNUNET_PeerIdentity target;
1730 * ID of a task that is using this struct
1731 * and that must be cancelled when the download
1732 * is being stopped (if not GNUNET_SCHEDULER_NO_TASK).
1733 * Used for the task that adds some artificial
1734 * delay when trying to reconnect to the FS
1737 GNUNET_SCHEDULER_TaskIdentifier task;
1740 * What was the size of the file on disk that we're downloading
1741 * before we started? Used to detect if there is a point in
1742 * checking an existing block on disk for matching the desired
1743 * content. 0 if the file did not exist already.
1745 uint64_t old_file_size;
1748 * What is the first offset that we're interested
1754 * How many bytes starting from offset are desired?
1755 * This is NOT the overall length of the file!
1760 * How many bytes have we already received within
1761 * the specified range (DBlocks only).
1766 * Time download was started.
1768 struct GNUNET_TIME_Absolute start_time;
1771 * Desired level of anonymity.
1776 * The depth of the file-tree.
1778 unsigned int treedepth;
1781 * Options for the download.
1783 enum GNUNET_FS_DownloadOptions options;
1786 * Flag set upon transitive completion (includes child downloads).
1787 * This flag is only set to GNUNET_YES for directories where all
1788 * child-downloads have also completed (and signalled completion).
1794 struct GNUNET_FS_Namespace
1798 * Private key for the namespace.
1800 struct GNUNET_CRYPTO_RsaPrivateKey *key;
1803 * Name of the file with the private key.
1808 * Name of the namespace.
1813 * Reference counter.
1820 * Message sent from a GNUnet (fs) publishing activity to the
1821 * gnunet-fs-service to initiate indexing of a file. The service is
1822 * supposed to check if the specified file is available and has the
1823 * same cryptographic hash. It should then respond with either a
1824 * confirmation or a denial.
1826 * On OSes where this works, it is considered acceptable if the
1827 * service only checks that the path, device and inode match (it can
1828 * then be assumed that the hash will also match without actually
1829 * computing it; this is an optimization that should be safe given
1830 * that the client is not our adversary).
1832 struct IndexStartMessage
1836 * Message type will be GNUNET_MESSAGE_TYPE_FS_INDEX_START.
1838 struct GNUNET_MessageHeader header;
1841 * ID of device containing the file, as seen by the client. This
1842 * device ID is obtained using a call like "statvfs" (and converting
1843 * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
1844 * OS does not support this, in which case the service must do a
1845 * full hash recomputation.
1847 uint32_t device GNUNET_PACKED;
1850 * Inode of the file on the given device, as seen by the client
1851 * ("st_ino" field from "struct stat"). Use 0 if the OS does not
1852 * support this, in which case the service must do a full hash
1855 uint64_t inode GNUNET_PACKED;
1858 * Hash of the file that we would like to index.
1860 GNUNET_HashCode file_id;
1862 /* this is followed by a 0-terminated
1863 filename of a file with the hash
1864 "file_id" as seen by the client */
1870 * Message send by FS service in response to a request
1871 * asking for a list of all indexed files.
1873 struct IndexInfoMessage
1876 * Message type will be
1877 * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
1879 struct GNUNET_MessageHeader header;
1884 uint32_t reserved GNUNET_PACKED;
1887 * Hash of the indexed file.
1889 GNUNET_HashCode file_id;
1891 /* this is followed by a 0-terminated
1892 filename of a file with the hash
1893 "file_id" as seen by the client */
1899 * Message sent from a GNUnet (fs) unindexing activity to the
1900 * gnunet-service-fs to indicate that a file will be unindexed. The
1901 * service is supposed to remove the file from the list of indexed
1902 * files and response with a confirmation message (even if the file
1903 * was already not on the list).
1905 struct UnindexMessage
1909 * Message type will be
1910 * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
1912 struct GNUNET_MessageHeader header;
1917 uint32_t reserved GNUNET_PACKED;
1920 * Hash of the file that we will unindex.
1922 GNUNET_HashCode file_id;
1928 * Message sent from a GNUnet (fs) search activity to the
1929 * gnunet-service-fs to start a search.
1931 struct SearchMessage
1935 * Message type will be
1936 * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
1938 struct GNUNET_MessageHeader header;
1941 * Bitmask with options. Zero for no options, one for loopback-only.
1942 * Other bits are currently not defined.
1944 int32_t options GNUNET_PACKED;
1947 * Type of the content that we're looking for.
1949 uint32_t type GNUNET_PACKED;
1952 * Desired anonymity level, big-endian.
1954 uint32_t anonymity_level GNUNET_PACKED;
1957 * If the request is for a DBLOCK or IBLOCK, this is the identity of
1958 * the peer that is known to have a response. Set to all-zeros if
1959 * such a target is not known (note that even if OUR anonymity
1960 * level is >0 we may happen to know the responder's identity;
1961 * nevertheless, we should probably not use it for a DHT-lookup
1962 * or similar blunt actions in order to avoid exposing ourselves).
1964 * If the request is for an SBLOCK, this is the identity of the
1965 * pseudonym to which the SBLOCK belongs.
1967 * If the request is for a KBLOCK, "target" must be all zeros.
1969 GNUNET_HashCode target;
1972 * Hash of the keyword (aka query) for KBLOCKs; Hash of
1973 * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
1974 * and hash of the identifier XORed with the target for
1975 * SBLOCKS (aka query).
1977 GNUNET_HashCode query;
1979 /* this is followed by the hash codes of already-known
1980 results (which should hence be excluded from what
1981 the service returns); naturally, this only applies
1982 to queries that can have multiple results, such as
1983 those for KBLOCKS (KSK) and SBLOCKS (SKS) */
1988 * Only the (mandatory) query is included.
1990 #define GET_MESSAGE_BIT_QUERY_ONLY 0
1993 * The peer identity of a peer waiting for the
1994 * reply is included (used if the response
1995 * should be transmitted to someone other than
1996 * the sender of the GET).
1998 #define GET_MESSAGE_BIT_RETURN_TO 1
2001 * The hash of the public key of the target
2002 * namespace is included (for SKS queries).
2004 #define GET_MESSAGE_BIT_SKS_NAMESPACE 2
2007 * The peer identity of a peer that had claimed to have the content
2008 * previously is included (can be used if responder-anonymity is not
2009 * desired; note that the precursor presumably lacked a direct
2010 * connection to the specified peer; still, the receiver is in no way
2011 * required to limit forwarding only to the specified peer, it should
2012 * only prefer it somewhat if possible).
2014 #define GET_MESSAGE_BIT_TRANSMIT_TO 4
2018 * Message sent between peers asking for FS-content.
2024 * Message type will be GNUNET_MESSAGE_TYPE_FS_GET.
2026 struct GNUNET_MessageHeader header;
2029 * Type of the query (block type).
2031 uint32_t type GNUNET_PACKED;
2034 * How important is this request (network byte order)
2036 uint32_t priority GNUNET_PACKED;
2039 * Relative time to live in MILLISECONDS (network byte order)
2041 int32_t ttl GNUNET_PACKED;
2044 * The content hash should be mutated using this value
2045 * before checking against the bloomfilter (used to
2046 * get many different filters for the same hash codes).
2047 * The number should be in big-endian format when used
2050 int32_t filter_mutator GNUNET_PACKED;
2053 * Which of the optional hash codes are present at the end of the
2054 * message? See GET_MESSAGE_BIT_xx constants. For each bit that is
2055 * set, an additional GNUNET_HashCode with the respective content
2056 * (in order of the bits) will be appended to the end of the GET
2059 uint32_t hash_bitmap GNUNET_PACKED;
2062 * Hashcodes of the file(s) we're looking for.
2063 * Details depend on the query type.
2065 GNUNET_HashCode query GNUNET_PACKED;
2067 /* this is followed by hash codes
2068 as specified in the "hash_bitmap";
2069 after that, an optional bloomfilter
2070 (with bits set for replies that should
2071 be suppressed) can be present */
2076 * Response from FS service with a result for a previous FS search.
2077 * Note that queries for DBLOCKS and IBLOCKS that have received a
2078 * single response are considered done. This message is transmitted
2079 * between peers as well as between the service and a client.
2085 * Message type will be GNUNET_MESSAGE_TYPE_FS_PUT.
2087 struct GNUNET_MessageHeader header;
2090 * Type of the block (in big endian). Should never be zero.
2092 uint32_t type GNUNET_PACKED;
2095 * When does this result expire?
2097 struct GNUNET_TIME_AbsoluteNBO expiration;
2099 /* this is followed by the actual encrypted content */