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 0x00090101
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.
75 struct GNUNET_FS_DirScanner;
78 * Iterator over keywords
81 * @param keyword the keyword
82 * @param is_mandatory is the keyword mandatory (in a search)
83 * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
85 typedef int (*GNUNET_FS_KeywordIterator) (void *cls, const char *keyword,
89 * Get a unique key from a URI. This is for putting URIs
90 * into HashMaps. The key may change between FS implementations.
92 * @param uri uri to convert to a unique key
93 * @param key wherer to store the unique key
96 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, GNUNET_HashCode * key);
99 * Convert a URI to a UTF-8 String.
101 * @param uri uri to convert to a string
102 * @return the UTF-8 string
105 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
108 * Convert keyword URI to a human readable format
109 * (i.e. the search query that was used in the first place)
111 * @param uri ksk uri to convert to a string
112 * @return string with the keywords
115 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
119 * Add the given keyword to the set of keywords represented by the URI.
120 * Does nothing if the keyword is already present.
122 * @param uri ksk uri to modify
123 * @param keyword keyword to add
124 * @param is_mandatory is this keyword mandatory?
127 GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, const char *keyword,
132 * Remove the given keyword from the set of keywords represented by the URI.
133 * Does nothing if the keyword is not present.
135 * @param uri ksk uri to modify
136 * @param keyword keyword to add
139 GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
140 const char *keyword);
144 * Convert a UTF-8 String to a URI.
146 * @param uri string to parse
147 * @param emsg where to store the parser error message (if any)
148 * @return NULL on error
150 struct GNUNET_FS_Uri *
151 GNUNET_FS_uri_parse (const char *uri, char **emsg);
156 * @param uri uri to free
159 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
163 * How many keywords are ANDed in this keyword URI?
165 * @param uri ksk uri to get the number of keywords from
166 * @return 0 if this is not a keyword URI
169 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
173 * Iterate over all keywords in this keyword URI.
175 * @param uri ksk uri to get the keywords from
176 * @param iterator function to call on each keyword
177 * @param iterator_cls closure for iterator
178 * @return -1 if this is not a keyword URI, otherwise number of
179 * keywords iterated over until iterator aborted
182 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
183 GNUNET_FS_KeywordIterator iterator,
188 * Obtain the identity of the peer offering the data
190 * @param uri the location URI to inspect
191 * @param peer where to store the identify of the peer (presumably) offering the content
192 * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK
195 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
196 struct GNUNET_PeerIdentity *peer);
200 * Obtain the URI of the content itself.
202 * @param uri location URI to get the content URI from
203 * @return NULL if argument is not a location URI
205 struct GNUNET_FS_Uri *
206 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
210 * Obtain the expiration of the LOC URI.
212 * @param uri location URI to get the expiration from
213 * @return expiration time of the URI
215 struct GNUNET_TIME_Absolute
216 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
220 * Construct a location URI (this peer will be used for the location).
222 * @param baseUri content offered by the sender
223 * @param cfg configuration information (used to find our hostkey)
224 * @param expiration_time how long will the content be offered?
225 * @return the location URI, NULL on error
227 struct GNUNET_FS_Uri *
228 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
229 const struct GNUNET_CONFIGURATION_Handle *cfg,
230 struct GNUNET_TIME_Absolute expiration_time);
234 * Merge the sets of keywords from two KSK URIs.
236 * @param u1 first uri
237 * @param u2 second uri
238 * @return merged URI, NULL on error
240 struct GNUNET_FS_Uri *
241 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
242 const struct GNUNET_FS_Uri *u2);
248 * @param uri the URI to duplicate
249 * @return copy of the URI
251 struct GNUNET_FS_Uri *
252 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
256 * Create an FS URI from a single user-supplied string of keywords.
257 * The string is broken up at spaces into individual keywords.
258 * Keywords that start with "+" are mandatory. Double-quotes can
259 * be used to prevent breaking up strings at spaces (and also
260 * to specify non-mandatory keywords starting with "+").
262 * Keywords must contain a balanced number of double quotes and
263 * double quotes can not be used in the actual keywords (for
264 * example, the string '""foo bar""' will be turned into two
265 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
267 * @param keywords the keyword string
268 * @param emsg where to store an error message
269 * @return an FS URI for the given keywords, NULL
270 * if keywords is not legal (i.e. empty).
272 struct GNUNET_FS_Uri *
273 GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg);
277 * Create an FS URI from a user-supplied command line of keywords.
278 * Arguments should start with "+" to indicate mandatory
281 * @param argc number of keywords
282 * @param argv keywords (double quotes are not required for
283 * keywords containing spaces; however, double
284 * quotes are required for keywords starting with
285 * "+"); there is no mechanism for having double
286 * quotes in the actual keywords (if the user
287 * did specifically specify double quotes, the
288 * caller should convert each double quote
289 * into two single quotes).
290 * @return an FS URI for the given keywords, NULL
291 * if keywords is not legal (i.e. empty).
293 struct GNUNET_FS_Uri *
294 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv);
298 * Test if two URIs are equal.
300 * @param u1 one of the URIs
301 * @param u2 the other URI
302 * @return GNUNET_YES if the URIs are equal
305 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
306 const struct GNUNET_FS_Uri *u2);
310 * Is this a namespace URI?
312 * @param uri the uri to check
313 * @return GNUNET_YES if this is an SKS uri
316 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
320 * Handle to one of our namespaces.
322 struct GNUNET_FS_Namespace;
326 * Create an SKS URI from a namespace and an identifier.
328 * @param ns namespace
329 * @param id identifier
330 * @param emsg where to store an error message
331 * @return an FS URI for the given namespace and identifier
333 struct GNUNET_FS_Uri *
334 GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id,
339 * Create an SKS URI from a namespace ID and an identifier.
341 * @param nsid namespace ID
342 * @param id identifier
343 * @return an FS URI for the given namespace and identifier
345 struct GNUNET_FS_Uri *
346 GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode * nsid, const char *id);
350 * Get the ID of a namespace from the given
353 * @param uri the uri to get the namespace ID from
354 * @param nsid where to store the ID of the namespace
355 * @return GNUNET_OK on success
358 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
359 GNUNET_HashCode * nsid);
363 * Get the content identifier of an SKS URI.
365 * @param uri the sks uri
366 * @return NULL on error (not a valid SKS URI)
369 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
373 * Convert namespace URI to a human readable format
374 * (using the namespace description, if available).
376 * @param cfg configuration to use
377 * @param uri SKS uri to convert
378 * @return NULL on error (not an SKS URI)
381 GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
382 const struct GNUNET_FS_Uri *uri);
386 * Is this a keyword URI?
389 * @return GNUNET_YES if this is a KSK uri
392 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
396 * Is this a file (or directory) URI?
398 * @param uri the uri to check
399 * @return GNUNET_YES if this is a CHK uri
402 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
406 * What is the size of the file that this URI
409 * @param uri the CHK (or LOC) URI to inspect
410 * @return size of the file as specified in the CHK URI
413 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
417 * Is this a location URI?
419 * @param uri the uri to check
420 * @return GNUNET_YES if this is a LOC uri
423 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
427 * Construct a keyword-URI from meta-data (take all entries
428 * in the meta-data and construct one large keyword URI
429 * that lists all keywords that can be found in the meta-data).
431 * @param md metadata to use
432 * @return NULL on error, otherwise a KSK URI
434 struct GNUNET_FS_Uri *
435 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
439 /* ******************** command-line option parsing API *********************** */
442 * Command-line option parser function that allows the user
443 * to specify one or more '-k' options with keywords. Each
444 * specified keyword will be added to the URI. A pointer to
445 * the URI must be passed as the "scls" argument.
447 * @param ctx command line processor context
448 * @param scls must be of type "struct GNUNET_FS_Uri **"
449 * @param option name of the option (typically 'k')
450 * @param value command line argument given
451 * @return GNUNET_OK on success
454 GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext
455 *ctx, void *scls, const char *option,
460 * Command-line option parser function that allows the user to specify
461 * one or more '-m' options with metadata. Each specified entry of
462 * the form "type=value" will be added to the metadata. A pointer to
463 * the metadata must be passed as the "scls" argument.
465 * @param ctx command line processor context
466 * @param scls must be of type "struct GNUNET_CONTAINER_MetaData **"
467 * @param option name of the option (typically 'k')
468 * @param value command line argument given
469 * @return GNUNET_OK on success
472 GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext
473 *ctx, void *scls, const char *option,
478 /* ************************* sharing API ***************** */
482 * Possible status codes used in the callback for the
483 * various file-sharing operations. On each file (or search),
484 * the callback is guaranteed to be called once with "START"
485 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
486 * are optional and depend on the circumstances; parent operations
487 * will be STARTED before child-operations and STOPPED after
488 * their respective child-operations. START and STOP signals
489 * are typically generated either due to explicit client requests
490 * or because of suspend/resume operations.
492 enum GNUNET_FS_Status
495 * Notification that we have started to publish a file structure.
497 GNUNET_FS_STATUS_PUBLISH_START = 0,
500 * Notification that we have resumed sharing a file structure.
502 GNUNET_FS_STATUS_PUBLISH_RESUME = 1,
505 * Notification that we have suspended sharing a file structure.
507 GNUNET_FS_STATUS_PUBLISH_SUSPEND = 2,
510 * Notification that we are making progress sharing a file structure.
512 GNUNET_FS_STATUS_PUBLISH_PROGRESS = 3,
515 * Notification that an error was encountered sharing a file structure.
516 * The application will continue to receive resume/suspend events for
517 * this structure until "GNUNET_FS_publish_stop" is called.
519 GNUNET_FS_STATUS_PUBLISH_ERROR = 4,
522 * Notification that we completed sharing a file structure.
523 * The application will continue to receive resume/suspend events for
524 * this structure until "GNUNET_FS_publish_stop" is called.
526 GNUNET_FS_STATUS_PUBLISH_COMPLETED = 5,
529 * Notification that we have stopped
530 * the process of uploading a file structure; no
531 * futher events will be generated for this action.
533 GNUNET_FS_STATUS_PUBLISH_STOPPED = 6,
536 * Notification that we have started this download.
538 GNUNET_FS_STATUS_DOWNLOAD_START = 7,
541 * Notification that this download is being resumed.
543 GNUNET_FS_STATUS_DOWNLOAD_RESUME = 8,
546 * Notification that this download was suspended.
548 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND = 9,
551 * Notification about progress with this download.
553 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS = 10,
556 * Notification that this download encountered an error.
558 GNUNET_FS_STATUS_DOWNLOAD_ERROR = 11,
561 * Notification that this download completed. Note that for
562 * directories, completion does not imply completion of all files in
565 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED = 12,
568 * Notification that this download was stopped
569 * (final event with respect to this action).
571 GNUNET_FS_STATUS_DOWNLOAD_STOPPED = 13,
574 * Notification that this download is now actively being
575 * pursued (as opposed to waiting in the queue).
577 GNUNET_FS_STATUS_DOWNLOAD_ACTIVE = 14,
580 * Notification that this download is no longer actively
581 * being pursued (back in the queue).
583 GNUNET_FS_STATUS_DOWNLOAD_INACTIVE = 15,
586 * Notification that this download is no longer part of a
587 * recursive download or search but now a 'stand-alone'
588 * download (and may thus need to be moved in the GUI
589 * into a different category).
591 GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT = 16,
594 * First event generated when a client requests
595 * a search to begin or when a namespace result
596 * automatically triggers the search for updates.
598 GNUNET_FS_STATUS_SEARCH_START = 17,
601 * Last event when a search is being resumed;
602 * note that "GNUNET_FS_SEARCH_START" will not
603 * be generated in this case.
605 GNUNET_FS_STATUS_SEARCH_RESUME = 18,
608 * Event generated for each search result
609 * when the respective search is resumed.
611 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT = 19,
614 * Last event when a search is being suspended;
615 * note that "GNUNET_FS_SEARCH_STOPPED" will not
616 * be generated in this case.
618 GNUNET_FS_STATUS_SEARCH_SUSPEND = 20,
621 * This search has yielded a result.
623 GNUNET_FS_STATUS_SEARCH_RESULT = 21,
626 * We have discovered a new namespace.
628 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE = 22,
631 * We have additional data about the quality
632 * or availability of a search result.
634 GNUNET_FS_STATUS_SEARCH_UPDATE = 23,
637 * Signals a problem with this search.
639 GNUNET_FS_STATUS_SEARCH_ERROR = 24,
642 * Signals that this search was paused.
644 GNUNET_FS_STATUS_SEARCH_PAUSED = 25,
647 * Signals that this search was continued (unpaused).
649 GNUNET_FS_STATUS_SEARCH_CONTINUED = 26,
652 * Event generated for each search result
653 * when the respective search is stopped.
655 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED = 27,
658 * Event generated for each search result
659 * when the respective search is suspended.
661 GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND = 28,
664 * Last message from a search; this signals
665 * that there will be no further events associated
668 GNUNET_FS_STATUS_SEARCH_STOPPED = 29,
671 * Notification that we started to unindex a file.
673 GNUNET_FS_STATUS_UNINDEX_START = 30,
676 * Notification that we resumed unindexing of a file.
678 GNUNET_FS_STATUS_UNINDEX_RESUME = 31,
681 * Notification that we suspended unindexing a file.
683 GNUNET_FS_STATUS_UNINDEX_SUSPEND = 32,
686 * Notification that we made progress unindexing a file.
688 GNUNET_FS_STATUS_UNINDEX_PROGRESS = 33,
691 * Notification that we encountered an error unindexing
694 GNUNET_FS_STATUS_UNINDEX_ERROR = 34,
697 * Notification that the unindexing of this file
700 GNUNET_FS_STATUS_UNINDEX_COMPLETED = 35,
703 * Notification that the unindexing of this file
704 * was stopped (final event for this action).
706 GNUNET_FS_STATUS_UNINDEX_STOPPED = 36
711 * Handle for controlling an upload.
713 struct GNUNET_FS_PublishContext;
717 * Handle for controlling an unindexing operation.
719 struct GNUNET_FS_UnindexContext;
723 * Handle for controlling a search.
725 struct GNUNET_FS_SearchContext;
729 * Result from a search. Opaque handle to refer to the search
730 * (typically used when starting a download associated with the search
733 struct GNUNET_FS_SearchResult;
737 * Context for controlling a download.
739 struct GNUNET_FS_DownloadContext;
743 * Handle for detail information about a file that is being publishd.
744 * Specifies metadata, keywords, how to get the contents of the file
745 * (i.e. data-buffer in memory, filename on disk) and other options.
747 struct GNUNET_FS_FileInformation;
751 * Argument given to the progress callback with
752 * information about what is going on.
754 struct GNUNET_FS_ProgressInfo
758 * Values that depend on the event type.
764 * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
770 * Context for controlling the upload.
772 struct GNUNET_FS_PublishContext *pc;
775 * Information about the file that is being publishd.
777 const struct GNUNET_FS_FileInformation *fi;
780 * Client context pointer (set the last time by the client for
781 * this operation; initially NULL on START/RESUME events).
786 * Client context pointer for the parent operation
787 * (if this is a file in a directory or a subdirectory).
792 * Name of the file being published; can be NULL.
794 const char *filename;
797 * How large is the file overall? For directories,
798 * this is only the size of the directory itself,
799 * not of the other files contained within the
805 * At what time do we expect to finish the upload?
806 * (will be a value in the past for completed
809 struct GNUNET_TIME_Relative eta;
812 * How long has this upload been actively running
813 * (excludes times where the upload was suspended).
815 struct GNUNET_TIME_Relative duration;
818 * How many bytes have we completed?
823 * What anonymity level is used for this upload?
828 * Additional values for specific events.
834 * These values are only valid for
835 * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
841 * Data block we just published.
846 * At what offset in the file is "data"?
851 * Length of the data block.
856 * Depth of the given block in the tree;
857 * 0 would be the lowest level (DBLOCKs).
864 * These values are only valid for
865 * GNUNET_FS_STATUS_PUBLISH_RESUME events.
871 * Error message, NULL if no error was encountered so far.
876 * URI of the file (if the download had been completed)
878 const struct GNUNET_FS_Uri *chk_uri;
883 * These values are only valid for
884 * GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
892 const struct GNUNET_FS_Uri *chk_uri;
897 * These values are only valid for
898 * GNUNET_FS_STATUS_PUBLISH_ERROR events.
904 * Error message, never NULL.
916 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
922 * Context for controlling the download.
924 struct GNUNET_FS_DownloadContext *dc;
927 * Client context pointer (set the last time
928 * by the client for this operation; initially
929 * NULL on START/RESUME events).
934 * Client context pointer for the parent operation
935 * (if this is a file in a directory or a subdirectory).
940 * Client context pointer for the associated search operation
941 * (specifically, context pointer for the specific search
942 * result, not the overall search); only set if this
943 * download was started from a search result.
948 * URI used for this download.
950 const struct GNUNET_FS_Uri *uri;
953 * Name of the file that we are downloading.
955 const char *filename;
958 * How large is the download overall? This
959 * is NOT necessarily the size from the
960 * URI since we may be doing a partial download.
965 * At what time do we expect to finish the download?
966 * (will be a value in the past for completed
969 struct GNUNET_TIME_Relative eta;
972 * How long has this download been active?
974 struct GNUNET_TIME_Relative duration;
977 * How many bytes have we completed?
982 * What anonymity level is used for this download?
987 * Is the download currently active.
992 * Additional values for specific events.
998 * These values are only valid for
999 * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
1005 * Data block we just obtained, can be NULL (even if
1006 * data_len > 0) if we found the entire block 'intact' on
1007 * disk. In this case, it is also possible for 'data_len'
1008 * to be larger than an individual (32k) block.
1013 * At what offset in the file is "data"?
1018 * Length of the data block.
1023 * Depth of the given block in the tree;
1024 * 0 would be the lowest level (DBLOCKS).
1029 * How much trust did we offer for downloading this block?
1031 unsigned int trust_offered;
1034 * How much time passed between us asking for this block and
1035 * actually getting it? GNUNET_TIME_UNIT_FOREVER_REL if unknown.
1037 struct GNUNET_TIME_Relative block_download_duration;
1042 * These values are only valid for
1043 * GNUNET_FS_STATUS_DOWNLOAD_START events.
1049 * Known metadata for the download.
1051 const struct GNUNET_CONTAINER_MetaData *meta;
1056 * These values are only valid for
1057 * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
1063 * Known metadata for the download.
1065 const struct GNUNET_CONTAINER_MetaData *meta;
1068 * Error message, NULL if we have not encountered any error yet.
1070 const char *message;
1075 * These values are only valid for
1076 * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1084 const char *message;
1093 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1099 * Context for controlling the search, NULL for
1100 * searches that were not explicitly triggered
1101 * by the client (i.e., searches for updates in
1104 struct GNUNET_FS_SearchContext *sc;
1107 * Client context pointer (set the last time by the client for
1108 * this operation; initially NULL on START/RESUME events). Note
1109 * that this value can only be set on START/RESUME; returning
1110 * non-NULL on RESULT/RESUME_RESULT will actually update the
1111 * private context for "UPDATE" events.
1116 * Client parent-context pointer; NULL for top-level searches,
1117 * refers to the client context of the associated search result
1118 * for automatically triggered searches for updates in
1119 * namespaces. In this case, 'presult' refers to that search
1125 * What query is used for this search
1126 * (list of keywords or SKS identifier).
1128 const struct GNUNET_FS_Uri *query;
1131 * How long has this search been actively running
1132 * (excludes times where the search was paused or
1135 struct GNUNET_TIME_Relative duration;
1138 * What anonymity level is used for this search?
1143 * Additional values for specific events.
1149 * These values are only valid for
1150 * GNUNET_FS_STATUS_SEARCH_RESULT events.
1156 * Metadata for the search result.
1158 const struct GNUNET_CONTAINER_MetaData *meta;
1161 * URI for the search result.
1163 const struct GNUNET_FS_Uri *uri;
1166 * Handle to the result (for starting downloads).
1168 struct GNUNET_FS_SearchResult *result;
1171 * Applicability rank (the larger, the better the result
1172 * fits the search criteria).
1174 uint32_t applicability_rank;
1179 * These values are only valid for
1180 * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1186 * Metadata for the search result.
1188 const struct GNUNET_CONTAINER_MetaData *meta;
1191 * URI for the search result.
1193 const struct GNUNET_FS_Uri *uri;
1196 * Handle to the result (for starting downloads).
1198 struct GNUNET_FS_SearchResult *result;
1201 * Current availability rank (negative:
1202 * unavailable, positive: available)
1204 int32_t availability_rank;
1207 * On how many total queries is the given
1208 * availability_rank based?
1210 uint32_t availability_certainty;
1213 * Updated applicability rank (the larger,
1214 * the better the result fits the search
1217 uint32_t applicability_rank;
1222 * These values are only valid for
1223 * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1229 * Private context set for for this result
1230 * during the "RESULT" event.
1235 * Metadata for the search result.
1237 const struct GNUNET_CONTAINER_MetaData *meta;
1240 * URI for the search result.
1242 const struct GNUNET_FS_Uri *uri;
1245 * Current availability rank (negative:
1246 * unavailable, positive: available)
1248 int32_t availability_rank;
1251 * On how many total queries is the given
1252 * availability_rank based?
1254 uint32_t availability_certainty;
1257 * Updated applicability rank (the larger,
1258 * the better the result fits the search
1261 uint32_t applicability_rank;
1266 * These values are only valid for
1267 * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1268 * These events are automatically triggered for
1269 * each search result before the
1270 * GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1271 * happens primarily to give the client a chance
1272 * to clean up the "cctx" (if needed).
1278 * Private context set for for this result
1279 * during the "RESULT" event.
1284 * Metadata for the search result.
1286 const struct GNUNET_CONTAINER_MetaData *meta;
1289 * URI for the search result.
1291 const struct GNUNET_FS_Uri *uri;
1296 * These values are only valid for
1297 * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1298 * These events are automatically triggered for
1299 * each search result before the
1300 * GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1301 * happens primarily to give the client a chance
1302 * to clean up the "cctx" (if needed).
1308 * Private context set for for this result
1309 * during the "RESULT" event.
1314 * Metadata for the search result.
1316 const struct GNUNET_CONTAINER_MetaData *meta;
1319 * URI for the search result.
1321 const struct GNUNET_FS_Uri *uri;
1326 * These values are only valid for
1327 * GNUNET_FS_STATUS_SEARCH_RESUME events.
1333 * Error message, NULL if we have not encountered any error yet.
1335 const char *message;
1338 * Is this search currently paused?
1345 * These values are only valid for
1346 * GNUNET_FS_STATUS_SEARCH_ERROR events.
1354 const char *message;
1359 * Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events.
1365 * Handle to the namespace (NULL if it is not a local
1368 struct GNUNET_FS_Namespace *ns;
1371 * Short, human-readable name of the namespace.
1376 * Root identifier for the namespace, can be NULL.
1381 * Metadata for the namespace.
1383 const struct GNUNET_CONTAINER_MetaData *meta;
1386 * Hash-identifier for the namespace.
1397 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1403 * Context for controlling the unindexing.
1405 struct GNUNET_FS_UnindexContext *uc;
1408 * Client context pointer (set the last time
1409 * by the client for this operation; initially
1410 * NULL on START/RESUME events).
1415 * Name of the file that is being unindexed.
1417 const char *filename;
1420 * How large is the file overall?
1425 * At what time do we expect to finish unindexing?
1426 * (will be a value in the past for completed
1427 * unindexing opeations).
1429 struct GNUNET_TIME_Relative eta;
1432 * How long has this upload been actively running
1433 * (excludes times where the upload was suspended).
1435 struct GNUNET_TIME_Relative duration;
1438 * How many bytes have we completed?
1443 * Additional values for specific events.
1449 * These values are only valid for
1450 * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1456 * Data block we just unindexed.
1461 * At what offset in the file is "data"?
1466 * Length of the data block.
1471 * Depth of the given block in the tree;
1472 * 0 would be the lowest level (DBLOCKS).
1479 * These values are only valid for
1480 * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1486 * Error message, NULL if we have not encountered any error yet.
1488 const char *message;
1493 * These values are only valid for
1494 * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1502 const char *message;
1513 * Specific status code (determines the event type).
1515 enum GNUNET_FS_Status status;
1521 * Notification of FS to a client about the progress of an
1522 * operation. Callbacks of this type will be used for uploads,
1523 * downloads and searches. Some of the arguments depend a bit
1524 * in their meaning on the context in which the callback is used.
1526 * @param cls closure
1527 * @param info details about the event, specifying the event type
1528 * and various bits about the event
1529 * @return client-context (for the next progress call
1530 * for this operation; should be set to NULL for
1531 * SUSPEND and STOPPED events). The value returned
1532 * will be passed to future callbacks in the respective
1533 * field in the GNUNET_FS_ProgressInfo struct.
1535 typedef void *(*GNUNET_FS_ProgressCallback) (void *cls,
1536 const struct GNUNET_FS_ProgressInfo
1541 * General (global) option flags for file-sharing.
1543 enum GNUNET_FS_Flags
1546 * No special flags set.
1548 GNUNET_FS_FLAGS_NONE = 0,
1551 * Is persistence of operations desired?
1552 * (will create SUSPEND/RESUME events).
1554 GNUNET_FS_FLAGS_PERSISTENCE = 1,
1557 * Should we automatically trigger probes for search results
1558 * to determine availability?
1559 * (will create GNUNET_FS_STATUS_SEARCH_UPDATE events).
1561 GNUNET_FS_FLAGS_DO_PROBES = 2
1565 * Options specified in the VARARGs portion of GNUNET_FS_start.
1567 enum GNUNET_FS_OPTIONS
1571 * Last option in the VARARG list.
1573 GNUNET_FS_OPTIONS_END = 0,
1576 * Select the desired amount of parallelism (this option should be
1577 * followed by an "unsigned int" giving the desired maximum number
1578 * of parallel downloads).
1580 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
1583 * Maximum number of requests that should be pending at a given
1584 * point in time (invidivual downloads may go above this, but
1585 * if we are above this threshold, we should not activate any
1586 * additional downloads.
1588 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
1593 * Settings for publishing a block (which may of course also
1594 * apply to an entire directory or file).
1596 struct GNUNET_FS_BlockOptions
1600 * At what time should the block expire? Data blocks (DBLOCKS and
1601 * IBLOCKS) may still be used even if they are expired (however,
1602 * they'd be removed quickly from the datastore if we are short on
1603 * space), all other types of blocks will no longer be returned
1604 * after they expire.
1606 struct GNUNET_TIME_Absolute expiration_time;
1609 * At which anonymity level should the block be shared?
1610 * (0: no anonymity, 1: normal GAP, >1: with cover traffic).
1612 uint32_t anonymity_level;
1615 * How important is it for us to store the block? If we run
1616 * out of space, the highest-priority, non-expired blocks will
1619 uint32_t content_priority;
1622 * How often should we try to migrate the block to other peers?
1623 * Only used if "CONTENT_PUSHING" is set to YES, in which case we
1624 * first push each block to other peers according to their
1625 * replication levels. Once each block has been pushed that many
1626 * times to other peers, blocks are chosen for migration at random.
1627 * Naturally, there is no guarantee that the other peers will keep
1628 * these blocks for any period of time (since they won't have any
1629 * priority or might be too busy to even store the block in the
1632 uint32_t replication_level;
1638 * Return the current year (i.e. '2011').
1641 GNUNET_FS_get_current_year (void);
1645 * Convert a year to an expiration time of January 1st of that year.
1647 * @param year a year (after 1970, please ;-)).
1648 * @return absolute time for January 1st of that year.
1650 struct GNUNET_TIME_Absolute
1651 GNUNET_FS_year_to_time (unsigned int year);
1655 * Convert an expiration time to the respective year (rounds)
1657 * @param at absolute time
1658 * @return year a year (after 1970), 0 on error
1661 GNUNET_FS_time_to_year (struct GNUNET_TIME_Absolute at);
1665 * Handle to the file-sharing service.
1667 struct GNUNET_FS_Handle;
1671 * Setup a connection to the file-sharing service.
1673 * @param cfg configuration to use
1674 * @param client_name unique identifier for this client
1675 * @param upcb function to call to notify about FS actions
1676 * @param upcb_cls closure for upcb
1677 * @param flags specific attributes for fs-operations
1678 * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
1679 * @return NULL on error
1681 struct GNUNET_FS_Handle *
1682 GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1683 const char *client_name, GNUNET_FS_ProgressCallback upcb,
1684 void *upcb_cls, enum GNUNET_FS_Flags flags, ...);
1688 * Close our connection with the file-sharing service.
1689 * The callback given to GNUNET_FS_start will no longer be
1690 * called after this function returns.
1692 * @param h handle that was returned from GNUNET_FS_start
1695 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1699 * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
1701 * @param cls closure
1702 * @param fi the entry in the publish-structure
1703 * @param length length of the file or directory
1704 * @param meta metadata for the file or directory (can be modified)
1705 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1706 * @param bo block options (can be modified)
1707 * @param do_index should we index (can be modified)
1708 * @param client_info pointer to client context set upon creation (can be modified)
1709 * @return GNUNET_OK to continue, GNUNET_NO to remove
1710 * this entry from the directory, GNUNET_SYSERR
1711 * to abort the iteration
1713 typedef int (*GNUNET_FS_FileInformationProcessor) (void *cls,
1715 GNUNET_FS_FileInformation *
1716 fi, uint64_t length,
1718 GNUNET_CONTAINER_MetaData *
1720 struct GNUNET_FS_Uri ** uri,
1721 struct GNUNET_FS_BlockOptions
1722 * bo, int *do_index,
1723 void **client_info);
1727 * Obtain the name under which this file information
1728 * structure is stored on disk. Only works for top-level
1729 * file information structures.
1731 * @param s structure to get the filename for
1732 * @return NULL on error, otherwise filename that
1733 * can be passed to "GNUNET_FS_file_information_recover"
1734 * to read this fi-struct from disk.
1737 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1741 * Obtain the filename from the file information structure.
1743 * @param s structure to get the filename for
1744 * @return "filename" field of the structure (can be NULL)
1747 GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s);
1751 * Set the filename in the file information structure.
1752 * If filename was already set, frees it before setting the new one.
1753 * Makes a copy of the argument.
1755 * @param s structure to get the filename for
1756 * @param filename filename to set
1759 GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s,
1760 const char *filename);
1764 * Create an entry for a file in a publish-structure.
1766 * @param h handle to the file sharing subsystem
1767 * @param client_info initial client-info value for this entry
1768 * @param filename name of the file or directory to publish
1769 * @param keywords under which keywords should this file be available
1770 * directly; can be NULL
1771 * @param meta metadata for the file
1772 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1773 * GNUNET_SYSERR for simulation
1774 * @param bo block options
1775 * @return publish structure entry for the file
1777 struct GNUNET_FS_FileInformation *
1778 GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
1780 const char *filename,
1781 const struct GNUNET_FS_Uri
1784 GNUNET_CONTAINER_MetaData *meta,
1786 const struct GNUNET_FS_BlockOptions
1791 * Create an entry for a file in a publish-structure.
1793 * @param h handle to the file sharing subsystem
1794 * @param client_info initial client-info value for this entry
1795 * @param length length of the file
1796 * @param data data for the file (should not be used afterwards by
1797 * the caller; callee will "free")
1798 * @param keywords under which keywords should this file be available
1799 * directly; can be NULL
1800 * @param meta metadata for the file
1801 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1802 * GNUNET_SYSERR for simulation
1803 * @param bo block options
1804 * @return publish structure entry for the file
1806 struct GNUNET_FS_FileInformation *
1807 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
1808 void *client_info, uint64_t length,
1810 const struct GNUNET_FS_Uri
1813 GNUNET_CONTAINER_MetaData *meta,
1815 const struct GNUNET_FS_BlockOptions
1820 * Function that provides data.
1822 * @param cls closure
1823 * @param offset offset to read from; it is possible
1824 * that the caller might need to go backwards
1826 * @param max maximum number of bytes that should be
1827 * copied to buf; readers are not allowed
1828 * to provide less data unless there is an error;
1829 * a value of "0" will be used at the end to allow
1830 * the reader to clean up its internal state
1831 * @param buf where the reader should write the data
1832 * @param emsg location for the reader to store an error message
1833 * @return number of bytes written, usually "max", 0 on error
1835 typedef size_t (*GNUNET_FS_DataReader) (void *cls, uint64_t offset, size_t max,
1836 void *buf, char **emsg);
1840 * Create an entry for a file in a publish-structure.
1842 * @param h handle to the file sharing subsystem
1843 * @param client_info initial client-info value for this entry
1844 * @param length length of the file
1845 * @param reader function that can be used to obtain the data for the file
1846 * @param reader_cls closure for "reader"
1847 * @param keywords under which keywords should this file be available
1848 * directly; can be NULL
1849 * @param meta metadata for the file
1850 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1851 * GNUNET_SYSERR for simulation
1852 * @param bo block options
1853 * @return publish structure entry for the file
1855 struct GNUNET_FS_FileInformation *
1856 GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
1859 GNUNET_FS_DataReader reader,
1861 const struct GNUNET_FS_Uri
1864 GNUNET_CONTAINER_MetaData *meta,
1867 GNUNET_FS_BlockOptions *bo);
1871 * Create an entry for an empty directory in a publish-structure.
1872 * This function should be used by applications for which the
1873 * use of "GNUNET_FS_file_information_create_from_directory"
1874 * is not appropriate.
1876 * @param h handle to the file sharing subsystem
1877 * @param client_info initial client-info value for this entry
1878 * @param keywords under which keywords should this directory be available
1879 * directly; can be NULL
1880 * @param meta metadata for the directory
1881 * @param bo block options
1882 * @param filename name of the directory; can be NULL
1883 * @return publish structure entry for the directory , NULL on error
1885 struct GNUNET_FS_FileInformation *
1886 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
1888 const struct GNUNET_FS_Uri
1891 GNUNET_CONTAINER_MetaData
1894 GNUNET_FS_BlockOptions *bo,
1895 const char *filename);
1899 * Test if a given entry represents a directory.
1901 * @param ent check if this FI represents a directory
1902 * @return GNUNET_YES if so, GNUNET_NO if not
1905 GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
1910 * Add an entry to a directory in a publish-structure. Clients
1911 * should never modify publish structures that were passed to
1912 * "GNUNET_FS_publish_start" already.
1914 * @param dir the directory
1915 * @param ent the entry to add; the entry must not have been
1916 * added to any other directory at this point and
1917 * must not include "dir" in its structure
1918 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1921 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1922 struct GNUNET_FS_FileInformation *ent);
1926 * Inspect a file or directory in a publish-structure. Clients
1927 * should never modify publish structures that were passed to
1928 * "GNUNET_FS_publish_start" already. When called on a directory,
1929 * this function will FIRST call "proc" with information about
1930 * the directory itself and then for each of the files in the
1931 * directory (but not for files in subdirectories). When called
1932 * on a file, "proc" will be called exactly once (with information
1933 * about the specific file).
1935 * @param dir the directory
1936 * @param proc function to call on each entry
1937 * @param proc_cls closure for proc
1940 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1941 GNUNET_FS_FileInformationProcessor proc,
1946 * Destroy publish-structure. Clients should never destroy publish
1947 * structures that were passed to "GNUNET_FS_publish_start" already.
1949 * @param fi structure to destroy
1950 * @param cleaner function to call on each entry in the structure
1951 * (useful to clean up client_info); can be NULL; return
1952 * values are ignored
1953 * @param cleaner_cls closure for cleaner
1956 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
1957 GNUNET_FS_FileInformationProcessor cleaner,
1962 * Options for publishing. Compatible options
1963 * can be OR'ed together.
1965 enum GNUNET_FS_PublishOptions
1968 * No options (use defaults for everything).
1970 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
1973 * Simulate publishing. With this option, no data will be stored
1974 * in the datastore. Useful for computing URIs from files.
1976 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
1980 * Publish a file or directory.
1982 * @param h handle to the file sharing subsystem
1983 * @param fi information about the file or directory structure to publish
1984 * @param namespace namespace to publish the file in, NULL for no namespace
1985 * @param nid identifier to use for the publishd content in the namespace
1986 * (can be NULL, must be NULL if namespace is NULL)
1987 * @param nuid update-identifier that will be used for future updates
1988 * (can be NULL, must be NULL if namespace or nid is NULL)
1989 * @param options options for the publication
1990 * @return context that can be used to control the publish operation
1992 struct GNUNET_FS_PublishContext *
1993 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1994 struct GNUNET_FS_FileInformation *fi,
1995 struct GNUNET_FS_Namespace *namespace, const char *nid,
1997 enum GNUNET_FS_PublishOptions options);
2001 * Stop a publication. Will abort incomplete publications (but
2002 * not remove blocks that have already been published) or
2003 * simply clean up the state for completed publications.
2004 * Must NOT be called from within the event callback!
2006 * @param pc context for the publication to stop
2009 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
2013 * Signature of a function called as the continuation of a KBlock or
2014 * SBlock publication.
2016 * @param cls closure
2017 * @param uri URI under which the block is now available, NULL on error
2018 * @param emsg error message, NULL on success
2020 typedef void (*GNUNET_FS_PublishContinuation) (void *cls,
2021 const struct GNUNET_FS_Uri * uri,
2026 * Publish a KBlock on GNUnet.
2028 * @param h handle to the file sharing subsystem
2029 * @param ksk_uri keywords to use
2030 * @param meta metadata to use
2031 * @param uri URI to refer to in the KBlock
2032 * @param bo block options
2033 * @param options publication options
2034 * @param cont continuation
2035 * @param cont_cls closure for cont
2038 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2039 const struct GNUNET_FS_Uri *ksk_uri,
2040 const struct GNUNET_CONTAINER_MetaData *meta,
2041 const struct GNUNET_FS_Uri *uri,
2042 const struct GNUNET_FS_BlockOptions *bo,
2043 enum GNUNET_FS_PublishOptions options,
2044 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2048 * Publish an SBlock on GNUnet.
2050 * @param h handle to the file sharing subsystem
2051 * @param namespace namespace to publish in
2052 * @param identifier identifier to use
2053 * @param update update identifier to use
2054 * @param meta metadata to use
2055 * @param uri URI to refer to in the SBlock
2056 * @param bo block options
2057 * @param options publication options
2058 * @param cont continuation
2059 * @param cont_cls closure for cont
2062 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2063 struct GNUNET_FS_Namespace *namespace,
2064 const char *identifier, const char *update,
2065 const struct GNUNET_CONTAINER_MetaData *meta,
2066 const struct GNUNET_FS_Uri *uri,
2067 const struct GNUNET_FS_BlockOptions *bo,
2068 enum GNUNET_FS_PublishOptions options,
2069 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2073 * Type of a function called by "GNUNET_FS_get_indexed_files".
2075 * @param cls closure
2076 * @param filename the name of the file
2077 * @param file_id hash of the contents of the indexed file
2078 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
2080 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls, const char *filename,
2081 const GNUNET_HashCode * file_id);
2085 * Iterate over all indexed files.
2087 * @param h handle to the file sharing subsystem
2088 * @param iterator function to call on each indexed file
2089 * @param iterator_cls closure for iterator
2090 * @param cont continuation to call when done;
2091 * reason should be "TIMEOUT" (on
2092 * error) or "PREREQ_DONE" (on success)
2093 * @param cont_cls closure for cont
2096 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2097 GNUNET_FS_IndexedFileProcessor iterator,
2098 void *iterator_cls, GNUNET_SCHEDULER_Task cont,
2105 * @param h handle to the file sharing subsystem
2106 * @param filename file to unindex
2107 * @param cctx initial value for the client context
2108 * @return NULL on error, otherwise handle
2110 struct GNUNET_FS_UnindexContext *
2111 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, const char *filename,
2116 * Clean up after completion of an unindex operation.
2121 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2125 * Publish an advertismement for a namespace.
2127 * @param h handle to the file sharing subsystem
2128 * @param ksk_uri keywords to use for advertisment
2129 * @param namespace handle for the namespace that should be advertised
2130 * @param meta meta-data for the namespace advertisement
2131 * @param bo block options
2132 * @param rootEntry name of the root of the namespace
2133 * @param cont continuation
2134 * @param cont_cls closure for cont
2137 GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
2138 struct GNUNET_FS_Uri *ksk_uri,
2139 struct GNUNET_FS_Namespace *namespace,
2140 const struct GNUNET_CONTAINER_MetaData *meta,
2141 const struct GNUNET_FS_BlockOptions *bo,
2142 const char *rootEntry,
2143 GNUNET_FS_PublishContinuation cont,
2148 * Create a namespace with the given name; if one already
2149 * exists, return a handle to the existing namespace.
2151 * @param h handle to the file sharing subsystem
2152 * @param name name to use for the namespace
2153 * @return handle to the namespace, NULL on error
2155 struct GNUNET_FS_Namespace *
2156 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, const char *name);
2160 * Delete a namespace handle. Can be used for a clean shutdown (free
2161 * memory) or also to freeze the namespace to prevent further
2162 * insertions by anyone.
2164 * @param namespace handle to the namespace that should be deleted / freed
2165 * @param freeze prevents future insertions; creating a namespace
2166 * with the same name again will create a fresh namespace instead
2168 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2171 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace, int freeze);
2175 * Callback with information about local (!) namespaces.
2176 * Contains the names of the local namespace and the global
2179 * @param cls closure
2180 * @param name human-readable identifier of the namespace
2181 * @param id hash identifier for the namespace
2183 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls, const char *name,
2184 const GNUNET_HashCode * id);
2188 * Build a list of all available local (!) namespaces The returned
2189 * names are only the nicknames since we only iterate over the local
2192 * @param h handle to the file sharing subsystem
2193 * @param cb function to call on each known namespace
2194 * @param cb_cls closure for cb
2197 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2198 GNUNET_FS_NamespaceInfoProcessor cb, void *cb_cls);
2202 * Function called on updateable identifiers.
2204 * @param cls closure
2205 * @param last_id last identifier
2206 * @param last_uri uri used for the content published under the last_id
2207 * @param last_meta metadata associated with last_uri
2208 * @param next_id identifier that should be used for updates
2210 typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls, const char *last_id,
2211 const struct GNUNET_FS_Uri *
2214 GNUNET_CONTAINER_MetaData *
2215 last_meta, const char *next_id);
2219 * List all of the identifiers in the namespace for which we could
2220 * produce an update. Namespace updates form a graph where each node
2221 * has a name. Each node can have any number of URI/meta-data entries
2222 * which can each be linked to other nodes. Cycles are possible.
2224 * Calling this function with "next_id" NULL will cause the library to
2225 * call "ip" with a root for each strongly connected component of the
2226 * graph (a root being a node from which all other nodes in the Scc
2229 * Calling this function with "next_id" being the name of a node will
2230 * cause the library to call "ip" with all children of the node. Note
2231 * that cycles within an SCC are possible (including self-loops).
2233 * @param namespace namespace to inspect for updateable content
2234 * @param next_id ID to look for; use NULL to look for SCC roots
2235 * @param ip function to call on each updateable identifier
2236 * @param ip_cls closure for ip
2239 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
2240 const char *next_id,
2241 GNUNET_FS_IdentifierProcessor ip,
2246 * Options for searching. Compatible options
2247 * can be OR'ed together.
2249 enum GNUNET_FS_SearchOptions
2252 * No options (use defaults for everything).
2254 GNUNET_FS_SEARCH_OPTION_NONE = 0,
2257 * Only search the local host, do not search remote systems (no P2P)
2259 GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
2264 * Start search for content.
2266 * @param h handle to the file sharing subsystem
2267 * @param uri specifies the search parameters; can be
2268 * a KSK URI or an SKS URI.
2269 * @param anonymity desired level of anonymity
2270 * @param options options for the search
2271 * @param cctx initial value for the client context
2272 * @return context that can be used to control the search
2274 struct GNUNET_FS_SearchContext *
2275 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2276 const struct GNUNET_FS_Uri *uri, uint32_t anonymity,
2277 enum GNUNET_FS_SearchOptions options, void *cctx);
2283 * @param sc context for the search that should be paused
2286 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2290 * Continue paused search.
2292 * @param sc context for the search that should be resumed
2295 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2299 * Stop search for content.
2301 * @param sc context for the search that should be stopped
2304 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2310 * Options for downloading. Compatible options
2311 * can be OR'ed together.
2313 enum GNUNET_FS_DownloadOptions
2316 * No options (use defaults for everything).
2318 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2321 * Only download from the local host, do not access remote systems (no P2P)
2323 GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
2326 * Do a recursive download (that is, automatically trigger the
2327 * download of files in directories).
2329 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
2332 * Do not append temporary data to
2333 * the target file (for the IBlocks).
2335 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
2338 * Internal option used to flag this download as a 'probe' for a
2339 * search result. Impacts the priority with which the download is
2340 * run and causes signalling callbacks to be done differently.
2341 * Also, probe downloads are not serialized on suspension. Normal
2342 * clients should not use this!
2344 GNUNET_FS_DOWNLOAD_IS_PROBE = (1 << 31)
2350 * Download parts of a file. Note that this will store
2351 * the blocks at the respective offset in the given file. Also, the
2352 * download is still using the blocking of the underlying FS
2353 * encoding. As a result, the download may *write* outside of the
2354 * given boundaries (if offset and length do not match the 32k FS
2355 * block boundaries). <p>
2357 * The given range can be used to focus a download towards a
2358 * particular portion of the file (optimization), not to strictly
2359 * limit the download to exactly those bytes.
2361 * @param h handle to the file sharing subsystem
2362 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2363 * @param meta known metadata for the file (can be NULL)
2364 * @param filename where to store the file, maybe NULL (then no file is
2365 * created on disk and data must be grabbed from the callbacks)
2366 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2367 * can be NULL (in which case we will pick a name if needed); the temporary file
2368 * may already exist, in which case we will try to use the data that is there and
2369 * if it is not what is desired, will overwrite it
2370 * @param offset at what offset should we start the download (typically 0)
2371 * @param length how many bytes should be downloaded starting at offset
2372 * @param anonymity anonymity level to use for the download
2373 * @param options various download options
2374 * @param cctx initial value for the client context for this download
2375 * @param parent parent download to associate this download with (use NULL
2376 * for top-level downloads; useful for manually-triggered recursive downloads)
2377 * @return context that can be used to control this download
2379 struct GNUNET_FS_DownloadContext *
2380 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2381 const struct GNUNET_FS_Uri *uri,
2382 const struct GNUNET_CONTAINER_MetaData *meta,
2383 const char *filename, const char *tempname,
2384 uint64_t offset, uint64_t length, uint32_t anonymity,
2385 enum GNUNET_FS_DownloadOptions options, void *cctx,
2386 struct GNUNET_FS_DownloadContext *parent);
2390 * Download parts of a file based on a search result. The download
2391 * will be associated with the search result (and the association
2392 * will be preserved when serializing/deserializing the state).
2393 * If the search is stopped, the download will not be aborted but
2394 * be 'promoted' to a stand-alone download.
2396 * As with the other download function, this will store
2397 * the blocks at the respective offset in the given file. Also, the
2398 * download is still using the blocking of the underlying FS
2399 * encoding. As a result, the download may *write* outside of the
2400 * given boundaries (if offset and length do not match the 32k FS
2401 * block boundaries). <p>
2403 * The given range can be used to focus a download towards a
2404 * particular portion of the file (optimization), not to strictly
2405 * limit the download to exactly those bytes.
2407 * @param h handle to the file sharing subsystem
2408 * @param sr the search result to use for the download (determines uri and
2409 * meta data and associations)
2410 * @param filename where to store the file, maybe NULL (then no file is
2411 * created on disk and data must be grabbed from the callbacks)
2412 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2413 * can be NULL (in which case we will pick a name if needed); the temporary file
2414 * may already exist, in which case we will try to use the data that is there and
2415 * if it is not what is desired, will overwrite it
2416 * @param offset at what offset should we start the download (typically 0)
2417 * @param length how many bytes should be downloaded starting at offset
2418 * @param anonymity anonymity level to use for the download
2419 * @param options various download options
2420 * @param cctx initial value for the client context for this download
2421 * @return context that can be used to control this download
2423 struct GNUNET_FS_DownloadContext *
2424 GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2425 struct GNUNET_FS_SearchResult *sr,
2426 const char *filename,
2427 const char *tempname, uint64_t offset,
2428 uint64_t length, uint32_t anonymity,
2429 enum GNUNET_FS_DownloadOptions options,
2434 * Stop a download (aborts if download is incomplete).
2436 * @param dc handle for the download
2437 * @param do_delete delete files of incomplete downloads
2440 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete);
2444 /* ******************** Directory API *********************** */
2447 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2448 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2449 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2452 * Does the meta-data claim that this is a directory?
2453 * Checks if the mime-type is that of a GNUnet directory.
2455 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2456 * we have no mime-type information (treat as 'GNUNET_NO')
2459 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
2464 * Set the MIMETYPE information for the given
2465 * metadata to "application/gnunet-directory".
2467 * @param md metadata to add mimetype to
2470 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2474 * Suggest a filename based on given metadata.
2476 * @param md given meta data
2477 * @return NULL if meta data is useless for suggesting a filename
2480 GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData
2485 * Function used to process entries in a directory.
2487 * @param cls closure
2488 * @param filename name of the file in the directory
2489 * @param uri URI of the file
2490 * @param metadata metadata for the file; metadata for
2491 * the directory if everything else is NULL/zero
2492 * @param length length of the available data for the file
2493 * (of type size_t since data must certainly fit
2494 * into memory; if files are larger than size_t
2495 * permits, then they will certainly not be
2496 * embedded with the directory itself).
2497 * @param data data available for the file (length bytes)
2499 typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
2500 const char *filename,
2501 const struct GNUNET_FS_Uri *
2504 GNUNET_CONTAINER_MetaData *
2505 meta, size_t length,
2510 * Iterate over all entries in a directory. Note that directories
2511 * are structured such that it is possible to iterate over the
2512 * individual blocks as well as over the entire directory. Thus
2513 * a client can call this function on the buffer in the
2514 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2515 * include the contents of (small) files embedded in the directory
2516 * itself; for those files, the processor may be given the
2517 * contents of the file directly by this function.
2519 * @param size number of bytes in data
2520 * @param data pointer to the beginning of the directory
2521 * @param offset offset of data in the directory
2522 * @param dep function to call on each entry
2523 * @param dep_cls closure for dep
2524 * @return GNUNET_OK if this could be a block in a directory,
2525 * GNUNET_NO if this could be part of a directory (but not 100% OK)
2526 * GNUNET_SYSERR if 'data' does not represent a directory
2529 GNUNET_FS_directory_list_contents (size_t size, const void *data,
2531 GNUNET_FS_DirectoryEntryProcessor dep,
2536 * Opaque handle to a directory builder.
2538 struct GNUNET_FS_DirectoryBuilder;
2541 * Create a directory builder.
2543 * @param mdir metadata for the directory
2545 struct GNUNET_FS_DirectoryBuilder *
2546 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
2551 * Add an entry to a directory.
2553 * @param bld directory to extend
2554 * @param uri uri of the entry (must not be a KSK)
2555 * @param md metadata of the entry
2556 * @param data raw data of the entry, can be NULL, otherwise
2557 * data must point to exactly the number of bytes specified
2561 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2562 const struct GNUNET_FS_Uri *uri,
2563 const struct GNUNET_CONTAINER_MetaData *md,
2568 * Finish building the directory. Frees the
2569 * builder context and returns the directory
2572 * @param bld directory to finish
2573 * @param rsize set to the number of bytes needed
2574 * @param rdata set to the encoded directory
2575 * @return GNUNET_OK on success
2578 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2579 size_t * rsize, void **rdata);
2582 /* ******************** DirScanner API *********************** */
2585 * Progress reasons of the directory scanner.
2587 enum GNUNET_FS_DirScannerProgressUpdateReason
2591 * We've started processing a file or directory.
2593 GNUNET_FS_DIRSCANNER_FILE_START = 0,
2596 * We're having trouble accessing a file (soft-error); it will
2599 GNUNET_FS_DIRSCANNER_FILE_IGNORED,
2602 * We've found all files (in the pre-pass).
2604 GNUNET_FS_DIRSCANNER_ALL_COUNTED,
2607 * We've finished extracting meta data from a file.
2609 GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED,
2612 * Last call to the progress function: we have finished scanning
2615 GNUNET_FS_DIRSCANNER_FINISHED,
2618 * There was an internal error. Application should abort the scan.
2620 GNUNET_FS_DIRSCANNER_INTERNAL_ERROR
2626 * Function called over time as the directory scanner makes
2627 * progress on the job at hand.
2629 * @param cls closure
2630 * @param filename which file we are making progress on
2631 * @param is_directory GNUNET_YES if this is a directory,
2632 * GNUNET_NO if this is a file
2633 * GNUNET_SYSERR if it is neither (or unknown)
2634 * @param reason kind of progress we are making
2636 typedef void (*GNUNET_FS_DirScannerProgressCallback) (void *cls,
2637 const char *filename,
2639 enum GNUNET_FS_DirScannerProgressUpdateReason reason);
2643 * A node of a directory tree (produced by dirscanner)
2645 struct GNUNET_FS_ShareTreeItem
2648 * This is a doubly-linked list
2650 struct GNUNET_FS_ShareTreeItem *prev;
2653 * This is a doubly-linked list
2655 struct GNUNET_FS_ShareTreeItem *next;
2658 * This is a doubly-linked tree
2659 * NULL for top-level entries.
2661 struct GNUNET_FS_ShareTreeItem *parent;
2664 * This is a doubly-linked tree
2665 * NULL for files and empty directories
2667 struct GNUNET_FS_ShareTreeItem *children_head;
2670 * This is a doubly-linked tree
2671 * NULL for files and empty directories
2673 struct GNUNET_FS_ShareTreeItem *children_tail;
2676 * Metadata for this file or directory
2678 struct GNUNET_CONTAINER_MetaData *meta;
2681 * Keywords for this file or directory (derived from metadata).
2683 struct GNUNET_FS_Uri *ksk_uri;
2686 * Name of the file/directory
2691 * Base name of the file/directory.
2693 char *short_filename;
2696 * GNUNET_YES if this is a directory
2704 * Opaqe handle to an asynchronous directory scanning activity.
2706 struct GNUNET_FS_DirScanner;
2710 * Start a directory scanner.
2712 * @param filename name of the directory to scan
2713 * @param GNUNET_YES to not to run libextractor on files (only build a tree)
2714 * @param ex if not NULL, must be a list of extra plugins for extractor
2715 * @param cb the callback to call when there are scanning progress messages
2716 * @param cb_cls closure for 'cb'
2717 * @return directory scanner object to be used for controlling the scanner
2719 struct GNUNET_FS_DirScanner *
2720 GNUNET_FS_directory_scan_start (const char *filename,
2721 int disable_extractor,
2723 GNUNET_FS_DirScannerProgressCallback cb,
2730 * @param ds directory scanner structure
2733 GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds);
2737 * Obtain the result of the scan after the scan has signalled
2738 * completion. Must not be called prior to completion. The 'ds' is
2739 * freed as part of this call.
2741 * @param ds directory scanner structure
2742 * @return the results of the scan (a directory tree)
2744 struct GNUNET_FS_ShareTreeItem *
2745 GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds);
2749 * Process a share item tree, moving frequent keywords up and
2750 * copying frequent metadata up.
2752 * @param toplevel toplevel directory in the tree, returned by the scanner
2755 GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel);
2759 * Release memory of a share item tree.
2761 * @param toplevel toplevel of the tree to be freed
2764 GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
2767 #if 0 /* keep Emacsens' auto-indent happy */