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);
121 * Convert a UTF-8 String to a URI.
123 * @param uri string to parse
124 * @param emsg where to store the parser error message (if any)
125 * @return NULL on error
127 struct GNUNET_FS_Uri *
128 GNUNET_FS_uri_parse (const char *uri,
134 * @param uri uri to free
137 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
141 * How many keywords are ANDed in this keyword URI?
143 * @param uri ksk uri to get the number of keywords from
144 * @return 0 if this is not a keyword URI
147 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
151 * Iterate over all keywords in this keyword URI.
153 * @param uri ksk uri to get the keywords from
154 * @param iterator function to call on each keyword
155 * @param iterator_cls closure for iterator
156 * @return -1 if this is not a keyword URI, otherwise number of
157 * keywords iterated over until iterator aborted
160 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
161 GNUNET_FS_KeywordIterator iterator,
166 * Obtain the identity of the peer offering the data
168 * @param uri the location URI to inspect
169 * @param peer where to store the identify of the peer (presumably) offering the content
170 * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK
173 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
174 struct GNUNET_PeerIdentity * peer);
178 * Obtain the URI of the content itself.
180 * @param uri location URI to get the content URI from
181 * @return NULL if argument is not a location URI
183 struct GNUNET_FS_Uri *
184 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
188 * Construct a location URI (this peer will be used for the location).
190 * @param baseURI content offered by the sender
191 * @param cfg configuration information (used to find our hostkey)
192 * @param expiration_time how long will the content be offered?
193 * @return the location URI, NULL on error
195 struct GNUNET_FS_Uri *
196 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
197 struct GNUNET_CONFIGURATION_Handle *cfg,
198 struct GNUNET_TIME_Absolute expiration_time);
202 * Canonicalize keyword URI. Performs operations such
203 * as decapitalization and removal of certain characters.
204 * (useful for search).
206 * @param uri the URI to canonicalize
207 * @return canonicalized version of the URI, NULL on error
209 struct GNUNET_FS_Uri *
210 GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri);
214 * Merge the sets of keywords from two KSK URIs.
215 * (useful for merging the canonicalized keywords with
216 * the original keywords for sharing).
218 * @param u1 first uri
219 * @param u2 second uri
220 * @return merged URI, NULL on error
222 struct GNUNET_FS_Uri *
223 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
224 const struct GNUNET_FS_Uri *u2);
230 * @param uri the URI to duplicate
231 * @return copy of the URI
233 struct GNUNET_FS_Uri *
234 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
238 * Create an FS URI from a single user-supplied string of keywords.
239 * The string is broken up at spaces into individual keywords.
240 * Keywords that start with "+" are mandatory. Double-quotes can
241 * be used to prevent breaking up strings at spaces (and also
242 * to specify non-mandatory keywords starting with "+").
244 * Keywords must contain a balanced number of double quotes and
245 * double quotes can not be used in the actual keywords (for
246 * example, the string '""foo bar""' will be turned into two
247 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
249 * @param keywords the keyword string
250 * @param emsg where to store an error message
251 * @return an FS URI for the given keywords, NULL
252 * if keywords is not legal (i.e. empty).
254 struct GNUNET_FS_Uri *
255 GNUNET_FS_uri_ksk_create (const char *keywords,
260 * Create an FS URI from a user-supplied command line of keywords.
261 * Arguments should start with "+" to indicate mandatory
264 * @param argc number of keywords
265 * @param argv keywords (double quotes are not required for
266 * keywords containing spaces; however, double
267 * quotes are required for keywords starting with
268 * "+"); there is no mechanism for having double
269 * quotes in the actual keywords (if the user
270 * did specifically specify double quotes, the
271 * caller should convert each double quote
272 * into two single quotes).
273 * @return an FS URI for the given keywords, NULL
274 * if keywords is not legal (i.e. empty).
276 struct GNUNET_FS_Uri *
277 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
282 * Test if two URIs are equal.
284 * @param u1 one of the URIs
285 * @param u2 the other URI
286 * @return GNUNET_YES if the URIs are equal
289 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
290 const struct GNUNET_FS_Uri *u2);
294 * Is this a namespace URI?
296 * @param uri the uri to check
297 * @return GNUNET_YES if this is an SKS uri
300 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
304 * Get the ID of a namespace from the given
307 * @param uri the uri to get the namespace ID from
308 * @param nsid where to store the ID of the namespace
309 * @return GNUNET_OK on success
312 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
313 GNUNET_HashCode * nsid);
317 * Get the content identifier of an SKS URI.
319 * @param uri the sks uri
320 * @return NULL on error (not a valid SKS URI)
323 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
327 * Convert namespace URI to a human readable format
328 * (using the namespace description, if available).
330 * @param cfg configuration to use
331 * @param uri SKS uri to convert
332 * @return NULL on error (not an SKS URI)
335 GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
336 const struct GNUNET_FS_Uri *uri);
340 * Is this a keyword URI?
343 * @return GNUNET_YES if this is a KSK uri
346 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
350 * Is this a file (or directory) URI?
352 * @param uri the uri to check
353 * @return GNUNET_YES if this is a CHK uri
356 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
360 * What is the size of the file that this URI
363 * @param uri the CHK URI to inspect
364 * @return size of the file as specified in the CHK URI
367 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
371 * Is this a location URI?
373 * @param uri the uri to check
374 * @return GNUNET_YES if this is a LOC uri
377 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
381 * Construct a keyword-URI from meta-data (take all entries
382 * in the meta-data and construct one large keyword URI
383 * that lists all keywords that can be found in the meta-data).
386 struct GNUNET_FS_Uri *
387 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md);
390 /* ******************** command-line option parsing API *********************** */
393 * Command-line option parser function that allows the user
394 * to specify one or more '-k' options with keywords. Each
395 * specified keyword will be added to the URI. A pointer to
396 * the URI must be passed as the "scls" argument.
398 * @param ctx command line processor context
399 * @param scls must be of type "struct GNUNET_FS_Uri **"
400 * @param option name of the option (typically 'k')
401 * @param value command line argument given
402 * @return GNUNET_OK on success
405 GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx,
412 * Command-line option parser function that allows the user to specify
413 * one or more '-m' options with metadata. Each specified entry of
414 * the form "type=value" will be added to the metadata. A pointer to
415 * the metadata must be passed as the "scls" argument.
417 * @param ctx command line processor context
418 * @param scls must be of type "struct GNUNET_MetaData **"
419 * @param option name of the option (typically 'k')
420 * @param value command line argument given
421 * @return GNUNET_OK on success
424 GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx,
431 /* ************************* sharing API ***************** */
435 * Possible status codes used in the callback for the
436 * various file-sharing operations. On each file (or search),
437 * the callback is guaranteed to be called once with "START"
438 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
439 * are optional and depend on the circumstances; parent operations
440 * will be STARTED before child-operations and STOPPED after
441 * their respective child-operations. START and STOP signals
442 * are typically generated either due to explicit client requests
443 * or because of suspend/resume operations.
445 enum GNUNET_FS_Status
448 * Notification that we have started to publish a file structure.
450 GNUNET_FS_STATUS_PUBLISH_START,
453 * Notification that we have resumed sharing a file structure.
455 GNUNET_FS_STATUS_PUBLISH_RESUME,
458 * Notification that we have suspended sharing a file structure.
460 GNUNET_FS_STATUS_PUBLISH_SUSPEND,
463 * Notification that we are making progress sharing a file structure.
465 GNUNET_FS_STATUS_PUBLISH_PROGRESS,
468 * Notification that an error was encountered sharing a file structure.
469 * The application will continue to receive resume/suspend events for
470 * this structure until "GNUNET_FS_publish_stop" is called.
472 GNUNET_FS_STATUS_PUBLISH_ERROR,
475 * Notification that we completed sharing a file structure.
476 * The application will continue to receive resume/suspend events for
477 * this structure until "GNUNET_FS_publish_stop" is called.
479 GNUNET_FS_STATUS_PUBLISH_COMPLETED,
482 * Notification that we have stopped
483 * the process of uploading a file structure; no
484 * futher events will be generated for this action.
486 GNUNET_FS_STATUS_PUBLISH_STOPPED,
489 * Notification that we have started this download.
491 GNUNET_FS_STATUS_DOWNLOAD_START,
494 * Notification that this download is being resumed.
496 GNUNET_FS_STATUS_DOWNLOAD_RESUME,
499 * Notification that this download was suspended.
501 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND,
504 * Notification about progress with this download.
506 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS,
509 * Notification that this download encountered an error.
511 GNUNET_FS_STATUS_DOWNLOAD_ERROR,
514 * Notification that this download completed. Note that for
515 * directories, completion does not imply completion of all files in
518 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED,
521 * Notification that this download was stopped
522 * (final event with respect to this action).
524 GNUNET_FS_STATUS_DOWNLOAD_STOPPED,
527 * First event generated when a client requests
528 * a search to begin or when a namespace result
529 * automatically triggers the search for updates.
531 GNUNET_FS_STATUS_SEARCH_START,
534 * Last event when a search is being resumed;
535 * note that "GNUNET_FS_SEARCH_START" will not
536 * be generated in this case.
538 GNUNET_FS_STATUS_SEARCH_RESUME,
541 * Event generated for each search result
542 * when the respective search is resumed.
544 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT,
547 * Last event when a search is being suspended;
548 * note that "GNUNET_FS_SEARCH_STOPPED" will not
549 * be generated in this case.
551 GNUNET_FS_STATUS_SEARCH_SUSPEND,
554 * Event generated for each search result
555 * when the respective search is suspended.
557 GNUNET_FS_STATUS_SEARCH_SUSPEND_RESULT,
560 * This search has yielded a result.
562 GNUNET_FS_STATUS_SEARCH_RESULT,
565 * We have discovered a new namespace.
567 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE,
570 * We have additional data about the quality
571 * or availability of a search result.
573 GNUNET_FS_STATUS_SEARCH_UPDATE,
576 * Signals a problem with this search.
578 GNUNET_FS_STATUS_SEARCH_ERROR,
581 * Signals that this search was paused.
583 GNUNET_FS_STATUS_SEARCH_PAUSED,
586 * Signals that this search was continued (unpaused).
588 GNUNET_FS_STATUS_SEARCH_CONTINUED,
591 * Event generated for each search result
592 * when the respective search is stopped.
594 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED,
597 * Last message from a search; this signals
598 * that there will be no further events associated
601 GNUNET_FS_STATUS_SEARCH_STOPPED,
604 * Notification that we started to unindex a file.
606 GNUNET_FS_STATUS_UNINDEX_START,
609 * Notification that we resumed unindexing of a file.
611 GNUNET_FS_STATUS_UNINDEX_RESUME,
614 * Notification that we suspended unindexing a file.
616 GNUNET_FS_STATUS_UNINDEX_SUSPEND,
619 * Notification that we made progress unindexing a file.
621 GNUNET_FS_STATUS_UNINDEX_PROGRESS,
624 * Notification that we encountered an error unindexing
627 GNUNET_FS_STATUS_UNINDEX_ERROR,
630 * Notification that the unindexing of this file
633 GNUNET_FS_STATUS_UNINDEX_COMPLETED,
636 * Notification that the unindexing of this file
637 * was stopped (final event for this action).
639 GNUNET_FS_STATUS_UNINDEX_STOPPED
645 * Handle to one of our namespaces.
647 struct GNUNET_FS_Namespace;
651 * Handle for controlling an upload.
653 struct GNUNET_FS_PublishContext;
657 * Handle for controlling an unindexing operation.
659 struct GNUNET_FS_UnindexContext;
663 * Handle for controlling a search.
665 struct GNUNET_FS_SearchContext;
669 * Context for controlling a download.
671 struct GNUNET_FS_DownloadContext;
675 * Handle for detail information about a file that is being publishd.
676 * Specifies metadata, keywords, how to get the contents of the file
677 * (i.e. data-buffer in memory, filename on disk) and other options.
679 struct GNUNET_FS_FileInformation;
683 * Argument given to the progress callback with
684 * information about what is going on.
686 struct GNUNET_FS_ProgressInfo
690 * Values that depend on the event type.
695 * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
700 * Context for controlling the upload.
702 struct GNUNET_FS_PublishContext *sc;
705 * Information about the file that is being publishd.
707 const struct GNUNET_FS_FileInformation *fi;
710 * Client context pointer (set the last time
711 * by the client for this operation; initially
712 * NULL on START/RESUME events).
717 * Client context pointer for the parent operation
718 * (if this is a file in a directory or a subdirectory).
723 * How large is the file overall? For directories,
724 * this is only the size of the directory itself,
725 * not of the other files contained within the
731 * At what time do we expect to finish the upload?
732 * (will be a value in the past for completed
735 struct GNUNET_TIME_Relative eta;
738 * How long has this upload been actively running
739 * (excludes times where the upload was suspended).
741 struct GNUNET_TIME_Relative duration;
744 * How many bytes have we completed?
749 * What anonymity level is used for this upload?
751 unsigned int anonymity;
754 * Additional values for specific events.
759 * These values are only valid for
760 * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
765 * Data block we just published.
770 * At what offset in the file is "data"?
775 * Length of the data block.
780 * Depth of the given block in the tree;
781 * 0 would be the highest level (the first
782 * call is guaranteed to be for the lowest
790 * These values are only valid for
791 * GNUNET_FS_STATUS_PUBLISH_RESUME events.
796 * Error message, NULL if no error was encountered so far.
801 * URI of the file (if the download had been completed)
803 const struct GNUNET_FS_Uri *chk_uri;
808 * These values are only valid for
809 * GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
816 const struct GNUNET_FS_Uri *chk_uri;
821 * These values are only valid for
822 * GNUNET_FS_STATUS_PUBLISH_ERROR events.
827 * Error message, never NULL.
839 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
844 * Context for controlling the download.
846 struct GNUNET_FS_DownloadContext *dc;
849 * Client context pointer (set the last time
850 * by the client for this operation; initially
851 * NULL on START/RESUME events).
856 * Client context pointer for the parent operation
857 * (if this is a file in a directory or a subdirectory).
862 * URI used for this download.
864 const struct GNUNET_FS_Uri *uri;
867 * How large is the file overall? For directories,
868 * this is only the size of the directory itself,
869 * not of the other files contained within the
875 * At what time do we expect to finish the download?
876 * (will be a value in the past for completed
879 struct GNUNET_TIME_Relative eta;
882 * How long has this download been active?
884 struct GNUNET_TIME_Relative duration;
887 * How many bytes have we completed?
892 * What anonymity level is used for this download?
894 unsigned int anonymity;
897 * Additional values for specific events.
902 * These values are only valid for
903 * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
908 * Data block we just obtained.
913 * At what offset in the file is "data"?
918 * Length of the data block.
923 * Depth of the given block in the tree;
924 * 0 would be the highest level (the first
925 * call is guaranteed to be for the lowest
931 * Amount of trust we offered to get the block.
933 unsigned int trust_offered;
938 * These values are only valid for
939 * GNUNET_FS_STATUS_DOWNLOAD_START events.
944 * Known metadata for the download.
946 const struct GNUNET_MetaData *meta;
951 * These values are only valid for
952 * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
957 * Known metadata for the download.
959 const struct GNUNET_MetaData *meta;
962 * Error message, NULL if we have not encountered any error yet.
969 * These values are only valid for
970 * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
986 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
991 * Context for controlling the search, NULL for
992 * searches that were not explicitly triggered
993 * by the client (i.e., searches for updates in
996 struct GNUNET_FS_SearchContext *sc;
999 * Client context pointer (set the last time by the client for
1000 * this operation; initially NULL on START/RESUME events). Note
1001 * that this value can only be set on START/RESUME; returning
1002 * non-NULL on RESULT/RESUME_RESULT will actually update the
1003 * private context for "UPDATE" events.
1008 * Client parent-context pointer; NULL for top-level searches,
1009 * non-NULL for automatically triggered searches for updates in
1015 * What query is used for this search
1016 * (list of keywords or SKS identifier).
1018 const struct GNUNET_FS_Uri *query;
1021 * How long has this search been actively running
1022 * (excludes times where the search was paused or
1025 struct GNUNET_TIME_Relative duration;
1028 * What anonymity level is used for this search?
1030 unsigned int anonymity;
1033 * How much trust have we been offering for this search
1036 unsigned int trust_offered;
1039 * Additional values for specific events.
1044 * These values are only valid for
1045 * GNUNET_FS_STATUS_SEARCH_RESULT events.
1050 * Metadata for the search result.
1052 const struct GNUNET_MetaData *meta;
1055 * URI for the search result.
1057 const struct GNUNET_FS_Uri *uri;
1062 * These values are only valid for
1063 * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1068 * Metadata for the search result.
1070 const struct GNUNET_MetaData *meta;
1073 * URI for the search result.
1075 const struct GNUNET_FS_Uri *uri;
1078 * Current availability rank (negative:
1079 * unavailable, positive: available)
1081 int availability_rank;
1084 * On how many total queries is the given
1085 * availability_rank based?
1087 unsigned int availabiliy_certainty;
1090 * Updated applicability rank (the larger,
1091 * the better the result fits the search
1094 unsigned int applicabiliy_rank;
1099 * These values are only valid for
1100 * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1105 * Private context set for for this result
1106 * during the "RESULT" event.
1111 * Metadata for the search result.
1113 const struct GNUNET_MetaData *meta;
1116 * URI for the search result.
1118 const struct GNUNET_FS_Uri *uri;
1121 * Current availability rank (negative:
1122 * unavailable, positive: available)
1124 int availability_rank;
1127 * On how many total queries is the given
1128 * availability_rank based?
1130 unsigned int availabiliy_certainty;
1133 * Updated applicability rank (the larger,
1134 * the better the result fits the search
1137 unsigned int applicabiliy_rank;
1142 * These values are only valid for
1143 * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1144 * These events are automatically triggered for
1145 * each search result before the
1146 * GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1147 * happens primarily to give the client a chance
1148 * to clean up the "cctx" (if needed).
1153 * Private context set for for this result
1154 * during the "RESULT" event.
1159 * Metadata for the search result.
1161 const struct GNUNET_MetaData *meta;
1164 * URI for the search result.
1166 const struct GNUNET_FS_Uri *uri;
1171 * These values are only valid for
1172 * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1173 * These events are automatically triggered for
1174 * each search result before the
1175 * GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1176 * happens primarily to give the client a chance
1177 * to clean up the "cctx" (if needed).
1182 * Private context set for for this result
1183 * during the "RESULT" event.
1188 * Metadata for the search result.
1190 const struct GNUNET_MetaData *meta;
1193 * URI for the search result.
1195 const struct GNUNET_FS_Uri *uri;
1200 * These values are only valid for
1201 * GNUNET_FS_STATUS_SEARCH_RESUME events.
1206 * Error message, NULL if we have not encountered any error yet.
1208 const char *message;
1211 * Is this search currently paused?
1218 * These values are only valid for
1219 * GNUNET_FS_STATUS_SEARCH_ERROR events.
1226 const char *message;
1231 * Values for all "GNUNET_FS_STATUS_RESULT_NAMESPACE" events.
1236 * Handle to the namespace (NULL if it is not a local
1239 struct GNUNET_FS_Namespace *ns;
1242 * Short, human-readable name of the namespace.
1247 * Root identifier for the namespace, can be NULL.
1252 * Metadata for the namespace.
1254 const struct GNUNET_CONTAINER_MetaData *meta;
1257 * Hash-identifier for the namespace.
1268 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1273 * Context for controlling the unindexing.
1275 struct GNUNET_FS_UnindexContext *uc;
1278 * Client context pointer (set the last time
1279 * by the client for this operation; initially
1280 * NULL on START/RESUME events).
1285 * Name of the file that is being unindexed.
1287 const char *filename;
1290 * How large is the file overall?
1295 * At what time do we expect to finish unindexing?
1296 * (will be a value in the past for completed
1297 * unindexing opeations).
1299 struct GNUNET_TIME_Relative eta;
1302 * How long has this upload been actively running
1303 * (excludes times where the upload was suspended).
1305 struct GNUNET_TIME_Relative duration;
1308 * How many bytes have we completed?
1313 * Additional values for specific events.
1318 * These values are only valid for
1319 * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1324 * Data block we just unindexed.
1329 * At what offset in the file is "data"?
1334 * Length of the data block.
1339 * Depth of the given block in the tree;
1340 * 0 would be the highest level (the first
1341 * call is guaranteed to be for the lowest
1349 * These values are only valid for
1350 * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1355 * Error message, NULL if we have not encountered any error yet.
1357 const char *message;
1362 * These values are only valid for
1363 * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1370 const char *message;
1381 * Specific status code (determines the event type).
1383 enum GNUNET_FS_Status status;
1389 * Notification of FS to a client about the progress of an
1390 * operation. Callbacks of this type will be used for uploads,
1391 * downloads and searches. Some of the arguments depend a bit
1392 * in their meaning on the context in which the callback is used.
1394 * @param cls closure
1395 * @param info details about the event, specifying the event type
1396 * and various bits about the event
1397 * @return client-context (for the next progress call
1398 * for this operation; should be set to NULL for
1399 * SUSPEND and STOPPED events). The value returned
1400 * will be passed to future callbacks in the respective
1401 * field in the GNUNET_FS_ProgressInfo struct.
1403 typedef void* (*GNUNET_FS_ProgressCallback)
1405 const struct GNUNET_FS_ProgressInfo *info);
1409 * Handle to the file-sharing service.
1411 struct GNUNET_FS_Handle;
1415 * Setup a connection to the file-sharing service.
1417 * @param sched scheduler to use
1418 * @param cfg configuration to use
1419 * @param client_name unique identifier for this client
1420 * @param upcb function to call to notify about FS actions
1421 * @param upcb_cls closure for upcb
1423 struct GNUNET_FS_Handle *
1424 GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched,
1425 const struct GNUNET_CONFIGURATION_Handle *cfg,
1426 const char *client_name,
1427 GNUNET_FS_ProgressCallback upcb,
1432 * Close our connection with the file-sharing service.
1433 * The callback given to GNUNET_FS_start will no longer be
1434 * called after this function returns.
1436 * @param h handle that was returned from GNUNET_FS_start
1439 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1443 * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
1445 * @param cls closure
1446 * @param fi the entry in the publish-structure
1447 * @param length length of the file or directory
1448 * @param meta metadata for the file or directory (can be modified)
1449 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1450 * @param anonymity pointer to selected anonymity level (can be modified)
1451 * @param priority pointer to selected priority (can be modified)
1452 * @param expirationTime pointer to selected expiration time (can be modified)
1453 * @param client_info pointer to client context set upon creation (can be modified)
1454 * @return GNUNET_OK to continue, GNUNET_NO to remove
1455 * this entry from the directory, GNUNET_SYSERR
1456 * to abort the iteration
1458 typedef int (*GNUNET_FS_FileInformationProcessor)(void *cls,
1459 struct GNUNET_FS_FileInformation *fi,
1461 struct GNUNET_CONTAINER_MetaData *meta,
1462 struct GNUNET_FS_Uri **uri,
1463 unsigned int *anonymity,
1464 unsigned int *priority,
1465 struct GNUNET_TIME_Absolute *expirationTime,
1466 void **client_info);
1470 * Recover file information structure from disk.
1472 * @param name filename for the structure on disk
1473 * @return NULL on error
1475 struct GNUNET_FS_FileInformation *
1476 GNUNET_FS_file_information_recover (const char *name);
1480 * Obtain the name under which this file information
1481 * structure is stored on disk. Only works for top-level
1482 * file information structures.
1484 * @param s structure to get the filename for
1485 * @return NULL on error, otherwise filename that
1486 * can be passed to "GNUNET_FS_file_information_recover"
1487 * to read this fi-struct from disk.
1490 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1494 * Synchronize this file-information struct with its mirror
1495 * on disk. Note that all internal FS-operations that change
1496 * file information data should already call "sync" internally,
1497 * so this function is likely not useful for clients.
1499 * @param s the struct to sync
1502 GNUNET_FS_file_information_sync (struct GNUNET_FS_FileInformation *s);
1506 * Create an entry for a file in a publish-structure.
1508 * @param filename name of the file or directory to publish
1509 * @param keywords under which keywords should this file be available
1510 * directly; can be NULL
1511 * @param meta metadata for the file
1512 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1513 * GNUNET_SYSERR for simulation
1514 * @param anonymity what is the desired anonymity level for sharing?
1515 * @param priority what is the priority for OUR node to
1516 * keep this file available? Use 0 for maximum anonymity and
1517 * minimum reliability...
1518 * @param expirationTime when should this content expire?
1519 * @return publish structure entry for the file
1521 struct GNUNET_FS_FileInformation *
1522 GNUNET_FS_file_information_create_from_file (void *client_info,
1523 const char *filename,
1524 const struct GNUNET_FS_Uri *keywords,
1525 const struct GNUNET_CONTAINER_MetaData *meta,
1527 unsigned int anonymity,
1528 unsigned int priority,
1529 struct GNUNET_TIME_Absolute expirationTime);
1533 * Create an entry for a file in a publish-structure.
1535 * @param length length of the file
1536 * @param data data for the file (should not be used afterwards by
1537 * the caller; caller will "free")
1538 * @param keywords under which keywords should this file be available
1539 * directly; can be NULL
1540 * @param meta metadata for the file
1541 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1542 * GNUNET_SYSERR for simulation
1543 * @param anonymity what is the desired anonymity level for sharing?
1544 * @param priority what is the priority for OUR node to
1545 * keep this file available? Use 0 for maximum anonymity and
1546 * minimum reliability...
1547 * @param expirationTime when should this content expire?
1548 * @return publish structure entry for the file
1550 struct GNUNET_FS_FileInformation *
1551 GNUNET_FS_file_information_create_from_data (void *client_info,
1554 const struct GNUNET_FS_Uri *keywords,
1555 const struct GNUNET_CONTAINER_MetaData *meta,
1557 unsigned int anonymity,
1558 unsigned int priority,
1559 struct GNUNET_TIME_Absolute expirationTime);
1563 * Function that provides data.
1565 * @param cls closure
1566 * @param offset offset to read from; it is possible
1567 * that the caller might need to go backwards
1569 * @param max maximum number of bytes that should be
1570 * copied to buf; readers are not allowed
1571 * to provide less data unless there is an error;
1572 * a value of "0" will be used at the end to allow
1573 * the reader to clean up its internal state
1574 * @param buf where the reader should write the data
1575 * @param emsg location for the reader to store an error message
1576 * @return number of bytes written, usually "max", 0 on error
1578 typedef size_t (*GNUNET_FS_DataReader)(void *cls,
1586 * Create an entry for a file in a publish-structure.
1588 * @param length length of the file
1589 * @param reader function that can be used to obtain the data for the file
1590 * @param reader_cls closure for "reader"
1591 * @param keywords under which keywords should this file be available
1592 * directly; can be NULL
1593 * @param meta metadata for the file
1594 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1595 * GNUNET_SYSERR for simulation
1596 * @param anonymity what is the desired anonymity level for sharing?
1597 * @param priority what is the priority for OUR node to
1598 * keep this file available? Use 0 for maximum anonymity and
1599 * minimum reliability...
1600 * @param expirationTime when should this content expire?
1601 * @return publish structure entry for the file
1603 struct GNUNET_FS_FileInformation *
1604 GNUNET_FS_file_information_create_from_reader (void *client_info,
1606 GNUNET_FS_DataReader reader,
1608 const struct GNUNET_FS_Uri *keywords,
1609 const struct GNUNET_CONTAINER_MetaData *meta,
1611 unsigned int anonymity,
1612 unsigned int priority,
1613 struct GNUNET_TIME_Absolute expirationTime);
1617 * Function that a "GNUNET_FS_DirectoryScanner" should call
1618 * for each entry in the directory.
1620 * @param cls closure
1621 * @param filename name of the file (including path); must end
1622 * in a "/" (even on W32) if this is a directory
1623 * @param fi information about the file (should not be
1624 * used henceforth by the caller)
1626 typedef void (*GNUNET_FS_FileProcessor)(void *cls,
1627 const char *filename,
1628 struct GNUNET_FS_FileInformation *fi);
1632 * Type of a function that will be used to scan a directory.
1634 * @param cls closure
1635 * @param dirname name of the directory to scan
1636 * @param do_index should files be indexed or inserted
1637 * @param anonymity desired anonymity level
1638 * @param priority priority for publishing
1639 * @param expirationTime expiration for publication
1640 * @param proc function to call on each entry
1641 * @param proc_cls closure for proc
1642 * @param emsg where to store an error message (on errors)
1643 * @return GNUNET_OK on success
1645 typedef int (*GNUNET_FS_DirectoryScanner)(void *cls,
1646 const char *dirname,
1648 unsigned int anonymity,
1649 unsigned int priority,
1650 struct GNUNET_TIME_Absolute expirationTime,
1651 GNUNET_FS_FileProcessor proc,
1658 * Simple, useful default implementation of a directory scanner
1659 * (GNUNET_FS_DirectoryScanner). This implementation expects to get a
1660 * UNIX filename, will publish all files in the directory except hidden
1661 * files (those starting with a "."). Metadata will be extracted
1662 * using GNU libextractor; the specific list of plugins should be
1663 * specified in "cls", passing NULL will disable (!) metadata
1664 * extraction. Keywords will be derived from the metadata and be
1665 * subject to default canonicalization. This is strictly a
1666 * convenience function.
1668 * @param cls must be of type "struct EXTRACTOR_Extractor*"
1669 * @param dirname name of the directory to scan
1670 * @param do_index should files be indexed or inserted
1671 * @param anonymity desired anonymity level
1672 * @param priority priority for publishing
1673 * @param expirationTime expiration for publication
1674 * @param proc function called on each entry
1675 * @param proc_cls closure for proc
1676 * @param emsg where to store an error message (on errors)
1677 * @return GNUNET_OK on success
1680 GNUNET_FS_directory_scanner_default (void *cls,
1681 const char *dirname,
1683 unsigned int anonymity,
1684 unsigned int priority,
1685 struct GNUNET_TIME_Absolute expirationTime,
1686 GNUNET_FS_FileProcessor proc,
1692 * Create a publish-structure from an existing file hierarchy, inferring
1693 * and organizing keywords and metadata as much as possible. This
1694 * function primarily performs the recursive build and re-organizes
1695 * keywords and metadata; for automatically getting metadata
1696 * extraction, scanning of directories and creation of the respective
1697 * GNUNET_FS_FileInformation entries the default scanner should be
1698 * passed (GNUNET_FS_directory_scanner_default). This is strictly a
1699 * convenience function.
1701 * @param filename name of the top-level file or directory
1702 * @param scanner function used to get a list of files in a directory
1703 * @param scanner_cls closure for scanner
1704 * @param do_index should files in the hierarchy be indexed?
1705 * @param anonymity what is the desired anonymity level for sharing?
1706 * @param priority what is the priority for OUR node to
1707 * keep this file available? Use 0 for maximum anonymity and
1708 * minimum reliability...
1709 * @param expirationTime when should this content expire?
1710 * @param emsg where to store an error message
1711 * @return publish structure entry for the directory, NULL on error
1713 struct GNUNET_FS_FileInformation *
1714 GNUNET_FS_file_information_create_from_directory (void *client_info,
1715 const char *filename,
1716 GNUNET_FS_DirectoryScanner scanner,
1719 unsigned int anonymity,
1720 unsigned int priority,
1721 struct GNUNET_TIME_Absolute expirationTime,
1726 * Create an entry for an empty directory in a publish-structure.
1727 * This function should be used by applications for which the
1728 * use of "GNUNET_FS_file_information_create_from_directory"
1729 * is not appropriate.
1731 * @param meta metadata for the directory
1732 * @param keywords under which keywords should this directory be available
1733 * directly; can be NULL
1734 * @param anonymity what is the desired anonymity level for sharing?
1735 * @param priority what is the priority for OUR node to
1736 * keep this file available? Use 0 for maximum anonymity and
1737 * minimum reliability...
1738 * @param expirationTime when should this content expire?
1739 * @return publish structure entry for the directory , NULL on error
1741 struct GNUNET_FS_FileInformation *
1742 GNUNET_FS_file_information_create_empty_directory (void *client_info,
1743 const struct GNUNET_CONTAINER_MetaData *meta,
1744 const struct GNUNET_FS_Uri *keywords,
1745 unsigned int anonymity,
1746 unsigned int priority,
1747 struct GNUNET_TIME_Absolute expirationTime);
1751 * Add an entry to a directory in a publish-structure. Clients
1752 * should never modify publish structures that were passed to
1753 * "GNUNET_FS_publish_start" already.
1755 * @param dir the directory
1756 * @param end the entry to add; the entry must not have been
1757 * added to any other directory at this point and
1758 * must not include "dir" in its structure
1759 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1762 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1763 struct GNUNET_FS_FileInformation *end);
1767 * Inspect a file or directory in a publish-structure. Clients
1768 * should never modify publish structures that were passed to
1769 * "GNUNET_FS_publish_start" already. When called on a directory,
1770 * this function will FIRST call "proc" with information about
1771 * the directory itself and then for each of the files in the
1772 * directory (but not for files in subdirectories). When called
1773 * on a file, "proc" will be called exactly once (with information
1774 * about the specific file).
1776 * @param dir the directory
1777 * @param proc function to call on each entry
1778 * @param proc_cls closure for proc
1781 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1782 GNUNET_FS_FileInformationProcessor proc,
1787 * Destroy publish-structure. Clients should never destroy publish
1788 * structures that were passed to "GNUNET_FS_publish_start" already.
1790 * @param fi structure to destroy
1791 * @param cleaner function to call on each entry in the structure
1792 * (useful to clean up client_info); can be NULL; return
1793 * values are ignored
1794 * @param cleaner_cls closure for cleaner
1797 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
1798 GNUNET_FS_FileInformationProcessor cleaner,
1803 * Options for publishing. Compatible options
1804 * can be OR'ed together.
1806 enum GNUNET_FS_PublishOptions
1809 * No options (use defaults for everything).
1811 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
1814 * Simulate publishing. With this option, no data will be stored
1815 * in the datastore. Useful for computing URIs from files.
1817 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
1821 * Publish a file or directory.
1823 * @param h handle to the file sharing subsystem
1824 * @param ctx initial value to use for the '*ctx'
1825 * in the callback (for the GNUNET_FS_STATUS_PUBLISH_START event).
1826 * @param fi information about the file or directory structure to publish
1827 * @param namespace namespace to publish the file in, NULL for no namespace
1828 * @param nid identifier to use for the publishd content in the namespace
1829 * (can be NULL, must be NULL if namespace is NULL)
1830 * @param nuid update-identifier that will be used for future updates
1831 * (can be NULL, must be NULL if namespace or nid is NULL)
1832 * @param options options for the publication
1833 * @return context that can be used to control the publish operation
1835 struct GNUNET_FS_PublishContext *
1836 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1838 struct GNUNET_FS_FileInformation *fi,
1839 struct GNUNET_FS_Namespace *namespace,
1842 enum GNUNET_FS_PublishOptions options);
1846 * Stop an upload. Will abort incomplete uploads (but
1847 * not remove blocks that have already been publishd) or
1848 * simply clean up the state for completed uploads.
1850 * @param sc context for the upload to stop
1853 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *sc);
1857 * Signature of a function called as the continuation of a KBlock or
1858 * SBlock publication.
1860 * @param cls closure
1861 * @param uri URI under which the block is now available, NULL on error
1862 * @param emsg error message, NULL on success
1864 typedef void (*GNUNET_FS_PublishContinuation)(void *cls,
1865 const struct GNUNET_FS_Uri *uri,
1870 * Publish a KBlock on GNUnet.
1872 * @param h handle to the file sharing subsystem
1873 * @param keywords keywords to use
1874 * @param meta metadata to use
1875 * @param uri URI to refer to in the KBlock
1876 * @param expirationTime when the KBlock expires
1877 * @param anonymity anonymity level for the KBlock
1878 * @param priority priority for the KBlock
1879 * @param cont continuation
1880 * @param cont_cls closure for cont
1883 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1884 struct GNUNET_FS_Uri *keywords,
1885 struct GNUNET_CONTAINER_MetaData *meta,
1886 struct GNUNET_FS_Uri *uri,
1887 struct GNUNET_TIME_Absolute expirationTime,
1888 unsigned int anonymity,
1889 unsigned int priority,
1890 enum GNUNET_FS_PublishOptions options,
1891 GNUNET_FS_PublishContinuation cont,
1896 * Publish an SBlock on GNUnet.
1898 * @param h handle to the file sharing subsystem
1899 * @param namespace namespace to publish in
1900 * @param identifier identifier to use
1901 * @param update update identifier to use
1902 * @param meta metadata to use
1903 * @param uri URI to refer to in the SBlock
1904 * @param expirationTime when the SBlock expires
1905 * @param anonymity anonymity level for the SBlock
1906 * @param priority priority for the SBlock
1907 * @param cont continuation
1908 * @param cont_cls closure for cont
1911 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
1912 struct GNUNET_FS_Namespace *namespace,
1913 const char *identifier,
1915 struct GNUNET_CONTAINER_MetaData *meta,
1916 struct GNUNET_FS_Uri *uri,
1917 struct GNUNET_TIME_Absolute expirationTime,
1918 unsigned int anonymity,
1919 unsigned int priority,
1920 enum GNUNET_FS_PublishOptions options,
1921 GNUNET_FS_PublishContinuation cont,
1926 * Type of a function called by "GNUNET_FS_get_indexed_files".
1928 * @param cls closure
1929 * @param filename the name of the file
1930 * @param file_id hash of the contents of the indexed file
1931 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
1933 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls,
1934 const char *filename,
1935 const GNUNET_HashCode *file_id);
1939 * Iterate over all indexed files.
1941 * @param h handle to the file sharing subsystem
1942 * @param iterator function to call on each indexed file
1943 * @param iterator_cls closure for iterator
1944 * @param cont continuation to call when done;
1945 * reason should be "TIMEOUT" (on
1946 * error) or "PREREQ_DONE" (on success)
1947 * @param cont_cls closure for cont
1950 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
1951 GNUNET_FS_IndexedFileProcessor iterator,
1953 GNUNET_SCHEDULER_Task cont,
1960 * @param h handle to the file sharing subsystem
1961 * @param filename file to unindex
1962 * @return NULL on error, otherwise handle
1964 struct GNUNET_FS_UnindexContext *
1965 GNUNET_FS_unindex (struct GNUNET_FS_Handle *h,
1966 const char *filename);
1970 * Clean up after completion of an unindex operation.
1975 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
1979 * Publish an advertismement for a namespace.
1981 * @param h handle to the file sharing subsystem
1982 * @param namespace handle for the namespace that should be advertised
1983 * @param meta meta-data for the namespace advertisement
1984 * @param anonymity for the namespace advertismement
1985 * @param priority for the namespace advertisement
1986 * @param expiration for the namespace advertisement
1987 * @param advertisementURI the keyword (!) URI to advertise the
1988 * namespace under (we will create a GNUNET_EC_KNBlock)
1989 * @param rootEntry name of the root entry in the namespace (for
1990 * the namespace advertisement)
1992 * @return uri of the advertisement
1994 struct GNUNET_FS_Uri *
1995 GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
1996 struct GNUNET_FS_Namespace *namespace,
1997 const struct GNUNET_MetaData *meta,
1998 unsigned int anonymity,
1999 unsigned int priority,
2000 struct GNUNET_TIME_Absolute expiration,
2001 const struct GNUNET_FS_Uri *advertisementURI,
2002 const char *rootEntry);
2006 * Create a namespace with the given name; if one already
2007 * exists, return a handle to the existing namespace.
2009 * @param h handle to the file sharing subsystem
2010 * @param name name to use for the namespace
2011 * @return handle to the namespace, NULL on error
2013 struct GNUNET_FS_Namespace *
2014 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h,
2019 * Delete a namespace handle. Can be used for a clean shutdown (free
2020 * memory) or also to freeze the namespace to prevent further
2021 * insertions by anyone.
2023 * @param namespace handle to the namespace that should be deleted / freed
2024 * @param freeze prevents future insertions; creating a namespace
2025 * with the same name again will create a fresh namespace instead
2027 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2030 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace,
2035 * Callback with information about local (!) namespaces.
2036 * Contains the names of the local namespace and the global
2039 * @param cls closure
2040 * @param name human-readable identifier of the namespace
2041 * @param id hash identifier for the namespace
2043 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls,
2045 const GNUNET_HashCode *id);
2049 * Build a list of all available local (!) namespaces The returned
2050 * names are only the nicknames since we only iterate over the local
2053 * @param h handle to the file sharing subsystem
2054 * @param cb function to call on each known namespace
2055 * @param cb_cls closure for cb
2058 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2059 GNUNET_FS_NamespaceInfoProcessor cb,
2064 * Function called on updateable identifiers.
2066 * @param cls closure
2067 * @param last_id last identifier
2068 * @param last_uri uri used for the content published under the last_id
2069 * @param last_meta metadata associated with last_uri
2070 * @param next_id identifier that should be used for updates
2073 (*GNUNET_FS_IdentifierProcessor)(void *cls,
2074 const char *last_id,
2075 const struct GNUNET_FS_Uri *last_uri,
2076 const struct GNUNET_CONTAINER_MetaData *last_meta,
2077 const char *next_id);
2081 * List all of the identifiers in the namespace for
2082 * which we could produce an update.
2084 * @param namespace namespace to inspect for updateable content
2085 * @param ip function to call on each updateable identifier
2086 * @param ip_cls closure for ip
2089 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
2090 GNUNET_FS_IdentifierProcessor ip,
2095 * Start search for content.
2097 * @param h handle to the file sharing subsystem
2098 * @param uri specifies the search parameters; can be
2099 * a KSK URI or an SKS URI.
2100 * @param anonymity desired level of anonymity
2101 * @return context that can be used to control the search
2103 struct GNUNET_FS_SearchContext *
2104 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2105 const struct GNUNET_FS_Uri *uri,
2106 unsigned int anonymity);
2112 * @param sc context for the search that should be paused
2115 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2119 * Continue paused search.
2121 * @param sc context for the search that should be resumed
2124 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2128 * Stop search for content.
2130 * @param sc context for the search that should be stopped
2133 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2137 * Download parts of a file. Note that this will store
2138 * the blocks at the respective offset in the given file. Also, the
2139 * download is still using the blocking of the underlying FS
2140 * encoding. As a result, the download may *write* outside of the
2141 * given boundaries (if offset and length do not match the 32k FS
2142 * block boundaries). <p>
2144 * This function should be used to focus a download towards a
2145 * particular portion of the file (optimization), not to strictly
2146 * limit the download to exactly those bytes.
2148 * @param h handle to the file sharing subsystem
2149 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2150 * @param filename where to store the file, maybe NULL (then no file is
2151 * created on disk and data must be grabbed from the callbacks)
2152 * @param offset at what offset should we start the download (typically 0)
2153 * @param length how many bytes should be downloaded starting at offset
2154 * @param anonymity anonymity level to use for the download
2155 * @param no_temporaries set to GNUNET_YES to disallow generation of temporary files
2156 * @param recursive should this be a recursive download (useful for directories
2157 * to automatically trigger download of files in the directories)
2158 * @param parent parent download to associate this download with (use NULL
2159 * for top-level downloads; useful for manually-triggered recursive downloads)
2160 * @return context that can be used to control this download
2162 struct GNUNET_FS_DownloadContext *
2163 GNUNET_FS_file_download_start (struct GNUNET_FS_Handle *h,
2164 const struct GNUNET_FS_Uri *uri,
2165 const char *filename,
2166 unsigned long long offset,
2167 unsigned long long length,
2168 unsigned int anonymity,
2171 struct GNUNET_FS_DownloadContext *parent);
2175 * Stop a download (aborts if download is incomplete).
2177 * @param rm handle for the download
2178 * @param do_delete delete files of incomplete downloads
2181 GNUNET_FS_file_download_stop (struct GNUNET_FS_DownloadContext *rm,
2186 * Initialize collection.
2188 * @param h handle to the file sharing subsystem
2189 * @param namespace namespace to use for the collection
2190 * @return GNUNET_OK on success, GNUNET_SYSERR if another
2191 * namespace is already set for our collection
2194 GNUNET_FS_collection_start (struct GNUNET_FS_Handle *h,
2195 struct GNUNET_FS_Namespace *namespace);
2201 * @param h handle to the file sharing subsystem
2202 * @return GNUNET_OK on success, GNUNET_SYSERR if no collection is active
2205 GNUNET_FS_collection_stop (struct GNUNET_FS_Handle *h);
2209 * Are we using a collection?
2211 * @param h handle to the file sharing subsystem
2212 * @return NULL if there is no collection,
2214 struct GNUNET_FS_Namespace *
2215 GNUNET_FS_collection_get(struct GNUNET_FS_Handle *h);
2219 * Publish an update of the current collection information to the
2220 * network now. The function has no effect if the collection has not
2221 * changed since the last publication. If we are currently not
2222 * collecting, this function does nothing.
2224 * @param h handle to the file sharing subsystem
2226 void GNUNET_FS_collection_publish (struct GNUNET_FS_Handle *h);
2230 * If we are currently building a collection, publish the given file
2231 * information in that collection. If we are currently not
2232 * collecting, this function does nothing.
2234 * @param h handle to the file sharing subsystem
2235 * @param uri uri to add to the collection
2236 * @param meta metadata for the uri
2238 void GNUNET_FS_collection_add (const struct GNUNET_FS_Handle *h,
2239 const struct GNUNET_FS_Uri *uri,
2240 const struct GNUNET_CONTAINER_MetaData *meta);
2246 /* ******************** Directory API *********************** */
2249 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2250 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2251 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2254 * Does the meta-data claim that this is a directory?
2255 * Checks if the mime-type is that of a GNUnet directory.
2257 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2258 * we have no mime-type information (treat as 'GNUNET_NO')
2261 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData *md);
2265 * Set the MIMETYPE information for the given
2266 * metadata to "application/gnunet-directory".
2268 * @param md metadata to add mimetype to
2271 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2275 * Function used to process entries in a directory.
2277 * @param cls closure
2278 * @param filename name of the file in the directory
2279 * @param uri URI of the file
2280 * @param metadata metadata for the file; metadata for
2281 * the directory if everything else is NULL/zero
2282 * @param length length of the available data for the file
2283 * (of type size_t since data must certainly fit
2284 * into memory; if files are larger than size_t
2285 * permits, then they will certainly not be
2286 * embedded with the directory itself).
2287 * @param data data available for the file (length bytes)
2289 typedef void (*GNUNET_FS_DirectoryEntryProcessor)(void *cls,
2290 const char *filename,
2291 const struct GNUNET_FS_Uri *uri,
2292 const struct GNUNET_CONTAINER_MetaData *meta,
2298 * Iterate over all entries in a directory. Note that directories
2299 * are structured such that it is possible to iterate over the
2300 * individual blocks as well as over the entire directory. Thus
2301 * a client can call this function on the buffer in the
2302 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2303 * include the contents of (small) files embedded in the directory
2304 * itself; for those files, the processor may be given the
2305 * contents of the file directly by this function.
2307 * @param size number of bytes in data
2308 * @param data pointer to the beginning of the directory
2309 * @param offset offset of data in the directory
2310 * @param dep function to call on each entry
2311 * @param dep_cls closure for dep
2314 GNUNET_FS_directory_list_contents (size_t size,
2317 GNUNET_FS_DirectoryEntryProcessor dep,
2322 * Opaque handle to a directory builder.
2324 struct GNUNET_FS_DirectoryBuilder;
2327 * Create a directory builder.
2329 * @param mdir metadata for the directory
2331 struct GNUNET_FS_DirectoryBuilder *
2332 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData *mdir);
2336 * Add an entry to a directory.
2338 * @param bld directory to extend
2339 * @param uri uri of the entry (must not be a KSK)
2340 * @param md metadata of the entry
2341 * @param data raw data of the entry, can be NULL, otherwise
2342 * data must point to exactly the number of bytes specified
2346 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2347 const struct GNUNET_FS_Uri *uri,
2348 const struct GNUNET_CONTAINER_MetaData *md,
2353 * Finish building the directory. Frees the
2354 * builder context and returns the directory
2357 * @param bld directory to finish
2358 * @param size set to the number of bytes needed
2359 * @param data set to the encoded directory
2362 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2367 #if 0 /* keep Emacsens' auto-indent happy */