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).
386 * @param md metadata to use
387 * @return NULL on error, otherwise a KSK URI
389 struct GNUNET_FS_Uri *
390 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md);
393 /* ******************** command-line option parsing API *********************** */
396 * Command-line option parser function that allows the user
397 * to specify one or more '-k' options with keywords. Each
398 * specified keyword will be added to the URI. A pointer to
399 * the URI must be passed as the "scls" argument.
401 * @param ctx command line processor context
402 * @param scls must be of type "struct GNUNET_FS_Uri **"
403 * @param option name of the option (typically 'k')
404 * @param value command line argument given
405 * @return GNUNET_OK on success
408 GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx,
415 * Command-line option parser function that allows the user to specify
416 * one or more '-m' options with metadata. Each specified entry of
417 * the form "type=value" will be added to the metadata. A pointer to
418 * the metadata must be passed as the "scls" argument.
420 * @param ctx command line processor context
421 * @param scls must be of type "struct GNUNET_CONTAINER_MetaData **"
422 * @param option name of the option (typically 'k')
423 * @param value command line argument given
424 * @return GNUNET_OK on success
427 GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx,
434 /* ************************* sharing API ***************** */
438 * Possible status codes used in the callback for the
439 * various file-sharing operations. On each file (or search),
440 * the callback is guaranteed to be called once with "START"
441 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
442 * are optional and depend on the circumstances; parent operations
443 * will be STARTED before child-operations and STOPPED after
444 * their respective child-operations. START and STOP signals
445 * are typically generated either due to explicit client requests
446 * or because of suspend/resume operations.
448 enum GNUNET_FS_Status
451 * Notification that we have started to publish a file structure.
453 GNUNET_FS_STATUS_PUBLISH_START,
456 * Notification that we have resumed sharing a file structure.
458 GNUNET_FS_STATUS_PUBLISH_RESUME,
461 * Notification that we have suspended sharing a file structure.
463 GNUNET_FS_STATUS_PUBLISH_SUSPEND,
466 * Notification that we are making progress sharing a file structure.
468 GNUNET_FS_STATUS_PUBLISH_PROGRESS,
471 * Notification that an error was encountered sharing a file structure.
472 * The application will continue to receive resume/suspend events for
473 * this structure until "GNUNET_FS_publish_stop" is called.
475 GNUNET_FS_STATUS_PUBLISH_ERROR,
478 * Notification that we completed sharing a file structure.
479 * The application will continue to receive resume/suspend events for
480 * this structure until "GNUNET_FS_publish_stop" is called.
482 GNUNET_FS_STATUS_PUBLISH_COMPLETED,
485 * Notification that we have stopped
486 * the process of uploading a file structure; no
487 * futher events will be generated for this action.
489 GNUNET_FS_STATUS_PUBLISH_STOPPED,
492 * Notification that we have started this download.
494 GNUNET_FS_STATUS_DOWNLOAD_START,
497 * Notification that this download is being resumed.
499 GNUNET_FS_STATUS_DOWNLOAD_RESUME,
502 * Notification that this download was suspended.
504 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND,
507 * Notification about progress with this download.
509 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS,
512 * Notification that this download encountered an error.
514 GNUNET_FS_STATUS_DOWNLOAD_ERROR,
517 * Notification that this download completed. Note that for
518 * directories, completion does not imply completion of all files in
521 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED,
524 * Notification that this download was stopped
525 * (final event with respect to this action).
527 GNUNET_FS_STATUS_DOWNLOAD_STOPPED,
530 * First event generated when a client requests
531 * a search to begin or when a namespace result
532 * automatically triggers the search for updates.
534 GNUNET_FS_STATUS_SEARCH_START,
537 * Last event when a search is being resumed;
538 * note that "GNUNET_FS_SEARCH_START" will not
539 * be generated in this case.
541 GNUNET_FS_STATUS_SEARCH_RESUME,
544 * Event generated for each search result
545 * when the respective search is resumed.
547 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT,
550 * Last event when a search is being suspended;
551 * note that "GNUNET_FS_SEARCH_STOPPED" will not
552 * be generated in this case.
554 GNUNET_FS_STATUS_SEARCH_SUSPEND,
557 * Event generated for each search result
558 * when the respective search is suspended.
560 GNUNET_FS_STATUS_SEARCH_SUSPEND_RESULT,
563 * This search has yielded a result.
565 GNUNET_FS_STATUS_SEARCH_RESULT,
568 * We have discovered a new namespace.
570 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE,
573 * We have additional data about the quality
574 * or availability of a search result.
576 GNUNET_FS_STATUS_SEARCH_UPDATE,
579 * Signals a problem with this search.
581 GNUNET_FS_STATUS_SEARCH_ERROR,
584 * Signals that this search was paused.
586 GNUNET_FS_STATUS_SEARCH_PAUSED,
589 * Signals that this search was continued (unpaused).
591 GNUNET_FS_STATUS_SEARCH_CONTINUED,
594 * Event generated for each search result
595 * when the respective search is stopped.
597 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED,
600 * Last message from a search; this signals
601 * that there will be no further events associated
604 GNUNET_FS_STATUS_SEARCH_STOPPED,
607 * Notification that we started to unindex a file.
609 GNUNET_FS_STATUS_UNINDEX_START,
612 * Notification that we resumed unindexing of a file.
614 GNUNET_FS_STATUS_UNINDEX_RESUME,
617 * Notification that we suspended unindexing a file.
619 GNUNET_FS_STATUS_UNINDEX_SUSPEND,
622 * Notification that we made progress unindexing a file.
624 GNUNET_FS_STATUS_UNINDEX_PROGRESS,
627 * Notification that we encountered an error unindexing
630 GNUNET_FS_STATUS_UNINDEX_ERROR,
633 * Notification that the unindexing of this file
636 GNUNET_FS_STATUS_UNINDEX_COMPLETED,
639 * Notification that the unindexing of this file
640 * was stopped (final event for this action).
642 GNUNET_FS_STATUS_UNINDEX_STOPPED
648 * Handle to one of our namespaces.
650 struct GNUNET_FS_Namespace;
654 * Handle for controlling an upload.
656 struct GNUNET_FS_PublishContext;
660 * Handle for controlling an unindexing operation.
662 struct GNUNET_FS_UnindexContext;
666 * Handle for controlling a search.
668 struct GNUNET_FS_SearchContext;
672 * Context for controlling a download.
674 struct GNUNET_FS_DownloadContext;
678 * Handle for detail information about a file that is being publishd.
679 * Specifies metadata, keywords, how to get the contents of the file
680 * (i.e. data-buffer in memory, filename on disk) and other options.
682 struct GNUNET_FS_FileInformation;
686 * Argument given to the progress callback with
687 * information about what is going on.
689 struct GNUNET_FS_ProgressInfo
693 * Values that depend on the event type.
698 * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
703 * Context for controlling the upload.
705 struct GNUNET_FS_PublishContext *sc;
708 * Information about the file that is being publishd.
710 const struct GNUNET_FS_FileInformation *fi;
713 * Client context pointer (set the last time
714 * by the client for this operation; initially
715 * NULL on START/RESUME events).
720 * Client context pointer for the parent operation
721 * (if this is a file in a directory or a subdirectory).
726 * Name of the file being published; can be NULL.
728 const char *filename;
731 * How large is the file overall? For directories,
732 * this is only the size of the directory itself,
733 * not of the other files contained within the
739 * At what time do we expect to finish the upload?
740 * (will be a value in the past for completed
743 struct GNUNET_TIME_Relative eta;
746 * How long has this upload been actively running
747 * (excludes times where the upload was suspended).
749 struct GNUNET_TIME_Relative duration;
752 * How many bytes have we completed?
757 * What anonymity level is used for this upload?
762 * Additional values for specific events.
767 * These values are only valid for
768 * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
773 * Data block we just published.
778 * At what offset in the file is "data"?
783 * Length of the data block.
788 * Depth of the given block in the tree;
789 * 0 would be the highest level (the first
790 * call is guaranteed to be for the lowest
798 * These values are only valid for
799 * GNUNET_FS_STATUS_PUBLISH_RESUME events.
804 * Error message, NULL if no error was encountered so far.
809 * URI of the file (if the download had been completed)
811 const struct GNUNET_FS_Uri *chk_uri;
816 * These values are only valid for
817 * GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
824 const struct GNUNET_FS_Uri *chk_uri;
829 * These values are only valid for
830 * GNUNET_FS_STATUS_PUBLISH_ERROR events.
835 * Error message, never NULL.
847 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
852 * Context for controlling the download.
854 struct GNUNET_FS_DownloadContext *dc;
857 * Client context pointer (set the last time
858 * by the client for this operation; initially
859 * NULL on START/RESUME events).
864 * Client context pointer for the parent operation
865 * (if this is a file in a directory or a subdirectory).
870 * URI used for this download.
872 const struct GNUNET_FS_Uri *uri;
875 * Name of the file that we are downloading.
877 const char *filename;
880 * How large is the download overall? This
881 * is NOT necessarily the size from the
882 * URI since we may be doing a partial download.
887 * At what time do we expect to finish the download?
888 * (will be a value in the past for completed
891 struct GNUNET_TIME_Relative eta;
894 * How long has this download been active?
896 struct GNUNET_TIME_Relative duration;
899 * How many bytes have we completed?
904 * What anonymity level is used for this download?
909 * Additional values for specific events.
914 * These values are only valid for
915 * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
920 * Data block we just obtained.
925 * At what offset in the file is "data"?
930 * Length of the data block.
935 * Depth of the given block in the tree;
936 * 0 would be the highest level (the first
937 * call is guaranteed to be for the lowest
945 * These values are only valid for
946 * GNUNET_FS_STATUS_DOWNLOAD_START events.
951 * Known metadata for the download.
953 const struct GNUNET_CONTAINER_MetaData *meta;
958 * These values are only valid for
959 * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
964 * Known metadata for the download.
966 const struct GNUNET_CONTAINER_MetaData *meta;
969 * Error message, NULL if we have not encountered any error yet.
976 * These values are only valid for
977 * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
993 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
998 * Context for controlling the search, NULL for
999 * searches that were not explicitly triggered
1000 * by the client (i.e., searches for updates in
1003 struct GNUNET_FS_SearchContext *sc;
1006 * Client context pointer (set the last time by the client for
1007 * this operation; initially NULL on START/RESUME events). Note
1008 * that this value can only be set on START/RESUME; returning
1009 * non-NULL on RESULT/RESUME_RESULT will actually update the
1010 * private context for "UPDATE" events.
1015 * Client parent-context pointer; NULL for top-level searches,
1016 * non-NULL for automatically triggered searches for updates in
1022 * What query is used for this search
1023 * (list of keywords or SKS identifier).
1025 const struct GNUNET_FS_Uri *query;
1028 * How long has this search been actively running
1029 * (excludes times where the search was paused or
1032 struct GNUNET_TIME_Relative duration;
1035 * What anonymity level is used for this search?
1040 * Additional values for specific events.
1045 * These values are only valid for
1046 * GNUNET_FS_STATUS_SEARCH_RESULT events.
1051 * Metadata for the search result.
1053 const struct GNUNET_CONTAINER_MetaData *meta;
1056 * URI for the search result.
1058 const struct GNUNET_FS_Uri *uri;
1063 * These values are only valid for
1064 * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1069 * Metadata for the search result.
1071 const struct GNUNET_CONTAINER_MetaData *meta;
1074 * URI for the search result.
1076 const struct GNUNET_FS_Uri *uri;
1079 * Current availability rank (negative:
1080 * unavailable, positive: available)
1082 int32_t availability_rank;
1085 * On how many total queries is the given
1086 * availability_rank based?
1088 uint32_t availabiliy_certainty;
1091 * Updated applicability rank (the larger,
1092 * the better the result fits the search
1095 uint32_t applicabiliy_rank;
1100 * These values are only valid for
1101 * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1106 * Private context set for for this result
1107 * during the "RESULT" event.
1112 * Metadata for the search result.
1114 const struct GNUNET_CONTAINER_MetaData *meta;
1117 * URI for the search result.
1119 const struct GNUNET_FS_Uri *uri;
1122 * Current availability rank (negative:
1123 * unavailable, positive: available)
1125 int32_t availability_rank;
1128 * On how many total queries is the given
1129 * availability_rank based?
1131 uint32_t availability_certainty;
1134 * Updated applicability rank (the larger,
1135 * the better the result fits the search
1138 uint32_t applicability_rank;
1143 * These values are only valid for
1144 * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1145 * These events are automatically triggered for
1146 * each search result before the
1147 * GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1148 * happens primarily to give the client a chance
1149 * to clean up the "cctx" (if needed).
1154 * Private context set for for this result
1155 * during the "RESULT" event.
1160 * Metadata for the search result.
1162 const struct GNUNET_CONTAINER_MetaData *meta;
1165 * URI for the search result.
1167 const struct GNUNET_FS_Uri *uri;
1172 * These values are only valid for
1173 * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1174 * These events are automatically triggered for
1175 * each search result before the
1176 * GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1177 * happens primarily to give the client a chance
1178 * to clean up the "cctx" (if needed).
1183 * Private context set for for this result
1184 * during the "RESULT" event.
1189 * Metadata for the search result.
1191 const struct GNUNET_CONTAINER_MetaData *meta;
1194 * URI for the search result.
1196 const struct GNUNET_FS_Uri *uri;
1201 * These values are only valid for
1202 * GNUNET_FS_STATUS_SEARCH_RESUME events.
1207 * Error message, NULL if we have not encountered any error yet.
1209 const char *message;
1212 * Is this search currently paused?
1219 * These values are only valid for
1220 * GNUNET_FS_STATUS_SEARCH_ERROR events.
1227 const char *message;
1232 * Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events.
1237 * Handle to the namespace (NULL if it is not a local
1240 struct GNUNET_FS_Namespace *ns;
1243 * Short, human-readable name of the namespace.
1248 * Root identifier for the namespace, can be NULL.
1253 * Metadata for the namespace.
1255 const struct GNUNET_CONTAINER_MetaData *meta;
1258 * Hash-identifier for the namespace.
1269 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1274 * Context for controlling the unindexing.
1276 struct GNUNET_FS_UnindexContext *uc;
1279 * Client context pointer (set the last time
1280 * by the client for this operation; initially
1281 * NULL on START/RESUME events).
1286 * Name of the file that is being unindexed.
1288 const char *filename;
1291 * How large is the file overall?
1296 * At what time do we expect to finish unindexing?
1297 * (will be a value in the past for completed
1298 * unindexing opeations).
1300 struct GNUNET_TIME_Relative eta;
1303 * How long has this upload been actively running
1304 * (excludes times where the upload was suspended).
1306 struct GNUNET_TIME_Relative duration;
1309 * How many bytes have we completed?
1314 * Additional values for specific events.
1319 * These values are only valid for
1320 * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1325 * Data block we just unindexed.
1330 * At what offset in the file is "data"?
1335 * Length of the data block.
1340 * Depth of the given block in the tree;
1341 * 0 would be the highest level (the first
1342 * call is guaranteed to be for the lowest
1350 * These values are only valid for
1351 * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1356 * Error message, NULL if we have not encountered any error yet.
1358 const char *message;
1363 * These values are only valid for
1364 * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1371 const char *message;
1382 * Specific status code (determines the event type).
1384 enum GNUNET_FS_Status status;
1390 * Notification of FS to a client about the progress of an
1391 * operation. Callbacks of this type will be used for uploads,
1392 * downloads and searches. Some of the arguments depend a bit
1393 * in their meaning on the context in which the callback is used.
1395 * @param cls closure
1396 * @param info details about the event, specifying the event type
1397 * and various bits about the event
1398 * @return client-context (for the next progress call
1399 * for this operation; should be set to NULL for
1400 * SUSPEND and STOPPED events). The value returned
1401 * will be passed to future callbacks in the respective
1402 * field in the GNUNET_FS_ProgressInfo struct.
1404 typedef void* (*GNUNET_FS_ProgressCallback)
1406 const struct GNUNET_FS_ProgressInfo *info);
1410 * General (global) option flags for file-sharing.
1412 enum GNUNET_FS_Flags
1415 * No special flags set.
1417 GNUNET_FS_FLAGS_NONE = 0,
1420 * Is persistence of operations desired?
1421 * (will create SUSPEND/RESUME events).
1423 GNUNET_FS_FLAGS_PERSISTENCE = 1
1428 * Options specified in the VARARGs
1429 * portion of GNUNET_FS_start.
1431 enum GNUNET_FS_OPTIONS
1435 * Last option in the VARARG list.
1437 GNUNET_FS_OPTIONS_END = 0,
1440 * Select the desired amount of parallelism (this option should be
1441 * followed by an "unsigned int" giving the desired maximum number
1442 * of parallel downloads).
1444 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1
1450 * Handle to the file-sharing service.
1452 struct GNUNET_FS_Handle;
1456 * Setup a connection to the file-sharing service.
1458 * @param sched scheduler to use
1459 * @param cfg configuration to use
1460 * @param client_name unique identifier for this client
1461 * @param upcb function to call to notify about FS actions
1462 * @param upcb_cls closure for upcb
1463 * @param flags specific attributes for fs-operations
1464 * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
1465 * @return NULL on error
1467 struct GNUNET_FS_Handle *
1468 GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched,
1469 const struct GNUNET_CONFIGURATION_Handle *cfg,
1470 const char *client_name,
1471 GNUNET_FS_ProgressCallback upcb,
1473 enum GNUNET_FS_Flags flags,
1478 * Close our connection with the file-sharing service.
1479 * The callback given to GNUNET_FS_start will no longer be
1480 * called after this function returns.
1482 * @param h handle that was returned from GNUNET_FS_start
1485 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1489 * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
1491 * @param cls closure
1492 * @param fi the entry in the publish-structure
1493 * @param length length of the file or directory
1494 * @param meta metadata for the file or directory (can be modified)
1495 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1496 * @param anonymity pointer to selected anonymity level (can be modified)
1497 * @param priority pointer to selected priority (can be modified)
1498 * @param expirationTime pointer to selected expiration time (can be modified)
1499 * @param client_info pointer to client context set upon creation (can be modified)
1500 * @return GNUNET_OK to continue, GNUNET_NO to remove
1501 * this entry from the directory, GNUNET_SYSERR
1502 * to abort the iteration
1504 typedef int (*GNUNET_FS_FileInformationProcessor)(void *cls,
1505 struct GNUNET_FS_FileInformation *fi,
1507 struct GNUNET_CONTAINER_MetaData *meta,
1508 struct GNUNET_FS_Uri **uri,
1509 uint32_t *anonymity,
1511 struct GNUNET_TIME_Absolute *expirationTime,
1512 void **client_info);
1516 * Recover file information structure from disk.
1518 * @param name filename for the structure on disk
1519 * @return NULL on error
1521 struct GNUNET_FS_FileInformation *
1522 GNUNET_FS_file_information_recover (const char *name);
1526 * Obtain the name under which this file information
1527 * structure is stored on disk. Only works for top-level
1528 * file information structures.
1530 * @param s structure to get the filename for
1531 * @return NULL on error, otherwise filename that
1532 * can be passed to "GNUNET_FS_file_information_recover"
1533 * to read this fi-struct from disk.
1536 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1540 * Synchronize this file-information struct with its mirror
1541 * on disk. Note that all internal FS-operations that change
1542 * file information data should already call "sync" internally,
1543 * so this function is likely not useful for clients.
1545 * @param s the struct to sync
1548 GNUNET_FS_file_information_sync (struct GNUNET_FS_FileInformation *s);
1552 * Create an entry for a file in a publish-structure.
1554 * @param filename name of the file or directory to publish
1555 * @param keywords under which keywords should this file be available
1556 * directly; can be NULL
1557 * @param meta metadata for the file
1558 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1559 * GNUNET_SYSERR for simulation
1560 * @param anonymity what is the desired anonymity level for sharing?
1561 * @param priority what is the priority for OUR node to
1562 * keep this file available? Use 0 for maximum anonymity and
1563 * minimum reliability...
1564 * @param expirationTime when should this content expire?
1565 * @return publish structure entry for the file
1567 struct GNUNET_FS_FileInformation *
1568 GNUNET_FS_file_information_create_from_file (void *client_info,
1569 const char *filename,
1570 const struct GNUNET_FS_Uri *keywords,
1571 const struct GNUNET_CONTAINER_MetaData *meta,
1575 struct GNUNET_TIME_Absolute expirationTime);
1579 * Create an entry for a file in a publish-structure.
1581 * @param length length of the file
1582 * @param data data for the file (should not be used afterwards by
1583 * the caller; caller will "free")
1584 * @param keywords under which keywords should this file be available
1585 * directly; can be NULL
1586 * @param meta metadata for the file
1587 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1588 * GNUNET_SYSERR for simulation
1589 * @param anonymity what is the desired anonymity level for sharing?
1590 * @param priority what is the priority for OUR node to
1591 * keep this file available? Use 0 for maximum anonymity and
1592 * minimum reliability...
1593 * @param expirationTime when should this content expire?
1594 * @return publish structure entry for the file
1596 struct GNUNET_FS_FileInformation *
1597 GNUNET_FS_file_information_create_from_data (void *client_info,
1600 const struct GNUNET_FS_Uri *keywords,
1601 const struct GNUNET_CONTAINER_MetaData *meta,
1605 struct GNUNET_TIME_Absolute expirationTime);
1609 * Function that provides data.
1611 * @param cls closure
1612 * @param offset offset to read from; it is possible
1613 * that the caller might need to go backwards
1615 * @param max maximum number of bytes that should be
1616 * copied to buf; readers are not allowed
1617 * to provide less data unless there is an error;
1618 * a value of "0" will be used at the end to allow
1619 * the reader to clean up its internal state
1620 * @param buf where the reader should write the data
1621 * @param emsg location for the reader to store an error message
1622 * @return number of bytes written, usually "max", 0 on error
1624 typedef size_t (*GNUNET_FS_DataReader)(void *cls,
1632 * Create an entry for a file in a publish-structure.
1634 * @param length length of the file
1635 * @param reader function that can be used to obtain the data for the file
1636 * @param reader_cls closure for "reader"
1637 * @param keywords under which keywords should this file be available
1638 * directly; can be NULL
1639 * @param meta metadata for the file
1640 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1641 * GNUNET_SYSERR for simulation
1642 * @param anonymity what is the desired anonymity level for sharing?
1643 * @param priority what is the priority for OUR node to
1644 * keep this file available? Use 0 for maximum anonymity and
1645 * minimum reliability...
1646 * @param expirationTime when should this content expire?
1647 * @return publish structure entry for the file
1649 struct GNUNET_FS_FileInformation *
1650 GNUNET_FS_file_information_create_from_reader (void *client_info,
1652 GNUNET_FS_DataReader reader,
1654 const struct GNUNET_FS_Uri *keywords,
1655 const struct GNUNET_CONTAINER_MetaData *meta,
1659 struct GNUNET_TIME_Absolute expirationTime);
1663 * Function that a "GNUNET_FS_DirectoryScanner" should call
1664 * for each entry in the directory.
1666 * @param cls closure
1667 * @param filename name of the file (including path); must end
1668 * in a "/" (even on W32) if this is a directory
1669 * @param fi information about the file (should not be
1670 * used henceforth by the caller)
1672 typedef void (*GNUNET_FS_FileProcessor)(void *cls,
1673 const char *filename,
1674 struct GNUNET_FS_FileInformation *fi);
1678 * Type of a function that will be used to scan a directory.
1680 * @param cls closure
1681 * @param dirname name of the directory to scan
1682 * @param do_index should files be indexed or inserted
1683 * @param anonymity desired anonymity level
1684 * @param priority priority for publishing
1685 * @param expirationTime expiration for publication
1686 * @param proc function to call on each entry
1687 * @param proc_cls closure for proc
1688 * @param emsg where to store an error message (on errors)
1689 * @return GNUNET_OK on success
1691 typedef int (*GNUNET_FS_DirectoryScanner)(void *cls,
1692 const char *dirname,
1696 struct GNUNET_TIME_Absolute expirationTime,
1697 GNUNET_FS_FileProcessor proc,
1704 * Simple, useful default implementation of a directory scanner
1705 * (GNUNET_FS_DirectoryScanner). This implementation expects to get a
1706 * UNIX filename, will publish all files in the directory except hidden
1707 * files (those starting with a "."). Metadata will be extracted
1708 * using GNU libextractor; the specific list of plugins should be
1709 * specified in "cls", passing NULL will disable (!) metadata
1710 * extraction. Keywords will be derived from the metadata and be
1711 * subject to default canonicalization. This is strictly a
1712 * convenience function.
1714 * @param cls must be of type "struct EXTRACTOR_Extractor*"
1715 * @param dirname name of the directory to scan
1716 * @param do_index should files be indexed or inserted
1717 * @param anonymity desired anonymity level
1718 * @param priority priority for publishing
1719 * @param expirationTime expiration for publication
1720 * @param proc function called on each entry
1721 * @param proc_cls closure for proc
1722 * @param emsg where to store an error message (on errors)
1723 * @return GNUNET_OK on success
1726 GNUNET_FS_directory_scanner_default (void *cls,
1727 const char *dirname,
1731 struct GNUNET_TIME_Absolute expirationTime,
1732 GNUNET_FS_FileProcessor proc,
1738 * Create a publish-structure from an existing file hierarchy, inferring
1739 * and organizing keywords and metadata as much as possible. This
1740 * function primarily performs the recursive build and re-organizes
1741 * keywords and metadata; for automatically getting metadata
1742 * extraction, scanning of directories and creation of the respective
1743 * GNUNET_FS_FileInformation entries the default scanner should be
1744 * passed (GNUNET_FS_directory_scanner_default). This is strictly a
1745 * convenience function.
1747 * @param filename name of the top-level file or directory
1748 * @param scanner function used to get a list of files in a directory
1749 * @param scanner_cls closure for scanner
1750 * @param do_index should files in the hierarchy be indexed?
1751 * @param anonymity what is the desired anonymity level for sharing?
1752 * @param priority what is the priority for OUR node to
1753 * keep this file available? Use 0 for maximum anonymity and
1754 * minimum reliability...
1755 * @param expirationTime when should this content expire?
1756 * @param emsg where to store an error message
1757 * @return publish structure entry for the directory, NULL on error
1759 struct GNUNET_FS_FileInformation *
1760 GNUNET_FS_file_information_create_from_directory (void *client_info,
1761 const char *filename,
1762 GNUNET_FS_DirectoryScanner scanner,
1767 struct GNUNET_TIME_Absolute expirationTime,
1772 * Create an entry for an empty directory in a publish-structure.
1773 * This function should be used by applications for which the
1774 * use of "GNUNET_FS_file_information_create_from_directory"
1775 * is not appropriate.
1777 * @param meta metadata for the directory
1778 * @param keywords under which keywords should this directory be available
1779 * directly; can be NULL
1780 * @param anonymity what is the desired anonymity level for sharing?
1781 * @param priority what is the priority for OUR node to
1782 * keep this file available? Use 0 for maximum anonymity and
1783 * minimum reliability...
1784 * @param expirationTime when should this content expire?
1785 * @return publish structure entry for the directory , NULL on error
1787 struct GNUNET_FS_FileInformation *
1788 GNUNET_FS_file_information_create_empty_directory (void *client_info,
1789 const struct GNUNET_CONTAINER_MetaData *meta,
1790 const struct GNUNET_FS_Uri *keywords,
1793 struct GNUNET_TIME_Absolute expirationTime);
1797 * Add an entry to a directory in a publish-structure. Clients
1798 * should never modify publish structures that were passed to
1799 * "GNUNET_FS_publish_start" already.
1801 * @param dir the directory
1802 * @param end the entry to add; the entry must not have been
1803 * added to any other directory at this point and
1804 * must not include "dir" in its structure
1805 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1808 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1809 struct GNUNET_FS_FileInformation *end);
1813 * Inspect a file or directory in a publish-structure. Clients
1814 * should never modify publish structures that were passed to
1815 * "GNUNET_FS_publish_start" already. When called on a directory,
1816 * this function will FIRST call "proc" with information about
1817 * the directory itself and then for each of the files in the
1818 * directory (but not for files in subdirectories). When called
1819 * on a file, "proc" will be called exactly once (with information
1820 * about the specific file).
1822 * @param dir the directory
1823 * @param proc function to call on each entry
1824 * @param proc_cls closure for proc
1827 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1828 GNUNET_FS_FileInformationProcessor proc,
1833 * Destroy publish-structure. Clients should never destroy publish
1834 * structures that were passed to "GNUNET_FS_publish_start" already.
1836 * @param fi structure to destroy
1837 * @param cleaner function to call on each entry in the structure
1838 * (useful to clean up client_info); can be NULL; return
1839 * values are ignored
1840 * @param cleaner_cls closure for cleaner
1843 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
1844 GNUNET_FS_FileInformationProcessor cleaner,
1849 * Options for publishing. Compatible options
1850 * can be OR'ed together.
1852 enum GNUNET_FS_PublishOptions
1855 * No options (use defaults for everything).
1857 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
1860 * Simulate publishing. With this option, no data will be stored
1861 * in the datastore. Useful for computing URIs from files.
1863 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
1867 * Publish a file or directory.
1869 * @param h handle to the file sharing subsystem
1870 * @param ctx initial value to use for the '*ctx'
1871 * in the callback (for the GNUNET_FS_STATUS_PUBLISH_START event).
1872 * @param fi information about the file or directory structure to publish
1873 * @param namespace namespace to publish the file in, NULL for no namespace
1874 * @param nid identifier to use for the publishd content in the namespace
1875 * (can be NULL, must be NULL if namespace is NULL)
1876 * @param nuid update-identifier that will be used for future updates
1877 * (can be NULL, must be NULL if namespace or nid is NULL)
1878 * @param options options for the publication
1879 * @return context that can be used to control the publish operation
1881 struct GNUNET_FS_PublishContext *
1882 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1884 struct GNUNET_FS_FileInformation *fi,
1885 struct GNUNET_FS_Namespace *namespace,
1888 enum GNUNET_FS_PublishOptions options);
1892 * Stop an upload. Will abort incomplete uploads (but
1893 * not remove blocks that have already been publishd) or
1894 * simply clean up the state for completed uploads.
1896 * @param sc context for the upload to stop
1899 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *sc);
1903 * Signature of a function called as the continuation of a KBlock or
1904 * SBlock publication.
1906 * @param cls closure
1907 * @param uri URI under which the block is now available, NULL on error
1908 * @param emsg error message, NULL on success
1910 typedef void (*GNUNET_FS_PublishContinuation)(void *cls,
1911 const struct GNUNET_FS_Uri *uri,
1916 * Publish a KBlock on GNUnet.
1918 * @param h handle to the file sharing subsystem
1919 * @param keywords keywords to use
1920 * @param meta metadata to use
1921 * @param uri URI to refer to in the KBlock
1922 * @param expirationTime when the KBlock expires
1923 * @param anonymity anonymity level for the KBlock
1924 * @param priority priority for the KBlock
1925 * @param cont continuation
1926 * @param cont_cls closure for cont
1929 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1930 struct GNUNET_FS_Uri *keywords,
1931 struct GNUNET_CONTAINER_MetaData *meta,
1932 struct GNUNET_FS_Uri *uri,
1933 struct GNUNET_TIME_Absolute expirationTime,
1936 enum GNUNET_FS_PublishOptions options,
1937 GNUNET_FS_PublishContinuation cont,
1942 * Publish an SBlock on GNUnet.
1944 * @param h handle to the file sharing subsystem
1945 * @param namespace namespace to publish in
1946 * @param identifier identifier to use
1947 * @param update update identifier to use
1948 * @param meta metadata to use
1949 * @param uri URI to refer to in the SBlock
1950 * @param expirationTime when the SBlock expires
1951 * @param anonymity anonymity level for the SBlock
1952 * @param priority priority for the SBlock
1953 * @param cont continuation
1954 * @param cont_cls closure for cont
1957 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
1958 struct GNUNET_FS_Namespace *namespace,
1959 const char *identifier,
1961 struct GNUNET_CONTAINER_MetaData *meta,
1962 struct GNUNET_FS_Uri *uri,
1963 struct GNUNET_TIME_Absolute expirationTime,
1966 enum GNUNET_FS_PublishOptions options,
1967 GNUNET_FS_PublishContinuation cont,
1972 * Type of a function called by "GNUNET_FS_get_indexed_files".
1974 * @param cls closure
1975 * @param filename the name of the file
1976 * @param file_id hash of the contents of the indexed file
1977 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
1979 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls,
1980 const char *filename,
1981 const GNUNET_HashCode *file_id);
1985 * Iterate over all indexed files.
1987 * @param h handle to the file sharing subsystem
1988 * @param iterator function to call on each indexed file
1989 * @param iterator_cls closure for iterator
1990 * @param cont continuation to call when done;
1991 * reason should be "TIMEOUT" (on
1992 * error) or "PREREQ_DONE" (on success)
1993 * @param cont_cls closure for cont
1996 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
1997 GNUNET_FS_IndexedFileProcessor iterator,
1999 GNUNET_SCHEDULER_Task cont,
2006 * @param h handle to the file sharing subsystem
2007 * @param filename file to unindex
2008 * @return NULL on error, otherwise handle
2010 struct GNUNET_FS_UnindexContext *
2011 GNUNET_FS_unindex (struct GNUNET_FS_Handle *h,
2012 const char *filename);
2016 * Clean up after completion of an unindex operation.
2021 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2025 * Publish an advertismement for a namespace.
2027 * @param h handle to the file sharing subsystem
2028 * @param namespace handle for the namespace that should be advertised
2029 * @param meta meta-data for the namespace advertisement
2030 * @param anonymity for the namespace advertismement
2031 * @param priority for the namespace advertisement
2032 * @param expiration for the namespace advertisement
2033 * @param advertisementURI the keyword (!) URI to advertise the
2034 * namespace under (we will create a GNUNET_EC_KNBlock)
2035 * @param rootEntry name of the root entry in the namespace (for
2036 * the namespace advertisement)
2038 * @return uri of the advertisement
2040 struct GNUNET_FS_Uri *
2041 GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
2042 struct GNUNET_FS_Namespace *namespace,
2043 const struct GNUNET_CONTAINER_MetaData *meta,
2046 struct GNUNET_TIME_Absolute expiration,
2047 const struct GNUNET_FS_Uri *advertisementURI,
2048 const char *rootEntry);
2052 * Create a namespace with the given name; if one already
2053 * exists, return a handle to the existing namespace.
2055 * @param h handle to the file sharing subsystem
2056 * @param name name to use for the namespace
2057 * @return handle to the namespace, NULL on error
2059 struct GNUNET_FS_Namespace *
2060 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h,
2065 * Delete a namespace handle. Can be used for a clean shutdown (free
2066 * memory) or also to freeze the namespace to prevent further
2067 * insertions by anyone.
2069 * @param namespace handle to the namespace that should be deleted / freed
2070 * @param freeze prevents future insertions; creating a namespace
2071 * with the same name again will create a fresh namespace instead
2073 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2076 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace,
2081 * Callback with information about local (!) namespaces.
2082 * Contains the names of the local namespace and the global
2085 * @param cls closure
2086 * @param name human-readable identifier of the namespace
2087 * @param id hash identifier for the namespace
2089 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls,
2091 const GNUNET_HashCode *id);
2095 * Build a list of all available local (!) namespaces The returned
2096 * names are only the nicknames since we only iterate over the local
2099 * @param h handle to the file sharing subsystem
2100 * @param cb function to call on each known namespace
2101 * @param cb_cls closure for cb
2104 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2105 GNUNET_FS_NamespaceInfoProcessor cb,
2110 * Function called on updateable identifiers.
2112 * @param cls closure
2113 * @param last_id last identifier
2114 * @param last_uri uri used for the content published under the last_id
2115 * @param last_meta metadata associated with last_uri
2116 * @param next_id identifier that should be used for updates
2119 (*GNUNET_FS_IdentifierProcessor)(void *cls,
2120 const char *last_id,
2121 const struct GNUNET_FS_Uri *last_uri,
2122 const struct GNUNET_CONTAINER_MetaData *last_meta,
2123 const char *next_id);
2127 * List all of the identifiers in the namespace for
2128 * which we could produce an update.
2130 * @param namespace namespace to inspect for updateable content
2131 * @param ip function to call on each updateable identifier
2132 * @param ip_cls closure for ip
2135 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
2136 GNUNET_FS_IdentifierProcessor ip,
2141 * Start search for content.
2143 * @param h handle to the file sharing subsystem
2144 * @param uri specifies the search parameters; can be
2145 * a KSK URI or an SKS URI.
2146 * @param anonymity desired level of anonymity
2147 * @return context that can be used to control the search
2149 struct GNUNET_FS_SearchContext *
2150 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2151 const struct GNUNET_FS_Uri *uri,
2152 uint32_t anonymity);
2158 * @param sc context for the search that should be paused
2161 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2165 * Continue paused search.
2167 * @param sc context for the search that should be resumed
2170 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2174 * Stop search for content.
2176 * @param sc context for the search that should be stopped
2179 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2185 * Options for downloading. Compatible options
2186 * can be OR'ed together.
2188 enum GNUNET_FS_DownloadOptions
2191 * No options (use defaults for everything).
2193 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2196 * Do a recursive download (that is, automatically trigger the
2197 * download of files in directories).
2199 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 1,
2202 * Do not append temporary data to
2203 * the target file (for the IBlocks).
2205 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 2
2212 * Download parts of a file. Note that this will store
2213 * the blocks at the respective offset in the given file. Also, the
2214 * download is still using the blocking of the underlying FS
2215 * encoding. As a result, the download may *write* outside of the
2216 * given boundaries (if offset and length do not match the 32k FS
2217 * block boundaries). <p>
2219 * The given range can be used to focus a download towards a
2220 * particular portion of the file (optimization), not to strictly
2221 * limit the download to exactly those bytes.
2223 * @param h handle to the file sharing subsystem
2224 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2225 * @param meta known metadata for the file (can be NULL)
2226 * @param filename where to store the file, maybe NULL (then no file is
2227 * created on disk and data must be grabbed from the callbacks)
2228 * @param offset at what offset should we start the download (typically 0)
2229 * @param length how many bytes should be downloaded starting at offset
2230 * @param anonymity anonymity level to use for the download
2231 * @param options various download options
2232 * @param parent parent download to associate this download with (use NULL
2233 * for top-level downloads; useful for manually-triggered recursive downloads)
2234 * @return context that can be used to control this download
2236 struct GNUNET_FS_DownloadContext *
2237 GNUNET_FS_file_download_start (struct GNUNET_FS_Handle *h,
2238 const struct GNUNET_FS_Uri *uri,
2239 const struct GNUNET_CONTAINER_MetaData *meta,
2240 const char *filename,
2244 enum GNUNET_FS_DownloadOptions options,
2245 struct GNUNET_FS_DownloadContext *parent);
2249 * Stop a download (aborts if download is incomplete).
2251 * @param rm handle for the download
2252 * @param do_delete delete files of incomplete downloads
2255 GNUNET_FS_file_download_stop (struct GNUNET_FS_DownloadContext *rm,
2260 * Initialize collection.
2262 * @param h handle to the file sharing subsystem
2263 * @param namespace namespace to use for the collection
2264 * @return GNUNET_OK on success, GNUNET_SYSERR if another
2265 * namespace is already set for our collection
2268 GNUNET_FS_collection_start (struct GNUNET_FS_Handle *h,
2269 struct GNUNET_FS_Namespace *namespace);
2275 * @param h handle to the file sharing subsystem
2276 * @return GNUNET_OK on success, GNUNET_SYSERR if no collection is active
2279 GNUNET_FS_collection_stop (struct GNUNET_FS_Handle *h);
2283 * Are we using a collection?
2285 * @param h handle to the file sharing subsystem
2286 * @return NULL if there is no collection,
2288 struct GNUNET_FS_Namespace *
2289 GNUNET_FS_collection_get(struct GNUNET_FS_Handle *h);
2293 * Publish an update of the current collection information to the
2294 * network now. The function has no effect if the collection has not
2295 * changed since the last publication. If we are currently not
2296 * collecting, this function does nothing.
2298 * @param h handle to the file sharing subsystem
2300 void GNUNET_FS_collection_publish (struct GNUNET_FS_Handle *h);
2304 * If we are currently building a collection, publish the given file
2305 * information in that collection. If we are currently not
2306 * collecting, this function does nothing.
2308 * @param h handle to the file sharing subsystem
2309 * @param uri uri to add to the collection
2310 * @param meta metadata for the uri
2312 void GNUNET_FS_collection_add (const struct GNUNET_FS_Handle *h,
2313 const struct GNUNET_FS_Uri *uri,
2314 const struct GNUNET_CONTAINER_MetaData *meta);
2320 /* ******************** Directory API *********************** */
2323 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2324 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2325 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2328 * Does the meta-data claim that this is a directory?
2329 * Checks if the mime-type is that of a GNUnet directory.
2331 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2332 * we have no mime-type information (treat as 'GNUNET_NO')
2335 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData *md);
2339 * Set the MIMETYPE information for the given
2340 * metadata to "application/gnunet-directory".
2342 * @param md metadata to add mimetype to
2345 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2349 * Function used to process entries in a directory.
2351 * @param cls closure
2352 * @param filename name of the file in the directory
2353 * @param uri URI of the file
2354 * @param metadata metadata for the file; metadata for
2355 * the directory if everything else is NULL/zero
2356 * @param length length of the available data for the file
2357 * (of type size_t since data must certainly fit
2358 * into memory; if files are larger than size_t
2359 * permits, then they will certainly not be
2360 * embedded with the directory itself).
2361 * @param data data available for the file (length bytes)
2363 typedef void (*GNUNET_FS_DirectoryEntryProcessor)(void *cls,
2364 const char *filename,
2365 const struct GNUNET_FS_Uri *uri,
2366 const struct GNUNET_CONTAINER_MetaData *meta,
2372 * Iterate over all entries in a directory. Note that directories
2373 * are structured such that it is possible to iterate over the
2374 * individual blocks as well as over the entire directory. Thus
2375 * a client can call this function on the buffer in the
2376 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2377 * include the contents of (small) files embedded in the directory
2378 * itself; for those files, the processor may be given the
2379 * contents of the file directly by this function.
2381 * @param size number of bytes in data
2382 * @param data pointer to the beginning of the directory
2383 * @param offset offset of data in the directory
2384 * @param dep function to call on each entry
2385 * @param dep_cls closure for dep
2388 GNUNET_FS_directory_list_contents (size_t size,
2391 GNUNET_FS_DirectoryEntryProcessor dep,
2396 * Opaque handle to a directory builder.
2398 struct GNUNET_FS_DirectoryBuilder;
2401 * Create a directory builder.
2403 * @param mdir metadata for the directory
2405 struct GNUNET_FS_DirectoryBuilder *
2406 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData *mdir);
2410 * Add an entry to a directory.
2412 * @param bld directory to extend
2413 * @param uri uri of the entry (must not be a KSK)
2414 * @param md metadata of the entry
2415 * @param data raw data of the entry, can be NULL, otherwise
2416 * data must point to exactly the number of bytes specified
2420 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2421 const struct GNUNET_FS_Uri *uri,
2422 const struct GNUNET_CONTAINER_MetaData *md,
2427 * Finish building the directory. Frees the
2428 * builder context and returns the directory
2431 * @param bld directory to finish
2432 * @param size set to the number of bytes needed
2433 * @param data set to the encoded directory
2434 * @return GNUNET_OK on success
2437 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2442 #if 0 /* keep Emacsens' auto-indent happy */