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"
29 #include "gnunet_scheduler_lib.h"
34 #if 0 /* keep Emacsens' auto-indent happy */
40 * Version number of the implementation.
43 * 1.x.x: initial version with triple GNUNET_hash and merkle tree
44 * 2.x.x: root node with mime-type, filename and version number
45 * 2.1.x: combined GNUNET_EC_ContentHashKey/3HASH encoding with 25:1 super-nodes
46 * 2.2.x: with directories
47 * 3.0.x: with namespaces
48 * 3.1.x: with namespace meta-data
49 * 3.2.x: with collections
50 * 4.0.x: with expiration, variable meta-data, kblocks
51 * 4.1.x: with new error and configuration handling
52 * 5.0.x: with location URIs
53 * 6.0.0: with support for OR in KSKs
54 * 6.1.x: with simplified namespace support
55 * 9.0.0: CPS-style integrated API
56 * 9.1.1: asynchronous directory scanning
58 #define GNUNET_FS_VERSION 0x00090102
61 /* ******************** URI API *********************** */
63 #define GNUNET_FS_URI_PREFIX "gnunet://fs/"
64 #define GNUNET_FS_URI_KSK_INFIX "ksk/"
65 #define GNUNET_FS_URI_SKS_INFIX "sks/"
66 #define GNUNET_FS_URI_CHK_INFIX "chk/"
67 #define GNUNET_FS_URI_LOC_INFIX "loc/"
71 * A Universal Resource Identifier (URI), opaque.
76 * Iterator over keywords
79 * @param keyword the keyword
80 * @param is_mandatory is the keyword mandatory (in a search)
81 * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
83 typedef int (*GNUNET_FS_KeywordIterator) (void *cls, const char *keyword,
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, GNUNET_HashCode * key);
97 * Convert a URI to a UTF-8 String.
99 * @param uri uri to convert to a string
100 * @return the UTF-8 string
103 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
106 * Convert keyword URI to a human readable format
107 * (i.e. the search query that was used in the first place)
109 * @param uri ksk uri to convert to a string
110 * @return string with the keywords
113 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
117 * Add the given keyword to the set of keywords represented by the URI.
118 * Does nothing if the keyword is already present.
120 * @param uri ksk uri to modify
121 * @param keyword keyword to add
122 * @param is_mandatory is this keyword mandatory?
125 GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, const char *keyword,
130 * Remove the given keyword from the set of keywords represented by the URI.
131 * Does nothing if the keyword is not present.
133 * @param uri ksk uri to modify
134 * @param keyword keyword to add
137 GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
138 const char *keyword);
142 * Convert a UTF-8 String to a URI.
144 * @param uri string to parse
145 * @param emsg where to store the parser error message (if any)
146 * @return NULL on error
148 struct GNUNET_FS_Uri *
149 GNUNET_FS_uri_parse (const char *uri, char **emsg);
154 * @param uri uri to free
157 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
161 * How many keywords are ANDed in this keyword URI?
163 * @param uri ksk uri to get the number of keywords from
164 * @return 0 if this is not a keyword URI
167 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
171 * Iterate over all keywords in this keyword URI.
173 * @param uri ksk uri to get the keywords from
174 * @param iterator function to call on each keyword
175 * @param iterator_cls closure for iterator
176 * @return -1 if this is not a keyword URI, otherwise number of
177 * keywords iterated over until iterator aborted
180 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
181 GNUNET_FS_KeywordIterator iterator,
186 * Obtain the identity of the peer offering the data
188 * @param uri the location URI to inspect
189 * @param peer where to store the identify of the peer (presumably) offering the content
190 * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK
193 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
194 struct GNUNET_PeerIdentity *peer);
198 * Obtain the URI of the content itself.
200 * @param uri location URI to get the content URI from
201 * @return NULL if argument is not a location URI
203 struct GNUNET_FS_Uri *
204 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
208 * Obtain the expiration of the LOC URI.
210 * @param uri location URI to get the expiration from
211 * @return expiration time of the URI
213 struct GNUNET_TIME_Absolute
214 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
218 * Construct a location URI (this peer will be used for the location).
220 * @param baseUri content offered by the sender
221 * @param cfg configuration information (used to find our hostkey)
222 * @param expiration_time how long will the content be offered?
223 * @return the location URI, NULL on error
225 struct GNUNET_FS_Uri *
226 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
227 const struct GNUNET_CONFIGURATION_Handle *cfg,
228 struct GNUNET_TIME_Absolute expiration_time);
232 * Merge the sets of keywords from two KSK URIs.
234 * @param u1 first uri
235 * @param u2 second uri
236 * @return merged URI, NULL on error
238 struct GNUNET_FS_Uri *
239 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
240 const struct GNUNET_FS_Uri *u2);
246 * @param uri the URI to duplicate
247 * @return copy of the URI
249 struct GNUNET_FS_Uri *
250 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
254 * Create an FS URI from a single user-supplied string of keywords.
255 * The string is broken up at spaces into individual keywords.
256 * Keywords that start with "+" are mandatory. Double-quotes can
257 * be used to prevent breaking up strings at spaces (and also
258 * to specify non-mandatory keywords starting with "+").
260 * Keywords must contain a balanced number of double quotes and
261 * double quotes can not be used in the actual keywords (for
262 * example, the string '""foo bar""' will be turned into two
263 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
265 * @param keywords the keyword string
266 * @param emsg where to store an error message
267 * @return an FS URI for the given keywords, NULL
268 * if keywords is not legal (i.e. empty).
270 struct GNUNET_FS_Uri *
271 GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg);
275 * Create an FS URI from a user-supplied command line of keywords.
276 * Arguments should start with "+" to indicate mandatory
279 * @param argc number of keywords
280 * @param argv keywords (double quotes are not required for
281 * keywords containing spaces; however, double
282 * quotes are required for keywords starting with
283 * "+"); there is no mechanism for having double
284 * quotes in the actual keywords (if the user
285 * did specifically specify double quotes, the
286 * caller should convert each double quote
287 * into two single quotes).
288 * @return an FS URI for the given keywords, NULL
289 * if keywords is not legal (i.e. empty).
291 struct GNUNET_FS_Uri *
292 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv);
296 * Test if two URIs are equal.
298 * @param u1 one of the URIs
299 * @param u2 the other URI
300 * @return GNUNET_YES if the URIs are equal
303 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
304 const struct GNUNET_FS_Uri *u2);
308 * Is this a namespace URI?
310 * @param uri the uri to check
311 * @return GNUNET_YES if this is an SKS uri
314 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
318 * Handle to one of our namespaces.
320 struct GNUNET_FS_Namespace;
324 * Create an SKS URI from a namespace and an identifier.
326 * @param ns namespace
327 * @param id identifier
328 * @param emsg where to store an error message
329 * @return an FS URI for the given namespace and identifier
331 struct GNUNET_FS_Uri *
332 GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id,
337 * Create an SKS URI from a namespace ID and an identifier.
339 * @param nsid namespace ID
340 * @param id identifier
341 * @return an FS URI for the given namespace and identifier
343 struct GNUNET_FS_Uri *
344 GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode * nsid, const char *id);
348 * Get the ID of a namespace from the given
351 * @param uri the uri to get the namespace ID from
352 * @param nsid where to store the ID of the namespace
353 * @return GNUNET_OK on success
356 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
357 GNUNET_HashCode * nsid);
361 * Get the content identifier of an SKS URI.
363 * @param uri the sks uri
364 * @return NULL on error (not a valid SKS URI)
367 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
371 * Convert namespace URI to a human readable format
372 * (using the namespace description, if available).
374 * @param cfg configuration to use
375 * @param uri SKS uri to convert
376 * @return NULL on error (not an SKS URI)
379 GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
380 const struct GNUNET_FS_Uri *uri);
384 * Is this a keyword URI?
387 * @return GNUNET_YES if this is a KSK uri
390 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
394 * Is this a file (or directory) URI?
396 * @param uri the uri to check
397 * @return GNUNET_YES if this is a CHK uri
400 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
404 * What is the size of the file that this URI
407 * @param uri the CHK (or LOC) URI to inspect
408 * @return size of the file as specified in the CHK URI
411 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
415 * Is this a location URI?
417 * @param uri the uri to check
418 * @return GNUNET_YES if this is a LOC uri
421 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
425 * Construct a keyword-URI from meta-data (take all entries
426 * in the meta-data and construct one large keyword URI
427 * that lists all keywords that can be found in the meta-data).
429 * @param md metadata to use
430 * @return NULL on error, otherwise a KSK URI
432 struct GNUNET_FS_Uri *
433 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
437 /* ******************** command-line option parsing API *********************** */
440 * Command-line option parser function that allows the user
441 * to specify one or more '-k' options with keywords. Each
442 * specified keyword will be added to the URI. A pointer to
443 * the URI must be passed as the "scls" argument.
445 * @param ctx command line processor context
446 * @param scls must be of type "struct GNUNET_FS_Uri **"
447 * @param option name of the option (typically 'k')
448 * @param value command line argument given
449 * @return GNUNET_OK on success
452 GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext
453 *ctx, void *scls, const char *option,
458 * Command-line option parser function that allows the user to specify
459 * one or more '-m' options with metadata. Each specified entry of
460 * the form "type=value" will be added to the metadata. A pointer to
461 * the metadata must be passed as the "scls" argument.
463 * @param ctx command line processor context
464 * @param scls must be of type "struct GNUNET_CONTAINER_MetaData **"
465 * @param option name of the option (typically 'k')
466 * @param value command line argument given
467 * @return GNUNET_OK on success
470 GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext
471 *ctx, void *scls, const char *option,
476 /* ************************* sharing API ***************** */
480 * Possible status codes used in the callback for the
481 * various file-sharing operations. On each file (or search),
482 * the callback is guaranteed to be called once with "START"
483 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
484 * are optional and depend on the circumstances; parent operations
485 * will be STARTED before child-operations and STOPPED after
486 * their respective child-operations. START and STOP signals
487 * are typically generated either due to explicit client requests
488 * or because of suspend/resume operations.
490 enum GNUNET_FS_Status
493 * Notification that we have started to publish a file structure.
495 GNUNET_FS_STATUS_PUBLISH_START = 0,
498 * Notification that we have resumed sharing a file structure.
500 GNUNET_FS_STATUS_PUBLISH_RESUME = 1,
503 * Notification that we have suspended sharing a file structure.
505 GNUNET_FS_STATUS_PUBLISH_SUSPEND = 2,
508 * Notification that we are making progress sharing a file structure.
510 GNUNET_FS_STATUS_PUBLISH_PROGRESS = 3,
513 * Notification that an error was encountered sharing a file structure.
514 * The application will continue to receive resume/suspend events for
515 * this structure until "GNUNET_FS_publish_stop" is called.
517 GNUNET_FS_STATUS_PUBLISH_ERROR = 4,
520 * Notification that we completed sharing a file structure.
521 * The application will continue to receive resume/suspend events for
522 * this structure until "GNUNET_FS_publish_stop" is called.
524 GNUNET_FS_STATUS_PUBLISH_COMPLETED = 5,
527 * Notification that we have stopped
528 * the process of uploading a file structure; no
529 * futher events will be generated for this action.
531 GNUNET_FS_STATUS_PUBLISH_STOPPED = 6,
534 * Notification that we have started this download.
536 GNUNET_FS_STATUS_DOWNLOAD_START = 7,
539 * Notification that this download is being resumed.
541 GNUNET_FS_STATUS_DOWNLOAD_RESUME = 8,
544 * Notification that this download was suspended.
546 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND = 9,
549 * Notification about progress with this download.
551 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS = 10,
554 * Notification that this download encountered an error.
556 GNUNET_FS_STATUS_DOWNLOAD_ERROR = 11,
559 * Notification that this download completed. Note that for
560 * directories, completion does not imply completion of all files in
563 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED = 12,
566 * Notification that this download was stopped
567 * (final event with respect to this action).
569 GNUNET_FS_STATUS_DOWNLOAD_STOPPED = 13,
572 * Notification that this download is now actively being
573 * pursued (as opposed to waiting in the queue).
575 GNUNET_FS_STATUS_DOWNLOAD_ACTIVE = 14,
578 * Notification that this download is no longer actively
579 * being pursued (back in the queue).
581 GNUNET_FS_STATUS_DOWNLOAD_INACTIVE = 15,
584 * Notification that this download is no longer part of a
585 * recursive download or search but now a 'stand-alone'
586 * download (and may thus need to be moved in the GUI
587 * into a different category).
589 GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT = 16,
592 * First event generated when a client requests
593 * a search to begin or when a namespace result
594 * automatically triggers the search for updates.
596 GNUNET_FS_STATUS_SEARCH_START = 17,
599 * Last event when a search is being resumed;
600 * note that "GNUNET_FS_SEARCH_START" will not
601 * be generated in this case.
603 GNUNET_FS_STATUS_SEARCH_RESUME = 18,
606 * Event generated for each search result
607 * when the respective search is resumed.
609 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT = 19,
612 * Last event when a search is being suspended;
613 * note that "GNUNET_FS_SEARCH_STOPPED" will not
614 * be generated in this case.
616 GNUNET_FS_STATUS_SEARCH_SUSPEND = 20,
619 * This search has yielded a result.
621 GNUNET_FS_STATUS_SEARCH_RESULT = 21,
624 * We have discovered a new namespace.
626 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE = 22,
629 * We have additional data about the quality
630 * or availability of a search result.
632 GNUNET_FS_STATUS_SEARCH_UPDATE = 23,
635 * Signals a problem with this search.
637 GNUNET_FS_STATUS_SEARCH_ERROR = 24,
640 * Signals that this search was paused.
642 GNUNET_FS_STATUS_SEARCH_PAUSED = 25,
645 * Signals that this search was continued (unpaused).
647 GNUNET_FS_STATUS_SEARCH_CONTINUED = 26,
650 * Event generated for each search result
651 * when the respective search is stopped.
653 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED = 27,
656 * Event generated for each search result
657 * when the respective search is suspended.
659 GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND = 28,
662 * Last message from a search; this signals
663 * that there will be no further events associated
666 GNUNET_FS_STATUS_SEARCH_STOPPED = 29,
669 * Notification that we started to unindex a file.
671 GNUNET_FS_STATUS_UNINDEX_START = 30,
674 * Notification that we resumed unindexing of a file.
676 GNUNET_FS_STATUS_UNINDEX_RESUME = 31,
679 * Notification that we suspended unindexing a file.
681 GNUNET_FS_STATUS_UNINDEX_SUSPEND = 32,
684 * Notification that we made progress unindexing a file.
686 GNUNET_FS_STATUS_UNINDEX_PROGRESS = 33,
689 * Notification that we encountered an error unindexing
692 GNUNET_FS_STATUS_UNINDEX_ERROR = 34,
695 * Notification that the unindexing of this file
698 GNUNET_FS_STATUS_UNINDEX_COMPLETED = 35,
701 * Notification that the unindexing of this file
702 * was stopped (final event for this action).
704 GNUNET_FS_STATUS_UNINDEX_STOPPED = 36
709 * Handle for controlling an upload.
711 struct GNUNET_FS_PublishContext;
715 * Handle for controlling an unindexing operation.
717 struct GNUNET_FS_UnindexContext;
721 * Handle for controlling a search.
723 struct GNUNET_FS_SearchContext;
727 * Result from a search. Opaque handle to refer to the search
728 * (typically used when starting a download associated with the search
731 struct GNUNET_FS_SearchResult;
735 * Context for controlling a download.
737 struct GNUNET_FS_DownloadContext;
741 * Handle for detail information about a file that is being publishd.
742 * Specifies metadata, keywords, how to get the contents of the file
743 * (i.e. data-buffer in memory, filename on disk) and other options.
745 struct GNUNET_FS_FileInformation;
749 * Argument given to the progress callback with
750 * information about what is going on.
752 struct GNUNET_FS_ProgressInfo
756 * Values that depend on the event type.
762 * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
768 * Context for controlling the upload.
770 struct GNUNET_FS_PublishContext *pc;
773 * Information about the file that is being publishd.
775 const struct GNUNET_FS_FileInformation *fi;
778 * Client context pointer (set the last time by the client for
779 * this operation; initially NULL on START/RESUME events).
784 * Client context pointer for the parent operation
785 * (if this is a file in a directory or a subdirectory).
790 * Name of the file being published; can be NULL.
792 const char *filename;
795 * How large is the file overall? For directories,
796 * this is only the size of the directory itself,
797 * not of the other files contained within the
803 * At what time do we expect to finish the upload?
804 * (will be a value in the past for completed
807 struct GNUNET_TIME_Relative eta;
810 * How long has this upload been actively running
811 * (excludes times where the upload was suspended).
813 struct GNUNET_TIME_Relative duration;
816 * How many bytes have we completed?
821 * What anonymity level is used for this upload?
826 * Additional values for specific events.
832 * These values are only valid for
833 * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
839 * Data block we just published.
844 * At what offset in the file is "data"?
849 * Length of the data block.
854 * Depth of the given block in the tree;
855 * 0 would be the lowest level (DBLOCKs).
862 * These values are only valid for
863 * GNUNET_FS_STATUS_PUBLISH_RESUME events.
869 * Error message, NULL if no error was encountered so far.
874 * URI of the file (if the download had been completed)
876 const struct GNUNET_FS_Uri *chk_uri;
881 * These values are only valid for
882 * GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
890 const struct GNUNET_FS_Uri *chk_uri;
895 * These values are only valid for
896 * GNUNET_FS_STATUS_PUBLISH_ERROR events.
902 * Error message, never NULL.
914 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
920 * Context for controlling the download.
922 struct GNUNET_FS_DownloadContext *dc;
925 * Client context pointer (set the last time
926 * by the client for this operation; initially
927 * NULL on START/RESUME events).
932 * Client context pointer for the parent operation
933 * (if this is a file in a directory or a subdirectory).
938 * Client context pointer for the associated search operation
939 * (specifically, context pointer for the specific search
940 * result, not the overall search); only set if this
941 * download was started from a search result.
946 * URI used for this download.
948 const struct GNUNET_FS_Uri *uri;
951 * Name of the file that we are downloading.
953 const char *filename;
956 * How large is the download overall? This
957 * is NOT necessarily the size from the
958 * URI since we may be doing a partial download.
963 * At what time do we expect to finish the download?
964 * (will be a value in the past for completed
967 struct GNUNET_TIME_Relative eta;
970 * How long has this download been active?
972 struct GNUNET_TIME_Relative duration;
975 * How many bytes have we completed?
980 * What anonymity level is used for this download?
985 * Is the download currently active.
990 * Additional values for specific events.
996 * These values are only valid for
997 * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
1003 * Data block we just obtained, can be NULL (even if
1004 * data_len > 0) if we found the entire block 'intact' on
1005 * disk. In this case, it is also possible for 'data_len'
1006 * to be larger than an individual (32k) block.
1011 * At what offset in the file is "data"?
1016 * Length of the data block.
1021 * Depth of the given block in the tree;
1022 * 0 would be the lowest level (DBLOCKS).
1027 * How much trust did we offer for downloading this block?
1029 unsigned int trust_offered;
1032 * How much time passed between us asking for this block and
1033 * actually getting it? GNUNET_TIME_UNIT_FOREVER_REL if unknown.
1035 struct GNUNET_TIME_Relative block_download_duration;
1040 * These values are only valid for
1041 * GNUNET_FS_STATUS_DOWNLOAD_START events.
1047 * Known metadata for the download.
1049 const struct GNUNET_CONTAINER_MetaData *meta;
1054 * These values are only valid for
1055 * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
1061 * Known metadata for the download.
1063 const struct GNUNET_CONTAINER_MetaData *meta;
1066 * Error message, NULL if we have not encountered any error yet.
1068 const char *message;
1073 * These values are only valid for
1074 * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1082 const char *message;
1091 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1097 * Context for controlling the search, NULL for
1098 * searches that were not explicitly triggered
1099 * by the client (i.e., searches for updates in
1102 struct GNUNET_FS_SearchContext *sc;
1105 * Client context pointer (set the last time by the client for
1106 * this operation; initially NULL on START/RESUME events). Note
1107 * that this value can only be set on START/RESUME; returning
1108 * non-NULL on RESULT/RESUME_RESULT will actually update the
1109 * private context for "UPDATE" events.
1114 * Client parent-context pointer; NULL for top-level searches,
1115 * refers to the client context of the associated search result
1116 * for automatically triggered searches for updates in
1117 * namespaces. In this case, 'presult' refers to that search
1123 * What query is used for this search
1124 * (list of keywords or SKS identifier).
1126 const struct GNUNET_FS_Uri *query;
1129 * How long has this search been actively running
1130 * (excludes times where the search was paused or
1133 struct GNUNET_TIME_Relative duration;
1136 * What anonymity level is used for this search?
1141 * Additional values for specific events.
1147 * These values are only valid for
1148 * GNUNET_FS_STATUS_SEARCH_RESULT events.
1154 * Metadata for the search result.
1156 const struct GNUNET_CONTAINER_MetaData *meta;
1159 * URI for the search result.
1161 const struct GNUNET_FS_Uri *uri;
1164 * Handle to the result (for starting downloads).
1166 struct GNUNET_FS_SearchResult *result;
1169 * Applicability rank (the larger, the better the result
1170 * fits the search criteria).
1172 uint32_t applicability_rank;
1177 * These values are only valid for
1178 * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1184 * Metadata for the search result.
1186 const struct GNUNET_CONTAINER_MetaData *meta;
1189 * URI for the search result.
1191 const struct GNUNET_FS_Uri *uri;
1194 * Handle to the result (for starting downloads).
1196 struct GNUNET_FS_SearchResult *result;
1199 * Current availability rank (negative:
1200 * unavailable, positive: available)
1202 int32_t availability_rank;
1205 * On how many total queries is the given
1206 * availability_rank based?
1208 uint32_t availability_certainty;
1211 * Updated applicability rank (the larger,
1212 * the better the result fits the search
1215 uint32_t applicability_rank;
1220 * These values are only valid for
1221 * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1227 * Private context set for for this result
1228 * during the "RESULT" event.
1233 * Metadata for the search result.
1235 const struct GNUNET_CONTAINER_MetaData *meta;
1238 * URI for the search result.
1240 const struct GNUNET_FS_Uri *uri;
1243 * Current availability rank (negative:
1244 * unavailable, positive: available)
1246 int32_t availability_rank;
1249 * On how many total queries is the given
1250 * availability_rank based?
1252 uint32_t availability_certainty;
1255 * Updated applicability rank (the larger,
1256 * the better the result fits the search
1259 uint32_t applicability_rank;
1264 * These values are only valid for
1265 * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1266 * These events are automatically triggered for
1267 * each search result before the
1268 * GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1269 * happens primarily to give the client a chance
1270 * to clean up the "cctx" (if needed).
1276 * Private context set for for this result
1277 * during the "RESULT" event.
1282 * Metadata for the search result.
1284 const struct GNUNET_CONTAINER_MetaData *meta;
1287 * URI for the search result.
1289 const struct GNUNET_FS_Uri *uri;
1294 * These values are only valid for
1295 * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1296 * These events are automatically triggered for
1297 * each search result before the
1298 * GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1299 * happens primarily to give the client a chance
1300 * to clean up the "cctx" (if needed).
1306 * Private context set for for this result
1307 * during the "RESULT" event.
1312 * Metadata for the search result.
1314 const struct GNUNET_CONTAINER_MetaData *meta;
1317 * URI for the search result.
1319 const struct GNUNET_FS_Uri *uri;
1324 * These values are only valid for
1325 * GNUNET_FS_STATUS_SEARCH_RESUME events.
1331 * Error message, NULL if we have not encountered any error yet.
1333 const char *message;
1336 * Is this search currently paused?
1343 * These values are only valid for
1344 * GNUNET_FS_STATUS_SEARCH_ERROR events.
1352 const char *message;
1357 * Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events.
1363 * Handle to the namespace (NULL if it is not a local
1366 struct GNUNET_FS_Namespace *ns;
1369 * Short, human-readable name of the namespace.
1374 * Root identifier for the namespace, can be NULL.
1379 * Metadata for the namespace.
1381 const struct GNUNET_CONTAINER_MetaData *meta;
1384 * Hash-identifier for the namespace.
1395 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1401 * Context for controlling the unindexing.
1403 struct GNUNET_FS_UnindexContext *uc;
1406 * Client context pointer (set the last time
1407 * by the client for this operation; initially
1408 * NULL on START/RESUME events).
1413 * Name of the file that is being unindexed.
1415 const char *filename;
1418 * How large is the file overall?
1423 * At what time do we expect to finish unindexing?
1424 * (will be a value in the past for completed
1425 * unindexing opeations).
1427 struct GNUNET_TIME_Relative eta;
1430 * How long has this upload been actively running
1431 * (excludes times where the upload was suspended).
1433 struct GNUNET_TIME_Relative duration;
1436 * How many bytes have we completed?
1441 * Additional values for specific events.
1447 * These values are only valid for
1448 * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1454 * Data block we just unindexed.
1459 * At what offset in the file is "data"?
1464 * Length of the data block.
1469 * Depth of the given block in the tree;
1470 * 0 would be the lowest level (DBLOCKS).
1477 * These values are only valid for
1478 * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1484 * Error message, NULL if we have not encountered any error yet.
1486 const char *message;
1491 * These values are only valid for
1492 * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1500 const char *message;
1511 * Specific status code (determines the event type).
1513 enum GNUNET_FS_Status status;
1519 * Notification of FS to a client about the progress of an
1520 * operation. Callbacks of this type will be used for uploads,
1521 * downloads and searches. Some of the arguments depend a bit
1522 * in their meaning on the context in which the callback is used.
1524 * @param cls closure
1525 * @param info details about the event, specifying the event type
1526 * and various bits about the event
1527 * @return client-context (for the next progress call
1528 * for this operation; should be set to NULL for
1529 * SUSPEND and STOPPED events). The value returned
1530 * will be passed to future callbacks in the respective
1531 * field in the GNUNET_FS_ProgressInfo struct.
1533 typedef void *(*GNUNET_FS_ProgressCallback) (void *cls,
1534 const struct GNUNET_FS_ProgressInfo
1539 * General (global) option flags for file-sharing.
1541 enum GNUNET_FS_Flags
1544 * No special flags set.
1546 GNUNET_FS_FLAGS_NONE = 0,
1549 * Is persistence of operations desired?
1550 * (will create SUSPEND/RESUME events).
1552 GNUNET_FS_FLAGS_PERSISTENCE = 1,
1555 * Should we automatically trigger probes for search results
1556 * to determine availability?
1557 * (will create GNUNET_FS_STATUS_SEARCH_UPDATE events).
1559 GNUNET_FS_FLAGS_DO_PROBES = 2
1563 * Options specified in the VARARGs portion of GNUNET_FS_start.
1565 enum GNUNET_FS_OPTIONS
1569 * Last option in the VARARG list.
1571 GNUNET_FS_OPTIONS_END = 0,
1574 * Select the desired amount of parallelism (this option should be
1575 * followed by an "unsigned int" giving the desired maximum number
1576 * of parallel downloads).
1578 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
1581 * Maximum number of requests that should be pending at a given
1582 * point in time (invidivual downloads may go above this, but
1583 * if we are above this threshold, we should not activate any
1584 * additional downloads.
1586 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
1591 * Settings for publishing a block (which may of course also
1592 * apply to an entire directory or file).
1594 struct GNUNET_FS_BlockOptions
1598 * At what time should the block expire? Data blocks (DBLOCKS and
1599 * IBLOCKS) may still be used even if they are expired (however,
1600 * they'd be removed quickly from the datastore if we are short on
1601 * space), all other types of blocks will no longer be returned
1602 * after they expire.
1604 struct GNUNET_TIME_Absolute expiration_time;
1607 * At which anonymity level should the block be shared?
1608 * (0: no anonymity, 1: normal GAP, >1: with cover traffic).
1610 uint32_t anonymity_level;
1613 * How important is it for us to store the block? If we run
1614 * out of space, the highest-priority, non-expired blocks will
1617 uint32_t content_priority;
1620 * How often should we try to migrate the block to other peers?
1621 * Only used if "CONTENT_PUSHING" is set to YES, in which case we
1622 * first push each block to other peers according to their
1623 * replication levels. Once each block has been pushed that many
1624 * times to other peers, blocks are chosen for migration at random.
1625 * Naturally, there is no guarantee that the other peers will keep
1626 * these blocks for any period of time (since they won't have any
1627 * priority or might be too busy to even store the block in the
1630 uint32_t replication_level;
1636 * Return the current year (i.e. '2011').
1639 GNUNET_FS_get_current_year (void);
1643 * Convert a year to an expiration time of January 1st of that year.
1645 * @param year a year (after 1970, please ;-)).
1646 * @return absolute time for January 1st of that year.
1648 struct GNUNET_TIME_Absolute
1649 GNUNET_FS_year_to_time (unsigned int year);
1653 * Convert an expiration time to the respective year (rounds)
1655 * @param at absolute time
1656 * @return year a year (after 1970), 0 on error
1659 GNUNET_FS_time_to_year (struct GNUNET_TIME_Absolute at);
1663 * Handle to the file-sharing service.
1665 struct GNUNET_FS_Handle;
1669 * Setup a connection to the file-sharing service.
1671 * @param cfg configuration to use
1672 * @param client_name unique identifier for this client
1673 * @param upcb function to call to notify about FS actions
1674 * @param upcb_cls closure for upcb
1675 * @param flags specific attributes for fs-operations
1676 * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
1677 * @return NULL on error
1679 struct GNUNET_FS_Handle *
1680 GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1681 const char *client_name, GNUNET_FS_ProgressCallback upcb,
1682 void *upcb_cls, enum GNUNET_FS_Flags flags, ...);
1686 * Close our connection with the file-sharing service.
1687 * The callback given to GNUNET_FS_start will no longer be
1688 * called after this function returns.
1690 * @param h handle that was returned from GNUNET_FS_start
1693 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1697 * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
1699 * @param cls closure
1700 * @param fi the entry in the publish-structure
1701 * @param length length of the file or directory
1702 * @param meta metadata for the file or directory (can be modified)
1703 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1704 * @param bo block options (can be modified)
1705 * @param do_index should we index (can be modified)
1706 * @param client_info pointer to client context set upon creation (can be modified)
1707 * @return GNUNET_OK to continue, GNUNET_NO to remove
1708 * this entry from the directory, GNUNET_SYSERR
1709 * to abort the iteration
1711 typedef int (*GNUNET_FS_FileInformationProcessor) (void *cls,
1713 GNUNET_FS_FileInformation *
1714 fi, uint64_t length,
1716 GNUNET_CONTAINER_MetaData *
1718 struct GNUNET_FS_Uri ** uri,
1719 struct GNUNET_FS_BlockOptions
1720 * bo, int *do_index,
1721 void **client_info);
1725 * Obtain the name under which this file information
1726 * structure is stored on disk. Only works for top-level
1727 * file information structures.
1729 * @param s structure to get the filename for
1730 * @return NULL on error, otherwise filename that
1731 * can be passed to "GNUNET_FS_file_information_recover"
1732 * to read this fi-struct from disk.
1735 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1739 * Obtain the filename from the file information structure.
1741 * @param s structure to get the filename for
1742 * @return "filename" field of the structure (can be NULL)
1745 GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s);
1749 * Set the filename in the file information structure.
1750 * If filename was already set, frees it before setting the new one.
1751 * Makes a copy of the argument.
1753 * @param s structure to get the filename for
1754 * @param filename filename to set
1757 GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s,
1758 const char *filename);
1762 * Create an entry for a file in a publish-structure.
1764 * @param h handle to the file sharing subsystem
1765 * @param client_info initial client-info value for this entry
1766 * @param filename name of the file or directory to publish
1767 * @param keywords under which keywords should this file be available
1768 * directly; can be NULL
1769 * @param meta metadata for the file
1770 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1771 * GNUNET_SYSERR for simulation
1772 * @param bo block options
1773 * @return publish structure entry for the file
1775 struct GNUNET_FS_FileInformation *
1776 GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
1778 const char *filename,
1779 const struct GNUNET_FS_Uri
1782 GNUNET_CONTAINER_MetaData *meta,
1784 const struct GNUNET_FS_BlockOptions
1789 * Create an entry for a file in a publish-structure.
1791 * @param h handle to the file sharing subsystem
1792 * @param client_info initial client-info value for this entry
1793 * @param length length of the file
1794 * @param data data for the file (should not be used afterwards by
1795 * the caller; callee will "free")
1796 * @param keywords under which keywords should this file be available
1797 * directly; can be NULL
1798 * @param meta metadata for the file
1799 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1800 * GNUNET_SYSERR for simulation
1801 * @param bo block options
1802 * @return publish structure entry for the file
1804 struct GNUNET_FS_FileInformation *
1805 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
1806 void *client_info, uint64_t length,
1808 const struct GNUNET_FS_Uri
1811 GNUNET_CONTAINER_MetaData *meta,
1813 const struct GNUNET_FS_BlockOptions
1818 * Function that provides data.
1820 * @param cls closure
1821 * @param offset offset to read from; it is possible
1822 * that the caller might need to go backwards
1823 * a bit at times; set to UINT64_MAX to tell
1824 * the reader that we won't be reading for a while
1825 * (used to close the file descriptor but NOT fully
1826 * clean up the reader's state); in this case,
1827 * a value of '0' for max should be ignored
1828 * @param max maximum number of bytes that should be
1829 * copied to buf; readers are not allowed
1830 * to provide less data unless there is an error;
1831 * a value of "0" will be used at the end to allow
1832 * the reader to clean up its internal state
1833 * @param buf where the reader should write the data
1834 * @param emsg location for the reader to store an error message
1835 * @return number of bytes written, usually "max", 0 on error
1837 typedef size_t (*GNUNET_FS_DataReader) (void *cls, uint64_t offset, size_t max,
1838 void *buf, char **emsg);
1842 * Create an entry for a file in a publish-structure.
1844 * @param h handle to the file sharing subsystem
1845 * @param client_info initial client-info value for this entry
1846 * @param length length of the file
1847 * @param reader function that can be used to obtain the data for the file
1848 * @param reader_cls closure for "reader"
1849 * @param keywords under which keywords should this file be available
1850 * directly; can be NULL
1851 * @param meta metadata for the file
1852 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1853 * GNUNET_SYSERR for simulation
1854 * @param bo block options
1855 * @return publish structure entry for the file
1857 struct GNUNET_FS_FileInformation *
1858 GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
1861 GNUNET_FS_DataReader reader,
1863 const struct GNUNET_FS_Uri
1866 GNUNET_CONTAINER_MetaData *meta,
1869 GNUNET_FS_BlockOptions *bo);
1873 * Create an entry for an empty directory in a publish-structure.
1874 * This function should be used by applications for which the
1875 * use of "GNUNET_FS_file_information_create_from_directory"
1876 * is not appropriate.
1878 * @param h handle to the file sharing subsystem
1879 * @param client_info initial client-info value for this entry
1880 * @param keywords under which keywords should this directory be available
1881 * directly; can be NULL
1882 * @param meta metadata for the directory
1883 * @param bo block options
1884 * @param filename name of the directory; can be NULL
1885 * @return publish structure entry for the directory , NULL on error
1887 struct GNUNET_FS_FileInformation *
1888 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
1890 const struct GNUNET_FS_Uri
1893 GNUNET_CONTAINER_MetaData
1896 GNUNET_FS_BlockOptions *bo,
1897 const char *filename);
1901 * Test if a given entry represents a directory.
1903 * @param ent check if this FI represents a directory
1904 * @return GNUNET_YES if so, GNUNET_NO if not
1907 GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
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, const char *nid,
1999 enum GNUNET_FS_PublishOptions options);
2003 * Stop a publication. Will abort incomplete publications (but
2004 * not remove blocks that have already been published) or
2005 * simply clean up the state for completed publications.
2006 * Must NOT be called from within the event callback!
2008 * @param pc context for the publication to stop
2011 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
2015 * Signature of a function called as the continuation of a KBlock or
2016 * SBlock publication.
2018 * @param cls closure
2019 * @param uri URI under which the block is now available, NULL on error
2020 * @param emsg error message, NULL on success
2022 typedef void (*GNUNET_FS_PublishContinuation) (void *cls,
2023 const struct GNUNET_FS_Uri * uri,
2028 * Handle to cancel publish KSK operation.
2030 struct GNUNET_FS_PublishKskContext;
2034 * Publish a KBlock on GNUnet.
2036 * @param h handle to the file sharing subsystem
2037 * @param ksk_uri keywords to use
2038 * @param meta metadata to use
2039 * @param uri URI to refer to in the KBlock
2040 * @param bo block options
2041 * @param options publication options
2042 * @param cont continuation
2043 * @param cont_cls closure for cont
2044 * @return NULL on error ('cont' will still be called)
2046 struct GNUNET_FS_PublishKskContext *
2047 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2048 const struct GNUNET_FS_Uri *ksk_uri,
2049 const struct GNUNET_CONTAINER_MetaData *meta,
2050 const struct GNUNET_FS_Uri *uri,
2051 const struct GNUNET_FS_BlockOptions *bo,
2052 enum GNUNET_FS_PublishOptions options,
2053 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2057 * Abort the KSK publishing operation.
2059 * @param pkc context of the operation to abort.
2062 GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc);
2066 * Handle to cancel publish SKS operation.
2068 struct GNUNET_FS_PublishSksContext;
2072 * Publish an SBlock on GNUnet.
2074 * @param h handle to the file sharing subsystem
2075 * @param namespace namespace to publish in
2076 * @param identifier identifier to use
2077 * @param update update identifier to use
2078 * @param meta metadata to use
2079 * @param uri URI to refer to in the SBlock
2080 * @param bo block options
2081 * @param options publication options
2082 * @param cont continuation
2083 * @param cont_cls closure for cont
2084 * @return NULL on error ('cont' will still be called)
2086 struct GNUNET_FS_PublishSksContext *
2087 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2088 struct GNUNET_FS_Namespace *namespace,
2089 const char *identifier, const char *update,
2090 const struct GNUNET_CONTAINER_MetaData *meta,
2091 const struct GNUNET_FS_Uri *uri,
2092 const struct GNUNET_FS_BlockOptions *bo,
2093 enum GNUNET_FS_PublishOptions options,
2094 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2098 * Abort the SKS publishing operation.
2100 * @param psc context of the operation to abort.
2103 GNUNET_FS_publish_sks_cancel (struct GNUNET_FS_PublishSksContext *psc);
2107 * Type of a function called by "GNUNET_FS_get_indexed_files".
2109 * @param cls closure
2110 * @param filename the name of the file, NULL for end of list
2111 * @param file_id hash of the contents of the indexed file
2112 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
2114 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls, const char *filename,
2115 const GNUNET_HashCode * file_id);
2119 * Handle to cancel 'GNUNET_FS_get_indexed_files'.
2121 struct GNUNET_FS_GetIndexedContext;
2125 * Iterate over all indexed files.
2127 * @param h handle to the file sharing subsystem
2128 * @param iterator function to call on each indexed file
2129 * @param iterator_cls closure for iterator
2130 * @return NULL on error ('iter' is not called)
2132 struct GNUNET_FS_GetIndexedContext *
2133 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2134 GNUNET_FS_IndexedFileProcessor iterator,
2135 void *iterator_cls);
2139 * Cancel iteration over all indexed files.
2141 * @param gic operation to cancel
2144 GNUNET_FS_get_indexed_files_cancel (struct GNUNET_FS_GetIndexedContext *gic);
2150 * @param h handle to the file sharing subsystem
2151 * @param filename file to unindex
2152 * @param cctx initial value for the client context
2153 * @return NULL on error, otherwise handle
2155 struct GNUNET_FS_UnindexContext *
2156 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, const char *filename,
2161 * Clean up after completion of an unindex operation.
2166 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2170 * Context for advertising a namespace.
2172 struct GNUNET_FS_AdvertisementContext;
2176 * Publish an advertismement for a namespace.
2178 * @param h handle to the file sharing subsystem
2179 * @param ksk_uri keywords to use for advertisment
2180 * @param namespace handle for the namespace that should be advertised
2181 * @param meta meta-data for the namespace advertisement
2182 * @param bo block options
2183 * @param rootEntry name of the root of the namespace
2184 * @param cont continuation
2185 * @param cont_cls closure for cont
2186 * @return NULL on error ('cont' will still be called)
2188 struct GNUNET_FS_AdvertisementContext *
2189 GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
2190 struct GNUNET_FS_Uri *ksk_uri,
2191 struct GNUNET_FS_Namespace *namespace,
2192 const struct GNUNET_CONTAINER_MetaData *meta,
2193 const struct GNUNET_FS_BlockOptions *bo,
2194 const char *rootEntry,
2195 GNUNET_FS_PublishContinuation cont,
2200 * Abort the namespace advertisement operation.
2202 * @param ac context of the operation to abort.
2205 GNUNET_FS_namespace_advertise_cancel (struct GNUNET_FS_AdvertisementContext *ac);
2209 * Create a namespace with the given name; if one already
2210 * exists, return a handle to the existing namespace.
2212 * @param h handle to the file sharing subsystem
2213 * @param name name to use for the namespace
2214 * @return handle to the namespace, NULL on error
2216 struct GNUNET_FS_Namespace *
2217 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, const char *name);
2221 * Duplicate a namespace handle.
2223 * @param ns namespace handle
2224 * @return duplicated handle to the namespace
2226 struct GNUNET_FS_Namespace *
2227 GNUNET_FS_namespace_dup (struct GNUNET_FS_Namespace *ns);
2231 * Delete a namespace handle. Can be used for a clean shutdown (free
2232 * memory) or also to freeze the namespace to prevent further
2233 * insertions by anyone.
2235 * @param namespace handle to the namespace that should be deleted / freed
2236 * @param freeze prevents future insertions; creating a namespace
2237 * with the same name again will create a fresh namespace instead
2239 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2242 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace, int freeze);
2246 * Callback with information about local (!) namespaces.
2247 * Contains the names of the local namespace and the global
2250 * @param cls closure
2251 * @param name human-readable identifier of the namespace
2252 * @param id hash identifier for the namespace
2254 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls, const char *name,
2255 const GNUNET_HashCode * id);
2259 * Build a list of all available local (!) namespaces The returned
2260 * names are only the nicknames since we only iterate over the local
2263 * @param h handle to the file sharing subsystem
2264 * @param cb function to call on each known namespace
2265 * @param cb_cls closure for cb
2268 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2269 GNUNET_FS_NamespaceInfoProcessor cb, void *cb_cls);
2273 * Function called on updateable identifiers.
2275 * @param cls closure
2276 * @param last_id last identifier
2277 * @param last_uri uri used for the content published under the last_id
2278 * @param last_meta metadata associated with last_uri
2279 * @param next_id identifier that should be used for updates
2281 typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls, const char *last_id,
2282 const struct GNUNET_FS_Uri *
2285 GNUNET_CONTAINER_MetaData *
2286 last_meta, const char *next_id);
2290 * List all of the identifiers in the namespace for which we could
2291 * produce an update. Namespace updates form a graph where each node
2292 * has a name. Each node can have any number of URI/meta-data entries
2293 * which can each be linked to other nodes. Cycles are possible.
2295 * Calling this function with "next_id" NULL will cause the library to
2296 * call "ip" with a root for each strongly connected component of the
2297 * graph (a root being a node from which all other nodes in the Scc
2300 * Calling this function with "next_id" being the name of a node will
2301 * cause the library to call "ip" with all children of the node. Note
2302 * that cycles within an SCC are possible (including self-loops).
2304 * @param namespace namespace to inspect for updateable content
2305 * @param next_id ID to look for; use NULL to look for SCC roots
2306 * @param ip function to call on each updateable identifier
2307 * @param ip_cls closure for ip
2310 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
2311 const char *next_id,
2312 GNUNET_FS_IdentifierProcessor ip,
2317 * Options for searching. Compatible options
2318 * can be OR'ed together.
2320 enum GNUNET_FS_SearchOptions
2323 * No options (use defaults for everything).
2325 GNUNET_FS_SEARCH_OPTION_NONE = 0,
2328 * Only search the local host, do not search remote systems (no P2P)
2330 GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
2335 * Start search for content.
2337 * @param h handle to the file sharing subsystem
2338 * @param uri specifies the search parameters; can be
2339 * a KSK URI or an SKS URI.
2340 * @param anonymity desired level of anonymity
2341 * @param options options for the search
2342 * @param cctx initial value for the client context
2343 * @return context that can be used to control the search
2345 struct GNUNET_FS_SearchContext *
2346 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2347 const struct GNUNET_FS_Uri *uri, uint32_t anonymity,
2348 enum GNUNET_FS_SearchOptions options, void *cctx);
2354 * @param sc context for the search that should be paused
2357 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2361 * Continue paused search.
2363 * @param sc context for the search that should be resumed
2366 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2370 * Stop search for content.
2372 * @param sc context for the search that should be stopped
2375 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2381 * Options for downloading. Compatible options
2382 * can be OR'ed together.
2384 enum GNUNET_FS_DownloadOptions
2387 * No options (use defaults for everything).
2389 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2392 * Only download from the local host, do not access remote systems (no P2P)
2394 GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
2397 * Do a recursive download (that is, automatically trigger the
2398 * download of files in directories).
2400 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
2403 * Do not append temporary data to
2404 * the target file (for the IBlocks).
2406 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
2409 * Internal option used to flag this download as a 'probe' for a
2410 * search result. Impacts the priority with which the download is
2411 * run and causes signalling callbacks to be done differently.
2412 * Also, probe downloads are not serialized on suspension. Normal
2413 * clients should not use this!
2415 GNUNET_FS_DOWNLOAD_IS_PROBE = (1 << 31)
2421 * Download parts of a file. Note that this will store
2422 * the blocks at the respective offset in the given file. Also, the
2423 * download is still using the blocking of the underlying FS
2424 * encoding. As a result, the download may *write* outside of the
2425 * given boundaries (if offset and length do not match the 32k FS
2426 * block boundaries). <p>
2428 * The given range can be used to focus a download towards a
2429 * particular portion of the file (optimization), not to strictly
2430 * limit the download to exactly those bytes.
2432 * @param h handle to the file sharing subsystem
2433 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2434 * @param meta known metadata for the file (can be NULL)
2435 * @param filename where to store the file, maybe NULL (then no file is
2436 * created on disk and data must be grabbed from the callbacks)
2437 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2438 * can be NULL (in which case we will pick a name if needed); the temporary file
2439 * may already exist, in which case we will try to use the data that is there and
2440 * if it is not what is desired, will overwrite it
2441 * @param offset at what offset should we start the download (typically 0)
2442 * @param length how many bytes should be downloaded starting at offset
2443 * @param anonymity anonymity level to use for the download
2444 * @param options various download options
2445 * @param cctx initial value for the client context for this download
2446 * @param parent parent download to associate this download with (use NULL
2447 * for top-level downloads; useful for manually-triggered recursive downloads)
2448 * @return context that can be used to control this download
2450 struct GNUNET_FS_DownloadContext *
2451 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2452 const struct GNUNET_FS_Uri *uri,
2453 const struct GNUNET_CONTAINER_MetaData *meta,
2454 const char *filename, const char *tempname,
2455 uint64_t offset, uint64_t length, uint32_t anonymity,
2456 enum GNUNET_FS_DownloadOptions options, void *cctx,
2457 struct GNUNET_FS_DownloadContext *parent);
2461 * Download parts of a file based on a search result. The download
2462 * will be associated with the search result (and the association
2463 * will be preserved when serializing/deserializing the state).
2464 * If the search is stopped, the download will not be aborted but
2465 * be 'promoted' to a stand-alone download.
2467 * As with the other download function, this will store
2468 * the blocks at the respective offset in the given file. Also, the
2469 * download is still using the blocking of the underlying FS
2470 * encoding. As a result, the download may *write* outside of the
2471 * given boundaries (if offset and length do not match the 32k FS
2472 * block boundaries). <p>
2474 * The given range can be used to focus a download towards a
2475 * particular portion of the file (optimization), not to strictly
2476 * limit the download to exactly those bytes.
2478 * @param h handle to the file sharing subsystem
2479 * @param sr the search result to use for the download (determines uri and
2480 * meta data and associations)
2481 * @param filename where to store the file, maybe NULL (then no file is
2482 * created on disk and data must be grabbed from the callbacks)
2483 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2484 * can be NULL (in which case we will pick a name if needed); the temporary file
2485 * may already exist, in which case we will try to use the data that is there and
2486 * if it is not what is desired, will overwrite it
2487 * @param offset at what offset should we start the download (typically 0)
2488 * @param length how many bytes should be downloaded starting at offset
2489 * @param anonymity anonymity level to use for the download
2490 * @param options various download options
2491 * @param cctx initial value for the client context for this download
2492 * @return context that can be used to control this download
2494 struct GNUNET_FS_DownloadContext *
2495 GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2496 struct GNUNET_FS_SearchResult *sr,
2497 const char *filename,
2498 const char *tempname, uint64_t offset,
2499 uint64_t length, uint32_t anonymity,
2500 enum GNUNET_FS_DownloadOptions options,
2505 * Stop a download (aborts if download is incomplete).
2507 * @param dc handle for the download
2508 * @param do_delete delete files of incomplete downloads
2511 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete);
2515 /* ******************** Directory API *********************** */
2518 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2519 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2520 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2523 * Does the meta-data claim that this is a directory?
2524 * Checks if the mime-type is that of a GNUnet directory.
2526 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2527 * we have no mime-type information (treat as 'GNUNET_NO')
2530 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
2535 * Set the MIMETYPE information for the given
2536 * metadata to "application/gnunet-directory".
2538 * @param md metadata to add mimetype to
2541 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2545 * Suggest a filename based on given metadata.
2547 * @param md given meta data
2548 * @return NULL if meta data is useless for suggesting a filename
2551 GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData
2556 * Function used to process entries in a directory.
2558 * @param cls closure
2559 * @param filename name of the file in the directory
2560 * @param uri URI of the file
2561 * @param metadata metadata for the file; metadata for
2562 * the directory if everything else is NULL/zero
2563 * @param length length of the available data for the file
2564 * (of type size_t since data must certainly fit
2565 * into memory; if files are larger than size_t
2566 * permits, then they will certainly not be
2567 * embedded with the directory itself).
2568 * @param data data available for the file (length bytes)
2570 typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
2571 const char *filename,
2572 const struct GNUNET_FS_Uri *
2575 GNUNET_CONTAINER_MetaData *
2576 meta, size_t length,
2581 * Iterate over all entries in a directory. Note that directories
2582 * are structured such that it is possible to iterate over the
2583 * individual blocks as well as over the entire directory. Thus
2584 * a client can call this function on the buffer in the
2585 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2586 * include the contents of (small) files embedded in the directory
2587 * itself; for those files, the processor may be given the
2588 * contents of the file directly by this function.
2590 * @param size number of bytes in data
2591 * @param data pointer to the beginning of the directory
2592 * @param offset offset of data in the directory
2593 * @param dep function to call on each entry
2594 * @param dep_cls closure for dep
2595 * @return GNUNET_OK if this could be a block in a directory,
2596 * GNUNET_NO if this could be part of a directory (but not 100% OK)
2597 * GNUNET_SYSERR if 'data' does not represent a directory
2600 GNUNET_FS_directory_list_contents (size_t size, const void *data,
2602 GNUNET_FS_DirectoryEntryProcessor dep,
2607 * Opaque handle to a directory builder.
2609 struct GNUNET_FS_DirectoryBuilder;
2612 * Create a directory builder.
2614 * @param mdir metadata for the directory
2616 struct GNUNET_FS_DirectoryBuilder *
2617 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
2622 * Add an entry to a directory.
2624 * @param bld directory to extend
2625 * @param uri uri of the entry (must not be a KSK)
2626 * @param md metadata of the entry
2627 * @param data raw data of the entry, can be NULL, otherwise
2628 * data must point to exactly the number of bytes specified
2632 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2633 const struct GNUNET_FS_Uri *uri,
2634 const struct GNUNET_CONTAINER_MetaData *md,
2639 * Finish building the directory. Frees the
2640 * builder context and returns the directory
2643 * @param bld directory to finish
2644 * @param rsize set to the number of bytes needed
2645 * @param rdata set to the encoded directory
2646 * @return GNUNET_OK on success
2649 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2650 size_t * rsize, void **rdata);
2653 /* ******************** DirScanner API *********************** */
2656 * Progress reasons of the directory scanner.
2658 enum GNUNET_FS_DirScannerProgressUpdateReason
2662 * We've started processing a file or directory.
2664 GNUNET_FS_DIRSCANNER_FILE_START = 0,
2667 * We're having trouble accessing a file (soft-error); it will
2670 GNUNET_FS_DIRSCANNER_FILE_IGNORED,
2673 * We've found all files (in the pre-pass).
2675 GNUNET_FS_DIRSCANNER_ALL_COUNTED,
2678 * We've finished extracting meta data from a file.
2680 GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED,
2683 * Last call to the progress function: we have finished scanning
2686 GNUNET_FS_DIRSCANNER_FINISHED,
2689 * There was an internal error. Application should abort the scan.
2691 GNUNET_FS_DIRSCANNER_INTERNAL_ERROR
2697 * Function called over time as the directory scanner makes
2698 * progress on the job at hand.
2700 * @param cls closure
2701 * @param filename which file we are making progress on
2702 * @param is_directory GNUNET_YES if this is a directory,
2703 * GNUNET_NO if this is a file
2704 * GNUNET_SYSERR if it is neither (or unknown)
2705 * @param reason kind of progress we are making
2707 typedef void (*GNUNET_FS_DirScannerProgressCallback) (void *cls,
2708 const char *filename,
2710 enum GNUNET_FS_DirScannerProgressUpdateReason reason);
2714 * A node of a directory tree (produced by dirscanner)
2716 struct GNUNET_FS_ShareTreeItem
2719 * This is a doubly-linked list
2721 struct GNUNET_FS_ShareTreeItem *prev;
2724 * This is a doubly-linked list
2726 struct GNUNET_FS_ShareTreeItem *next;
2729 * This is a doubly-linked tree
2730 * NULL for top-level entries.
2732 struct GNUNET_FS_ShareTreeItem *parent;
2735 * This is a doubly-linked tree
2736 * NULL for files and empty directories
2738 struct GNUNET_FS_ShareTreeItem *children_head;
2741 * This is a doubly-linked tree
2742 * NULL for files and empty directories
2744 struct GNUNET_FS_ShareTreeItem *children_tail;
2747 * Metadata for this file or directory
2749 struct GNUNET_CONTAINER_MetaData *meta;
2752 * Keywords for this file or directory (derived from metadata).
2754 struct GNUNET_FS_Uri *ksk_uri;
2757 * Name of the file/directory
2762 * Base name of the file/directory.
2764 char *short_filename;
2767 * GNUNET_YES if this is a directory
2775 * Opaqe handle to an asynchronous directory scanning activity.
2777 struct GNUNET_FS_DirScanner;
2781 * Start a directory scanner.
2783 * @param filename name of the directory to scan
2784 * @param disable_extractor GNUNET_YES to not to run libextractor on files (only build a tree)
2785 * @param ex if not NULL, must be a list of extra plugins for extractor
2786 * @param cb the callback to call when there are scanning progress messages
2787 * @param cb_cls closure for 'cb'
2788 * @return directory scanner object to be used for controlling the scanner
2790 struct GNUNET_FS_DirScanner *
2791 GNUNET_FS_directory_scan_start (const char *filename,
2792 int disable_extractor,
2794 GNUNET_FS_DirScannerProgressCallback cb,
2799 * Abort the scan. Must not be called from within the progress_callback
2802 * @param ds directory scanner structure
2805 GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds);
2809 * Obtain the result of the scan after the scan has signalled
2810 * completion. Must not be called prior to completion. The 'ds' is
2811 * freed as part of this call.
2813 * @param ds directory scanner structure
2814 * @return the results of the scan (a directory tree)
2816 struct GNUNET_FS_ShareTreeItem *
2817 GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds);
2821 * Process a share item tree, moving frequent keywords up and
2822 * copying frequent metadata up.
2824 * @param toplevel toplevel directory in the tree, returned by the scanner
2827 GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel);
2831 * Release memory of a share item tree.
2833 * @param toplevel toplevel of the tree to be freed
2836 GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
2839 #if 0 /* keep Emacsens' auto-indent happy */