2 This file is part of GNUnet
3 (C) 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.
21 * @file include/gnunet_fs_service.h
22 * @brief API for file-sharing via GNUnet
23 * @author Christian Grothoff
26 * - extend API with support for publish simulation (-s)
27 * and URI-argument binding to keyword/namespace (-u)
29 #ifndef GNUNET_FS_LIB_H
30 #define GNUNET_FS_LIB_H
32 #include "gnunet_util_lib.h"
37 #if 0 /* keep Emacsens' auto-indent happy */
43 * Version number of the implementation.
46 * 1.x.x: initial version with triple GNUNET_hash and merkle tree
47 * 2.x.x: root node with mime-type, filename and version number
48 * 2.1.x: combined GNUNET_EC_ContentHashKey/3HASH encoding with 25:1 super-nodes
49 * 2.2.x: with directories
50 * 3.0.x: with namespaces
51 * 3.1.x: with namespace meta-data
52 * 3.2.x: with collections
53 * 4.0.x: with expiration, variable meta-data, kblocks
54 * 4.1.x: with new error and configuration handling
55 * 5.0.x: with location URIs
56 * 6.0.0: with support for OR in KSKs
57 * 6.1.x: with simplified namespace support
58 * 9.0.0: CPS-style integrated API
60 #define GNUNET_FS_VERSION 0x00090000
63 /* ******************** URI API *********************** */
65 #define GNUNET_FS_URI_PREFIX "gnunet://fs/"
66 #define GNUNET_FS_URI_KSK_INFIX "ksk/"
67 #define GNUNET_FS_URI_SKS_INFIX "sks/"
68 #define GNUNET_FS_URI_CHK_INFIX "chk/"
69 #define GNUNET_FS_URI_LOC_INFIX "loc/"
73 * A Universal Resource Identifier (URI), opaque.
79 * Iterator over keywords
82 * @param keyword the keyword
83 * @param is_mandatory is the keyword mandatory (in a search)
84 * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
86 typedef int (*GNUNET_FS_KeywordIterator) (void *cls,
91 * Get a unique key from a URI. This is for putting URIs
92 * into HashMaps. The key may change between FS implementations.
94 * @param uri uri to convert to a unique key
95 * @param key wherer to store the unique key
98 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
99 GNUNET_HashCode * key);
102 * Convert a URI to a UTF-8 String.
104 * @param uri uri to convert to a string
105 * @return the UTF-8 string
108 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
111 * Convert keyword URI to a human readable format
112 * (i.e. the search query that was used in the first place)
114 * @param uri ksk uri to convert to a string
115 * @return string with the keywords
118 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
122 * Convert a UTF-8 String to a URI.
124 * @param uri string to parse
125 * @param emsg where to store the parser error message (if any)
126 * @return NULL on error
128 struct GNUNET_FS_Uri *
129 GNUNET_FS_uri_parse (const char *uri,
135 * @param uri uri to free
138 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
142 * How many keywords are ANDed in this keyword URI?
144 * @param uri ksk uri to get the number of keywords from
145 * @return 0 if this is not a keyword URI
148 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
152 * Iterate over all keywords in this keyword URI.
154 * @param uri ksk uri to get the keywords from
155 * @param iterator function to call on each keyword
156 * @param iterator_cls closure for iterator
157 * @return -1 if this is not a keyword URI, otherwise number of
158 * keywords iterated over until iterator aborted
161 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
162 GNUNET_FS_KeywordIterator iterator,
167 * Obtain the identity of the peer offering the data
169 * @param uri the location URI to inspect
170 * @param peer where to store the identify of the peer (presumably) offering the content
171 * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK
174 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
175 struct GNUNET_PeerIdentity * peer);
179 * Obtain the URI of the content itself.
181 * @param uri location URI to get the content URI from
182 * @return NULL if argument is not a location URI
184 struct GNUNET_FS_Uri *
185 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
189 * Construct a location URI (this peer will be used for the location).
191 * @param baseURI content offered by the sender
192 * @param cfg configuration information (used to find our hostkey)
193 * @param expiration_time how long will the content be offered?
194 * @return the location URI, NULL on error
196 struct GNUNET_FS_Uri *
197 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
198 struct GNUNET_CONFIGURATION_Handle *cfg,
199 struct GNUNET_TIME_Absolute expiration_time);
203 * Canonicalize keyword URI. Performs operations such
204 * as decapitalization and removal of certain characters.
205 * (useful for search).
207 * @param uri the URI to canonicalize
208 * @return canonicalized version of the URI, NULL on error
210 struct GNUNET_FS_Uri *
211 GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri);
215 * Merge the sets of keywords from two KSK URIs.
216 * (useful for merging the canonicalized keywords with
217 * the original keywords for sharing).
219 * @param u1 first uri
220 * @param u2 second uri
221 * @return merged URI, NULL on error
223 struct GNUNET_FS_Uri *
224 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
225 const struct GNUNET_FS_Uri *u2);
231 * @param uri the URI to duplicate
232 * @return copy of the URI
234 struct GNUNET_FS_Uri *
235 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
239 * Create an FS URI from a single user-supplied string of keywords.
240 * The string is broken up at spaces into individual keywords.
241 * Keywords that start with "+" are mandatory. Double-quotes can
242 * be used to prevent breaking up strings at spaces (and also
243 * to specify non-mandatory keywords starting with "+").
245 * Keywords must contain a balanced number of double quotes and
246 * double quotes can not be used in the actual keywords (for
247 * example, the string '""foo bar""' will be turned into two
248 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
250 * @param keywords the keyword string
251 * @param emsg where to store an error message
252 * @return an FS URI for the given keywords, NULL
253 * if keywords is not legal (i.e. empty).
255 struct GNUNET_FS_Uri *
256 GNUNET_FS_uri_ksk_create (const char *keywords,
261 * Create an FS URI from a user-supplied command line of keywords.
262 * Arguments should start with "+" to indicate mandatory
265 * @param argc number of keywords
266 * @param argv keywords (double quotes are not required for
267 * keywords containing spaces; however, double
268 * quotes are required for keywords starting with
269 * "+"); there is no mechanism for having double
270 * quotes in the actual keywords (if the user
271 * did specifically specify double quotes, the
272 * caller should convert each double quote
273 * into two single quotes).
274 * @return an FS URI for the given keywords, NULL
275 * if keywords is not legal (i.e. empty).
277 struct GNUNET_FS_Uri *
278 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
283 * Test if two URIs are equal.
285 * @param u1 one of the URIs
286 * @param u2 the other URI
287 * @return GNUNET_YES if the URIs are equal
290 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
291 const struct GNUNET_FS_Uri *u2);
295 * Is this a namespace URI?
297 * @param uri the uri to check
298 * @return GNUNET_YES if this is an SKS uri
301 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
305 * Get the ID of a namespace from the given
308 * @param uri the uri to get the namespace ID from
309 * @param nsid where to store the ID of the namespace
310 * @return GNUNET_OK on success
313 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
314 GNUNET_HashCode * nsid);
318 * Get the content identifier of an SKS URI.
320 * @param uri the sks uri
321 * @return NULL on error (not a valid SKS URI)
324 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
328 * Convert namespace URI to a human readable format
329 * (using the namespace description, if available).
331 * @param cfg configuration to use
332 * @param uri SKS uri to convert
333 * @return NULL on error (not an SKS URI)
336 GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
337 const struct GNUNET_FS_Uri *uri);
341 * Is this a keyword URI?
344 * @return GNUNET_YES if this is a KSK uri
347 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
351 * Is this a file (or directory) URI?
353 * @param uri the uri to check
354 * @return GNUNET_YES if this is a CHK uri
357 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
361 * What is the size of the file that this URI
364 * @param uri the CHK (or LOC) URI to inspect
365 * @return size of the file as specified in the CHK URI
368 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
372 * Is this a location URI?
374 * @param uri the uri to check
375 * @return GNUNET_YES if this is a LOC uri
378 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
382 * Construct a keyword-URI from meta-data (take all entries
383 * in the meta-data and construct one large keyword URI
384 * that lists all keywords that can be found in the meta-data).
387 struct GNUNET_FS_Uri *
388 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md);
391 /* ******************** command-line option parsing API *********************** */
394 * Command-line option parser function that allows the user
395 * to specify one or more '-k' options with keywords. Each
396 * specified keyword will be added to the URI. A pointer to
397 * the URI must be passed as the "scls" argument.
399 * @param ctx command line processor context
400 * @param scls must be of type "struct GNUNET_FS_Uri **"
401 * @param option name of the option (typically 'k')
402 * @param value command line argument given
403 * @return GNUNET_OK on success
406 GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx,
413 * Command-line option parser function that allows the user to specify
414 * one or more '-m' options with metadata. Each specified entry of
415 * the form "type=value" will be added to the metadata. A pointer to
416 * the metadata must be passed as the "scls" argument.
418 * @param ctx command line processor context
419 * @param scls must be of type "struct GNUNET_CONTAINER_MetaData **"
420 * @param option name of the option (typically 'k')
421 * @param value command line argument given
422 * @return GNUNET_OK on success
425 GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx,
432 /* ************************* sharing API ***************** */
436 * Possible status codes used in the callback for the
437 * various file-sharing operations. On each file (or search),
438 * the callback is guaranteed to be called once with "START"
439 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
440 * are optional and depend on the circumstances; parent operations
441 * will be STARTED before child-operations and STOPPED after
442 * their respective child-operations. START and STOP signals
443 * are typically generated either due to explicit client requests
444 * or because of suspend/resume operations.
446 enum GNUNET_FS_Status
449 * Notification that we have started to publish a file structure.
451 GNUNET_FS_STATUS_PUBLISH_START,
454 * Notification that we have resumed sharing a file structure.
456 GNUNET_FS_STATUS_PUBLISH_RESUME,
459 * Notification that we have suspended sharing a file structure.
461 GNUNET_FS_STATUS_PUBLISH_SUSPEND,
464 * Notification that we are making progress sharing a file structure.
466 GNUNET_FS_STATUS_PUBLISH_PROGRESS,
469 * Notification that an error was encountered sharing a file structure.
470 * The application will continue to receive resume/suspend events for
471 * this structure until "GNUNET_FS_publish_stop" is called.
473 GNUNET_FS_STATUS_PUBLISH_ERROR,
476 * Notification that we completed sharing a file structure.
477 * The application will continue to receive resume/suspend events for
478 * this structure until "GNUNET_FS_publish_stop" is called.
480 GNUNET_FS_STATUS_PUBLISH_COMPLETED,
483 * Notification that we have stopped
484 * the process of uploading a file structure; no
485 * futher events will be generated for this action.
487 GNUNET_FS_STATUS_PUBLISH_STOPPED,
490 * Notification that we have started this download.
492 GNUNET_FS_STATUS_DOWNLOAD_START,
495 * Notification that this download is being resumed.
497 GNUNET_FS_STATUS_DOWNLOAD_RESUME,
500 * Notification that this download was suspended.
502 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND,
505 * Notification about progress with this download.
507 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS,
510 * Notification that this download encountered an error.
512 GNUNET_FS_STATUS_DOWNLOAD_ERROR,
515 * Notification that this download completed. Note that for
516 * directories, completion does not imply completion of all files in
519 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED,
522 * Notification that this download was stopped
523 * (final event with respect to this action).
525 GNUNET_FS_STATUS_DOWNLOAD_STOPPED,
528 * First event generated when a client requests
529 * a search to begin or when a namespace result
530 * automatically triggers the search for updates.
532 GNUNET_FS_STATUS_SEARCH_START,
535 * Last event when a search is being resumed;
536 * note that "GNUNET_FS_SEARCH_START" will not
537 * be generated in this case.
539 GNUNET_FS_STATUS_SEARCH_RESUME,
542 * Event generated for each search result
543 * when the respective search is resumed.
545 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT,
548 * Last event when a search is being suspended;
549 * note that "GNUNET_FS_SEARCH_STOPPED" will not
550 * be generated in this case.
552 GNUNET_FS_STATUS_SEARCH_SUSPEND,
555 * Event generated for each search result
556 * when the respective search is suspended.
558 GNUNET_FS_STATUS_SEARCH_SUSPEND_RESULT,
561 * This search has yielded a result.
563 GNUNET_FS_STATUS_SEARCH_RESULT,
566 * We have discovered a new namespace.
568 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE,
571 * We have additional data about the quality
572 * or availability of a search result.
574 GNUNET_FS_STATUS_SEARCH_UPDATE,
577 * Signals a problem with this search.
579 GNUNET_FS_STATUS_SEARCH_ERROR,
582 * Signals that this search was paused.
584 GNUNET_FS_STATUS_SEARCH_PAUSED,
587 * Signals that this search was continued (unpaused).
589 GNUNET_FS_STATUS_SEARCH_CONTINUED,
592 * Event generated for each search result
593 * when the respective search is stopped.
595 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED,
598 * Last message from a search; this signals
599 * that there will be no further events associated
602 GNUNET_FS_STATUS_SEARCH_STOPPED,
605 * Notification that we started to unindex a file.
607 GNUNET_FS_STATUS_UNINDEX_START,
610 * Notification that we resumed unindexing of a file.
612 GNUNET_FS_STATUS_UNINDEX_RESUME,
615 * Notification that we suspended unindexing a file.
617 GNUNET_FS_STATUS_UNINDEX_SUSPEND,
620 * Notification that we made progress unindexing a file.
622 GNUNET_FS_STATUS_UNINDEX_PROGRESS,
625 * Notification that we encountered an error unindexing
628 GNUNET_FS_STATUS_UNINDEX_ERROR,
631 * Notification that the unindexing of this file
634 GNUNET_FS_STATUS_UNINDEX_COMPLETED,
637 * Notification that the unindexing of this file
638 * was stopped (final event for this action).
640 GNUNET_FS_STATUS_UNINDEX_STOPPED
646 * Handle to one of our namespaces.
648 struct GNUNET_FS_Namespace;
652 * Handle for controlling an upload.
654 struct GNUNET_FS_PublishContext;
658 * Handle for controlling an unindexing operation.
660 struct GNUNET_FS_UnindexContext;
664 * Handle for controlling a search.
666 struct GNUNET_FS_SearchContext;
670 * Context for controlling a download.
672 struct GNUNET_FS_DownloadContext;
676 * Handle for detail information about a file that is being publishd.
677 * Specifies metadata, keywords, how to get the contents of the file
678 * (i.e. data-buffer in memory, filename on disk) and other options.
680 struct GNUNET_FS_FileInformation;
684 * Argument given to the progress callback with
685 * information about what is going on.
687 struct GNUNET_FS_ProgressInfo
691 * Values that depend on the event type.
696 * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
701 * Context for controlling the upload.
703 struct GNUNET_FS_PublishContext *sc;
706 * Information about the file that is being publishd.
708 const struct GNUNET_FS_FileInformation *fi;
711 * Client context pointer (set the last time
712 * by the client for this operation; initially
713 * NULL on START/RESUME events).
718 * Client context pointer for the parent operation
719 * (if this is a file in a directory or a subdirectory).
724 * Name of the file being published; can be NULL.
726 const char *filename;
729 * How large is the file overall? For directories,
730 * this is only the size of the directory itself,
731 * not of the other files contained within the
737 * At what time do we expect to finish the upload?
738 * (will be a value in the past for completed
741 struct GNUNET_TIME_Relative eta;
744 * How long has this upload been actively running
745 * (excludes times where the upload was suspended).
747 struct GNUNET_TIME_Relative duration;
750 * How many bytes have we completed?
755 * What anonymity level is used for this upload?
760 * Additional values for specific events.
765 * These values are only valid for
766 * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
771 * Data block we just published.
776 * At what offset in the file is "data"?
781 * Length of the data block.
786 * Depth of the given block in the tree;
787 * 0 would be the highest level (the first
788 * call is guaranteed to be for the lowest
796 * These values are only valid for
797 * GNUNET_FS_STATUS_PUBLISH_RESUME events.
802 * Error message, NULL if no error was encountered so far.
807 * URI of the file (if the download had been completed)
809 const struct GNUNET_FS_Uri *chk_uri;
814 * These values are only valid for
815 * GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
822 const struct GNUNET_FS_Uri *chk_uri;
827 * These values are only valid for
828 * GNUNET_FS_STATUS_PUBLISH_ERROR events.
833 * Error message, never NULL.
845 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
850 * Context for controlling the download.
852 struct GNUNET_FS_DownloadContext *dc;
855 * Client context pointer (set the last time
856 * by the client for this operation; initially
857 * NULL on START/RESUME events).
862 * Client context pointer for the parent operation
863 * (if this is a file in a directory or a subdirectory).
868 * URI used for this download.
870 const struct GNUNET_FS_Uri *uri;
873 * Name of the file that we are downloading.
875 const char *filename;
878 * How large is the download overall? This
879 * is NOT necessarily the size from the
880 * URI since we may be doing a partial download.
885 * At what time do we expect to finish the download?
886 * (will be a value in the past for completed
889 struct GNUNET_TIME_Relative eta;
892 * How long has this download been active?
894 struct GNUNET_TIME_Relative duration;
897 * How many bytes have we completed?
902 * What anonymity level is used for this download?
907 * Additional values for specific events.
912 * These values are only valid for
913 * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
918 * Data block we just obtained.
923 * At what offset in the file is "data"?
928 * Length of the data block.
933 * Depth of the given block in the tree;
934 * 0 would be the highest level (the first
935 * call is guaranteed to be for the lowest
943 * These values are only valid for
944 * GNUNET_FS_STATUS_DOWNLOAD_START events.
949 * Known metadata for the download.
951 const struct GNUNET_CONTAINER_MetaData *meta;
956 * These values are only valid for
957 * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
962 * Known metadata for the download.
964 const struct GNUNET_CONTAINER_MetaData *meta;
967 * Error message, NULL if we have not encountered any error yet.
974 * These values are only valid for
975 * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
991 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
996 * Context for controlling the search, NULL for
997 * searches that were not explicitly triggered
998 * by the client (i.e., searches for updates in
1001 struct GNUNET_FS_SearchContext *sc;
1004 * Client context pointer (set the last time by the client for
1005 * this operation; initially NULL on START/RESUME events). Note
1006 * that this value can only be set on START/RESUME; returning
1007 * non-NULL on RESULT/RESUME_RESULT will actually update the
1008 * private context for "UPDATE" events.
1013 * Client parent-context pointer; NULL for top-level searches,
1014 * non-NULL for automatically triggered searches for updates in
1020 * What query is used for this search
1021 * (list of keywords or SKS identifier).
1023 const struct GNUNET_FS_Uri *query;
1026 * How long has this search been actively running
1027 * (excludes times where the search was paused or
1030 struct GNUNET_TIME_Relative duration;
1033 * What anonymity level is used for this search?
1038 * Additional values for specific events.
1043 * These values are only valid for
1044 * GNUNET_FS_STATUS_SEARCH_RESULT events.
1049 * Metadata for the search result.
1051 const struct GNUNET_CONTAINER_MetaData *meta;
1054 * URI for the search result.
1056 const struct GNUNET_FS_Uri *uri;
1061 * These values are only valid for
1062 * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1067 * Metadata for the search result.
1069 const struct GNUNET_CONTAINER_MetaData *meta;
1072 * URI for the search result.
1074 const struct GNUNET_FS_Uri *uri;
1077 * Current availability rank (negative:
1078 * unavailable, positive: available)
1080 int32_t availability_rank;
1083 * On how many total queries is the given
1084 * availability_rank based?
1086 uint32_t availabiliy_certainty;
1089 * Updated applicability rank (the larger,
1090 * the better the result fits the search
1093 uint32_t applicabiliy_rank;
1098 * These values are only valid for
1099 * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1104 * Private context set for for this result
1105 * during the "RESULT" event.
1110 * Metadata for the search result.
1112 const struct GNUNET_CONTAINER_MetaData *meta;
1115 * URI for the search result.
1117 const struct GNUNET_FS_Uri *uri;
1120 * Current availability rank (negative:
1121 * unavailable, positive: available)
1123 int32_t availability_rank;
1126 * On how many total queries is the given
1127 * availability_rank based?
1129 uint32_t availability_certainty;
1132 * Updated applicability rank (the larger,
1133 * the better the result fits the search
1136 uint32_t applicability_rank;
1141 * These values are only valid for
1142 * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1143 * These events are automatically triggered for
1144 * each search result before the
1145 * GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1146 * happens primarily to give the client a chance
1147 * to clean up the "cctx" (if needed).
1152 * Private context set for for this result
1153 * during the "RESULT" event.
1158 * Metadata for the search result.
1160 const struct GNUNET_CONTAINER_MetaData *meta;
1163 * URI for the search result.
1165 const struct GNUNET_FS_Uri *uri;
1170 * These values are only valid for
1171 * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1172 * These events are automatically triggered for
1173 * each search result before the
1174 * GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1175 * happens primarily to give the client a chance
1176 * to clean up the "cctx" (if needed).
1181 * Private context set for for this result
1182 * during the "RESULT" event.
1187 * Metadata for the search result.
1189 const struct GNUNET_CONTAINER_MetaData *meta;
1192 * URI for the search result.
1194 const struct GNUNET_FS_Uri *uri;
1199 * These values are only valid for
1200 * GNUNET_FS_STATUS_SEARCH_RESUME events.
1205 * Error message, NULL if we have not encountered any error yet.
1207 const char *message;
1210 * Is this search currently paused?
1217 * These values are only valid for
1218 * GNUNET_FS_STATUS_SEARCH_ERROR events.
1225 const char *message;
1230 * Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events.
1235 * Handle to the namespace (NULL if it is not a local
1238 struct GNUNET_FS_Namespace *ns;
1241 * Short, human-readable name of the namespace.
1246 * Root identifier for the namespace, can be NULL.
1251 * Metadata for the namespace.
1253 const struct GNUNET_CONTAINER_MetaData *meta;
1256 * Hash-identifier for the namespace.
1267 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1272 * Context for controlling the unindexing.
1274 struct GNUNET_FS_UnindexContext *uc;
1277 * Client context pointer (set the last time
1278 * by the client for this operation; initially
1279 * NULL on START/RESUME events).
1284 * Name of the file that is being unindexed.
1286 const char *filename;
1289 * How large is the file overall?
1294 * At what time do we expect to finish unindexing?
1295 * (will be a value in the past for completed
1296 * unindexing opeations).
1298 struct GNUNET_TIME_Relative eta;
1301 * How long has this upload been actively running
1302 * (excludes times where the upload was suspended).
1304 struct GNUNET_TIME_Relative duration;
1307 * How many bytes have we completed?
1312 * Additional values for specific events.
1317 * These values are only valid for
1318 * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1323 * Data block we just unindexed.
1328 * At what offset in the file is "data"?
1333 * Length of the data block.
1338 * Depth of the given block in the tree;
1339 * 0 would be the highest level (the first
1340 * call is guaranteed to be for the lowest
1348 * These values are only valid for
1349 * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1354 * Error message, NULL if we have not encountered any error yet.
1356 const char *message;
1361 * These values are only valid for
1362 * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1369 const char *message;
1380 * Specific status code (determines the event type).
1382 enum GNUNET_FS_Status status;
1388 * Notification of FS to a client about the progress of an
1389 * operation. Callbacks of this type will be used for uploads,
1390 * downloads and searches. Some of the arguments depend a bit
1391 * in their meaning on the context in which the callback is used.
1393 * @param cls closure
1394 * @param info details about the event, specifying the event type
1395 * and various bits about the event
1396 * @return client-context (for the next progress call
1397 * for this operation; should be set to NULL for
1398 * SUSPEND and STOPPED events). The value returned
1399 * will be passed to future callbacks in the respective
1400 * field in the GNUNET_FS_ProgressInfo struct.
1402 typedef void* (*GNUNET_FS_ProgressCallback)
1404 const struct GNUNET_FS_ProgressInfo *info);
1408 * General (global) option flags for file-sharing.
1410 enum GNUNET_FS_Flags
1413 * No special flags set.
1415 GNUNET_FS_FLAGS_NONE = 0,
1418 * Is persistence of operations desired?
1419 * (will create SUSPEND/RESUME events).
1421 GNUNET_FS_FLAGS_PERSISTENCE = 1
1426 * Options specified in the VARARGs
1427 * portion of GNUNET_FS_start.
1429 enum GNUNET_FS_OPTIONS
1433 * Last option in the VARARG list.
1435 GNUNET_FS_OPTIONS_END = 0,
1438 * Select the desired amount of parallelism (this option should be
1439 * followed by an "unsigned int" giving the desired maximum number
1440 * of parallel downloads).
1442 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1
1448 * Handle to the file-sharing service.
1450 struct GNUNET_FS_Handle;
1454 * Setup a connection to the file-sharing service.
1456 * @param sched scheduler to use
1457 * @param cfg configuration to use
1458 * @param client_name unique identifier for this client
1459 * @param upcb function to call to notify about FS actions
1460 * @param upcb_cls closure for upcb
1461 * @param flags specific attributes for fs-operations
1462 * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
1463 * @return NULL on error
1465 struct GNUNET_FS_Handle *
1466 GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched,
1467 const struct GNUNET_CONFIGURATION_Handle *cfg,
1468 const char *client_name,
1469 GNUNET_FS_ProgressCallback upcb,
1471 enum GNUNET_FS_Flags flags,
1476 * Close our connection with the file-sharing service.
1477 * The callback given to GNUNET_FS_start will no longer be
1478 * called after this function returns.
1480 * @param h handle that was returned from GNUNET_FS_start
1483 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1487 * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
1489 * @param cls closure
1490 * @param fi the entry in the publish-structure
1491 * @param length length of the file or directory
1492 * @param meta metadata for the file or directory (can be modified)
1493 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1494 * @param anonymity pointer to selected anonymity level (can be modified)
1495 * @param priority pointer to selected priority (can be modified)
1496 * @param expirationTime pointer to selected expiration time (can be modified)
1497 * @param client_info pointer to client context set upon creation (can be modified)
1498 * @return GNUNET_OK to continue, GNUNET_NO to remove
1499 * this entry from the directory, GNUNET_SYSERR
1500 * to abort the iteration
1502 typedef int (*GNUNET_FS_FileInformationProcessor)(void *cls,
1503 struct GNUNET_FS_FileInformation *fi,
1505 struct GNUNET_CONTAINER_MetaData *meta,
1506 struct GNUNET_FS_Uri **uri,
1507 uint32_t *anonymity,
1509 struct GNUNET_TIME_Absolute *expirationTime,
1510 void **client_info);
1514 * Recover file information structure from disk.
1516 * @param name filename for the structure on disk
1517 * @return NULL on error
1519 struct GNUNET_FS_FileInformation *
1520 GNUNET_FS_file_information_recover (const char *name);
1524 * Obtain the name under which this file information
1525 * structure is stored on disk. Only works for top-level
1526 * file information structures.
1528 * @param s structure to get the filename for
1529 * @return NULL on error, otherwise filename that
1530 * can be passed to "GNUNET_FS_file_information_recover"
1531 * to read this fi-struct from disk.
1534 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1538 * Synchronize this file-information struct with its mirror
1539 * on disk. Note that all internal FS-operations that change
1540 * file information data should already call "sync" internally,
1541 * so this function is likely not useful for clients.
1543 * @param s the struct to sync
1546 GNUNET_FS_file_information_sync (struct GNUNET_FS_FileInformation *s);
1550 * Create an entry for a file in a publish-structure.
1552 * @param filename name of the file or directory to publish
1553 * @param keywords under which keywords should this file be available
1554 * directly; can be NULL
1555 * @param meta metadata for the file
1556 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1557 * GNUNET_SYSERR for simulation
1558 * @param anonymity what is the desired anonymity level for sharing?
1559 * @param priority what is the priority for OUR node to
1560 * keep this file available? Use 0 for maximum anonymity and
1561 * minimum reliability...
1562 * @param expirationTime when should this content expire?
1563 * @return publish structure entry for the file
1565 struct GNUNET_FS_FileInformation *
1566 GNUNET_FS_file_information_create_from_file (void *client_info,
1567 const char *filename,
1568 const struct GNUNET_FS_Uri *keywords,
1569 const struct GNUNET_CONTAINER_MetaData *meta,
1573 struct GNUNET_TIME_Absolute expirationTime);
1577 * Create an entry for a file in a publish-structure.
1579 * @param length length of the file
1580 * @param data data for the file (should not be used afterwards by
1581 * the caller; caller will "free")
1582 * @param keywords under which keywords should this file be available
1583 * directly; can be NULL
1584 * @param meta metadata for the file
1585 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1586 * GNUNET_SYSERR for simulation
1587 * @param anonymity what is the desired anonymity level for sharing?
1588 * @param priority what is the priority for OUR node to
1589 * keep this file available? Use 0 for maximum anonymity and
1590 * minimum reliability...
1591 * @param expirationTime when should this content expire?
1592 * @return publish structure entry for the file
1594 struct GNUNET_FS_FileInformation *
1595 GNUNET_FS_file_information_create_from_data (void *client_info,
1598 const struct GNUNET_FS_Uri *keywords,
1599 const struct GNUNET_CONTAINER_MetaData *meta,
1603 struct GNUNET_TIME_Absolute expirationTime);
1607 * Function that provides data.
1609 * @param cls closure
1610 * @param offset offset to read from; it is possible
1611 * that the caller might need to go backwards
1613 * @param max maximum number of bytes that should be
1614 * copied to buf; readers are not allowed
1615 * to provide less data unless there is an error;
1616 * a value of "0" will be used at the end to allow
1617 * the reader to clean up its internal state
1618 * @param buf where the reader should write the data
1619 * @param emsg location for the reader to store an error message
1620 * @return number of bytes written, usually "max", 0 on error
1622 typedef size_t (*GNUNET_FS_DataReader)(void *cls,
1630 * Create an entry for a file in a publish-structure.
1632 * @param length length of the file
1633 * @param reader function that can be used to obtain the data for the file
1634 * @param reader_cls closure for "reader"
1635 * @param keywords under which keywords should this file be available
1636 * directly; can be NULL
1637 * @param meta metadata for the file
1638 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1639 * GNUNET_SYSERR for simulation
1640 * @param anonymity what is the desired anonymity level for sharing?
1641 * @param priority what is the priority for OUR node to
1642 * keep this file available? Use 0 for maximum anonymity and
1643 * minimum reliability...
1644 * @param expirationTime when should this content expire?
1645 * @return publish structure entry for the file
1647 struct GNUNET_FS_FileInformation *
1648 GNUNET_FS_file_information_create_from_reader (void *client_info,
1650 GNUNET_FS_DataReader reader,
1652 const struct GNUNET_FS_Uri *keywords,
1653 const struct GNUNET_CONTAINER_MetaData *meta,
1657 struct GNUNET_TIME_Absolute expirationTime);
1661 * Function that a "GNUNET_FS_DirectoryScanner" should call
1662 * for each entry in the directory.
1664 * @param cls closure
1665 * @param filename name of the file (including path); must end
1666 * in a "/" (even on W32) if this is a directory
1667 * @param fi information about the file (should not be
1668 * used henceforth by the caller)
1670 typedef void (*GNUNET_FS_FileProcessor)(void *cls,
1671 const char *filename,
1672 struct GNUNET_FS_FileInformation *fi);
1676 * Type of a function that will be used to scan a directory.
1678 * @param cls closure
1679 * @param dirname name of the directory to scan
1680 * @param do_index should files be indexed or inserted
1681 * @param anonymity desired anonymity level
1682 * @param priority priority for publishing
1683 * @param expirationTime expiration for publication
1684 * @param proc function to call on each entry
1685 * @param proc_cls closure for proc
1686 * @param emsg where to store an error message (on errors)
1687 * @return GNUNET_OK on success
1689 typedef int (*GNUNET_FS_DirectoryScanner)(void *cls,
1690 const char *dirname,
1694 struct GNUNET_TIME_Absolute expirationTime,
1695 GNUNET_FS_FileProcessor proc,
1702 * Simple, useful default implementation of a directory scanner
1703 * (GNUNET_FS_DirectoryScanner). This implementation expects to get a
1704 * UNIX filename, will publish all files in the directory except hidden
1705 * files (those starting with a "."). Metadata will be extracted
1706 * using GNU libextractor; the specific list of plugins should be
1707 * specified in "cls", passing NULL will disable (!) metadata
1708 * extraction. Keywords will be derived from the metadata and be
1709 * subject to default canonicalization. This is strictly a
1710 * convenience function.
1712 * @param cls must be of type "struct EXTRACTOR_Extractor*"
1713 * @param dirname name of the directory to scan
1714 * @param do_index should files be indexed or inserted
1715 * @param anonymity desired anonymity level
1716 * @param priority priority for publishing
1717 * @param expirationTime expiration for publication
1718 * @param proc function called on each entry
1719 * @param proc_cls closure for proc
1720 * @param emsg where to store an error message (on errors)
1721 * @return GNUNET_OK on success
1724 GNUNET_FS_directory_scanner_default (void *cls,
1725 const char *dirname,
1729 struct GNUNET_TIME_Absolute expirationTime,
1730 GNUNET_FS_FileProcessor proc,
1736 * Create a publish-structure from an existing file hierarchy, inferring
1737 * and organizing keywords and metadata as much as possible. This
1738 * function primarily performs the recursive build and re-organizes
1739 * keywords and metadata; for automatically getting metadata
1740 * extraction, scanning of directories and creation of the respective
1741 * GNUNET_FS_FileInformation entries the default scanner should be
1742 * passed (GNUNET_FS_directory_scanner_default). This is strictly a
1743 * convenience function.
1745 * @param filename name of the top-level file or directory
1746 * @param scanner function used to get a list of files in a directory
1747 * @param scanner_cls closure for scanner
1748 * @param do_index should files in the hierarchy be indexed?
1749 * @param anonymity what is the desired anonymity level for sharing?
1750 * @param priority what is the priority for OUR node to
1751 * keep this file available? Use 0 for maximum anonymity and
1752 * minimum reliability...
1753 * @param expirationTime when should this content expire?
1754 * @param emsg where to store an error message
1755 * @return publish structure entry for the directory, NULL on error
1757 struct GNUNET_FS_FileInformation *
1758 GNUNET_FS_file_information_create_from_directory (void *client_info,
1759 const char *filename,
1760 GNUNET_FS_DirectoryScanner scanner,
1765 struct GNUNET_TIME_Absolute expirationTime,
1770 * Create an entry for an empty directory in a publish-structure.
1771 * This function should be used by applications for which the
1772 * use of "GNUNET_FS_file_information_create_from_directory"
1773 * is not appropriate.
1775 * @param meta metadata for the directory
1776 * @param keywords under which keywords should this directory be available
1777 * directly; can be NULL
1778 * @param anonymity what is the desired anonymity level for sharing?
1779 * @param priority what is the priority for OUR node to
1780 * keep this file available? Use 0 for maximum anonymity and
1781 * minimum reliability...
1782 * @param expirationTime when should this content expire?
1783 * @return publish structure entry for the directory , NULL on error
1785 struct GNUNET_FS_FileInformation *
1786 GNUNET_FS_file_information_create_empty_directory (void *client_info,
1787 const struct GNUNET_CONTAINER_MetaData *meta,
1788 const struct GNUNET_FS_Uri *keywords,
1791 struct GNUNET_TIME_Absolute expirationTime);
1795 * Add an entry to a directory in a publish-structure. Clients
1796 * should never modify publish structures that were passed to
1797 * "GNUNET_FS_publish_start" already.
1799 * @param dir the directory
1800 * @param end the entry to add; the entry must not have been
1801 * added to any other directory at this point and
1802 * must not include "dir" in its structure
1803 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1806 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1807 struct GNUNET_FS_FileInformation *end);
1811 * Inspect a file or directory in a publish-structure. Clients
1812 * should never modify publish structures that were passed to
1813 * "GNUNET_FS_publish_start" already. When called on a directory,
1814 * this function will FIRST call "proc" with information about
1815 * the directory itself and then for each of the files in the
1816 * directory (but not for files in subdirectories). When called
1817 * on a file, "proc" will be called exactly once (with information
1818 * about the specific file).
1820 * @param dir the directory
1821 * @param proc function to call on each entry
1822 * @param proc_cls closure for proc
1825 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1826 GNUNET_FS_FileInformationProcessor proc,
1831 * Destroy publish-structure. Clients should never destroy publish
1832 * structures that were passed to "GNUNET_FS_publish_start" already.
1834 * @param fi structure to destroy
1835 * @param cleaner function to call on each entry in the structure
1836 * (useful to clean up client_info); can be NULL; return
1837 * values are ignored
1838 * @param cleaner_cls closure for cleaner
1841 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
1842 GNUNET_FS_FileInformationProcessor cleaner,
1847 * Options for publishing. Compatible options
1848 * can be OR'ed together.
1850 enum GNUNET_FS_PublishOptions
1853 * No options (use defaults for everything).
1855 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
1858 * Simulate publishing. With this option, no data will be stored
1859 * in the datastore. Useful for computing URIs from files.
1861 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
1865 * Publish a file or directory.
1867 * @param h handle to the file sharing subsystem
1868 * @param ctx initial value to use for the '*ctx'
1869 * in the callback (for the GNUNET_FS_STATUS_PUBLISH_START event).
1870 * @param fi information about the file or directory structure to publish
1871 * @param namespace namespace to publish the file in, NULL for no namespace
1872 * @param nid identifier to use for the publishd content in the namespace
1873 * (can be NULL, must be NULL if namespace is NULL)
1874 * @param nuid update-identifier that will be used for future updates
1875 * (can be NULL, must be NULL if namespace or nid is NULL)
1876 * @param options options for the publication
1877 * @return context that can be used to control the publish operation
1879 struct GNUNET_FS_PublishContext *
1880 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1882 struct GNUNET_FS_FileInformation *fi,
1883 struct GNUNET_FS_Namespace *namespace,
1886 enum GNUNET_FS_PublishOptions options);
1890 * Stop an upload. Will abort incomplete uploads (but
1891 * not remove blocks that have already been publishd) or
1892 * simply clean up the state for completed uploads.
1894 * @param sc context for the upload to stop
1897 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *sc);
1901 * Signature of a function called as the continuation of a KBlock or
1902 * SBlock publication.
1904 * @param cls closure
1905 * @param uri URI under which the block is now available, NULL on error
1906 * @param emsg error message, NULL on success
1908 typedef void (*GNUNET_FS_PublishContinuation)(void *cls,
1909 const struct GNUNET_FS_Uri *uri,
1914 * Publish a KBlock on GNUnet.
1916 * @param h handle to the file sharing subsystem
1917 * @param keywords keywords to use
1918 * @param meta metadata to use
1919 * @param uri URI to refer to in the KBlock
1920 * @param expirationTime when the KBlock expires
1921 * @param anonymity anonymity level for the KBlock
1922 * @param priority priority for the KBlock
1923 * @param cont continuation
1924 * @param cont_cls closure for cont
1927 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1928 struct GNUNET_FS_Uri *keywords,
1929 struct GNUNET_CONTAINER_MetaData *meta,
1930 struct GNUNET_FS_Uri *uri,
1931 struct GNUNET_TIME_Absolute expirationTime,
1934 enum GNUNET_FS_PublishOptions options,
1935 GNUNET_FS_PublishContinuation cont,
1940 * Publish an SBlock on GNUnet.
1942 * @param h handle to the file sharing subsystem
1943 * @param namespace namespace to publish in
1944 * @param identifier identifier to use
1945 * @param update update identifier to use
1946 * @param meta metadata to use
1947 * @param uri URI to refer to in the SBlock
1948 * @param expirationTime when the SBlock expires
1949 * @param anonymity anonymity level for the SBlock
1950 * @param priority priority for the SBlock
1951 * @param cont continuation
1952 * @param cont_cls closure for cont
1955 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
1956 struct GNUNET_FS_Namespace *namespace,
1957 const char *identifier,
1959 struct GNUNET_CONTAINER_MetaData *meta,
1960 struct GNUNET_FS_Uri *uri,
1961 struct GNUNET_TIME_Absolute expirationTime,
1964 enum GNUNET_FS_PublishOptions options,
1965 GNUNET_FS_PublishContinuation cont,
1970 * Type of a function called by "GNUNET_FS_get_indexed_files".
1972 * @param cls closure
1973 * @param filename the name of the file
1974 * @param file_id hash of the contents of the indexed file
1975 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
1977 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls,
1978 const char *filename,
1979 const GNUNET_HashCode *file_id);
1983 * Iterate over all indexed files.
1985 * @param h handle to the file sharing subsystem
1986 * @param iterator function to call on each indexed file
1987 * @param iterator_cls closure for iterator
1988 * @param cont continuation to call when done;
1989 * reason should be "TIMEOUT" (on
1990 * error) or "PREREQ_DONE" (on success)
1991 * @param cont_cls closure for cont
1994 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
1995 GNUNET_FS_IndexedFileProcessor iterator,
1997 GNUNET_SCHEDULER_Task cont,
2004 * @param h handle to the file sharing subsystem
2005 * @param filename file to unindex
2006 * @return NULL on error, otherwise handle
2008 struct GNUNET_FS_UnindexContext *
2009 GNUNET_FS_unindex (struct GNUNET_FS_Handle *h,
2010 const char *filename);
2014 * Clean up after completion of an unindex operation.
2019 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2023 * Publish an advertismement for a namespace.
2025 * @param h handle to the file sharing subsystem
2026 * @param namespace handle for the namespace that should be advertised
2027 * @param meta meta-data for the namespace advertisement
2028 * @param anonymity for the namespace advertismement
2029 * @param priority for the namespace advertisement
2030 * @param expiration for the namespace advertisement
2031 * @param advertisementURI the keyword (!) URI to advertise the
2032 * namespace under (we will create a GNUNET_EC_KNBlock)
2033 * @param rootEntry name of the root entry in the namespace (for
2034 * the namespace advertisement)
2036 * @return uri of the advertisement
2038 struct GNUNET_FS_Uri *
2039 GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
2040 struct GNUNET_FS_Namespace *namespace,
2041 const struct GNUNET_CONTAINER_MetaData *meta,
2044 struct GNUNET_TIME_Absolute expiration,
2045 const struct GNUNET_FS_Uri *advertisementURI,
2046 const char *rootEntry);
2050 * Create a namespace with the given name; if one already
2051 * exists, return a handle to the existing namespace.
2053 * @param h handle to the file sharing subsystem
2054 * @param name name to use for the namespace
2055 * @return handle to the namespace, NULL on error
2057 struct GNUNET_FS_Namespace *
2058 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h,
2063 * Delete a namespace handle. Can be used for a clean shutdown (free
2064 * memory) or also to freeze the namespace to prevent further
2065 * insertions by anyone.
2067 * @param namespace handle to the namespace that should be deleted / freed
2068 * @param freeze prevents future insertions; creating a namespace
2069 * with the same name again will create a fresh namespace instead
2071 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2074 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace,
2079 * Callback with information about local (!) namespaces.
2080 * Contains the names of the local namespace and the global
2083 * @param cls closure
2084 * @param name human-readable identifier of the namespace
2085 * @param id hash identifier for the namespace
2087 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls,
2089 const GNUNET_HashCode *id);
2093 * Build a list of all available local (!) namespaces The returned
2094 * names are only the nicknames since we only iterate over the local
2097 * @param h handle to the file sharing subsystem
2098 * @param cb function to call on each known namespace
2099 * @param cb_cls closure for cb
2102 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2103 GNUNET_FS_NamespaceInfoProcessor cb,
2108 * Function called on updateable identifiers.
2110 * @param cls closure
2111 * @param last_id last identifier
2112 * @param last_uri uri used for the content published under the last_id
2113 * @param last_meta metadata associated with last_uri
2114 * @param next_id identifier that should be used for updates
2117 (*GNUNET_FS_IdentifierProcessor)(void *cls,
2118 const char *last_id,
2119 const struct GNUNET_FS_Uri *last_uri,
2120 const struct GNUNET_CONTAINER_MetaData *last_meta,
2121 const char *next_id);
2125 * List all of the identifiers in the namespace for
2126 * which we could produce an update.
2128 * @param namespace namespace to inspect for updateable content
2129 * @param ip function to call on each updateable identifier
2130 * @param ip_cls closure for ip
2133 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
2134 GNUNET_FS_IdentifierProcessor ip,
2139 * Start search for content.
2141 * @param h handle to the file sharing subsystem
2142 * @param uri specifies the search parameters; can be
2143 * a KSK URI or an SKS URI.
2144 * @param anonymity desired level of anonymity
2145 * @return context that can be used to control the search
2147 struct GNUNET_FS_SearchContext *
2148 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2149 const struct GNUNET_FS_Uri *uri,
2150 uint32_t anonymity);
2156 * @param sc context for the search that should be paused
2159 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2163 * Continue paused search.
2165 * @param sc context for the search that should be resumed
2168 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2172 * Stop search for content.
2174 * @param sc context for the search that should be stopped
2177 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2183 * Options for downloading. Compatible options
2184 * can be OR'ed together.
2186 enum GNUNET_FS_DownloadOptions
2189 * No options (use defaults for everything).
2191 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2194 * Do a recursive download (that is, automatically trigger the
2195 * download of files in directories).
2197 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 1,
2200 * Do not append temporary data to
2201 * the target file (for the IBlocks).
2203 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 2
2210 * Download parts of a file. Note that this will store
2211 * the blocks at the respective offset in the given file. Also, the
2212 * download is still using the blocking of the underlying FS
2213 * encoding. As a result, the download may *write* outside of the
2214 * given boundaries (if offset and length do not match the 32k FS
2215 * block boundaries). <p>
2217 * The given range can be used to focus a download towards a
2218 * particular portion of the file (optimization), not to strictly
2219 * limit the download to exactly those bytes.
2221 * @param h handle to the file sharing subsystem
2222 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2223 * @param meta known metadata for the file (can be NULL)
2224 * @param filename where to store the file, maybe NULL (then no file is
2225 * created on disk and data must be grabbed from the callbacks)
2226 * @param offset at what offset should we start the download (typically 0)
2227 * @param length how many bytes should be downloaded starting at offset
2228 * @param anonymity anonymity level to use for the download
2229 * @param options various download options
2230 * @param parent parent download to associate this download with (use NULL
2231 * for top-level downloads; useful for manually-triggered recursive downloads)
2232 * @return context that can be used to control this download
2234 struct GNUNET_FS_DownloadContext *
2235 GNUNET_FS_file_download_start (struct GNUNET_FS_Handle *h,
2236 const struct GNUNET_FS_Uri *uri,
2237 const struct GNUNET_CONTAINER_MetaData *meta,
2238 const char *filename,
2242 enum GNUNET_FS_DownloadOptions options,
2243 struct GNUNET_FS_DownloadContext *parent);
2247 * Stop a download (aborts if download is incomplete).
2249 * @param rm handle for the download
2250 * @param do_delete delete files of incomplete downloads
2253 GNUNET_FS_file_download_stop (struct GNUNET_FS_DownloadContext *rm,
2258 * Initialize collection.
2260 * @param h handle to the file sharing subsystem
2261 * @param namespace namespace to use for the collection
2262 * @return GNUNET_OK on success, GNUNET_SYSERR if another
2263 * namespace is already set for our collection
2266 GNUNET_FS_collection_start (struct GNUNET_FS_Handle *h,
2267 struct GNUNET_FS_Namespace *namespace);
2273 * @param h handle to the file sharing subsystem
2274 * @return GNUNET_OK on success, GNUNET_SYSERR if no collection is active
2277 GNUNET_FS_collection_stop (struct GNUNET_FS_Handle *h);
2281 * Are we using a collection?
2283 * @param h handle to the file sharing subsystem
2284 * @return NULL if there is no collection,
2286 struct GNUNET_FS_Namespace *
2287 GNUNET_FS_collection_get(struct GNUNET_FS_Handle *h);
2291 * Publish an update of the current collection information to the
2292 * network now. The function has no effect if the collection has not
2293 * changed since the last publication. If we are currently not
2294 * collecting, this function does nothing.
2296 * @param h handle to the file sharing subsystem
2298 void GNUNET_FS_collection_publish (struct GNUNET_FS_Handle *h);
2302 * If we are currently building a collection, publish the given file
2303 * information in that collection. If we are currently not
2304 * collecting, this function does nothing.
2306 * @param h handle to the file sharing subsystem
2307 * @param uri uri to add to the collection
2308 * @param meta metadata for the uri
2310 void GNUNET_FS_collection_add (const struct GNUNET_FS_Handle *h,
2311 const struct GNUNET_FS_Uri *uri,
2312 const struct GNUNET_CONTAINER_MetaData *meta);
2318 /* ******************** Directory API *********************** */
2321 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2322 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2323 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2326 * Does the meta-data claim that this is a directory?
2327 * Checks if the mime-type is that of a GNUnet directory.
2329 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2330 * we have no mime-type information (treat as 'GNUNET_NO')
2333 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData *md);
2337 * Set the MIMETYPE information for the given
2338 * metadata to "application/gnunet-directory".
2340 * @param md metadata to add mimetype to
2343 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2347 * Function used to process entries in a directory.
2349 * @param cls closure
2350 * @param filename name of the file in the directory
2351 * @param uri URI of the file
2352 * @param metadata metadata for the file; metadata for
2353 * the directory if everything else is NULL/zero
2354 * @param length length of the available data for the file
2355 * (of type size_t since data must certainly fit
2356 * into memory; if files are larger than size_t
2357 * permits, then they will certainly not be
2358 * embedded with the directory itself).
2359 * @param data data available for the file (length bytes)
2361 typedef void (*GNUNET_FS_DirectoryEntryProcessor)(void *cls,
2362 const char *filename,
2363 const struct GNUNET_FS_Uri *uri,
2364 const struct GNUNET_CONTAINER_MetaData *meta,
2370 * Iterate over all entries in a directory. Note that directories
2371 * are structured such that it is possible to iterate over the
2372 * individual blocks as well as over the entire directory. Thus
2373 * a client can call this function on the buffer in the
2374 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2375 * include the contents of (small) files embedded in the directory
2376 * itself; for those files, the processor may be given the
2377 * contents of the file directly by this function.
2379 * @param size number of bytes in data
2380 * @param data pointer to the beginning of the directory
2381 * @param offset offset of data in the directory
2382 * @param dep function to call on each entry
2383 * @param dep_cls closure for dep
2386 GNUNET_FS_directory_list_contents (size_t size,
2389 GNUNET_FS_DirectoryEntryProcessor dep,
2394 * Opaque handle to a directory builder.
2396 struct GNUNET_FS_DirectoryBuilder;
2399 * Create a directory builder.
2401 * @param mdir metadata for the directory
2403 struct GNUNET_FS_DirectoryBuilder *
2404 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData *mdir);
2408 * Add an entry to a directory.
2410 * @param bld directory to extend
2411 * @param uri uri of the entry (must not be a KSK)
2412 * @param md metadata of the entry
2413 * @param data raw data of the entry, can be NULL, otherwise
2414 * data must point to exactly the number of bytes specified
2418 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2419 const struct GNUNET_FS_Uri *uri,
2420 const struct GNUNET_CONTAINER_MetaData *md,
2425 * Finish building the directory. Frees the
2426 * builder context and returns the directory
2429 * @param bld directory to finish
2430 * @param size set to the number of bytes needed
2431 * @param data set to the encoded directory
2434 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2439 #if 0 /* keep Emacsens' auto-indent happy */