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 3, 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 0x00090001
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, const char *keyword,
86 * Get a unique key from a URI. This is for putting URIs
87 * into HashMaps. The key may change between FS implementations.
89 * @param uri uri to convert to a unique key
90 * @param key wherer to store the unique key
93 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, GNUNET_HashCode * key);
96 * Convert a URI to a UTF-8 String.
98 * @param uri uri to convert to a string
99 * @return the UTF-8 string
102 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
105 * Convert keyword URI to a human readable format
106 * (i.e. the search query that was used in the first place)
108 * @param uri ksk uri to convert to a string
109 * @return string with the keywords
112 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
116 * Add the given keyword to the set of keywords represented by the URI.
117 * Does nothing if the keyword is already present.
119 * @param uri ksk uri to modify
120 * @param keyword keyword to add
121 * @param is_mandatory is this keyword mandatory?
124 GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, const char *keyword,
129 * Remove the given keyword from the set of keywords represented by the URI.
130 * Does nothing if the keyword is not present.
132 * @param uri ksk uri to modify
133 * @param keyword keyword to add
136 GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
137 const char *keyword);
141 * Convert a UTF-8 String to a URI.
143 * @param uri string to parse
144 * @param emsg where to store the parser error message (if any)
145 * @return NULL on error
147 struct GNUNET_FS_Uri *
148 GNUNET_FS_uri_parse (const char *uri, char **emsg);
153 * @param uri uri to free
156 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
160 * How many keywords are ANDed in this keyword URI?
162 * @param uri ksk uri to get the number of keywords from
163 * @return 0 if this is not a keyword URI
166 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
170 * Iterate over all keywords in this keyword URI.
172 * @param uri ksk uri to get the keywords from
173 * @param iterator function to call on each keyword
174 * @param iterator_cls closure for iterator
175 * @return -1 if this is not a keyword URI, otherwise number of
176 * keywords iterated over until iterator aborted
179 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
180 GNUNET_FS_KeywordIterator iterator,
185 * Obtain the identity of the peer offering the data
187 * @param uri the location URI to inspect
188 * @param peer where to store the identify of the peer (presumably) offering the content
189 * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK
192 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
193 struct GNUNET_PeerIdentity *peer);
197 * Obtain the URI of the content itself.
199 * @param uri location URI to get the content URI from
200 * @return NULL if argument is not a location URI
202 struct GNUNET_FS_Uri *
203 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
207 * Obtain the expiration of the LOC URI.
209 * @param uri location URI to get the expiration from
210 * @return expiration time of the URI
212 struct GNUNET_TIME_Absolute
213 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
217 * Construct a location URI (this peer will be used for the location).
219 * @param baseUri content offered by the sender
220 * @param cfg configuration information (used to find our hostkey)
221 * @param expiration_time how long will the content be offered?
222 * @return the location URI, NULL on error
224 struct GNUNET_FS_Uri *
225 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
226 const struct GNUNET_CONFIGURATION_Handle *cfg,
227 struct GNUNET_TIME_Absolute expiration_time);
231 * Merge the sets of keywords from two KSK URIs.
233 * @param u1 first uri
234 * @param u2 second uri
235 * @return merged URI, NULL on error
237 struct GNUNET_FS_Uri *
238 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
239 const struct GNUNET_FS_Uri *u2);
245 * @param uri the URI to duplicate
246 * @return copy of the URI
248 struct GNUNET_FS_Uri *
249 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
253 * Create an FS URI from a single user-supplied string of keywords.
254 * The string is broken up at spaces into individual keywords.
255 * Keywords that start with "+" are mandatory. Double-quotes can
256 * be used to prevent breaking up strings at spaces (and also
257 * to specify non-mandatory keywords starting with "+").
259 * Keywords must contain a balanced number of double quotes and
260 * double quotes can not be used in the actual keywords (for
261 * example, the string '""foo bar""' will be turned into two
262 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
264 * @param keywords the keyword string
265 * @param emsg where to store an error message
266 * @return an FS URI for the given keywords, NULL
267 * if keywords is not legal (i.e. empty).
269 struct GNUNET_FS_Uri *
270 GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg);
274 * Create an FS URI from a user-supplied command line of keywords.
275 * Arguments should start with "+" to indicate mandatory
278 * @param argc number of keywords
279 * @param argv keywords (double quotes are not required for
280 * keywords containing spaces; however, double
281 * quotes are required for keywords starting with
282 * "+"); there is no mechanism for having double
283 * quotes in the actual keywords (if the user
284 * did specifically specify double quotes, the
285 * caller should convert each double quote
286 * into two single quotes).
287 * @return an FS URI for the given keywords, NULL
288 * if keywords is not legal (i.e. empty).
290 struct GNUNET_FS_Uri *
291 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv);
295 * Test if two URIs are equal.
297 * @param u1 one of the URIs
298 * @param u2 the other URI
299 * @return GNUNET_YES if the URIs are equal
302 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
303 const struct GNUNET_FS_Uri *u2);
307 * Is this a namespace URI?
309 * @param uri the uri to check
310 * @return GNUNET_YES if this is an SKS uri
313 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
317 * Handle to one of our namespaces.
319 struct GNUNET_FS_Namespace;
323 * Create an SKS URI from a namespace and an identifier.
325 * @param ns namespace
326 * @param id identifier
327 * @param emsg where to store an error message
328 * @return an FS URI for the given namespace and identifier
330 struct GNUNET_FS_Uri *
331 GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id,
336 * Create an SKS URI from a namespace ID and an identifier.
338 * @param nsid namespace ID
339 * @param id identifier
340 * @return an FS URI for the given namespace and identifier
342 struct GNUNET_FS_Uri *
343 GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode * nsid, const char *id);
347 * Get the ID of a namespace from the given
350 * @param uri the uri to get the namespace ID from
351 * @param nsid where to store the ID of the namespace
352 * @return GNUNET_OK on success
355 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
356 GNUNET_HashCode * nsid);
360 * Get the content identifier of an SKS URI.
362 * @param uri the sks uri
363 * @return NULL on error (not a valid SKS URI)
366 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
370 * Convert namespace URI to a human readable format
371 * (using the namespace description, if available).
373 * @param cfg configuration to use
374 * @param uri SKS uri to convert
375 * @return NULL on error (not an SKS URI)
378 GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
379 const struct GNUNET_FS_Uri *uri);
383 * Is this a keyword URI?
386 * @return GNUNET_YES if this is a KSK uri
389 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
393 * Is this a file (or directory) URI?
395 * @param uri the uri to check
396 * @return GNUNET_YES if this is a CHK uri
399 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
403 * What is the size of the file that this URI
406 * @param uri the CHK (or LOC) URI to inspect
407 * @return size of the file as specified in the CHK URI
410 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
414 * Is this a location URI?
416 * @param uri the uri to check
417 * @return GNUNET_YES if this is a LOC uri
420 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
424 * Construct a keyword-URI from meta-data (take all entries
425 * in the meta-data and construct one large keyword URI
426 * that lists all keywords that can be found in the meta-data).
428 * @param md metadata to use
429 * @return NULL on error, otherwise a KSK URI
431 struct GNUNET_FS_Uri *
432 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
436 /* ******************** command-line option parsing API *********************** */
439 * Command-line option parser function that allows the user
440 * to specify one or more '-k' options with keywords. Each
441 * specified keyword will be added to the URI. A pointer to
442 * the URI must be passed as the "scls" argument.
444 * @param ctx command line processor context
445 * @param scls must be of type "struct GNUNET_FS_Uri **"
446 * @param option name of the option (typically 'k')
447 * @param value command line argument given
448 * @return GNUNET_OK on success
451 GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext
452 *ctx, void *scls, const char *option,
457 * Command-line option parser function that allows the user to specify
458 * one or more '-m' options with metadata. Each specified entry of
459 * the form "type=value" will be added to the metadata. A pointer to
460 * the metadata must be passed as the "scls" argument.
462 * @param ctx command line processor context
463 * @param scls must be of type "struct GNUNET_CONTAINER_MetaData **"
464 * @param option name of the option (typically 'k')
465 * @param value command line argument given
466 * @return GNUNET_OK on success
469 GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext
470 *ctx, void *scls, const char *option,
475 /* ************************* sharing API ***************** */
479 * Possible status codes used in the callback for the
480 * various file-sharing operations. On each file (or search),
481 * the callback is guaranteed to be called once with "START"
482 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
483 * are optional and depend on the circumstances; parent operations
484 * will be STARTED before child-operations and STOPPED after
485 * their respective child-operations. START and STOP signals
486 * are typically generated either due to explicit client requests
487 * or because of suspend/resume operations.
489 enum GNUNET_FS_Status
492 * Notification that we have started to publish a file structure.
494 GNUNET_FS_STATUS_PUBLISH_START = 0,
497 * Notification that we have resumed sharing a file structure.
499 GNUNET_FS_STATUS_PUBLISH_RESUME = 1,
502 * Notification that we have suspended sharing a file structure.
504 GNUNET_FS_STATUS_PUBLISH_SUSPEND = 2,
507 * Notification that we are making progress sharing a file structure.
509 GNUNET_FS_STATUS_PUBLISH_PROGRESS = 3,
512 * Notification that an error was encountered sharing a file structure.
513 * The application will continue to receive resume/suspend events for
514 * this structure until "GNUNET_FS_publish_stop" is called.
516 GNUNET_FS_STATUS_PUBLISH_ERROR = 4,
519 * Notification that we completed sharing a file structure.
520 * The application will continue to receive resume/suspend events for
521 * this structure until "GNUNET_FS_publish_stop" is called.
523 GNUNET_FS_STATUS_PUBLISH_COMPLETED = 5,
526 * Notification that we have stopped
527 * the process of uploading a file structure; no
528 * futher events will be generated for this action.
530 GNUNET_FS_STATUS_PUBLISH_STOPPED = 6,
533 * Notification that we have started this download.
535 GNUNET_FS_STATUS_DOWNLOAD_START = 7,
538 * Notification that this download is being resumed.
540 GNUNET_FS_STATUS_DOWNLOAD_RESUME = 8,
543 * Notification that this download was suspended.
545 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND = 9,
548 * Notification about progress with this download.
550 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS = 10,
553 * Notification that this download encountered an error.
555 GNUNET_FS_STATUS_DOWNLOAD_ERROR = 11,
558 * Notification that this download completed. Note that for
559 * directories, completion does not imply completion of all files in
562 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED = 12,
565 * Notification that this download was stopped
566 * (final event with respect to this action).
568 GNUNET_FS_STATUS_DOWNLOAD_STOPPED = 13,
571 * Notification that this download is now actively being
572 * pursued (as opposed to waiting in the queue).
574 GNUNET_FS_STATUS_DOWNLOAD_ACTIVE = 14,
577 * Notification that this download is no longer actively
578 * being pursued (back in the queue).
580 GNUNET_FS_STATUS_DOWNLOAD_INACTIVE = 15,
583 * Notification that this download is no longer part of a
584 * recursive download or search but now a 'stand-alone'
585 * download (and may thus need to be moved in the GUI
586 * into a different category).
588 GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT = 16,
591 * First event generated when a client requests
592 * a search to begin or when a namespace result
593 * automatically triggers the search for updates.
595 GNUNET_FS_STATUS_SEARCH_START = 17,
598 * Last event when a search is being resumed;
599 * note that "GNUNET_FS_SEARCH_START" will not
600 * be generated in this case.
602 GNUNET_FS_STATUS_SEARCH_RESUME = 18,
605 * Event generated for each search result
606 * when the respective search is resumed.
608 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT = 19,
611 * Last event when a search is being suspended;
612 * note that "GNUNET_FS_SEARCH_STOPPED" will not
613 * be generated in this case.
615 GNUNET_FS_STATUS_SEARCH_SUSPEND = 20,
618 * This search has yielded a result.
620 GNUNET_FS_STATUS_SEARCH_RESULT = 21,
623 * We have discovered a new namespace.
625 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE = 22,
628 * We have additional data about the quality
629 * or availability of a search result.
631 GNUNET_FS_STATUS_SEARCH_UPDATE = 23,
634 * Signals a problem with this search.
636 GNUNET_FS_STATUS_SEARCH_ERROR = 24,
639 * Signals that this search was paused.
641 GNUNET_FS_STATUS_SEARCH_PAUSED = 25,
644 * Signals that this search was continued (unpaused).
646 GNUNET_FS_STATUS_SEARCH_CONTINUED = 26,
649 * Event generated for each search result
650 * when the respective search is stopped.
652 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED = 27,
655 * Event generated for each search result
656 * when the respective search is suspended.
658 GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND = 28,
661 * Last message from a search; this signals
662 * that there will be no further events associated
665 GNUNET_FS_STATUS_SEARCH_STOPPED = 29,
668 * Notification that we started to unindex a file.
670 GNUNET_FS_STATUS_UNINDEX_START = 30,
673 * Notification that we resumed unindexing of a file.
675 GNUNET_FS_STATUS_UNINDEX_RESUME = 31,
678 * Notification that we suspended unindexing a file.
680 GNUNET_FS_STATUS_UNINDEX_SUSPEND = 32,
683 * Notification that we made progress unindexing a file.
685 GNUNET_FS_STATUS_UNINDEX_PROGRESS = 33,
688 * Notification that we encountered an error unindexing
691 GNUNET_FS_STATUS_UNINDEX_ERROR = 34,
694 * Notification that the unindexing of this file
697 GNUNET_FS_STATUS_UNINDEX_COMPLETED = 35,
700 * Notification that the unindexing of this file
701 * was stopped (final event for this action).
703 GNUNET_FS_STATUS_UNINDEX_STOPPED = 36
708 * Handle for controlling an upload.
710 struct GNUNET_FS_PublishContext;
714 * Handle for controlling an unindexing operation.
716 struct GNUNET_FS_UnindexContext;
720 * Handle for controlling a search.
722 struct GNUNET_FS_SearchContext;
726 * Result from a search. Opaque handle to refer to the search
727 * (typically used when starting a download associated with the search
730 struct GNUNET_FS_SearchResult;
734 * Context for controlling a download.
736 struct GNUNET_FS_DownloadContext;
740 * Handle for detail information about a file that is being publishd.
741 * Specifies metadata, keywords, how to get the contents of the file
742 * (i.e. data-buffer in memory, filename on disk) and other options.
744 struct GNUNET_FS_FileInformation;
748 * Argument given to the progress callback with
749 * information about what is going on.
751 struct GNUNET_FS_ProgressInfo
755 * Values that depend on the event type.
761 * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
767 * Context for controlling the upload.
769 struct GNUNET_FS_PublishContext *pc;
772 * Information about the file that is being publishd.
774 const struct GNUNET_FS_FileInformation *fi;
777 * Client context pointer (set the last time by the client for
778 * this operation; initially NULL on START/RESUME events).
783 * Client context pointer for the parent operation
784 * (if this is a file in a directory or a subdirectory).
789 * Name of the file being published; can be NULL.
791 const char *filename;
794 * How large is the file overall? For directories,
795 * this is only the size of the directory itself,
796 * not of the other files contained within the
802 * At what time do we expect to finish the upload?
803 * (will be a value in the past for completed
806 struct GNUNET_TIME_Relative eta;
809 * How long has this upload been actively running
810 * (excludes times where the upload was suspended).
812 struct GNUNET_TIME_Relative duration;
815 * How many bytes have we completed?
820 * What anonymity level is used for this upload?
825 * Additional values for specific events.
831 * These values are only valid for
832 * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
838 * Data block we just published.
843 * At what offset in the file is "data"?
848 * Length of the data block.
853 * Depth of the given block in the tree;
854 * 0 would be the lowest level (DBLOCKs).
861 * These values are only valid for
862 * GNUNET_FS_STATUS_PUBLISH_RESUME events.
868 * Error message, NULL if no error was encountered so far.
873 * URI of the file (if the download had been completed)
875 const struct GNUNET_FS_Uri *chk_uri;
880 * These values are only valid for
881 * GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
889 const struct GNUNET_FS_Uri *chk_uri;
894 * These values are only valid for
895 * GNUNET_FS_STATUS_PUBLISH_ERROR events.
901 * Error message, never NULL.
913 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
919 * Context for controlling the download.
921 struct GNUNET_FS_DownloadContext *dc;
924 * Client context pointer (set the last time
925 * by the client for this operation; initially
926 * NULL on START/RESUME events).
931 * Client context pointer for the parent operation
932 * (if this is a file in a directory or a subdirectory).
937 * Client context pointer for the associated search operation
938 * (specifically, context pointer for the specific search
939 * result, not the overall search); only set if this
940 * download was started from a search result.
945 * URI used for this download.
947 const struct GNUNET_FS_Uri *uri;
950 * Name of the file that we are downloading.
952 const char *filename;
955 * How large is the download overall? This
956 * is NOT necessarily the size from the
957 * URI since we may be doing a partial download.
962 * At what time do we expect to finish the download?
963 * (will be a value in the past for completed
966 struct GNUNET_TIME_Relative eta;
969 * How long has this download been active?
971 struct GNUNET_TIME_Relative duration;
974 * How many bytes have we completed?
979 * What anonymity level is used for this download?
984 * Is the download currently active.
989 * Additional values for specific events.
995 * These values are only valid for
996 * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
1002 * Data block we just obtained, can be NULL (even if
1003 * data_len > 0) if we found the entire block 'intact' on
1004 * disk. In this case, it is also possible for 'data_len'
1005 * to be larger than an individual (32k) block.
1010 * At what offset in the file is "data"?
1015 * Length of the data block.
1020 * Depth of the given block in the tree;
1021 * 0 would be the lowest level (DBLOCKS).
1026 * How much trust did we offer for downloading this block?
1028 unsigned int trust_offered;
1033 * These values are only valid for
1034 * GNUNET_FS_STATUS_DOWNLOAD_START events.
1040 * Known metadata for the download.
1042 const struct GNUNET_CONTAINER_MetaData *meta;
1047 * These values are only valid for
1048 * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
1054 * Known metadata for the download.
1056 const struct GNUNET_CONTAINER_MetaData *meta;
1059 * Error message, NULL if we have not encountered any error yet.
1061 const char *message;
1066 * These values are only valid for
1067 * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1075 const char *message;
1084 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1090 * Context for controlling the search, NULL for
1091 * searches that were not explicitly triggered
1092 * by the client (i.e., searches for updates in
1095 struct GNUNET_FS_SearchContext *sc;
1098 * Client context pointer (set the last time by the client for
1099 * this operation; initially NULL on START/RESUME events). Note
1100 * that this value can only be set on START/RESUME; returning
1101 * non-NULL on RESULT/RESUME_RESULT will actually update the
1102 * private context for "UPDATE" events.
1107 * Client parent-context pointer; NULL for top-level searches,
1108 * refers to the client context of the associated search result
1109 * for automatically triggered searches for updates in
1110 * namespaces. In this case, 'presult' refers to that search
1116 * What query is used for this search
1117 * (list of keywords or SKS identifier).
1119 const struct GNUNET_FS_Uri *query;
1122 * How long has this search been actively running
1123 * (excludes times where the search was paused or
1126 struct GNUNET_TIME_Relative duration;
1129 * What anonymity level is used for this search?
1134 * Additional values for specific events.
1140 * These values are only valid for
1141 * GNUNET_FS_STATUS_SEARCH_RESULT events.
1147 * Metadata for the search result.
1149 const struct GNUNET_CONTAINER_MetaData *meta;
1152 * URI for the search result.
1154 const struct GNUNET_FS_Uri *uri;
1157 * Handle to the result (for starting downloads).
1159 struct GNUNET_FS_SearchResult *result;
1162 * Applicability rank (the larger, the better the result
1163 * fits the search criteria).
1165 uint32_t applicability_rank;
1170 * These values are only valid for
1171 * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1177 * Metadata for the search result.
1179 const struct GNUNET_CONTAINER_MetaData *meta;
1182 * URI for the search result.
1184 const struct GNUNET_FS_Uri *uri;
1187 * Handle to the result (for starting downloads).
1189 struct GNUNET_FS_SearchResult *result;
1192 * Current availability rank (negative:
1193 * unavailable, positive: available)
1195 int32_t availability_rank;
1198 * On how many total queries is the given
1199 * availability_rank based?
1201 uint32_t availability_certainty;
1204 * Updated applicability rank (the larger,
1205 * the better the result fits the search
1208 uint32_t applicability_rank;
1213 * These values are only valid for
1214 * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1220 * Private context set for for this result
1221 * during the "RESULT" event.
1226 * Metadata for the search result.
1228 const struct GNUNET_CONTAINER_MetaData *meta;
1231 * URI for the search result.
1233 const struct GNUNET_FS_Uri *uri;
1236 * Current availability rank (negative:
1237 * unavailable, positive: available)
1239 int32_t availability_rank;
1242 * On how many total queries is the given
1243 * availability_rank based?
1245 uint32_t availability_certainty;
1248 * Updated applicability rank (the larger,
1249 * the better the result fits the search
1252 uint32_t applicability_rank;
1257 * These values are only valid for
1258 * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1259 * These events are automatically triggered for
1260 * each search result before the
1261 * GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1262 * happens primarily to give the client a chance
1263 * to clean up the "cctx" (if needed).
1269 * Private context set for for this result
1270 * during the "RESULT" event.
1275 * Metadata for the search result.
1277 const struct GNUNET_CONTAINER_MetaData *meta;
1280 * URI for the search result.
1282 const struct GNUNET_FS_Uri *uri;
1287 * These values are only valid for
1288 * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1289 * These events are automatically triggered for
1290 * each search result before the
1291 * GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1292 * happens primarily to give the client a chance
1293 * to clean up the "cctx" (if needed).
1299 * Private context set for for this result
1300 * during the "RESULT" event.
1305 * Metadata for the search result.
1307 const struct GNUNET_CONTAINER_MetaData *meta;
1310 * URI for the search result.
1312 const struct GNUNET_FS_Uri *uri;
1317 * These values are only valid for
1318 * GNUNET_FS_STATUS_SEARCH_RESUME events.
1324 * Error message, NULL if we have not encountered any error yet.
1326 const char *message;
1329 * Is this search currently paused?
1336 * These values are only valid for
1337 * GNUNET_FS_STATUS_SEARCH_ERROR events.
1345 const char *message;
1350 * Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events.
1356 * Handle to the namespace (NULL if it is not a local
1359 struct GNUNET_FS_Namespace *ns;
1362 * Short, human-readable name of the namespace.
1367 * Root identifier for the namespace, can be NULL.
1372 * Metadata for the namespace.
1374 const struct GNUNET_CONTAINER_MetaData *meta;
1377 * Hash-identifier for the namespace.
1388 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1394 * Context for controlling the unindexing.
1396 struct GNUNET_FS_UnindexContext *uc;
1399 * Client context pointer (set the last time
1400 * by the client for this operation; initially
1401 * NULL on START/RESUME events).
1406 * Name of the file that is being unindexed.
1408 const char *filename;
1411 * How large is the file overall?
1416 * At what time do we expect to finish unindexing?
1417 * (will be a value in the past for completed
1418 * unindexing opeations).
1420 struct GNUNET_TIME_Relative eta;
1423 * How long has this upload been actively running
1424 * (excludes times where the upload was suspended).
1426 struct GNUNET_TIME_Relative duration;
1429 * How many bytes have we completed?
1434 * Additional values for specific events.
1440 * These values are only valid for
1441 * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1447 * Data block we just unindexed.
1452 * At what offset in the file is "data"?
1457 * Length of the data block.
1462 * Depth of the given block in the tree;
1463 * 0 would be the lowest level (DBLOCKS).
1470 * These values are only valid for
1471 * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1477 * Error message, NULL if we have not encountered any error yet.
1479 const char *message;
1484 * These values are only valid for
1485 * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1493 const char *message;
1504 * Specific status code (determines the event type).
1506 enum GNUNET_FS_Status status;
1512 * Notification of FS to a client about the progress of an
1513 * operation. Callbacks of this type will be used for uploads,
1514 * downloads and searches. Some of the arguments depend a bit
1515 * in their meaning on the context in which the callback is used.
1517 * @param cls closure
1518 * @param info details about the event, specifying the event type
1519 * and various bits about the event
1520 * @return client-context (for the next progress call
1521 * for this operation; should be set to NULL for
1522 * SUSPEND and STOPPED events). The value returned
1523 * will be passed to future callbacks in the respective
1524 * field in the GNUNET_FS_ProgressInfo struct.
1526 typedef void *(*GNUNET_FS_ProgressCallback) (void *cls,
1527 const struct GNUNET_FS_ProgressInfo
1532 * General (global) option flags for file-sharing.
1534 enum GNUNET_FS_Flags
1537 * No special flags set.
1539 GNUNET_FS_FLAGS_NONE = 0,
1542 * Is persistence of operations desired?
1543 * (will create SUSPEND/RESUME events).
1545 GNUNET_FS_FLAGS_PERSISTENCE = 1,
1548 * Should we automatically trigger probes for search results
1549 * to determine availability?
1550 * (will create GNUNET_FS_STATUS_SEARCH_UPDATE events).
1552 GNUNET_FS_FLAGS_DO_PROBES = 2
1556 * Options specified in the VARARGs portion of GNUNET_FS_start.
1558 enum GNUNET_FS_OPTIONS
1562 * Last option in the VARARG list.
1564 GNUNET_FS_OPTIONS_END = 0,
1567 * Select the desired amount of parallelism (this option should be
1568 * followed by an "unsigned int" giving the desired maximum number
1569 * of parallel downloads).
1571 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
1574 * Maximum number of requests that should be pending at a given
1575 * point in time (invidivual downloads may go above this, but
1576 * if we are above this threshold, we should not activate any
1577 * additional downloads.
1579 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
1584 * Settings for publishing a block (which may of course also
1585 * apply to an entire directory or file).
1587 struct GNUNET_FS_BlockOptions
1591 * At what time should the block expire? Data blocks (DBLOCKS and
1592 * IBLOCKS) may still be used even if they are expired (however,
1593 * they'd be removed quickly from the datastore if we are short on
1594 * space), all other types of blocks will no longer be returned
1595 * after they expire.
1597 struct GNUNET_TIME_Absolute expiration_time;
1600 * At which anonymity level should the block be shared?
1601 * (0: no anonymity, 1: normal GAP, >1: with cover traffic).
1603 uint32_t anonymity_level;
1606 * How important is it for us to store the block? If we run
1607 * out of space, the highest-priority, non-expired blocks will
1610 uint32_t content_priority;
1613 * How often should we try to migrate the block to other peers?
1614 * Only used if "CONTENT_PUSHING" is set to YES, in which case we
1615 * first push each block to other peers according to their
1616 * replication levels. Once each block has been pushed that many
1617 * times to other peers, blocks are chosen for migration at random.
1618 * Naturally, there is no guarantee that the other peers will keep
1619 * these blocks for any period of time (since they won't have any
1620 * priority or might be too busy to even store the block in the
1623 uint32_t replication_level;
1629 * Return the current year (i.e. '2011').
1632 GNUNET_FS_get_current_year (void);
1636 * Convert a year to an expiration time of January 1st of that year.
1638 * @param year a year (after 1970, please ;-)).
1639 * @return absolute time for January 1st of that year.
1641 struct GNUNET_TIME_Absolute
1642 GNUNET_FS_year_to_time (unsigned int year);
1646 * Convert an expiration time to the respective year (rounds)
1648 * @param at absolute time
1649 * @return year a year (after 1970), 0 on error
1652 GNUNET_FS_time_to_year (struct GNUNET_TIME_Absolute at);
1656 * Handle to the file-sharing service.
1658 struct GNUNET_FS_Handle;
1662 * Setup a connection to the file-sharing service.
1664 * @param cfg configuration to use
1665 * @param client_name unique identifier for this client
1666 * @param upcb function to call to notify about FS actions
1667 * @param upcb_cls closure for upcb
1668 * @param flags specific attributes for fs-operations
1669 * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
1670 * @return NULL on error
1672 struct GNUNET_FS_Handle *
1673 GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1674 const char *client_name, GNUNET_FS_ProgressCallback upcb,
1675 void *upcb_cls, enum GNUNET_FS_Flags flags, ...);
1679 * Close our connection with the file-sharing service.
1680 * The callback given to GNUNET_FS_start will no longer be
1681 * called after this function returns.
1683 * @param h handle that was returned from GNUNET_FS_start
1686 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1690 * Extract meta-data from a file.
1692 * @param md metadata to set
1693 * @param filename name of file to inspect
1694 * @param extractors plugins to use
1695 * @return GNUNET_SYSERR on error, otherwise the number
1696 * of meta-data items obtained
1699 GNUNET_FS_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData *md,
1700 const char *filename,
1701 struct EXTRACTOR_PluginList *extractors);
1705 * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
1707 * @param cls closure
1708 * @param fi the entry in the publish-structure
1709 * @param length length of the file or directory
1710 * @param meta metadata for the file or directory (can be modified)
1711 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1712 * @param bo block options (can be modified)
1713 * @param do_index should we index (can be modified)
1714 * @param client_info pointer to client context set upon creation (can be modified)
1715 * @return GNUNET_OK to continue, GNUNET_NO to remove
1716 * this entry from the directory, GNUNET_SYSERR
1717 * to abort the iteration
1719 typedef int (*GNUNET_FS_FileInformationProcessor) (void *cls,
1721 GNUNET_FS_FileInformation *
1722 fi, uint64_t length,
1724 GNUNET_CONTAINER_MetaData *
1726 struct GNUNET_FS_Uri ** uri,
1727 struct GNUNET_FS_BlockOptions
1728 * bo, int *do_index,
1729 void **client_info);
1733 * Obtain the name under which this file information
1734 * structure is stored on disk. Only works for top-level
1735 * file information structures.
1737 * @param s structure to get the filename for
1738 * @return NULL on error, otherwise filename that
1739 * can be passed to "GNUNET_FS_file_information_recover"
1740 * to read this fi-struct from disk.
1743 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1748 * Create an entry for a file in a publish-structure.
1750 * @param h handle to the file sharing subsystem
1751 * @param client_info initial client-info value for this entry
1752 * @param filename name of the file or directory to publish
1753 * @param keywords under which keywords should this file be available
1754 * directly; can be NULL
1755 * @param meta metadata for the file
1756 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1757 * GNUNET_SYSERR for simulation
1758 * @param bo block options
1759 * @return publish structure entry for the file
1761 struct GNUNET_FS_FileInformation *
1762 GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
1764 const char *filename,
1765 const struct GNUNET_FS_Uri
1768 GNUNET_CONTAINER_MetaData *meta,
1770 const struct GNUNET_FS_BlockOptions
1775 * Create an entry for a file in a publish-structure.
1777 * @param h handle to the file sharing subsystem
1778 * @param client_info initial client-info value for this entry
1779 * @param length length of the file
1780 * @param data data for the file (should not be used afterwards by
1781 * the caller; callee will "free")
1782 * @param keywords under which keywords should this file be available
1783 * directly; can be NULL
1784 * @param meta metadata for the file
1785 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1786 * GNUNET_SYSERR for simulation
1787 * @param bo block options
1788 * @return publish structure entry for the file
1790 struct GNUNET_FS_FileInformation *
1791 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
1792 void *client_info, uint64_t length,
1794 const struct GNUNET_FS_Uri
1797 GNUNET_CONTAINER_MetaData *meta,
1799 const struct GNUNET_FS_BlockOptions
1804 * Function that provides data.
1806 * @param cls closure
1807 * @param offset offset to read from; it is possible
1808 * that the caller might need to go backwards
1810 * @param max maximum number of bytes that should be
1811 * copied to buf; readers are not allowed
1812 * to provide less data unless there is an error;
1813 * a value of "0" will be used at the end to allow
1814 * the reader to clean up its internal state
1815 * @param buf where the reader should write the data
1816 * @param emsg location for the reader to store an error message
1817 * @return number of bytes written, usually "max", 0 on error
1819 typedef size_t (*GNUNET_FS_DataReader) (void *cls, uint64_t offset, size_t max,
1820 void *buf, char **emsg);
1824 * Create an entry for a file in a publish-structure.
1826 * @param h handle to the file sharing subsystem
1827 * @param client_info initial client-info value for this entry
1828 * @param length length of the file
1829 * @param reader function that can be used to obtain the data for the file
1830 * @param reader_cls closure for "reader"
1831 * @param keywords under which keywords should this file be available
1832 * directly; can be NULL
1833 * @param meta metadata for the file
1834 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1835 * GNUNET_SYSERR for simulation
1836 * @param bo block options
1837 * @return publish structure entry for the file
1839 struct GNUNET_FS_FileInformation *
1840 GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
1843 GNUNET_FS_DataReader reader,
1845 const struct GNUNET_FS_Uri
1848 GNUNET_CONTAINER_MetaData *meta,
1851 GNUNET_FS_BlockOptions *bo);
1855 * Function that a "GNUNET_FS_DirectoryScanner" should call
1856 * for each entry in the directory.
1858 * @param cls closure
1859 * @param filename name of the file (including path); must end
1860 * in a "/" (even on W32) if this is a directory
1861 * @param fi information about the file (should not be
1862 * used henceforth by the caller)
1864 typedef void (*GNUNET_FS_FileProcessor) (void *cls, const char *filename,
1865 struct GNUNET_FS_FileInformation * fi);
1869 * Type of a function that will be used to scan a directory.
1871 * @param cls closure
1872 * @param h handle to the file sharing subsystem
1873 * @param dirname name of the directory to scan
1874 * @param do_index should files be indexed or inserted
1875 * @param bo block options
1876 * @param proc function to call on each entry
1877 * @param proc_cls closure for proc
1878 * @param emsg where to store an error message (on errors)
1879 * @return GNUNET_OK on success
1881 typedef int (*GNUNET_FS_DirectoryScanner) (void *cls,
1882 struct GNUNET_FS_Handle * h,
1883 const char *dirname, int do_index,
1884 const struct GNUNET_FS_BlockOptions *
1885 bo, GNUNET_FS_FileProcessor proc,
1886 void *proc_cls, char **emsg);
1891 * Simple, useful default implementation of a directory scanner
1892 * (GNUNET_FS_DirectoryScanner). This implementation expects to get a
1893 * UNIX filename, will publish all files in the directory except hidden
1894 * files (those starting with a "."). Metadata will be extracted
1895 * using GNU libextractor; the specific list of plugins should be
1896 * specified in "cls", passing NULL will disable (!) metadata
1897 * extraction. Keywords will be derived from the metadata and
1898 * associated with directories as appropriate. This is strictly a
1899 * convenience function (however, if all tools use it, there will
1900 * be less of a chance of distinguishing users by the specific
1901 * user-interface they were using).
1903 * @param cls must be of type "struct EXTRACTOR_Extractor*"
1904 * @param h handle to the file sharing subsystem
1905 * @param dirname name of the directory to scan
1906 * @param do_index should files be indexed or inserted
1907 * @param bo block options
1908 * @param proc function called on each entry
1909 * @param proc_cls closure for proc
1910 * @param emsg where to store an error message (on errors)
1911 * @return GNUNET_OK on success
1914 GNUNET_FS_directory_scanner_default (void *cls, struct GNUNET_FS_Handle *h,
1915 const char *dirname, int do_index,
1916 const struct GNUNET_FS_BlockOptions *bo,
1917 GNUNET_FS_FileProcessor proc,
1918 void *proc_cls, char **emsg);
1922 * Create a publish-structure from an existing file hierarchy, inferring
1923 * and organizing keywords and metadata as much as possible. This
1924 * function primarily performs the recursive build and re-organizes
1925 * keywords and metadata; for automatically getting metadata
1926 * extraction, scanning of directories and creation of the respective
1927 * GNUNET_FS_FileInformation entries the default scanner should be
1928 * passed (GNUNET_FS_directory_scanner_default). This is strictly a
1929 * convenience function.
1931 * @param h handle to the file sharing subsystem
1932 * @param client_info initial client-info value for this entry
1933 * @param filename name of the top-level file or directory
1934 * @param scanner function used to get a list of files in a directory
1935 * @param scanner_cls closure for scanner
1936 * @param do_index should files in the hierarchy be indexed?
1937 * @param bo block options
1938 * @param emsg where to store an error message
1939 * @return publish structure entry for the directory, NULL on error
1941 struct GNUNET_FS_FileInformation *
1942 GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
1944 const char *filename,
1945 GNUNET_FS_DirectoryScanner
1946 scanner, void *scanner_cls,
1949 GNUNET_FS_BlockOptions *bo,
1954 * Create an entry for an empty directory in a publish-structure.
1955 * This function should be used by applications for which the
1956 * use of "GNUNET_FS_file_information_create_from_directory"
1957 * is not appropriate.
1959 * @param h handle to the file sharing subsystem
1960 * @param client_info initial client-info value for this entry
1961 * @param keywords under which keywords should this directory be available
1962 * directly; can be NULL
1963 * @param meta metadata for the directory
1964 * @param bo block options
1965 * @return publish structure entry for the directory , NULL on error
1967 struct GNUNET_FS_FileInformation *
1968 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
1970 const struct GNUNET_FS_Uri
1973 GNUNET_CONTAINER_MetaData
1976 GNUNET_FS_BlockOptions *bo);
1980 * Test if a given entry represents a directory.
1982 * @param ent check if this FI represents a directory
1983 * @return GNUNET_YES if so, GNUNET_NO if not
1986 GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
1991 * Add an entry to a directory in a publish-structure. Clients
1992 * should never modify publish structures that were passed to
1993 * "GNUNET_FS_publish_start" already.
1995 * @param dir the directory
1996 * @param ent the entry to add; the entry must not have been
1997 * added to any other directory at this point and
1998 * must not include "dir" in its structure
1999 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2002 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
2003 struct GNUNET_FS_FileInformation *ent);
2007 * Inspect a file or directory in a publish-structure. Clients
2008 * should never modify publish structures that were passed to
2009 * "GNUNET_FS_publish_start" already. When called on a directory,
2010 * this function will FIRST call "proc" with information about
2011 * the directory itself and then for each of the files in the
2012 * directory (but not for files in subdirectories). When called
2013 * on a file, "proc" will be called exactly once (with information
2014 * about the specific file).
2016 * @param dir the directory
2017 * @param proc function to call on each entry
2018 * @param proc_cls closure for proc
2021 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
2022 GNUNET_FS_FileInformationProcessor proc,
2027 * Destroy publish-structure. Clients should never destroy publish
2028 * structures that were passed to "GNUNET_FS_publish_start" already.
2030 * @param fi structure to destroy
2031 * @param cleaner function to call on each entry in the structure
2032 * (useful to clean up client_info); can be NULL; return
2033 * values are ignored
2034 * @param cleaner_cls closure for cleaner
2037 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
2038 GNUNET_FS_FileInformationProcessor cleaner,
2043 * Options for publishing. Compatible options
2044 * can be OR'ed together.
2046 enum GNUNET_FS_PublishOptions
2049 * No options (use defaults for everything).
2051 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
2054 * Simulate publishing. With this option, no data will be stored
2055 * in the datastore. Useful for computing URIs from files.
2057 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
2061 * Publish a file or directory.
2063 * @param h handle to the file sharing subsystem
2064 * @param fi information about the file or directory structure to publish
2065 * @param namespace namespace to publish the file in, NULL for no namespace
2066 * @param nid identifier to use for the publishd content in the namespace
2067 * (can be NULL, must be NULL if namespace is NULL)
2068 * @param nuid update-identifier that will be used for future updates
2069 * (can be NULL, must be NULL if namespace or nid is NULL)
2070 * @param options options for the publication
2071 * @return context that can be used to control the publish operation
2073 struct GNUNET_FS_PublishContext *
2074 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
2075 struct GNUNET_FS_FileInformation *fi,
2076 struct GNUNET_FS_Namespace *namespace, const char *nid,
2078 enum GNUNET_FS_PublishOptions options);
2082 * Stop a publication. Will abort incomplete publications (but
2083 * not remove blocks that have already been published) or
2084 * simply clean up the state for completed publications.
2085 * Must NOT be called from within the event callback!
2087 * @param pc context for the publication to stop
2090 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
2094 * Signature of a function called as the continuation of a KBlock or
2095 * SBlock publication.
2097 * @param cls closure
2098 * @param uri URI under which the block is now available, NULL on error
2099 * @param emsg error message, NULL on success
2101 typedef void (*GNUNET_FS_PublishContinuation) (void *cls,
2102 const struct GNUNET_FS_Uri * uri,
2107 * Publish a KBlock on GNUnet.
2109 * @param h handle to the file sharing subsystem
2110 * @param ksk_uri keywords to use
2111 * @param meta metadata to use
2112 * @param uri URI to refer to in the KBlock
2113 * @param bo block options
2114 * @param options publication options
2115 * @param cont continuation
2116 * @param cont_cls closure for cont
2119 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2120 const struct GNUNET_FS_Uri *ksk_uri,
2121 const struct GNUNET_CONTAINER_MetaData *meta,
2122 const struct GNUNET_FS_Uri *uri,
2123 const struct GNUNET_FS_BlockOptions *bo,
2124 enum GNUNET_FS_PublishOptions options,
2125 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2129 * Publish an SBlock on GNUnet.
2131 * @param h handle to the file sharing subsystem
2132 * @param namespace namespace to publish in
2133 * @param identifier identifier to use
2134 * @param update update identifier to use
2135 * @param meta metadata to use
2136 * @param uri URI to refer to in the SBlock
2137 * @param bo block options
2138 * @param options publication options
2139 * @param cont continuation
2140 * @param cont_cls closure for cont
2143 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2144 struct GNUNET_FS_Namespace *namespace,
2145 const char *identifier, const char *update,
2146 const struct GNUNET_CONTAINER_MetaData *meta,
2147 const struct GNUNET_FS_Uri *uri,
2148 const struct GNUNET_FS_BlockOptions *bo,
2149 enum GNUNET_FS_PublishOptions options,
2150 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2154 * Type of a function called by "GNUNET_FS_get_indexed_files".
2156 * @param cls closure
2157 * @param filename the name of the file
2158 * @param file_id hash of the contents of the indexed file
2159 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
2161 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls, const char *filename,
2162 const GNUNET_HashCode * file_id);
2166 * Iterate over all indexed files.
2168 * @param h handle to the file sharing subsystem
2169 * @param iterator function to call on each indexed file
2170 * @param iterator_cls closure for iterator
2171 * @param cont continuation to call when done;
2172 * reason should be "TIMEOUT" (on
2173 * error) or "PREREQ_DONE" (on success)
2174 * @param cont_cls closure for cont
2177 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2178 GNUNET_FS_IndexedFileProcessor iterator,
2179 void *iterator_cls, GNUNET_SCHEDULER_Task cont,
2186 * @param h handle to the file sharing subsystem
2187 * @param filename file to unindex
2188 * @param cctx initial value for the client context
2189 * @return NULL on error, otherwise handle
2191 struct GNUNET_FS_UnindexContext *
2192 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, const char *filename,
2197 * Clean up after completion of an unindex operation.
2202 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2206 * Publish an advertismement for a namespace.
2208 * @param h handle to the file sharing subsystem
2209 * @param ksk_uri keywords to use for advertisment
2210 * @param namespace handle for the namespace that should be advertised
2211 * @param meta meta-data for the namespace advertisement
2212 * @param bo block options
2213 * @param rootEntry name of the root of the namespace
2214 * @param cont continuation
2215 * @param cont_cls closure for cont
2218 GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
2219 struct GNUNET_FS_Uri *ksk_uri,
2220 struct GNUNET_FS_Namespace *namespace,
2221 const struct GNUNET_CONTAINER_MetaData *meta,
2222 const struct GNUNET_FS_BlockOptions *bo,
2223 const char *rootEntry,
2224 GNUNET_FS_PublishContinuation cont,
2229 * Create a namespace with the given name; if one already
2230 * exists, return a handle to the existing namespace.
2232 * @param h handle to the file sharing subsystem
2233 * @param name name to use for the namespace
2234 * @return handle to the namespace, NULL on error
2236 struct GNUNET_FS_Namespace *
2237 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, const char *name);
2241 * Delete a namespace handle. Can be used for a clean shutdown (free
2242 * memory) or also to freeze the namespace to prevent further
2243 * insertions by anyone.
2245 * @param namespace handle to the namespace that should be deleted / freed
2246 * @param freeze prevents future insertions; creating a namespace
2247 * with the same name again will create a fresh namespace instead
2249 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2252 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace, int freeze);
2256 * Callback with information about local (!) namespaces.
2257 * Contains the names of the local namespace and the global
2260 * @param cls closure
2261 * @param name human-readable identifier of the namespace
2262 * @param id hash identifier for the namespace
2264 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls, const char *name,
2265 const GNUNET_HashCode * id);
2269 * Build a list of all available local (!) namespaces The returned
2270 * names are only the nicknames since we only iterate over the local
2273 * @param h handle to the file sharing subsystem
2274 * @param cb function to call on each known namespace
2275 * @param cb_cls closure for cb
2278 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2279 GNUNET_FS_NamespaceInfoProcessor cb, void *cb_cls);
2283 * Function called on updateable identifiers.
2285 * @param cls closure
2286 * @param last_id last identifier
2287 * @param last_uri uri used for the content published under the last_id
2288 * @param last_meta metadata associated with last_uri
2289 * @param next_id identifier that should be used for updates
2291 typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls, const char *last_id,
2292 const struct GNUNET_FS_Uri *
2295 GNUNET_CONTAINER_MetaData *
2296 last_meta, const char *next_id);
2300 * List all of the identifiers in the namespace for which we could
2301 * produce an update. Namespace updates form a graph where each node
2302 * has a name. Each node can have any number of URI/meta-data entries
2303 * which can each be linked to other nodes. Cycles are possible.
2305 * Calling this function with "next_id" NULL will cause the library to
2306 * call "ip" with a root for each strongly connected component of the
2307 * graph (a root being a node from which all other nodes in the Scc
2310 * Calling this function with "next_id" being the name of a node will
2311 * cause the library to call "ip" with all children of the node. Note
2312 * that cycles within an SCC are possible (including self-loops).
2314 * @param namespace namespace to inspect for updateable content
2315 * @param next_id ID to look for; use NULL to look for SCC roots
2316 * @param ip function to call on each updateable identifier
2317 * @param ip_cls closure for ip
2320 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
2321 const char *next_id,
2322 GNUNET_FS_IdentifierProcessor ip,
2327 * Options for searching. Compatible options
2328 * can be OR'ed together.
2330 enum GNUNET_FS_SearchOptions
2333 * No options (use defaults for everything).
2335 GNUNET_FS_SEARCH_OPTION_NONE = 0,
2338 * Only search the local host, do not search remote systems (no P2P)
2340 GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
2345 * Start search for content.
2347 * @param h handle to the file sharing subsystem
2348 * @param uri specifies the search parameters; can be
2349 * a KSK URI or an SKS URI.
2350 * @param anonymity desired level of anonymity
2351 * @param options options for the search
2352 * @param cctx initial value for the client context
2353 * @return context that can be used to control the search
2355 struct GNUNET_FS_SearchContext *
2356 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2357 const struct GNUNET_FS_Uri *uri, uint32_t anonymity,
2358 enum GNUNET_FS_SearchOptions options, void *cctx);
2364 * @param sc context for the search that should be paused
2367 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2371 * Continue paused search.
2373 * @param sc context for the search that should be resumed
2376 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2380 * Stop search for content.
2382 * @param sc context for the search that should be stopped
2385 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2391 * Options for downloading. Compatible options
2392 * can be OR'ed together.
2394 enum GNUNET_FS_DownloadOptions
2397 * No options (use defaults for everything).
2399 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2402 * Only download from the local host, do not access remote systems (no P2P)
2404 GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
2407 * Do a recursive download (that is, automatically trigger the
2408 * download of files in directories).
2410 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
2413 * Do not append temporary data to
2414 * the target file (for the IBlocks).
2416 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
2419 * Internal option used to flag this download as a 'probe' for a
2420 * search result. Impacts the priority with which the download is
2421 * run and causes signalling callbacks to be done differently.
2422 * Also, probe downloads are not serialized on suspension. Normal
2423 * clients should not use this!
2425 GNUNET_FS_DOWNLOAD_IS_PROBE = (1 << 31)
2431 * Download parts of a file. Note that this will store
2432 * the blocks at the respective offset in the given file. Also, the
2433 * download is still using the blocking of the underlying FS
2434 * encoding. As a result, the download may *write* outside of the
2435 * given boundaries (if offset and length do not match the 32k FS
2436 * block boundaries). <p>
2438 * The given range can be used to focus a download towards a
2439 * particular portion of the file (optimization), not to strictly
2440 * limit the download to exactly those bytes.
2442 * @param h handle to the file sharing subsystem
2443 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2444 * @param meta known metadata for the file (can be NULL)
2445 * @param filename where to store the file, maybe NULL (then no file is
2446 * created on disk and data must be grabbed from the callbacks)
2447 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2448 * can be NULL (in which case we will pick a name if needed); the temporary file
2449 * may already exist, in which case we will try to use the data that is there and
2450 * if it is not what is desired, will overwrite it
2451 * @param offset at what offset should we start the download (typically 0)
2452 * @param length how many bytes should be downloaded starting at offset
2453 * @param anonymity anonymity level to use for the download
2454 * @param options various download options
2455 * @param cctx initial value for the client context for this download
2456 * @param parent parent download to associate this download with (use NULL
2457 * for top-level downloads; useful for manually-triggered recursive downloads)
2458 * @return context that can be used to control this download
2460 struct GNUNET_FS_DownloadContext *
2461 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2462 const struct GNUNET_FS_Uri *uri,
2463 const struct GNUNET_CONTAINER_MetaData *meta,
2464 const char *filename, const char *tempname,
2465 uint64_t offset, uint64_t length, uint32_t anonymity,
2466 enum GNUNET_FS_DownloadOptions options, void *cctx,
2467 struct GNUNET_FS_DownloadContext *parent);
2471 * Download parts of a file based on a search result. The download
2472 * will be associated with the search result (and the association
2473 * will be preserved when serializing/deserializing the state).
2474 * If the search is stopped, the download will not be aborted but
2475 * be 'promoted' to a stand-alone download.
2477 * As with the other download function, this will store
2478 * the blocks at the respective offset in the given file. Also, the
2479 * download is still using the blocking of the underlying FS
2480 * encoding. As a result, the download may *write* outside of the
2481 * given boundaries (if offset and length do not match the 32k FS
2482 * block boundaries). <p>
2484 * The given range can be used to focus a download towards a
2485 * particular portion of the file (optimization), not to strictly
2486 * limit the download to exactly those bytes.
2488 * @param h handle to the file sharing subsystem
2489 * @param sr the search result to use for the download (determines uri and
2490 * meta data and associations)
2491 * @param filename where to store the file, maybe NULL (then no file is
2492 * created on disk and data must be grabbed from the callbacks)
2493 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2494 * can be NULL (in which case we will pick a name if needed); the temporary file
2495 * may already exist, in which case we will try to use the data that is there and
2496 * if it is not what is desired, will overwrite it
2497 * @param offset at what offset should we start the download (typically 0)
2498 * @param length how many bytes should be downloaded starting at offset
2499 * @param anonymity anonymity level to use for the download
2500 * @param options various download options
2501 * @param cctx initial value for the client context for this download
2502 * @return context that can be used to control this download
2504 struct GNUNET_FS_DownloadContext *
2505 GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2506 struct GNUNET_FS_SearchResult *sr,
2507 const char *filename,
2508 const char *tempname, uint64_t offset,
2509 uint64_t length, uint32_t anonymity,
2510 enum GNUNET_FS_DownloadOptions options,
2515 * Stop a download (aborts if download is incomplete).
2517 * @param dc handle for the download
2518 * @param do_delete delete files of incomplete downloads
2521 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete);
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
2545 * Set the MIMETYPE information for the given
2546 * metadata to "application/gnunet-directory".
2548 * @param md metadata to add mimetype to
2551 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2555 * Suggest a filename based on given metadata.
2557 * @param md given meta data
2558 * @return NULL if meta data is useless for suggesting a filename
2561 GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData
2566 * Function used to process entries in a directory.
2568 * @param cls closure
2569 * @param filename name of the file in the directory
2570 * @param uri URI of the file
2571 * @param metadata metadata for the file; metadata for
2572 * the directory if everything else is NULL/zero
2573 * @param length length of the available data for the file
2574 * (of type size_t since data must certainly fit
2575 * into memory; if files are larger than size_t
2576 * permits, then they will certainly not be
2577 * embedded with the directory itself).
2578 * @param data data available for the file (length bytes)
2580 typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
2581 const char *filename,
2582 const struct GNUNET_FS_Uri *
2585 GNUNET_CONTAINER_MetaData *
2586 meta, size_t length,
2591 * Iterate over all entries in a directory. Note that directories
2592 * are structured such that it is possible to iterate over the
2593 * individual blocks as well as over the entire directory. Thus
2594 * a client can call this function on the buffer in the
2595 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2596 * include the contents of (small) files embedded in the directory
2597 * itself; for those files, the processor may be given the
2598 * contents of the file directly by this function.
2600 * @param size number of bytes in data
2601 * @param data pointer to the beginning of the directory
2602 * @param offset offset of data in the directory
2603 * @param dep function to call on each entry
2604 * @param dep_cls closure for dep
2605 * @return GNUNET_OK if this could be a block in a directory,
2606 * GNUNET_NO if this could be part of a directory (but not 100% OK)
2607 * GNUNET_SYSERR if 'data' does not represent a directory
2610 GNUNET_FS_directory_list_contents (size_t size, const void *data,
2612 GNUNET_FS_DirectoryEntryProcessor dep,
2617 * Opaque handle to a directory builder.
2619 struct GNUNET_FS_DirectoryBuilder;
2622 * Create a directory builder.
2624 * @param mdir metadata for the directory
2626 struct GNUNET_FS_DirectoryBuilder *
2627 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
2632 * Add an entry to a directory.
2634 * @param bld directory to extend
2635 * @param uri uri of the entry (must not be a KSK)
2636 * @param md metadata of the entry
2637 * @param data raw data of the entry, can be NULL, otherwise
2638 * data must point to exactly the number of bytes specified
2642 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2643 const struct GNUNET_FS_Uri *uri,
2644 const struct GNUNET_CONTAINER_MetaData *md,
2649 * Finish building the directory. Frees the
2650 * builder context and returns the directory
2653 * @param bld directory to finish
2654 * @param rsize set to the number of bytes needed
2655 * @param rdata set to the encoded directory
2656 * @return GNUNET_OK on success
2659 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2660 size_t * rsize, void **rdata);
2663 #if 0 /* keep Emacsens' auto-indent happy */