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
25 #ifndef GNUNET_FS_LIB_H
26 #define GNUNET_FS_LIB_H
28 #include "gnunet_util_lib.h"
33 #if 0 /* keep Emacsens' auto-indent happy */
39 * Version number of the implementation.
42 * 1.x.x: initial version with triple GNUNET_hash and merkle tree
43 * 2.x.x: root node with mime-type, filename and version number
44 * 2.1.x: combined GNUNET_EC_ContentHashKey/3HASH encoding with 25:1 super-nodes
45 * 2.2.x: with directories
46 * 3.0.x: with namespaces
47 * 3.1.x: with namespace meta-data
48 * 3.2.x: with collections
49 * 4.0.x: with expiration, variable meta-data, kblocks
50 * 4.1.x: with new error and configuration handling
51 * 5.0.x: with location URIs
52 * 6.0.0: with support for OR in KSKs
53 * 6.1.x: with simplified namespace support
54 * 9.0.0: CPS-style integrated API
56 #define GNUNET_FS_VERSION 0x00090000
59 /* ******************** URI API *********************** */
61 #define GNUNET_FS_URI_PREFIX "gnunet://fs/"
62 #define GNUNET_FS_URI_KSK_INFIX "ksk/"
63 #define GNUNET_FS_URI_SKS_INFIX "sks/"
64 #define GNUNET_FS_URI_CHK_INFIX "chk/"
65 #define GNUNET_FS_URI_LOC_INFIX "loc/"
69 * A Universal Resource Identifier (URI), opaque.
75 * Iterator over keywords
78 * @param keyword the keyword
79 * @param is_mandatory is the keyword mandatory (in a search)
80 * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
82 typedef int (*GNUNET_FS_KeywordIterator) (void *cls,
87 * Get a unique key from a URI. This is for putting URIs
88 * into HashMaps. The key may change between FS implementations.
90 * @param uri uri to convert to a unique key
91 * @param key wherer to store the unique key
94 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
95 GNUNET_HashCode * key);
98 * Convert a URI to a UTF-8 String.
100 * @param uri uri to convert to a string
101 * @return the UTF-8 string
104 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
107 * Convert keyword URI to a human readable format
108 * (i.e. the search query that was used in the first place)
110 * @param uri ksk uri to convert to a string
111 * @return string with the keywords
114 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
118 * Convert a UTF-8 String to a URI.
120 * @param uri string to parse
121 * @param emsg where to store the parser error message (if any)
122 * @return NULL on error
124 struct GNUNET_FS_Uri *
125 GNUNET_FS_uri_parse (const char *uri,
131 * @param uri uri to free
134 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
138 * How many keywords are ANDed in this keyword URI?
140 * @param uri ksk uri to get the number of keywords from
141 * @return 0 if this is not a keyword URI
144 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
148 * Iterate over all keywords in this keyword URI.
150 * @param uri ksk uri to get the keywords from
151 * @param iterator function to call on each keyword
152 * @param iterator_cls closure for iterator
153 * @return -1 if this is not a keyword URI, otherwise number of
154 * keywords iterated over until iterator aborted
157 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
158 GNUNET_FS_KeywordIterator iterator,
163 * Obtain the identity of the peer offering the data
165 * @param uri the location URI to inspect
166 * @param peer where to store the identify of the peer (presumably) offering the content
167 * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK
170 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
171 struct GNUNET_PeerIdentity * peer);
175 * Obtain the URI of the content itself.
177 * @param uri location URI to get the content URI from
178 * @return NULL if argument is not a location URI
180 struct GNUNET_FS_Uri *
181 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
185 * Obtain the expiration of the LOC URI.
187 * @param uri location URI to get the expiration from
188 * @return expiration time of the URI
190 struct GNUNET_TIME_Absolute
191 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
195 * Construct a location URI (this peer will be used for the location).
197 * @param baseUri content offered by the sender
198 * @param cfg configuration information (used to find our hostkey)
199 * @param expiration_time how long will the content be offered?
200 * @return the location URI, NULL on error
202 struct GNUNET_FS_Uri *
203 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
204 struct GNUNET_CONFIGURATION_Handle *cfg,
205 struct GNUNET_TIME_Absolute expiration_time);
209 * Canonicalize keyword URI. Performs operations such
210 * as decapitalization and removal of certain characters.
211 * (useful for search).
213 * @param uri the URI to canonicalize
214 * @return canonicalized version of the URI, NULL on error
216 struct GNUNET_FS_Uri *
217 GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri);
221 * Merge the sets of keywords from two KSK URIs.
222 * (useful for merging the canonicalized keywords with
223 * the original keywords for sharing).
225 * @param u1 first uri
226 * @param u2 second uri
227 * @return merged URI, NULL on error
229 struct GNUNET_FS_Uri *
230 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
231 const struct GNUNET_FS_Uri *u2);
237 * @param uri the URI to duplicate
238 * @return copy of the URI
240 struct GNUNET_FS_Uri *
241 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
245 * Create an FS URI from a single user-supplied string of keywords.
246 * The string is broken up at spaces into individual keywords.
247 * Keywords that start with "+" are mandatory. Double-quotes can
248 * be used to prevent breaking up strings at spaces (and also
249 * to specify non-mandatory keywords starting with "+").
251 * Keywords must contain a balanced number of double quotes and
252 * double quotes can not be used in the actual keywords (for
253 * example, the string '""foo bar""' will be turned into two
254 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
256 * @param keywords the keyword string
257 * @param emsg where to store an error message
258 * @return an FS URI for the given keywords, NULL
259 * if keywords is not legal (i.e. empty).
261 struct GNUNET_FS_Uri *
262 GNUNET_FS_uri_ksk_create (const char *keywords,
267 * Create an FS URI from a user-supplied command line of keywords.
268 * Arguments should start with "+" to indicate mandatory
271 * @param argc number of keywords
272 * @param argv keywords (double quotes are not required for
273 * keywords containing spaces; however, double
274 * quotes are required for keywords starting with
275 * "+"); there is no mechanism for having double
276 * quotes in the actual keywords (if the user
277 * did specifically specify double quotes, the
278 * caller should convert each double quote
279 * into two single quotes).
280 * @return an FS URI for the given keywords, NULL
281 * if keywords is not legal (i.e. empty).
283 struct GNUNET_FS_Uri *
284 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
289 * Test if two URIs are equal.
291 * @param u1 one of the URIs
292 * @param u2 the other URI
293 * @return GNUNET_YES if the URIs are equal
296 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
297 const struct GNUNET_FS_Uri *u2);
301 * Is this a namespace URI?
303 * @param uri the uri to check
304 * @return GNUNET_YES if this is an SKS uri
307 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
311 * Handle to one of our namespaces.
313 struct GNUNET_FS_Namespace;
317 * Create an SKS URI from a namespace and an identifier.
319 * @param ns namespace
320 * @param id identifier
321 * @param emsg where to store an error message
322 * @return an FS URI for the given namespace and identifier
324 struct GNUNET_FS_Uri *
325 GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns,
331 * Get the ID of a namespace from the given
334 * @param uri the uri to get the namespace ID from
335 * @param nsid where to store the ID of the namespace
336 * @return GNUNET_OK on success
339 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
340 GNUNET_HashCode * nsid);
344 * Get the content identifier of an SKS URI.
346 * @param uri the sks uri
347 * @return NULL on error (not a valid SKS URI)
350 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
354 * Convert namespace URI to a human readable format
355 * (using the namespace description, if available).
357 * @param cfg configuration to use
358 * @param uri SKS uri to convert
359 * @return NULL on error (not an SKS URI)
362 GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
363 const struct GNUNET_FS_Uri *uri);
367 * Is this a keyword URI?
370 * @return GNUNET_YES if this is a KSK uri
373 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
377 * Is this a file (or directory) URI?
379 * @param uri the uri to check
380 * @return GNUNET_YES if this is a CHK uri
383 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
387 * What is the size of the file that this URI
390 * @param uri the CHK (or LOC) URI to inspect
391 * @return size of the file as specified in the CHK URI
394 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
398 * Is this a location URI?
400 * @param uri the uri to check
401 * @return GNUNET_YES if this is a LOC uri
404 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
408 * Construct a keyword-URI from meta-data (take all entries
409 * in the meta-data and construct one large keyword URI
410 * that lists all keywords that can be found in the meta-data).
412 * @param md metadata to use
413 * @return NULL on error, otherwise a KSK URI
415 struct GNUNET_FS_Uri *
416 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md);
419 /* ******************** command-line option parsing API *********************** */
422 * Command-line option parser function that allows the user
423 * to specify one or more '-k' options with keywords. Each
424 * specified keyword will be added to the URI. A pointer to
425 * the URI must be passed as the "scls" argument.
427 * @param ctx command line processor context
428 * @param scls must be of type "struct GNUNET_FS_Uri **"
429 * @param option name of the option (typically 'k')
430 * @param value command line argument given
431 * @return GNUNET_OK on success
434 GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx,
441 * Command-line option parser function that allows the user to specify
442 * one or more '-m' options with metadata. Each specified entry of
443 * the form "type=value" will be added to the metadata. A pointer to
444 * the metadata must be passed as the "scls" argument.
446 * @param ctx command line processor context
447 * @param scls must be of type "struct GNUNET_CONTAINER_MetaData **"
448 * @param option name of the option (typically 'k')
449 * @param value command line argument given
450 * @return GNUNET_OK on success
453 GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx,
460 /* ************************* sharing API ***************** */
464 * Possible status codes used in the callback for the
465 * various file-sharing operations. On each file (or search),
466 * the callback is guaranteed to be called once with "START"
467 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
468 * are optional and depend on the circumstances; parent operations
469 * will be STARTED before child-operations and STOPPED after
470 * their respective child-operations. START and STOP signals
471 * are typically generated either due to explicit client requests
472 * or because of suspend/resume operations.
474 enum GNUNET_FS_Status
477 * Notification that we have started to publish a file structure.
479 GNUNET_FS_STATUS_PUBLISH_START,
482 * Notification that we have resumed sharing a file structure.
484 GNUNET_FS_STATUS_PUBLISH_RESUME,
487 * Notification that we have suspended sharing a file structure.
489 GNUNET_FS_STATUS_PUBLISH_SUSPEND,
492 * Notification that we are making progress sharing a file structure.
494 GNUNET_FS_STATUS_PUBLISH_PROGRESS,
497 * Notification that an error was encountered sharing a file structure.
498 * The application will continue to receive resume/suspend events for
499 * this structure until "GNUNET_FS_publish_stop" is called.
501 GNUNET_FS_STATUS_PUBLISH_ERROR,
504 * Notification that we completed sharing a file structure.
505 * The application will continue to receive resume/suspend events for
506 * this structure until "GNUNET_FS_publish_stop" is called.
508 GNUNET_FS_STATUS_PUBLISH_COMPLETED,
511 * Notification that we have stopped
512 * the process of uploading a file structure; no
513 * futher events will be generated for this action.
515 GNUNET_FS_STATUS_PUBLISH_STOPPED,
518 * Notification that we have started this download.
520 GNUNET_FS_STATUS_DOWNLOAD_START,
523 * Notification that this download is being resumed.
525 GNUNET_FS_STATUS_DOWNLOAD_RESUME,
528 * Notification that this download was suspended.
530 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND,
533 * Notification about progress with this download.
535 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS,
538 * Notification that this download encountered an error.
540 GNUNET_FS_STATUS_DOWNLOAD_ERROR,
543 * Notification that this download completed. Note that for
544 * directories, completion does not imply completion of all files in
547 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED,
550 * Notification that this download was stopped
551 * (final event with respect to this action).
553 GNUNET_FS_STATUS_DOWNLOAD_STOPPED,
556 * Notification that this download is now actively being
557 * pursued (as opposed to waiting in the queue).
559 GNUNET_FS_STATUS_DOWNLOAD_ACTIVE,
562 * Notification that this download is no longer actively
563 * being pursued (back in the queue).
565 GNUNET_FS_STATUS_DOWNLOAD_INACTIVE,
568 * Notification that this download is no longer part of a
569 * recursive download or search but now a 'stand-alone'
570 * download (and may thus need to be moved in the GUI
571 * into a different category).
573 GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT,
576 * First event generated when a client requests
577 * a search to begin or when a namespace result
578 * automatically triggers the search for updates.
580 GNUNET_FS_STATUS_SEARCH_START,
583 * Last event when a search is being resumed;
584 * note that "GNUNET_FS_SEARCH_START" will not
585 * be generated in this case.
587 GNUNET_FS_STATUS_SEARCH_RESUME,
590 * Event generated for each search result
591 * when the respective search is resumed.
593 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT,
596 * Last event when a search is being suspended;
597 * note that "GNUNET_FS_SEARCH_STOPPED" will not
598 * be generated in this case.
600 GNUNET_FS_STATUS_SEARCH_SUSPEND,
603 * This search has yielded a result.
605 GNUNET_FS_STATUS_SEARCH_RESULT,
608 * We have discovered a new namespace.
610 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE,
613 * We have additional data about the quality
614 * or availability of a search result.
616 GNUNET_FS_STATUS_SEARCH_UPDATE,
619 * Signals a problem with this search.
621 GNUNET_FS_STATUS_SEARCH_ERROR,
624 * Signals that this search was paused.
626 GNUNET_FS_STATUS_SEARCH_PAUSED,
629 * Signals that this search was continued (unpaused).
631 GNUNET_FS_STATUS_SEARCH_CONTINUED,
634 * Event generated for each search result
635 * when the respective search is stopped.
637 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED,
640 * Event generated for each search result
641 * when the respective search is suspended.
643 GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND,
646 * Last message from a search; this signals
647 * that there will be no further events associated
650 GNUNET_FS_STATUS_SEARCH_STOPPED,
653 * Notification that we started to unindex a file.
655 GNUNET_FS_STATUS_UNINDEX_START,
658 * Notification that we resumed unindexing of a file.
660 GNUNET_FS_STATUS_UNINDEX_RESUME,
663 * Notification that we suspended unindexing a file.
665 GNUNET_FS_STATUS_UNINDEX_SUSPEND,
668 * Notification that we made progress unindexing a file.
670 GNUNET_FS_STATUS_UNINDEX_PROGRESS,
673 * Notification that we encountered an error unindexing
676 GNUNET_FS_STATUS_UNINDEX_ERROR,
679 * Notification that the unindexing of this file
682 GNUNET_FS_STATUS_UNINDEX_COMPLETED,
685 * Notification that the unindexing of this file
686 * was stopped (final event for this action).
688 GNUNET_FS_STATUS_UNINDEX_STOPPED
694 * Handle for controlling an upload.
696 struct GNUNET_FS_PublishContext;
700 * Handle for controlling an unindexing operation.
702 struct GNUNET_FS_UnindexContext;
706 * Handle for controlling a search.
708 struct GNUNET_FS_SearchContext;
712 * Result from a search. Opaque handle to refer to the search
713 * (typically used when starting a download associated with the search
716 struct GNUNET_FS_SearchResult;
720 * Context for controlling a download.
722 struct GNUNET_FS_DownloadContext;
726 * Handle for detail information about a file that is being publishd.
727 * Specifies metadata, keywords, how to get the contents of the file
728 * (i.e. data-buffer in memory, filename on disk) and other options.
730 struct GNUNET_FS_FileInformation;
734 * Argument given to the progress callback with
735 * information about what is going on.
737 struct GNUNET_FS_ProgressInfo
741 * Values that depend on the event type.
746 * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
751 * Context for controlling the upload.
752 * FIXME: rename to 'pc'.
754 struct GNUNET_FS_PublishContext *sc;
757 * Information about the file that is being publishd.
759 const struct GNUNET_FS_FileInformation *fi;
762 * Client context pointer (set the last time by the client for
763 * this operation; initially NULL on START/RESUME events).
768 * Client context pointer for the parent operation
769 * (if this is a file in a directory or a subdirectory).
774 * Name of the file being published; can be NULL.
776 const char *filename;
779 * How large is the file overall? For directories,
780 * this is only the size of the directory itself,
781 * not of the other files contained within the
787 * At what time do we expect to finish the upload?
788 * (will be a value in the past for completed
791 struct GNUNET_TIME_Relative eta;
794 * How long has this upload been actively running
795 * (excludes times where the upload was suspended).
797 struct GNUNET_TIME_Relative duration;
800 * How many bytes have we completed?
805 * What anonymity level is used for this upload?
810 * Additional values for specific events.
815 * These values are only valid for
816 * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
821 * Data block we just published.
826 * At what offset in the file is "data"?
831 * Length of the data block.
836 * Depth of the given block in the tree;
837 * 0 would be the highest level (the first
838 * call is guaranteed to be for the lowest
846 * These values are only valid for
847 * GNUNET_FS_STATUS_PUBLISH_RESUME events.
852 * Error message, NULL if no error was encountered so far.
857 * URI of the file (if the download had been completed)
859 const struct GNUNET_FS_Uri *chk_uri;
864 * These values are only valid for
865 * GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
872 const struct GNUNET_FS_Uri *chk_uri;
877 * These values are only valid for
878 * GNUNET_FS_STATUS_PUBLISH_ERROR events.
883 * Error message, never NULL.
895 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
900 * Context for controlling the download.
902 struct GNUNET_FS_DownloadContext *dc;
905 * Client context pointer (set the last time
906 * by the client for this operation; initially
907 * NULL on START/RESUME events).
912 * Client context pointer for the parent operation
913 * (if this is a file in a directory or a subdirectory).
918 * Client context pointer for the associated search operation
919 * (specifically, context pointer for the specific search
920 * result, not the overall search); only set if this
921 * download was started from a search result.
926 * URI used for this download.
928 const struct GNUNET_FS_Uri *uri;
931 * Name of the file that we are downloading.
933 const char *filename;
936 * How large is the download overall? This
937 * is NOT necessarily the size from the
938 * URI since we may be doing a partial download.
943 * At what time do we expect to finish the download?
944 * (will be a value in the past for completed
947 struct GNUNET_TIME_Relative eta;
950 * How long has this download been active?
952 struct GNUNET_TIME_Relative duration;
955 * How many bytes have we completed?
960 * What anonymity level is used for this download?
965 * Additional values for specific events.
970 * These values are only valid for
971 * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
976 * Data block we just obtained.
981 * At what offset in the file is "data"?
986 * Length of the data block.
991 * Depth of the given block in the tree;
992 * 0 would be the highest level (the first
993 * call is guaranteed to be for the lowest
1001 * These values are only valid for
1002 * GNUNET_FS_STATUS_DOWNLOAD_START events.
1007 * Known metadata for the download.
1009 const struct GNUNET_CONTAINER_MetaData *meta;
1014 * These values are only valid for
1015 * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
1020 * Known metadata for the download.
1022 const struct GNUNET_CONTAINER_MetaData *meta;
1025 * Error message, NULL if we have not encountered any error yet.
1027 const char *message;
1032 * These values are only valid for
1033 * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1040 const char *message;
1049 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1054 * Context for controlling the search, NULL for
1055 * searches that were not explicitly triggered
1056 * by the client (i.e., searches for updates in
1059 struct GNUNET_FS_SearchContext *sc;
1062 * Client context pointer (set the last time by the client for
1063 * this operation; initially NULL on START/RESUME events). Note
1064 * that this value can only be set on START/RESUME; returning
1065 * non-NULL on RESULT/RESUME_RESULT will actually update the
1066 * private context for "UPDATE" events.
1071 * Client parent-context pointer; NULL for top-level searches,
1072 * refers to the client context of the associated search result
1073 * for automatically triggered searches for updates in
1074 * namespaces. In this case, 'presult' refers to that search
1080 * What query is used for this search
1081 * (list of keywords or SKS identifier).
1083 const struct GNUNET_FS_Uri *query;
1086 * How long has this search been actively running
1087 * (excludes times where the search was paused or
1090 struct GNUNET_TIME_Relative duration;
1093 * What anonymity level is used for this search?
1098 * Additional values for specific events.
1103 * These values are only valid for
1104 * GNUNET_FS_STATUS_SEARCH_RESULT events.
1109 * Metadata for the search result.
1111 const struct GNUNET_CONTAINER_MetaData *meta;
1114 * URI for the search result.
1116 const struct GNUNET_FS_Uri *uri;
1119 * Handle to the result (for starting downloads).
1121 struct GNUNET_FS_SearchResult *result;
1124 * Applicability rank (the larger, the better the result
1125 * fits the search criteria).
1127 uint32_t applicability_rank;
1132 * These values are only valid for
1133 * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1138 * Metadata for the search result.
1140 const struct GNUNET_CONTAINER_MetaData *meta;
1143 * URI for the search result.
1145 const struct GNUNET_FS_Uri *uri;
1148 * Handle to the result (for starting downloads).
1150 struct GNUNET_FS_SearchResult *result;
1153 * Current availability rank (negative:
1154 * unavailable, positive: available)
1156 int32_t availability_rank;
1159 * On how many total queries is the given
1160 * availability_rank based?
1162 uint32_t availability_certainty;
1165 * Updated applicability rank (the larger,
1166 * the better the result fits the search
1169 uint32_t applicability_rank;
1174 * These values are only valid for
1175 * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1180 * Private context set for for this result
1181 * during the "RESULT" event.
1186 * Metadata for the search result.
1188 const struct GNUNET_CONTAINER_MetaData *meta;
1191 * URI for the search result.
1193 const struct GNUNET_FS_Uri *uri;
1196 * Current availability rank (negative:
1197 * unavailable, positive: available)
1199 int32_t availability_rank;
1202 * On how many total queries is the given
1203 * availability_rank based?
1205 uint32_t availability_certainty;
1208 * Updated applicability rank (the larger,
1209 * the better the result fits the search
1212 uint32_t applicability_rank;
1217 * These values are only valid for
1218 * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1219 * These events are automatically triggered for
1220 * each search result before the
1221 * GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1222 * happens primarily to give the client a chance
1223 * to clean up the "cctx" (if needed).
1228 * Private context set for for this result
1229 * during the "RESULT" event.
1234 * Metadata for the search result.
1236 const struct GNUNET_CONTAINER_MetaData *meta;
1239 * URI for the search result.
1241 const struct GNUNET_FS_Uri *uri;
1246 * These values are only valid for
1247 * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1248 * These events are automatically triggered for
1249 * each search result before the
1250 * GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1251 * happens primarily to give the client a chance
1252 * to clean up the "cctx" (if needed).
1257 * Private context set for for this result
1258 * during the "RESULT" event.
1263 * Metadata for the search result.
1265 const struct GNUNET_CONTAINER_MetaData *meta;
1268 * URI for the search result.
1270 const struct GNUNET_FS_Uri *uri;
1275 * These values are only valid for
1276 * GNUNET_FS_STATUS_SEARCH_RESUME events.
1281 * Error message, NULL if we have not encountered any error yet.
1283 const char *message;
1286 * Is this search currently paused?
1293 * These values are only valid for
1294 * GNUNET_FS_STATUS_SEARCH_ERROR events.
1301 const char *message;
1306 * Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events.
1311 * Handle to the namespace (NULL if it is not a local
1314 struct GNUNET_FS_Namespace *ns;
1317 * Short, human-readable name of the namespace.
1322 * Root identifier for the namespace, can be NULL.
1327 * Metadata for the namespace.
1329 const struct GNUNET_CONTAINER_MetaData *meta;
1332 * Hash-identifier for the namespace.
1343 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1348 * Context for controlling the unindexing.
1350 struct GNUNET_FS_UnindexContext *uc;
1353 * Client context pointer (set the last time
1354 * by the client for this operation; initially
1355 * NULL on START/RESUME events).
1360 * Name of the file that is being unindexed.
1362 const char *filename;
1365 * How large is the file overall?
1370 * At what time do we expect to finish unindexing?
1371 * (will be a value in the past for completed
1372 * unindexing opeations).
1374 struct GNUNET_TIME_Relative eta;
1377 * How long has this upload been actively running
1378 * (excludes times where the upload was suspended).
1380 struct GNUNET_TIME_Relative duration;
1383 * How many bytes have we completed?
1388 * Additional values for specific events.
1393 * These values are only valid for
1394 * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1399 * Data block we just unindexed.
1404 * At what offset in the file is "data"?
1409 * Length of the data block.
1414 * Depth of the given block in the tree;
1415 * 0 would be the highest level (the first
1416 * call is guaranteed to be for the lowest
1424 * These values are only valid for
1425 * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1430 * Error message, NULL if we have not encountered any error yet.
1432 const char *message;
1437 * These values are only valid for
1438 * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1445 const char *message;
1456 * Specific status code (determines the event type).
1458 enum GNUNET_FS_Status status;
1464 * Notification of FS to a client about the progress of an
1465 * operation. Callbacks of this type will be used for uploads,
1466 * downloads and searches. Some of the arguments depend a bit
1467 * in their meaning on the context in which the callback is used.
1469 * @param cls closure
1470 * @param info details about the event, specifying the event type
1471 * and various bits about the event
1472 * @return client-context (for the next progress call
1473 * for this operation; should be set to NULL for
1474 * SUSPEND and STOPPED events). The value returned
1475 * will be passed to future callbacks in the respective
1476 * field in the GNUNET_FS_ProgressInfo struct.
1478 typedef void* (*GNUNET_FS_ProgressCallback)
1480 const struct GNUNET_FS_ProgressInfo *info);
1484 * General (global) option flags for file-sharing.
1486 enum GNUNET_FS_Flags
1489 * No special flags set.
1491 GNUNET_FS_FLAGS_NONE = 0,
1494 * Is persistence of operations desired?
1495 * (will create SUSPEND/RESUME events).
1497 GNUNET_FS_FLAGS_PERSISTENCE = 1,
1500 * Should we automatically trigger probes for search results
1501 * to determine availability?
1502 * (will create GNUNET_FS_STATUS_SEARCH_UPDATE events).
1504 GNUNET_FS_FLAGS_DO_PROBES = 2
1509 * Options specified in the VARARGs portion of GNUNET_FS_start.
1511 enum GNUNET_FS_OPTIONS
1515 * Last option in the VARARG list.
1517 GNUNET_FS_OPTIONS_END = 0,
1520 * Select the desired amount of parallelism (this option should be
1521 * followed by an "unsigned int" giving the desired maximum number
1522 * of parallel downloads).
1524 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
1527 * Maximum number of requests that should be pending at a given
1528 * point in time (invidivual downloads may go above this, but
1529 * if we are above this threshold, we should not activate any
1530 * additional downloads.
1532 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
1538 * Handle to the file-sharing service.
1540 struct GNUNET_FS_Handle;
1544 * Setup a connection to the file-sharing service.
1546 * @param sched scheduler to use
1547 * @param cfg configuration to use
1548 * @param client_name unique identifier for this client
1549 * @param upcb function to call to notify about FS actions
1550 * @param upcb_cls closure for upcb
1551 * @param flags specific attributes for fs-operations
1552 * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
1553 * @return NULL on error
1555 struct GNUNET_FS_Handle *
1556 GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched,
1557 const struct GNUNET_CONFIGURATION_Handle *cfg,
1558 const char *client_name,
1559 GNUNET_FS_ProgressCallback upcb,
1561 enum GNUNET_FS_Flags flags,
1566 * Close our connection with the file-sharing service.
1567 * The callback given to GNUNET_FS_start will no longer be
1568 * called after this function returns.
1570 * @param h handle that was returned from GNUNET_FS_start
1573 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1577 * Extract meta-data from a file.
1579 * @param md metadata to set
1580 * @param filename name of file to inspect
1581 * @param extractors plugins to use
1582 * @return GNUNET_SYSERR on error, otherwise the number
1583 * of meta-data items obtained
1586 GNUNET_FS_meta_data_extract_from_file (struct
1587 GNUNET_CONTAINER_MetaData
1588 *md, const char *filename,
1589 struct EXTRACTOR_PluginList *
1594 * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
1596 * @param cls closure
1597 * @param fi the entry in the publish-structure
1598 * @param length length of the file or directory
1599 * @param meta metadata for the file or directory (can be modified)
1600 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1601 * @param anonymity pointer to selected anonymity level (can be modified)
1602 * @param priority pointer to selected priority (can be modified)
1603 * @param do_index should we index (can be modified)
1604 * @param expirationTime pointer to selected expiration time (can be modified)
1605 * @param client_info pointer to client context set upon creation (can be modified)
1606 * @return GNUNET_OK to continue, GNUNET_NO to remove
1607 * this entry from the directory, GNUNET_SYSERR
1608 * to abort the iteration
1610 typedef int (*GNUNET_FS_FileInformationProcessor)(void *cls,
1611 struct GNUNET_FS_FileInformation *fi,
1613 struct GNUNET_CONTAINER_MetaData *meta,
1614 struct GNUNET_FS_Uri **uri,
1615 uint32_t *anonymity,
1618 struct GNUNET_TIME_Absolute *expirationTime,
1619 void **client_info);
1623 * Obtain the name under which this file information
1624 * structure is stored on disk. Only works for top-level
1625 * file information structures.
1627 * @param s structure to get the filename for
1628 * @return NULL on error, otherwise filename that
1629 * can be passed to "GNUNET_FS_file_information_recover"
1630 * to read this fi-struct from disk.
1633 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1638 * Create an entry for a file in a publish-structure.
1640 * @param h handle to the file sharing subsystem
1641 * @param client_info initial client-info value for this entry
1642 * @param filename name of the file or directory to publish
1643 * @param keywords under which keywords should this file be available
1644 * directly; can be NULL
1645 * @param meta metadata for the file
1646 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1647 * GNUNET_SYSERR for simulation
1648 * @param anonymity what is the desired anonymity level for sharing?
1649 * @param priority what is the priority for OUR node to
1650 * keep this file available? Use 0 for maximum anonymity and
1651 * minimum reliability...
1652 * @param expirationTime when should this content expire?
1653 * @return publish structure entry for the file
1655 struct GNUNET_FS_FileInformation *
1656 GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
1658 const char *filename,
1659 const struct GNUNET_FS_Uri *keywords,
1660 const struct GNUNET_CONTAINER_MetaData *meta,
1664 struct GNUNET_TIME_Absolute expirationTime);
1668 * Create an entry for a file in a publish-structure.
1670 * @param h handle to the file sharing subsystem
1671 * @param client_info initial client-info value for this entry
1672 * @param length length of the file
1673 * @param data data for the file (should not be used afterwards by
1674 * the caller; callee will "free")
1675 * @param keywords under which keywords should this file be available
1676 * directly; can be NULL
1677 * @param meta metadata for the file
1678 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1679 * GNUNET_SYSERR for simulation
1680 * @param anonymity what is the desired anonymity level for sharing?
1681 * @param priority what is the priority for OUR node to
1682 * keep this file available? Use 0 for maximum anonymity and
1683 * minimum reliability...
1684 * @param expirationTime when should this content expire?
1685 * @return publish structure entry for the file
1687 struct GNUNET_FS_FileInformation *
1688 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
1692 const struct GNUNET_FS_Uri *keywords,
1693 const struct GNUNET_CONTAINER_MetaData *meta,
1697 struct GNUNET_TIME_Absolute expirationTime);
1701 * Function that provides data.
1703 * @param cls closure
1704 * @param offset offset to read from; it is possible
1705 * that the caller might need to go backwards
1707 * @param max maximum number of bytes that should be
1708 * copied to buf; readers are not allowed
1709 * to provide less data unless there is an error;
1710 * a value of "0" will be used at the end to allow
1711 * the reader to clean up its internal state
1712 * @param buf where the reader should write the data
1713 * @param emsg location for the reader to store an error message
1714 * @return number of bytes written, usually "max", 0 on error
1716 typedef size_t (*GNUNET_FS_DataReader)(void *cls,
1724 * Create an entry for a file in a publish-structure.
1726 * @param h handle to the file sharing subsystem
1727 * @param client_info initial client-info value for this entry
1728 * @param length length of the file
1729 * @param reader function that can be used to obtain the data for the file
1730 * @param reader_cls closure for "reader"
1731 * @param keywords under which keywords should this file be available
1732 * directly; can be NULL
1733 * @param meta metadata for the file
1734 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1735 * GNUNET_SYSERR for simulation
1736 * @param anonymity what is the desired anonymity level for sharing?
1737 * @param priority what is the priority for OUR node to
1738 * keep this file available? Use 0 for maximum anonymity and
1739 * minimum reliability...
1740 * @param expirationTime when should this content expire?
1741 * @return publish structure entry for the file
1743 struct GNUNET_FS_FileInformation *
1744 GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
1747 GNUNET_FS_DataReader reader,
1749 const struct GNUNET_FS_Uri *keywords,
1750 const struct GNUNET_CONTAINER_MetaData *meta,
1754 struct GNUNET_TIME_Absolute expirationTime);
1758 * Function that a "GNUNET_FS_DirectoryScanner" should call
1759 * for each entry in the directory.
1761 * @param cls closure
1762 * @param filename name of the file (including path); must end
1763 * in a "/" (even on W32) if this is a directory
1764 * @param fi information about the file (should not be
1765 * used henceforth by the caller)
1767 typedef void (*GNUNET_FS_FileProcessor)(void *cls,
1768 const char *filename,
1769 struct GNUNET_FS_FileInformation *fi);
1773 * Type of a function that will be used to scan a directory.
1775 * @param cls closure
1776 * @param h handle to the file sharing subsystem
1777 * @param dirname name of the directory to scan
1778 * @param do_index should files be indexed or inserted
1779 * @param anonymity desired anonymity level
1780 * @param priority priority for publishing
1781 * @param expirationTime expiration for publication
1782 * @param proc function to call on each entry
1783 * @param proc_cls closure for proc
1784 * @param emsg where to store an error message (on errors)
1785 * @return GNUNET_OK on success
1787 typedef int (*GNUNET_FS_DirectoryScanner)(void *cls,
1788 struct GNUNET_FS_Handle *h,
1789 const char *dirname,
1793 struct GNUNET_TIME_Absolute expirationTime,
1794 GNUNET_FS_FileProcessor proc,
1801 * Simple, useful default implementation of a directory scanner
1802 * (GNUNET_FS_DirectoryScanner). This implementation expects to get a
1803 * UNIX filename, will publish all files in the directory except hidden
1804 * files (those starting with a "."). Metadata will be extracted
1805 * using GNU libextractor; the specific list of plugins should be
1806 * specified in "cls", passing NULL will disable (!) metadata
1807 * extraction. Keywords will be derived from the metadata and be
1808 * subject to default canonicalization. This is strictly a
1809 * convenience function.
1811 * @param cls must be of type "struct EXTRACTOR_Extractor*"
1812 * @param h handle to the file sharing subsystem
1813 * @param dirname name of the directory to scan
1814 * @param do_index should files be indexed or inserted
1815 * @param anonymity desired anonymity level
1816 * @param priority priority for publishing
1817 * @param expirationTime expiration for publication
1818 * @param proc function called on each entry
1819 * @param proc_cls closure for proc
1820 * @param emsg where to store an error message (on errors)
1821 * @return GNUNET_OK on success
1824 GNUNET_FS_directory_scanner_default (void *cls,
1825 struct GNUNET_FS_Handle *h,
1826 const char *dirname,
1830 struct GNUNET_TIME_Absolute expirationTime,
1831 GNUNET_FS_FileProcessor proc,
1837 * Create a publish-structure from an existing file hierarchy, inferring
1838 * and organizing keywords and metadata as much as possible. This
1839 * function primarily performs the recursive build and re-organizes
1840 * keywords and metadata; for automatically getting metadata
1841 * extraction, scanning of directories and creation of the respective
1842 * GNUNET_FS_FileInformation entries the default scanner should be
1843 * passed (GNUNET_FS_directory_scanner_default). This is strictly a
1844 * convenience function.
1846 * @param h handle to the file sharing subsystem
1847 * @param client_info initial client-info value for this entry
1848 * @param filename name of the top-level file or directory
1849 * @param scanner function used to get a list of files in a directory
1850 * @param scanner_cls closure for scanner
1851 * @param do_index should files in the hierarchy be indexed?
1852 * @param anonymity what is the desired anonymity level for sharing?
1853 * @param priority what is the priority for OUR node to
1854 * keep this file available? Use 0 for maximum anonymity and
1855 * minimum reliability...
1856 * @param expirationTime when should this content expire?
1857 * @param emsg where to store an error message
1858 * @return publish structure entry for the directory, NULL on error
1860 struct GNUNET_FS_FileInformation *
1861 GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
1863 const char *filename,
1864 GNUNET_FS_DirectoryScanner scanner,
1869 struct GNUNET_TIME_Absolute expirationTime,
1874 * Create an entry for an empty directory in a publish-structure.
1875 * This function should be used by applications for which the
1876 * use of "GNUNET_FS_file_information_create_from_directory"
1877 * is not appropriate.
1879 * @param h handle to the file sharing subsystem
1880 * @param client_info initial client-info value for this entry
1881 * @param keywords under which keywords should this directory be available
1882 * directly; can be NULL
1883 * @param meta metadata for the directory
1884 * @param anonymity what is the desired anonymity level for sharing?
1885 * @param priority what is the priority for OUR node to
1886 * keep this file available? Use 0 for maximum anonymity and
1887 * minimum reliability...
1888 * @param expirationTime when should this content expire?
1889 * @return publish structure entry for the directory , NULL on error
1891 struct GNUNET_FS_FileInformation *
1892 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
1894 const struct GNUNET_FS_Uri *keywords,
1895 const struct GNUNET_CONTAINER_MetaData *meta,
1898 struct GNUNET_TIME_Absolute expirationTime);
1902 * Test if a given entry represents a directory.
1904 * @param ent check if this FI represents a directory
1905 * @return GNUNET_YES if so, GNUNET_NO if not
1908 GNUNET_FS_file_information_is_directory (struct GNUNET_FS_FileInformation *ent);
1912 * Add an entry to a directory in a publish-structure. Clients
1913 * should never modify publish structures that were passed to
1914 * "GNUNET_FS_publish_start" already.
1916 * @param dir the directory
1917 * @param ent the entry to add; the entry must not have been
1918 * added to any other directory at this point and
1919 * must not include "dir" in its structure
1920 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1923 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1924 struct GNUNET_FS_FileInformation *ent);
1928 * Inspect a file or directory in a publish-structure. Clients
1929 * should never modify publish structures that were passed to
1930 * "GNUNET_FS_publish_start" already. When called on a directory,
1931 * this function will FIRST call "proc" with information about
1932 * the directory itself and then for each of the files in the
1933 * directory (but not for files in subdirectories). When called
1934 * on a file, "proc" will be called exactly once (with information
1935 * about the specific file).
1937 * @param dir the directory
1938 * @param proc function to call on each entry
1939 * @param proc_cls closure for proc
1942 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1943 GNUNET_FS_FileInformationProcessor proc,
1948 * Destroy publish-structure. Clients should never destroy publish
1949 * structures that were passed to "GNUNET_FS_publish_start" already.
1951 * @param fi structure to destroy
1952 * @param cleaner function to call on each entry in the structure
1953 * (useful to clean up client_info); can be NULL; return
1954 * values are ignored
1955 * @param cleaner_cls closure for cleaner
1958 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
1959 GNUNET_FS_FileInformationProcessor cleaner,
1964 * Options for publishing. Compatible options
1965 * can be OR'ed together.
1967 enum GNUNET_FS_PublishOptions
1970 * No options (use defaults for everything).
1972 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
1975 * Simulate publishing. With this option, no data will be stored
1976 * in the datastore. Useful for computing URIs from files.
1978 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
1982 * Publish a file or directory.
1984 * @param h handle to the file sharing subsystem
1985 * @param fi information about the file or directory structure to publish
1986 * @param namespace namespace to publish the file in, NULL for no namespace
1987 * @param nid identifier to use for the publishd content in the namespace
1988 * (can be NULL, must be NULL if namespace is NULL)
1989 * @param nuid update-identifier that will be used for future updates
1990 * (can be NULL, must be NULL if namespace or nid is NULL)
1991 * @param options options for the publication
1992 * @return context that can be used to control the publish operation
1994 struct GNUNET_FS_PublishContext *
1995 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1996 struct GNUNET_FS_FileInformation *fi,
1997 struct GNUNET_FS_Namespace *namespace,
2000 enum GNUNET_FS_PublishOptions options);
2004 * Stop a publication. Will abort incomplete publications (but
2005 * not remove blocks that have already been published) or
2006 * simply clean up the state for completed publications.
2007 * Must NOT be called from within the event callback!
2009 * @param pc context for the publication to stop
2012 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
2016 * Signature of a function called as the continuation of a KBlock or
2017 * SBlock publication.
2019 * @param cls closure
2020 * @param uri URI under which the block is now available, NULL on error
2021 * @param emsg error message, NULL on success
2023 typedef void (*GNUNET_FS_PublishContinuation)(void *cls,
2024 const struct GNUNET_FS_Uri *uri,
2029 * Publish a KBlock on GNUnet.
2031 * @param h handle to the file sharing subsystem
2032 * @param ksk_uri keywords to use
2033 * @param meta metadata to use
2034 * @param uri URI to refer to in the KBlock
2035 * @param expirationTime when the KBlock expires
2036 * @param anonymity anonymity level for the KBlock
2037 * @param priority priority for the KBlock
2038 * @param cont continuation
2039 * @param cont_cls closure for cont
2042 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2043 const struct GNUNET_FS_Uri *ksk_uri,
2044 const struct GNUNET_CONTAINER_MetaData *meta,
2045 const struct GNUNET_FS_Uri *uri,
2046 struct GNUNET_TIME_Absolute expirationTime,
2049 enum GNUNET_FS_PublishOptions options,
2050 GNUNET_FS_PublishContinuation cont,
2055 * Publish an SBlock on GNUnet.
2057 * @param h handle to the file sharing subsystem
2058 * @param namespace namespace to publish in
2059 * @param identifier identifier to use
2060 * @param update update identifier to use
2061 * @param meta metadata to use
2062 * @param uri URI to refer to in the SBlock
2063 * @param expirationTime when the SBlock expires
2064 * @param anonymity anonymity level for the SBlock
2065 * @param priority priority for the SBlock
2066 * @param cont continuation
2067 * @param cont_cls closure for cont
2070 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2071 struct GNUNET_FS_Namespace *namespace,
2072 const char *identifier,
2074 const struct GNUNET_CONTAINER_MetaData *meta,
2075 const struct GNUNET_FS_Uri *uri,
2076 struct GNUNET_TIME_Absolute expirationTime,
2079 enum GNUNET_FS_PublishOptions options,
2080 GNUNET_FS_PublishContinuation cont,
2085 * Type of a function called by "GNUNET_FS_get_indexed_files".
2087 * @param cls closure
2088 * @param filename the name of the file
2089 * @param file_id hash of the contents of the indexed file
2090 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
2092 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls,
2093 const char *filename,
2094 const GNUNET_HashCode *file_id);
2098 * Iterate over all indexed files.
2100 * @param h handle to the file sharing subsystem
2101 * @param iterator function to call on each indexed file
2102 * @param iterator_cls closure for iterator
2103 * @param cont continuation to call when done;
2104 * reason should be "TIMEOUT" (on
2105 * error) or "PREREQ_DONE" (on success)
2106 * @param cont_cls closure for cont
2109 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2110 GNUNET_FS_IndexedFileProcessor iterator,
2112 GNUNET_SCHEDULER_Task cont,
2119 * @param h handle to the file sharing subsystem
2120 * @param filename file to unindex
2121 * @param cctx initial value for the client context
2122 * @return NULL on error, otherwise handle
2124 struct GNUNET_FS_UnindexContext *
2125 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
2126 const char *filename,
2131 * Clean up after completion of an unindex operation.
2136 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2140 * Publish an advertismement for a namespace.
2142 * @param h handle to the file sharing subsystem
2143 * @param ksk_uri keywords to use for advertisment
2144 * @param namespace handle for the namespace that should be advertised
2145 * @param meta meta-data for the namespace advertisement
2146 * @param anonymity for the namespace advertismement
2147 * @param priority for the namespace advertisement
2148 * @param expiration for the namespace advertisement
2149 * @param rootEntry name of the root of the namespace
2150 * @param cont continuation
2151 * @param cont_cls closure for cont
2154 GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
2155 struct GNUNET_FS_Uri *ksk_uri,
2156 struct GNUNET_FS_Namespace *namespace,
2157 const struct GNUNET_CONTAINER_MetaData *meta,
2160 struct GNUNET_TIME_Absolute expiration,
2161 const char *rootEntry,
2162 GNUNET_FS_PublishContinuation cont,
2167 * Create a namespace with the given name; if one already
2168 * exists, return a handle to the existing namespace.
2170 * @param h handle to the file sharing subsystem
2171 * @param name name to use for the namespace
2172 * @return handle to the namespace, NULL on error
2174 struct GNUNET_FS_Namespace *
2175 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h,
2180 * Delete a namespace handle. Can be used for a clean shutdown (free
2181 * memory) or also to freeze the namespace to prevent further
2182 * insertions by anyone.
2184 * @param namespace handle to the namespace that should be deleted / freed
2185 * @param freeze prevents future insertions; creating a namespace
2186 * with the same name again will create a fresh namespace instead
2188 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2191 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace,
2196 * Callback with information about local (!) namespaces.
2197 * Contains the names of the local namespace and the global
2200 * @param cls closure
2201 * @param name human-readable identifier of the namespace
2202 * @param id hash identifier for the namespace
2204 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls,
2206 const GNUNET_HashCode *id);
2210 * Build a list of all available local (!) namespaces The returned
2211 * names are only the nicknames since we only iterate over the local
2214 * @param h handle to the file sharing subsystem
2215 * @param cb function to call on each known namespace
2216 * @param cb_cls closure for cb
2219 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2220 GNUNET_FS_NamespaceInfoProcessor cb,
2225 * Function called on updateable identifiers.
2227 * @param cls closure
2228 * @param last_id last identifier
2229 * @param last_uri uri used for the content published under the last_id
2230 * @param last_meta metadata associated with last_uri
2231 * @param next_id identifier that should be used for updates
2234 (*GNUNET_FS_IdentifierProcessor)(void *cls,
2235 const char *last_id,
2236 const struct GNUNET_FS_Uri *last_uri,
2237 const struct GNUNET_CONTAINER_MetaData *last_meta,
2238 const char *next_id);
2242 * List all of the identifiers in the namespace for
2243 * which we could produce an update.
2245 * @param namespace namespace to inspect for updateable content
2246 * @param ip function to call on each updateable identifier
2247 * @param ip_cls closure for ip
2250 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
2251 GNUNET_FS_IdentifierProcessor ip,
2256 * Options for searching. Compatible options
2257 * can be OR'ed together.
2259 enum GNUNET_FS_SearchOptions
2262 * No options (use defaults for everything).
2264 GNUNET_FS_SEARCH_OPTION_NONE = 0,
2267 * Only search the local host, do not search remote systems (no P2P)
2269 GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
2275 * Start search for content.
2277 * @param h handle to the file sharing subsystem
2278 * @param uri specifies the search parameters; can be
2279 * a KSK URI or an SKS URI.
2280 * @param anonymity desired level of anonymity
2281 * @param options options for the search
2282 * @param cctx initial value for the client context
2283 * @return context that can be used to control the search
2285 struct GNUNET_FS_SearchContext *
2286 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2287 const struct GNUNET_FS_Uri *uri,
2289 enum GNUNET_FS_SearchOptions options,
2296 * @param sc context for the search that should be paused
2299 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2303 * Continue paused search.
2305 * @param sc context for the search that should be resumed
2308 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2312 * Stop search for content.
2314 * @param sc context for the search that should be stopped
2317 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2323 * Options for downloading. Compatible options
2324 * can be OR'ed together.
2326 enum GNUNET_FS_DownloadOptions
2329 * No options (use defaults for everything).
2331 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2334 * Only download from the local host, do not access remote systems (no P2P)
2336 GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
2339 * Do a recursive download (that is, automatically trigger the
2340 * download of files in directories).
2342 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
2345 * Do not append temporary data to
2346 * the target file (for the IBlocks).
2348 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
2351 * Internal option used to flag this download as a 'probe' for a
2352 * search result. Impacts the priority with which the download is
2353 * run and causes signalling callbacks to be done differently.
2354 * Also, probe downloads are not serialized on suspension. Normal
2355 * clients should not use this!
2357 GNUNET_FS_DOWNLOAD_IS_PROBE = (1<<31)
2364 * Download parts of a file. Note that this will store
2365 * the blocks at the respective offset in the given file. Also, the
2366 * download is still using the blocking of the underlying FS
2367 * encoding. As a result, the download may *write* outside of the
2368 * given boundaries (if offset and length do not match the 32k FS
2369 * block boundaries). <p>
2371 * The given range can be used to focus a download towards a
2372 * particular portion of the file (optimization), not to strictly
2373 * limit the download to exactly those bytes.
2375 * @param h handle to the file sharing subsystem
2376 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2377 * @param meta known metadata for the file (can be NULL)
2378 * @param filename where to store the file, maybe NULL (then no file is
2379 * created on disk and data must be grabbed from the callbacks)
2380 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2381 * can be NULL (in which case we will pick a name if needed); the temporary file
2382 * may already exist, in which case we will try to use the data that is there and
2383 * if it is not what is desired, will overwrite it
2384 * @param offset at what offset should we start the download (typically 0)
2385 * @param length how many bytes should be downloaded starting at offset
2386 * @param anonymity anonymity level to use for the download
2387 * @param options various download options
2388 * @param cctx initial value for the client context for this download
2389 * @param parent parent download to associate this download with (use NULL
2390 * for top-level downloads; useful for manually-triggered recursive downloads)
2391 * @return context that can be used to control this download
2393 struct GNUNET_FS_DownloadContext *
2394 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2395 const struct GNUNET_FS_Uri *uri,
2396 const struct GNUNET_CONTAINER_MetaData *meta,
2397 const char *filename,
2398 const char *tempname,
2402 enum GNUNET_FS_DownloadOptions options,
2404 struct GNUNET_FS_DownloadContext *parent);
2408 * Download parts of a file based on a search result. The download
2409 * will be associated with the search result (and the association
2410 * will be preserved when serializing/deserializing the state).
2411 * If the search is stopped, the download will not be aborted but
2412 * be 'promoted' to a stand-alone download.
2414 * As with the other download function, this will store
2415 * the blocks at the respective offset in the given file. Also, the
2416 * download is still using the blocking of the underlying FS
2417 * encoding. As a result, the download may *write* outside of the
2418 * given boundaries (if offset and length do not match the 32k FS
2419 * block boundaries). <p>
2421 * The given range can be used to focus a download towards a
2422 * particular portion of the file (optimization), not to strictly
2423 * limit the download to exactly those bytes.
2425 * @param h handle to the file sharing subsystem
2426 * @param sr the search result to use for the download (determines uri and
2427 * meta data and associations)
2428 * @param filename where to store the file, maybe NULL (then no file is
2429 * created on disk and data must be grabbed from the callbacks)
2430 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2431 * can be NULL (in which case we will pick a name if needed); the temporary file
2432 * may already exist, in which case we will try to use the data that is there and
2433 * if it is not what is desired, will overwrite it
2434 * @param offset at what offset should we start the download (typically 0)
2435 * @param length how many bytes should be downloaded starting at offset
2436 * @param anonymity anonymity level to use for the download
2437 * @param options various download options
2438 * @param cctx initial value for the client context for this download
2439 * @return context that can be used to control this download
2441 struct GNUNET_FS_DownloadContext *
2442 GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2443 struct GNUNET_FS_SearchResult *sr,
2444 const char *filename,
2445 const char *tempname,
2449 enum GNUNET_FS_DownloadOptions options,
2454 * Stop a download (aborts if download is incomplete).
2456 * @param dc handle for the download
2457 * @param do_delete delete files of incomplete downloads
2460 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
2465 * Initialize collection.
2467 * @param h handle to the file sharing subsystem
2468 * @param namespace namespace to use for the collection
2469 * @return GNUNET_OK on success, GNUNET_SYSERR if another
2470 * namespace is already set for our collection
2473 GNUNET_FS_collection_start (struct GNUNET_FS_Handle *h,
2474 struct GNUNET_FS_Namespace *namespace);
2480 * @param h handle to the file sharing subsystem
2481 * @return GNUNET_OK on success, GNUNET_SYSERR if no collection is active
2484 GNUNET_FS_collection_stop (struct GNUNET_FS_Handle *h);
2488 * Are we using a collection?
2490 * @param h handle to the file sharing subsystem
2491 * @return NULL if there is no collection,
2493 struct GNUNET_FS_Namespace *
2494 GNUNET_FS_collection_get(struct GNUNET_FS_Handle *h);
2498 * Publish an update of the current collection information to the
2499 * network now. The function has no effect if the collection has not
2500 * changed since the last publication. If we are currently not
2501 * collecting, this function does nothing.
2503 * @param h handle to the file sharing subsystem
2505 void GNUNET_FS_collection_publish (struct GNUNET_FS_Handle *h);
2509 * If we are currently building a collection, publish the given file
2510 * information in that collection. If we are currently not
2511 * collecting, this function does nothing.
2513 * @param h handle to the file sharing subsystem
2514 * @param uri uri to add to the collection
2515 * @param meta metadata for the uri
2517 void GNUNET_FS_collection_add (const struct GNUNET_FS_Handle *h,
2518 const struct GNUNET_FS_Uri *uri,
2519 const struct GNUNET_CONTAINER_MetaData *meta);
2525 /* ******************** Directory API *********************** */
2528 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2529 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2530 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2533 * Does the meta-data claim that this is a directory?
2534 * Checks if the mime-type is that of a GNUnet directory.
2536 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2537 * we have no mime-type information (treat as 'GNUNET_NO')
2540 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData *md);
2544 * Set the MIMETYPE information for the given
2545 * metadata to "application/gnunet-directory".
2547 * @param md metadata to add mimetype to
2550 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2554 * Suggest a filename based on given metadata.
2556 * @param md given meta data
2557 * @return NULL if meta data is useless for suggesting a filename
2560 GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData *md);
2564 * Function used to process entries in a directory.
2566 * @param cls closure
2567 * @param filename name of the file in the directory
2568 * @param uri URI of the file
2569 * @param metadata metadata for the file; metadata for
2570 * the directory if everything else is NULL/zero
2571 * @param length length of the available data for the file
2572 * (of type size_t since data must certainly fit
2573 * into memory; if files are larger than size_t
2574 * permits, then they will certainly not be
2575 * embedded with the directory itself).
2576 * @param data data available for the file (length bytes)
2578 typedef void (*GNUNET_FS_DirectoryEntryProcessor)(void *cls,
2579 const char *filename,
2580 const struct GNUNET_FS_Uri *uri,
2581 const struct GNUNET_CONTAINER_MetaData *meta,
2587 * Iterate over all entries in a directory. Note that directories
2588 * are structured such that it is possible to iterate over the
2589 * individual blocks as well as over the entire directory. Thus
2590 * a client can call this function on the buffer in the
2591 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2592 * include the contents of (small) files embedded in the directory
2593 * itself; for those files, the processor may be given the
2594 * contents of the file directly by this function.
2596 * @param size number of bytes in data
2597 * @param data pointer to the beginning of the directory
2598 * @param offset offset of data in the directory
2599 * @param dep function to call on each entry
2600 * @param dep_cls closure for dep
2603 GNUNET_FS_directory_list_contents (size_t size,
2606 GNUNET_FS_DirectoryEntryProcessor dep,
2611 * Opaque handle to a directory builder.
2613 struct GNUNET_FS_DirectoryBuilder;
2616 * Create a directory builder.
2618 * @param mdir metadata for the directory
2620 struct GNUNET_FS_DirectoryBuilder *
2621 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData *mdir);
2625 * Add an entry to a directory.
2627 * @param bld directory to extend
2628 * @param uri uri of the entry (must not be a KSK)
2629 * @param md metadata of the entry
2630 * @param data raw data of the entry, can be NULL, otherwise
2631 * data must point to exactly the number of bytes specified
2635 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2636 const struct GNUNET_FS_Uri *uri,
2637 const struct GNUNET_CONTAINER_MetaData *md,
2642 * Finish building the directory. Frees the
2643 * builder context and returns the directory
2646 * @param bld directory to finish
2647 * @param rsize set to the number of bytes needed
2648 * @param rdata set to the encoded directory
2649 * @return GNUNET_OK on success
2652 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2657 #if 0 /* keep Emacsens' auto-indent happy */