2 This file is part of GNUnet
3 (C) 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file include/gnunet_fs_service.h
22 * @brief API for file-sharing via GNUnet
23 * @author Christian Grothoff
25 #ifndef GNUNET_FS_LIB_H
26 #define GNUNET_FS_LIB_H
28 #include "gnunet_util_lib.h"
33 #if 0 /* keep Emacsens' auto-indent happy */
39 * Version number of the implementation.
42 * 1.x.x: initial version with triple GNUNET_hash and merkle tree
43 * 2.x.x: root node with mime-type, filename and version number
44 * 2.1.x: combined GNUNET_EC_ContentHashKey/3HASH encoding with 25:1 super-nodes
45 * 2.2.x: with directories
46 * 3.0.x: with namespaces
47 * 3.1.x: with namespace meta-data
48 * 3.2.x: with collections
49 * 4.0.x: with expiration, variable meta-data, kblocks
50 * 4.1.x: with new error and configuration handling
51 * 5.0.x: with location URIs
52 * 6.0.0: with support for OR in KSKs
53 * 6.1.x: with simplified namespace support
54 * 9.0.0: CPS-style integrated API
56 #define GNUNET_FS_VERSION 0x00090000
59 /* ******************** URI API *********************** */
61 #define GNUNET_FS_URI_PREFIX "gnunet://fs/"
62 #define GNUNET_FS_URI_KSK_INFIX "ksk/"
63 #define GNUNET_FS_URI_SKS_INFIX "sks/"
64 #define GNUNET_FS_URI_CHK_INFIX "chk/"
65 #define GNUNET_FS_URI_LOC_INFIX "loc/"
69 * A Universal Resource Identifier (URI), opaque.
75 * Iterator over keywords
78 * @param keyword the keyword
79 * @param is_mandatory is the keyword mandatory (in a search)
80 * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
82 typedef int (*GNUNET_FS_KeywordIterator) (void *cls, const char *keyword,
86 * Get a unique key from a URI. This is for putting URIs
87 * into HashMaps. The key may change between FS implementations.
89 * @param uri uri to convert to a unique key
90 * @param key wherer to store the unique key
92 void GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
93 GNUNET_HashCode * key);
96 * Convert a URI to a UTF-8 String.
98 * @param uri uri to convert to a string
99 * @return the UTF-8 string
101 char *GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
104 * Convert keyword URI to a human readable format
105 * (i.e. the search query that was used in the first place)
107 * @param uri ksk uri to convert to a string
108 * @return string with the keywords
110 char *GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
114 * Add the given keyword to the set of keywords represented by the URI.
115 * Does nothing if the keyword is already present.
117 * @param uri ksk uri to modify
118 * @param keyword keyword to add
119 * @param is_mandatory is this keyword mandatory?
121 void GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
122 const char *keyword, int is_mandatory);
126 * Remove the given keyword from the set of keywords represented by the URI.
127 * Does nothing if the keyword is not present.
129 * @param uri ksk uri to modify
130 * @param keyword keyword to add
132 void GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
133 const char *keyword);
137 * Convert a UTF-8 String to a URI.
139 * @param uri string to parse
140 * @param emsg where to store the parser error message (if any)
141 * @return NULL on error
143 struct GNUNET_FS_Uri *GNUNET_FS_uri_parse (const char *uri, char **emsg);
148 * @param uri uri to free
150 void GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
154 * How many keywords are ANDed in this keyword URI?
156 * @param uri ksk uri to get the number of keywords from
157 * @return 0 if this is not a keyword URI
159 unsigned int GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri
164 * Iterate over all keywords in this keyword URI.
166 * @param uri ksk uri to get the keywords from
167 * @param iterator function to call on each keyword
168 * @param iterator_cls closure for iterator
169 * @return -1 if this is not a keyword URI, otherwise number of
170 * keywords iterated over until iterator aborted
172 int GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
173 GNUNET_FS_KeywordIterator iterator,
178 * Obtain the identity of the peer offering the data
180 * @param uri the location URI to inspect
181 * @param peer where to store the identify of the peer (presumably) offering the content
182 * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK
184 int GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
185 struct GNUNET_PeerIdentity *peer);
189 * Obtain the URI of the content itself.
191 * @param uri location URI to get the content URI from
192 * @return NULL if argument is not a location URI
194 struct GNUNET_FS_Uri *GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri
199 * Obtain the expiration of the LOC URI.
201 * @param uri location URI to get the expiration from
202 * @return expiration time of the URI
204 struct GNUNET_TIME_Absolute GNUNET_FS_uri_loc_get_expiration (const struct
210 * Construct a location URI (this peer will be used for the location).
212 * @param baseUri content offered by the sender
213 * @param cfg configuration information (used to find our hostkey)
214 * @param expiration_time how long will the content be offered?
215 * @return the location URI, NULL on error
217 struct GNUNET_FS_Uri *GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri
220 GNUNET_CONFIGURATION_Handle
222 struct GNUNET_TIME_Absolute
227 * Canonicalize keyword URI. Performs operations such
228 * as decapitalization and removal of certain characters.
229 * (useful for search).
231 * @param uri the URI to canonicalize
232 * @return canonicalized version of the URI, NULL on error
234 struct GNUNET_FS_Uri *GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri
239 * Merge the sets of keywords from two KSK URIs.
240 * (useful for merging the canonicalized keywords with
241 * the original keywords for sharing).
243 * @param u1 first uri
244 * @param u2 second uri
245 * @return merged URI, NULL on error
247 struct GNUNET_FS_Uri *GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
248 const struct GNUNET_FS_Uri *u2);
254 * @param uri the URI to duplicate
255 * @return copy of the URI
257 struct GNUNET_FS_Uri *GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
261 * Create an FS URI from a single user-supplied string of keywords.
262 * The string is broken up at spaces into individual keywords.
263 * Keywords that start with "+" are mandatory. Double-quotes can
264 * be used to prevent breaking up strings at spaces (and also
265 * to specify non-mandatory keywords starting with "+").
267 * Keywords must contain a balanced number of double quotes and
268 * double quotes can not be used in the actual keywords (for
269 * example, the string '""foo bar""' will be turned into two
270 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
272 * @param keywords the keyword string
273 * @param emsg where to store an error message
274 * @return an FS URI for the given keywords, NULL
275 * if keywords is not legal (i.e. empty).
277 struct GNUNET_FS_Uri *GNUNET_FS_uri_ksk_create (const char *keywords,
282 * Create an FS URI from a user-supplied command line of keywords.
283 * Arguments should start with "+" to indicate mandatory
286 * @param argc number of keywords
287 * @param argv keywords (double quotes are not required for
288 * keywords containing spaces; however, double
289 * quotes are required for keywords starting with
290 * "+"); there is no mechanism for having double
291 * quotes in the actual keywords (if the user
292 * did specifically specify double quotes, the
293 * caller should convert each double quote
294 * into two single quotes).
295 * @return an FS URI for the given keywords, NULL
296 * if keywords is not legal (i.e. empty).
298 struct GNUNET_FS_Uri *GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
303 * Test if two URIs are equal.
305 * @param u1 one of the URIs
306 * @param u2 the other URI
307 * @return GNUNET_YES if the URIs are equal
309 int GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
310 const struct GNUNET_FS_Uri *u2);
314 * Is this a namespace URI?
316 * @param uri the uri to check
317 * @return GNUNET_YES if this is an SKS uri
319 int GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
323 * Handle to one of our namespaces.
325 struct GNUNET_FS_Namespace;
329 * Create an SKS URI from a namespace and an identifier.
331 * @param ns namespace
332 * @param id identifier
333 * @param emsg where to store an error message
334 * @return an FS URI for the given namespace and identifier
336 struct GNUNET_FS_Uri *GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns,
337 const char *id, char **emsg);
341 * Create an SKS URI from a namespace ID and an identifier.
343 * @param nsid namespace ID
344 * @param id identifier
345 * @return an FS URI for the given namespace and identifier
347 struct GNUNET_FS_Uri *GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode *
348 nsid, const char *id);
352 * Get the ID of a namespace from the given
355 * @param uri the uri to get the namespace ID from
356 * @param nsid where to store the ID of the namespace
357 * @return GNUNET_OK on success
359 int GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
360 GNUNET_HashCode * nsid);
364 * Get the content identifier of an SKS URI.
366 * @param uri the sks uri
367 * @return NULL on error (not a valid SKS URI)
369 char *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)
380 char *GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle
381 *cfg, const struct GNUNET_FS_Uri *uri);
385 * Is this a keyword URI?
388 * @return GNUNET_YES if this is a KSK uri
390 int 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
399 int GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
403 * What is the size of the file that this URI
406 * @param uri the CHK (or LOC) URI to inspect
407 * @return size of the file as specified in the CHK URI
409 uint64_t GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
413 * Is this a location URI?
415 * @param uri the uri to check
416 * @return GNUNET_YES if this is a LOC uri
418 int GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
422 * Construct a keyword-URI from meta-data (take all entries
423 * in the meta-data and construct one large keyword URI
424 * that lists all keywords that can be found in the meta-data).
426 * @param md metadata to use
427 * @return NULL on error, otherwise a KSK URI
429 struct GNUNET_FS_Uri *GNUNET_FS_uri_ksk_create_from_meta_data (const struct
430 GNUNET_CONTAINER_MetaData
434 /* ******************** command-line option parsing API *********************** */
437 * Command-line option parser function that allows the user
438 * to specify one or more '-k' options with keywords. Each
439 * specified keyword will be added to the URI. A pointer to
440 * the URI must be passed as the "scls" argument.
442 * @param ctx command line processor context
443 * @param scls must be of type "struct GNUNET_FS_Uri **"
444 * @param option name of the option (typically 'k')
445 * @param value command line argument given
446 * @return GNUNET_OK on success
448 int GNUNET_FS_getopt_set_keywords (struct
449 GNUNET_GETOPT_CommandLineProcessorContext
450 *ctx, void *scls, const char *option,
455 * Command-line option parser function that allows the user to specify
456 * one or more '-m' options with metadata. Each specified entry of
457 * the form "type=value" will be added to the metadata. A pointer to
458 * the metadata must be passed as the "scls" argument.
460 * @param ctx command line processor context
461 * @param scls must be of type "struct GNUNET_CONTAINER_MetaData **"
462 * @param option name of the option (typically 'k')
463 * @param value command line argument given
464 * @return GNUNET_OK on success
466 int GNUNET_FS_getopt_set_metadata (struct
467 GNUNET_GETOPT_CommandLineProcessorContext
468 *ctx, void *scls, const char *option,
473 /* ************************* sharing API ***************** */
477 * Possible status codes used in the callback for the
478 * various file-sharing operations. On each file (or search),
479 * the callback is guaranteed to be called once with "START"
480 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
481 * are optional and depend on the circumstances; parent operations
482 * will be STARTED before child-operations and STOPPED after
483 * their respective child-operations. START and STOP signals
484 * are typically generated either due to explicit client requests
485 * or because of suspend/resume operations.
487 enum GNUNET_FS_Status
490 * Notification that we have started to publish a file structure.
492 GNUNET_FS_STATUS_PUBLISH_START,
495 * Notification that we have resumed sharing a file structure.
497 GNUNET_FS_STATUS_PUBLISH_RESUME,
500 * Notification that we have suspended sharing a file structure.
502 GNUNET_FS_STATUS_PUBLISH_SUSPEND,
505 * Notification that we are making progress sharing a file structure.
507 GNUNET_FS_STATUS_PUBLISH_PROGRESS,
510 * Notification that an error was encountered sharing a file structure.
511 * The application will continue to receive resume/suspend events for
512 * this structure until "GNUNET_FS_publish_stop" is called.
514 GNUNET_FS_STATUS_PUBLISH_ERROR,
517 * Notification that we completed sharing a file structure.
518 * The application will continue to receive resume/suspend events for
519 * this structure until "GNUNET_FS_publish_stop" is called.
521 GNUNET_FS_STATUS_PUBLISH_COMPLETED,
524 * Notification that we have stopped
525 * the process of uploading a file structure; no
526 * futher events will be generated for this action.
528 GNUNET_FS_STATUS_PUBLISH_STOPPED,
531 * Notification that we have started this download.
533 GNUNET_FS_STATUS_DOWNLOAD_START,
536 * Notification that this download is being resumed.
538 GNUNET_FS_STATUS_DOWNLOAD_RESUME,
541 * Notification that this download was suspended.
543 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND,
546 * Notification about progress with this download.
548 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS,
551 * Notification that this download encountered an error.
553 GNUNET_FS_STATUS_DOWNLOAD_ERROR,
556 * Notification that this download completed. Note that for
557 * directories, completion does not imply completion of all files in
560 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED,
563 * Notification that this download was stopped
564 * (final event with respect to this action).
566 GNUNET_FS_STATUS_DOWNLOAD_STOPPED,
569 * Notification that this download is now actively being
570 * pursued (as opposed to waiting in the queue).
572 GNUNET_FS_STATUS_DOWNLOAD_ACTIVE,
575 * Notification that this download is no longer actively
576 * being pursued (back in the queue).
578 GNUNET_FS_STATUS_DOWNLOAD_INACTIVE,
581 * Notification that this download is no longer part of a
582 * recursive download or search but now a 'stand-alone'
583 * download (and may thus need to be moved in the GUI
584 * into a different category).
586 GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT,
589 * First event generated when a client requests
590 * a search to begin or when a namespace result
591 * automatically triggers the search for updates.
593 GNUNET_FS_STATUS_SEARCH_START,
596 * Last event when a search is being resumed;
597 * note that "GNUNET_FS_SEARCH_START" will not
598 * be generated in this case.
600 GNUNET_FS_STATUS_SEARCH_RESUME,
603 * Event generated for each search result
604 * when the respective search is resumed.
606 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT,
609 * Last event when a search is being suspended;
610 * note that "GNUNET_FS_SEARCH_STOPPED" will not
611 * be generated in this case.
613 GNUNET_FS_STATUS_SEARCH_SUSPEND,
616 * This search has yielded a result.
618 GNUNET_FS_STATUS_SEARCH_RESULT,
621 * We have discovered a new namespace.
623 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE,
626 * We have additional data about the quality
627 * or availability of a search result.
629 GNUNET_FS_STATUS_SEARCH_UPDATE,
632 * Signals a problem with this search.
634 GNUNET_FS_STATUS_SEARCH_ERROR,
637 * Signals that this search was paused.
639 GNUNET_FS_STATUS_SEARCH_PAUSED,
642 * Signals that this search was continued (unpaused).
644 GNUNET_FS_STATUS_SEARCH_CONTINUED,
647 * Event generated for each search result
648 * when the respective search is stopped.
650 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED,
653 * Event generated for each search result
654 * when the respective search is suspended.
656 GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND,
659 * Last message from a search; this signals
660 * that there will be no further events associated
663 GNUNET_FS_STATUS_SEARCH_STOPPED,
666 * Notification that we started to unindex a file.
668 GNUNET_FS_STATUS_UNINDEX_START,
671 * Notification that we resumed unindexing of a file.
673 GNUNET_FS_STATUS_UNINDEX_RESUME,
676 * Notification that we suspended unindexing a file.
678 GNUNET_FS_STATUS_UNINDEX_SUSPEND,
681 * Notification that we made progress unindexing a file.
683 GNUNET_FS_STATUS_UNINDEX_PROGRESS,
686 * Notification that we encountered an error unindexing
689 GNUNET_FS_STATUS_UNINDEX_ERROR,
692 * Notification that the unindexing of this file
695 GNUNET_FS_STATUS_UNINDEX_COMPLETED,
698 * Notification that the unindexing of this file
699 * was stopped (final event for this action).
701 GNUNET_FS_STATUS_UNINDEX_STOPPED
706 * Handle for controlling an upload.
708 struct GNUNET_FS_PublishContext;
712 * Handle for controlling an unindexing operation.
714 struct GNUNET_FS_UnindexContext;
718 * Handle for controlling a search.
720 struct GNUNET_FS_SearchContext;
724 * Result from a search. Opaque handle to refer to the search
725 * (typically used when starting a download associated with the search
728 struct GNUNET_FS_SearchResult;
732 * Context for controlling a download.
734 struct GNUNET_FS_DownloadContext;
738 * Handle for detail information about a file that is being publishd.
739 * Specifies metadata, keywords, how to get the contents of the file
740 * (i.e. data-buffer in memory, filename on disk) and other options.
742 struct GNUNET_FS_FileInformation;
746 * Argument given to the progress callback with
747 * information about what is going on.
749 struct GNUNET_FS_ProgressInfo
753 * Values that depend on the event type.
759 * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
765 * Context for controlling the upload.
767 struct GNUNET_FS_PublishContext *pc;
770 * Information about the file that is being publishd.
772 const struct GNUNET_FS_FileInformation *fi;
775 * Client context pointer (set the last time by the client for
776 * this operation; initially NULL on START/RESUME events).
781 * Client context pointer for the parent operation
782 * (if this is a file in a directory or a subdirectory).
787 * Name of the file being published; can be NULL.
789 const char *filename;
792 * How large is the file overall? For directories,
793 * this is only the size of the directory itself,
794 * not of the other files contained within the
800 * At what time do we expect to finish the upload?
801 * (will be a value in the past for completed
804 struct GNUNET_TIME_Relative eta;
807 * How long has this upload been actively running
808 * (excludes times where the upload was suspended).
810 struct GNUNET_TIME_Relative duration;
813 * How many bytes have we completed?
818 * What anonymity level is used for this upload?
823 * Additional values for specific events.
829 * These values are only valid for
830 * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
836 * Data block we just published.
841 * At what offset in the file is "data"?
846 * Length of the data block.
851 * Depth of the given block in the tree;
852 * 0 would be the lowest level (DBLOCKs).
859 * These values are only valid for
860 * GNUNET_FS_STATUS_PUBLISH_RESUME events.
866 * Error message, NULL if no error was encountered so far.
871 * URI of the file (if the download had been completed)
873 const struct GNUNET_FS_Uri *chk_uri;
878 * These values are only valid for
879 * GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
887 const struct GNUNET_FS_Uri *chk_uri;
892 * These values are only valid for
893 * GNUNET_FS_STATUS_PUBLISH_ERROR events.
899 * Error message, never NULL.
911 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
917 * Context for controlling the download.
919 struct GNUNET_FS_DownloadContext *dc;
922 * Client context pointer (set the last time
923 * by the client for this operation; initially
924 * NULL on START/RESUME events).
929 * Client context pointer for the parent operation
930 * (if this is a file in a directory or a subdirectory).
935 * Client context pointer for the associated search operation
936 * (specifically, context pointer for the specific search
937 * result, not the overall search); only set if this
938 * download was started from a search result.
943 * URI used for this download.
945 const struct GNUNET_FS_Uri *uri;
948 * Name of the file that we are downloading.
950 const char *filename;
953 * How large is the download overall? This
954 * is NOT necessarily the size from the
955 * URI since we may be doing a partial download.
960 * At what time do we expect to finish the download?
961 * (will be a value in the past for completed
964 struct GNUNET_TIME_Relative eta;
967 * How long has this download been active?
969 struct GNUNET_TIME_Relative duration;
972 * How many bytes have we completed?
977 * What anonymity level is used for this download?
982 * Is the download currently active.
987 * Additional values for specific events.
993 * These values are only valid for
994 * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
1000 * Data block we just obtained, can be NULL (even if
1001 * data_len > 0) if we found the entire block 'intact' on
1002 * disk. In this case, it is also possible for 'data_len'
1003 * to be larger than an individual (32k) block.
1008 * At what offset in the file is "data"?
1013 * Length of the data block.
1018 * Depth of the given block in the tree;
1019 * 0 would be the lowest level (DBLOCKS).
1026 * These values are only valid for
1027 * GNUNET_FS_STATUS_DOWNLOAD_START events.
1033 * Known metadata for the download.
1035 const struct GNUNET_CONTAINER_MetaData *meta;
1040 * These values are only valid for
1041 * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
1047 * Known metadata for the download.
1049 const struct GNUNET_CONTAINER_MetaData *meta;
1052 * Error message, NULL if we have not encountered any error yet.
1054 const char *message;
1059 * These values are only valid for
1060 * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1068 const char *message;
1077 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1083 * Context for controlling the search, NULL for
1084 * searches that were not explicitly triggered
1085 * by the client (i.e., searches for updates in
1088 struct GNUNET_FS_SearchContext *sc;
1091 * Client context pointer (set the last time by the client for
1092 * this operation; initially NULL on START/RESUME events). Note
1093 * that this value can only be set on START/RESUME; returning
1094 * non-NULL on RESULT/RESUME_RESULT will actually update the
1095 * private context for "UPDATE" events.
1100 * Client parent-context pointer; NULL for top-level searches,
1101 * refers to the client context of the associated search result
1102 * for automatically triggered searches for updates in
1103 * namespaces. In this case, 'presult' refers to that search
1109 * What query is used for this search
1110 * (list of keywords or SKS identifier).
1112 const struct GNUNET_FS_Uri *query;
1115 * How long has this search been actively running
1116 * (excludes times where the search was paused or
1119 struct GNUNET_TIME_Relative duration;
1122 * What anonymity level is used for this search?
1127 * Additional values for specific events.
1133 * These values are only valid for
1134 * GNUNET_FS_STATUS_SEARCH_RESULT events.
1140 * Metadata for the search result.
1142 const struct GNUNET_CONTAINER_MetaData *meta;
1145 * URI for the search result.
1147 const struct GNUNET_FS_Uri *uri;
1150 * Handle to the result (for starting downloads).
1152 struct GNUNET_FS_SearchResult *result;
1155 * Applicability rank (the larger, the better the result
1156 * fits the search criteria).
1158 uint32_t applicability_rank;
1163 * These values are only valid for
1164 * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1170 * Metadata for the search result.
1172 const struct GNUNET_CONTAINER_MetaData *meta;
1175 * URI for the search result.
1177 const struct GNUNET_FS_Uri *uri;
1180 * Handle to the result (for starting downloads).
1182 struct GNUNET_FS_SearchResult *result;
1185 * Current availability rank (negative:
1186 * unavailable, positive: available)
1188 int32_t availability_rank;
1191 * On how many total queries is the given
1192 * availability_rank based?
1194 uint32_t availability_certainty;
1197 * Updated applicability rank (the larger,
1198 * the better the result fits the search
1201 uint32_t applicability_rank;
1206 * These values are only valid for
1207 * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1213 * Private context set for for this result
1214 * during the "RESULT" event.
1219 * Metadata for the search result.
1221 const struct GNUNET_CONTAINER_MetaData *meta;
1224 * URI for the search result.
1226 const struct GNUNET_FS_Uri *uri;
1229 * Current availability rank (negative:
1230 * unavailable, positive: available)
1232 int32_t availability_rank;
1235 * On how many total queries is the given
1236 * availability_rank based?
1238 uint32_t availability_certainty;
1241 * Updated applicability rank (the larger,
1242 * the better the result fits the search
1245 uint32_t applicability_rank;
1250 * These values are only valid for
1251 * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1252 * These events are automatically triggered for
1253 * each search result before the
1254 * GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1255 * happens primarily to give the client a chance
1256 * to clean up the "cctx" (if needed).
1262 * Private context set for for this result
1263 * during the "RESULT" event.
1268 * Metadata for the search result.
1270 const struct GNUNET_CONTAINER_MetaData *meta;
1273 * URI for the search result.
1275 const struct GNUNET_FS_Uri *uri;
1280 * These values are only valid for
1281 * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1282 * These events are automatically triggered for
1283 * each search result before the
1284 * GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1285 * happens primarily to give the client a chance
1286 * to clean up the "cctx" (if needed).
1292 * Private context set for for this result
1293 * during the "RESULT" event.
1298 * Metadata for the search result.
1300 const struct GNUNET_CONTAINER_MetaData *meta;
1303 * URI for the search result.
1305 const struct GNUNET_FS_Uri *uri;
1310 * These values are only valid for
1311 * GNUNET_FS_STATUS_SEARCH_RESUME events.
1317 * Error message, NULL if we have not encountered any error yet.
1319 const char *message;
1322 * Is this search currently paused?
1329 * These values are only valid for
1330 * GNUNET_FS_STATUS_SEARCH_ERROR events.
1338 const char *message;
1343 * Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events.
1349 * Handle to the namespace (NULL if it is not a local
1352 struct GNUNET_FS_Namespace *ns;
1355 * Short, human-readable name of the namespace.
1360 * Root identifier for the namespace, can be NULL.
1365 * Metadata for the namespace.
1367 const struct GNUNET_CONTAINER_MetaData *meta;
1370 * Hash-identifier for the namespace.
1381 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1387 * Context for controlling the unindexing.
1389 struct GNUNET_FS_UnindexContext *uc;
1392 * Client context pointer (set the last time
1393 * by the client for this operation; initially
1394 * NULL on START/RESUME events).
1399 * Name of the file that is being unindexed.
1401 const char *filename;
1404 * How large is the file overall?
1409 * At what time do we expect to finish unindexing?
1410 * (will be a value in the past for completed
1411 * unindexing opeations).
1413 struct GNUNET_TIME_Relative eta;
1416 * How long has this upload been actively running
1417 * (excludes times where the upload was suspended).
1419 struct GNUNET_TIME_Relative duration;
1422 * How many bytes have we completed?
1427 * Additional values for specific events.
1433 * These values are only valid for
1434 * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1440 * Data block we just unindexed.
1445 * At what offset in the file is "data"?
1450 * Length of the data block.
1455 * Depth of the given block in the tree;
1456 * 0 would be the lowest level (DBLOCKS).
1463 * These values are only valid for
1464 * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1470 * Error message, NULL if we have not encountered any error yet.
1472 const char *message;
1477 * These values are only valid for
1478 * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1486 const char *message;
1497 * Specific status code (determines the event type).
1499 enum GNUNET_FS_Status status;
1505 * Notification of FS to a client about the progress of an
1506 * operation. Callbacks of this type will be used for uploads,
1507 * downloads and searches. Some of the arguments depend a bit
1508 * in their meaning on the context in which the callback is used.
1510 * @param cls closure
1511 * @param info details about the event, specifying the event type
1512 * and various bits about the event
1513 * @return client-context (for the next progress call
1514 * for this operation; should be set to NULL for
1515 * SUSPEND and STOPPED events). The value returned
1516 * will be passed to future callbacks in the respective
1517 * field in the GNUNET_FS_ProgressInfo struct.
1519 typedef void *(*GNUNET_FS_ProgressCallback) (void *cls,
1520 const struct GNUNET_FS_ProgressInfo
1525 * General (global) option flags for file-sharing.
1527 enum GNUNET_FS_Flags
1530 * No special flags set.
1532 GNUNET_FS_FLAGS_NONE = 0,
1535 * Is persistence of operations desired?
1536 * (will create SUSPEND/RESUME events).
1538 GNUNET_FS_FLAGS_PERSISTENCE = 1,
1541 * Should we automatically trigger probes for search results
1542 * to determine availability?
1543 * (will create GNUNET_FS_STATUS_SEARCH_UPDATE events).
1545 GNUNET_FS_FLAGS_DO_PROBES = 2
1549 * Options specified in the VARARGs portion of GNUNET_FS_start.
1551 enum GNUNET_FS_OPTIONS
1555 * Last option in the VARARG list.
1557 GNUNET_FS_OPTIONS_END = 0,
1560 * Select the desired amount of parallelism (this option should be
1561 * followed by an "unsigned int" giving the desired maximum number
1562 * of parallel downloads).
1564 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
1567 * Maximum number of requests that should be pending at a given
1568 * point in time (invidivual downloads may go above this, but
1569 * if we are above this threshold, we should not activate any
1570 * additional downloads.
1572 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
1577 * Settings for publishing a block (which may of course also
1578 * apply to an entire directory or file).
1580 struct GNUNET_FS_BlockOptions
1584 * At what time should the block expire? Data blocks (DBLOCKS and
1585 * IBLOCKS) may still be used even if they are expired (however,
1586 * they'd be removed quickly from the datastore if we are short on
1587 * space), all other types of blocks will no longer be returned
1588 * after they expire.
1590 struct GNUNET_TIME_Absolute expiration_time;
1593 * At which anonymity level should the block be shared?
1594 * (0: no anonymity, 1: normal GAP, >1: with cover traffic).
1596 uint32_t anonymity_level;
1599 * How important is it for us to store the block? If we run
1600 * out of space, the highest-priority, non-expired blocks will
1603 uint32_t content_priority;
1606 * How often should we try to migrate the block to other peers?
1607 * Only used if "CONTENT_PUSHING" is set to YES, in which case we
1608 * first push each block to other peers according to their
1609 * replication levels. Once each block has been pushed that many
1610 * times to other peers, blocks are chosen for migration at random.
1611 * Naturally, there is no guarantee that the other peers will keep
1612 * these blocks for any period of time (since they won't have any
1613 * priority or might be too busy to even store the block in the
1616 uint32_t replication_level;
1622 * Return the current year (i.e. '2011').
1624 unsigned int GNUNET_FS_get_current_year (void);
1628 * Convert a year to an expiration time of January 1st of that year.
1630 * @param year a year (after 1970, please ;-)).
1631 * @return absolute time for January 1st of that year.
1633 struct GNUNET_TIME_Absolute GNUNET_FS_year_to_time (unsigned int year);
1637 * Handle to the file-sharing service.
1639 struct GNUNET_FS_Handle;
1643 * Setup a connection to the file-sharing service.
1645 * @param cfg configuration to use
1646 * @param client_name unique identifier for this client
1647 * @param upcb function to call to notify about FS actions
1648 * @param upcb_cls closure for upcb
1649 * @param flags specific attributes for fs-operations
1650 * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
1651 * @return NULL on error
1653 struct GNUNET_FS_Handle *GNUNET_FS_start (const struct
1654 GNUNET_CONFIGURATION_Handle *cfg,
1655 const char *client_name,
1656 GNUNET_FS_ProgressCallback upcb,
1658 enum GNUNET_FS_Flags flags, ...);
1662 * Close our connection with the file-sharing service.
1663 * The callback given to GNUNET_FS_start will no longer be
1664 * called after this function returns.
1666 * @param h handle that was returned from GNUNET_FS_start
1668 void GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1672 * Extract meta-data from a file.
1674 * @param md metadata to set
1675 * @param filename name of file to inspect
1676 * @param extractors plugins to use
1677 * @return GNUNET_SYSERR on error, otherwise the number
1678 * of meta-data items obtained
1680 int GNUNET_FS_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData *md,
1681 const char *filename,
1682 struct EXTRACTOR_PluginList
1687 * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
1689 * @param cls closure
1690 * @param fi the entry in the publish-structure
1691 * @param length length of the file or directory
1692 * @param meta metadata for the file or directory (can be modified)
1693 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1694 * @param bo block options (can be modified)
1695 * @param do_index should we index (can be modified)
1696 * @param client_info pointer to client context set upon creation (can be modified)
1697 * @return GNUNET_OK to continue, GNUNET_NO to remove
1698 * this entry from the directory, GNUNET_SYSERR
1699 * to abort the iteration
1701 typedef int (*GNUNET_FS_FileInformationProcessor) (void *cls,
1703 GNUNET_FS_FileInformation *
1704 fi, uint64_t length,
1706 GNUNET_CONTAINER_MetaData *
1708 struct GNUNET_FS_Uri ** uri,
1709 struct GNUNET_FS_BlockOptions
1710 * bo, int *do_index,
1711 void **client_info);
1715 * Obtain the name under which this file information
1716 * structure is stored on disk. Only works for top-level
1717 * file information structures.
1719 * @param s structure to get the filename for
1720 * @return NULL on error, otherwise filename that
1721 * can be passed to "GNUNET_FS_file_information_recover"
1722 * to read this fi-struct from disk.
1724 const char *GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation
1730 * Create an entry for a file in a publish-structure.
1732 * @param h handle to the file sharing subsystem
1733 * @param client_info initial client-info value for this entry
1734 * @param filename name of the file or directory to publish
1735 * @param keywords under which keywords should this file be available
1736 * directly; can be NULL
1737 * @param meta metadata for the file
1738 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1739 * GNUNET_SYSERR for simulation
1740 * @param bo block options
1741 * @return publish structure entry for the file
1743 struct GNUNET_FS_FileInformation
1744 *GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
1746 const char *filename,
1747 const struct GNUNET_FS_Uri
1750 GNUNET_CONTAINER_MetaData
1751 *meta, int do_index,
1753 GNUNET_FS_BlockOptions *bo);
1757 * Create an entry for a file in a publish-structure.
1759 * @param h handle to the file sharing subsystem
1760 * @param client_info initial client-info value for this entry
1761 * @param length length of the file
1762 * @param data data for the file (should not be used afterwards by
1763 * the caller; callee will "free")
1764 * @param keywords under which keywords should this file be available
1765 * directly; can be NULL
1766 * @param meta metadata for the file
1767 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1768 * GNUNET_SYSERR for simulation
1769 * @param bo block options
1770 * @return publish structure entry for the file
1772 struct GNUNET_FS_FileInformation
1773 *GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
1775 uint64_t length, void *data,
1776 const struct GNUNET_FS_Uri
1779 GNUNET_CONTAINER_MetaData
1780 *meta, int do_index,
1782 GNUNET_FS_BlockOptions *bo);
1786 * Function that provides data.
1788 * @param cls closure
1789 * @param offset offset to read from; it is possible
1790 * that the caller might need to go backwards
1792 * @param max maximum number of bytes that should be
1793 * copied to buf; readers are not allowed
1794 * to provide less data unless there is an error;
1795 * a value of "0" will be used at the end to allow
1796 * the reader to clean up its internal state
1797 * @param buf where the reader should write the data
1798 * @param emsg location for the reader to store an error message
1799 * @return number of bytes written, usually "max", 0 on error
1801 typedef size_t (*GNUNET_FS_DataReader) (void *cls, uint64_t offset, size_t max,
1802 void *buf, char **emsg);
1806 * Create an entry for a file in a publish-structure.
1808 * @param h handle to the file sharing subsystem
1809 * @param client_info initial client-info value for this entry
1810 * @param length length of the file
1811 * @param reader function that can be used to obtain the data for the file
1812 * @param reader_cls closure for "reader"
1813 * @param keywords under which keywords should this file be available
1814 * directly; can be NULL
1815 * @param meta metadata for the file
1816 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1817 * GNUNET_SYSERR for simulation
1818 * @param bo block options
1819 * @return publish structure entry for the file
1821 struct GNUNET_FS_FileInformation
1822 *GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
1825 GNUNET_FS_DataReader reader,
1827 const struct GNUNET_FS_Uri
1830 GNUNET_CONTAINER_MetaData
1831 *meta, int do_index,
1833 GNUNET_FS_BlockOptions *bo);
1837 * Function that a "GNUNET_FS_DirectoryScanner" should call
1838 * for each entry in the directory.
1840 * @param cls closure
1841 * @param filename name of the file (including path); must end
1842 * in a "/" (even on W32) if this is a directory
1843 * @param fi information about the file (should not be
1844 * used henceforth by the caller)
1846 typedef void (*GNUNET_FS_FileProcessor) (void *cls, const char *filename,
1847 struct GNUNET_FS_FileInformation * fi);
1851 * Type of a function that will be used to scan a directory.
1853 * @param cls closure
1854 * @param h handle to the file sharing subsystem
1855 * @param dirname name of the directory to scan
1856 * @param do_index should files be indexed or inserted
1857 * @param bo block options
1858 * @param proc function to call on each entry
1859 * @param proc_cls closure for proc
1860 * @param emsg where to store an error message (on errors)
1861 * @return GNUNET_OK on success
1863 typedef int (*GNUNET_FS_DirectoryScanner) (void *cls,
1864 struct GNUNET_FS_Handle * h,
1865 const char *dirname, int do_index,
1866 const struct GNUNET_FS_BlockOptions *
1867 bo, GNUNET_FS_FileProcessor proc,
1868 void *proc_cls, char **emsg);
1873 * Simple, useful default implementation of a directory scanner
1874 * (GNUNET_FS_DirectoryScanner). This implementation expects to get a
1875 * UNIX filename, will publish all files in the directory except hidden
1876 * files (those starting with a "."). Metadata will be extracted
1877 * using GNU libextractor; the specific list of plugins should be
1878 * specified in "cls", passing NULL will disable (!) metadata
1879 * extraction. Keywords will be derived from the metadata and be
1880 * subject to default canonicalization. This is strictly a
1881 * convenience function.
1883 * @param cls must be of type "struct EXTRACTOR_Extractor*"
1884 * @param h handle to the file sharing subsystem
1885 * @param dirname name of the directory to scan
1886 * @param do_index should files be indexed or inserted
1887 * @param bo block options
1888 * @param proc function called on each entry
1889 * @param proc_cls closure for proc
1890 * @param emsg where to store an error message (on errors)
1891 * @return GNUNET_OK on success
1893 int GNUNET_FS_directory_scanner_default (void *cls, struct GNUNET_FS_Handle *h,
1894 const char *dirname, int do_index,
1895 const struct GNUNET_FS_BlockOptions
1896 *bo, GNUNET_FS_FileProcessor proc,
1897 void *proc_cls, char **emsg);
1901 * Create a publish-structure from an existing file hierarchy, inferring
1902 * and organizing keywords and metadata as much as possible. This
1903 * function primarily performs the recursive build and re-organizes
1904 * keywords and metadata; for automatically getting metadata
1905 * extraction, scanning of directories and creation of the respective
1906 * GNUNET_FS_FileInformation entries the default scanner should be
1907 * passed (GNUNET_FS_directory_scanner_default). This is strictly a
1908 * convenience function.
1910 * @param h handle to the file sharing subsystem
1911 * @param client_info initial client-info value for this entry
1912 * @param filename name of the top-level file or directory
1913 * @param scanner function used to get a list of files in a directory
1914 * @param scanner_cls closure for scanner
1915 * @param do_index should files in the hierarchy be indexed?
1916 * @param bo block options
1917 * @param emsg where to store an error message
1918 * @return publish structure entry for the directory, NULL on error
1920 struct GNUNET_FS_FileInformation
1921 *GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle
1922 *h, void *client_info,
1923 const char *filename,
1924 GNUNET_FS_DirectoryScanner
1929 GNUNET_FS_BlockOptions
1934 * Create an entry for an empty directory in a publish-structure.
1935 * This function should be used by applications for which the
1936 * use of "GNUNET_FS_file_information_create_from_directory"
1937 * is not appropriate.
1939 * @param h handle to the file sharing subsystem
1940 * @param client_info initial client-info value for this entry
1941 * @param keywords under which keywords should this directory be available
1942 * directly; can be NULL
1943 * @param meta metadata for the directory
1944 * @param bo block options
1945 * @return publish structure entry for the directory , NULL on error
1947 struct GNUNET_FS_FileInformation
1948 *GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle
1949 *h, void *client_info,
1951 GNUNET_FS_Uri *keywords,
1953 GNUNET_CONTAINER_MetaData
1956 GNUNET_FS_BlockOptions
1961 * Test if a given entry represents a directory.
1963 * @param ent check if this FI represents a directory
1964 * @return GNUNET_YES if so, GNUNET_NO if not
1966 int GNUNET_FS_file_information_is_directory (const struct
1967 GNUNET_FS_FileInformation *ent);
1971 * Add an entry to a directory in a publish-structure. Clients
1972 * should never modify publish structures that were passed to
1973 * "GNUNET_FS_publish_start" already.
1975 * @param dir the directory
1976 * @param ent the entry to add; the entry must not have been
1977 * added to any other directory at this point and
1978 * must not include "dir" in its structure
1979 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1981 int GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1982 struct GNUNET_FS_FileInformation *ent);
1986 * Inspect a file or directory in a publish-structure. Clients
1987 * should never modify publish structures that were passed to
1988 * "GNUNET_FS_publish_start" already. When called on a directory,
1989 * this function will FIRST call "proc" with information about
1990 * the directory itself and then for each of the files in the
1991 * directory (but not for files in subdirectories). When called
1992 * on a file, "proc" will be called exactly once (with information
1993 * about the specific file).
1995 * @param dir the directory
1996 * @param proc function to call on each entry
1997 * @param proc_cls closure for proc
1999 void GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
2000 GNUNET_FS_FileInformationProcessor
2001 proc, void *proc_cls);
2005 * Destroy publish-structure. Clients should never destroy publish
2006 * structures that were passed to "GNUNET_FS_publish_start" already.
2008 * @param fi structure to destroy
2009 * @param cleaner function to call on each entry in the structure
2010 * (useful to clean up client_info); can be NULL; return
2011 * values are ignored
2012 * @param cleaner_cls closure for cleaner
2014 void GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
2015 GNUNET_FS_FileInformationProcessor
2016 cleaner, void *cleaner_cls);
2020 * Options for publishing. Compatible options
2021 * can be OR'ed together.
2023 enum GNUNET_FS_PublishOptions
2026 * No options (use defaults for everything).
2028 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
2031 * Simulate publishing. With this option, no data will be stored
2032 * in the datastore. Useful for computing URIs from files.
2034 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
2038 * Publish a file or directory.
2040 * @param h handle to the file sharing subsystem
2041 * @param fi information about the file or directory structure to publish
2042 * @param namespace namespace to publish the file in, NULL for no namespace
2043 * @param nid identifier to use for the publishd content in the namespace
2044 * (can be NULL, must be NULL if namespace is NULL)
2045 * @param nuid update-identifier that will be used for future updates
2046 * (can be NULL, must be NULL if namespace or nid is NULL)
2047 * @param options options for the publication
2048 * @return context that can be used to control the publish operation
2050 struct GNUNET_FS_PublishContext *GNUNET_FS_publish_start (struct
2051 GNUNET_FS_Handle *h,
2053 GNUNET_FS_FileInformation
2061 GNUNET_FS_PublishOptions
2066 * Stop a publication. Will abort incomplete publications (but
2067 * not remove blocks that have already been published) or
2068 * simply clean up the state for completed publications.
2069 * Must NOT be called from within the event callback!
2071 * @param pc context for the publication to stop
2073 void GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
2077 * Signature of a function called as the continuation of a KBlock or
2078 * SBlock publication.
2080 * @param cls closure
2081 * @param uri URI under which the block is now available, NULL on error
2082 * @param emsg error message, NULL on success
2084 typedef void (*GNUNET_FS_PublishContinuation) (void *cls,
2085 const struct GNUNET_FS_Uri * uri,
2090 * Publish a KBlock on GNUnet.
2092 * @param h handle to the file sharing subsystem
2093 * @param ksk_uri keywords to use
2094 * @param meta metadata to use
2095 * @param uri URI to refer to in the KBlock
2096 * @param bo block options
2097 * @param options publication options
2098 * @param cont continuation
2099 * @param cont_cls closure for cont
2101 void GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2102 const struct GNUNET_FS_Uri *ksk_uri,
2103 const struct GNUNET_CONTAINER_MetaData *meta,
2104 const struct GNUNET_FS_Uri *uri,
2105 const struct GNUNET_FS_BlockOptions *bo,
2106 enum GNUNET_FS_PublishOptions options,
2107 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2111 * Publish an SBlock on GNUnet.
2113 * @param h handle to the file sharing subsystem
2114 * @param namespace namespace to publish in
2115 * @param identifier identifier to use
2116 * @param update update identifier to use
2117 * @param meta metadata to use
2118 * @param uri URI to refer to in the SBlock
2119 * @param bo block options
2120 * @param options publication options
2121 * @param cont continuation
2122 * @param cont_cls closure for cont
2124 void GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2125 struct GNUNET_FS_Namespace *namespace,
2126 const char *identifier, const char *update,
2127 const struct GNUNET_CONTAINER_MetaData *meta,
2128 const struct GNUNET_FS_Uri *uri,
2129 const struct GNUNET_FS_BlockOptions *bo,
2130 enum GNUNET_FS_PublishOptions options,
2131 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2135 * Type of a function called by "GNUNET_FS_get_indexed_files".
2137 * @param cls closure
2138 * @param filename the name of the file
2139 * @param file_id hash of the contents of the indexed file
2140 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
2142 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls, const char *filename,
2143 const GNUNET_HashCode * file_id);
2147 * Iterate over all indexed files.
2149 * @param h handle to the file sharing subsystem
2150 * @param iterator function to call on each indexed file
2151 * @param iterator_cls closure for iterator
2152 * @param cont continuation to call when done;
2153 * reason should be "TIMEOUT" (on
2154 * error) or "PREREQ_DONE" (on success)
2155 * @param cont_cls closure for cont
2157 void GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2158 GNUNET_FS_IndexedFileProcessor iterator,
2160 GNUNET_SCHEDULER_Task cont, void *cont_cls);
2166 * @param h handle to the file sharing subsystem
2167 * @param filename file to unindex
2168 * @param cctx initial value for the client context
2169 * @return NULL on error, otherwise handle
2171 struct GNUNET_FS_UnindexContext *GNUNET_FS_unindex_start (struct
2172 GNUNET_FS_Handle *h,
2173 const char *filename,
2178 * Clean up after completion of an unindex operation.
2182 void GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2186 * Publish an advertismement for a namespace.
2188 * @param h handle to the file sharing subsystem
2189 * @param ksk_uri keywords to use for advertisment
2190 * @param namespace handle for the namespace that should be advertised
2191 * @param meta meta-data for the namespace advertisement
2192 * @param bo block options
2193 * @param rootEntry name of the root of the namespace
2194 * @param cont continuation
2195 * @param cont_cls closure for cont
2197 void GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
2198 struct GNUNET_FS_Uri *ksk_uri,
2199 struct GNUNET_FS_Namespace *namespace,
2200 const struct GNUNET_CONTAINER_MetaData
2202 const struct GNUNET_FS_BlockOptions *bo,
2203 const char *rootEntry,
2204 GNUNET_FS_PublishContinuation cont,
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 *GNUNET_FS_namespace_create (struct GNUNET_FS_Handle
2217 *h, const char *name);
2221 * Delete a namespace handle. Can be used for a clean shutdown (free
2222 * memory) or also to freeze the namespace to prevent further
2223 * insertions by anyone.
2225 * @param namespace handle to the namespace that should be deleted / freed
2226 * @param freeze prevents future insertions; creating a namespace
2227 * with the same name again will create a fresh namespace instead
2229 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2231 int GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace,
2236 * Callback with information about local (!) namespaces.
2237 * Contains the names of the local namespace and the global
2240 * @param cls closure
2241 * @param name human-readable identifier of the namespace
2242 * @param id hash identifier for the namespace
2244 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls, const char *name,
2245 const GNUNET_HashCode * id);
2249 * Build a list of all available local (!) namespaces The returned
2250 * names are only the nicknames since we only iterate over the local
2253 * @param h handle to the file sharing subsystem
2254 * @param cb function to call on each known namespace
2255 * @param cb_cls closure for cb
2257 void GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2258 GNUNET_FS_NamespaceInfoProcessor cb,
2263 * Function called on updateable identifiers.
2265 * @param cls closure
2266 * @param last_id last identifier
2267 * @param last_uri uri used for the content published under the last_id
2268 * @param last_meta metadata associated with last_uri
2269 * @param next_id identifier that should be used for updates
2271 typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls, const char *last_id,
2272 const struct GNUNET_FS_Uri *
2275 GNUNET_CONTAINER_MetaData *
2276 last_meta, const char *next_id);
2280 * List all of the identifiers in the namespace for which we could
2281 * produce an update. Namespace updates form a graph where each node
2282 * has a name. Each node can have any number of URI/meta-data entries
2283 * which can each be linked to other nodes. Cycles are possible.
2285 * Calling this function with "next_id" NULL will cause the library to
2286 * call "ip" with a root for each strongly connected component of the
2287 * graph (a root being a node from which all other nodes in the Scc
2290 * Calling this function with "next_id" being the name of a node will
2291 * cause the library to call "ip" with all children of the node. Note
2292 * that cycles within an SCC are possible (including self-loops).
2294 * @param namespace namespace to inspect for updateable content
2295 * @param next_id ID to look for; use NULL to look for SCC roots
2296 * @param ip function to call on each updateable identifier
2297 * @param ip_cls closure for ip
2299 void GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
2300 const char *next_id,
2301 GNUNET_FS_IdentifierProcessor ip,
2306 * Options for searching. Compatible options
2307 * can be OR'ed together.
2309 enum GNUNET_FS_SearchOptions
2312 * No options (use defaults for everything).
2314 GNUNET_FS_SEARCH_OPTION_NONE = 0,
2317 * Only search the local host, do not search remote systems (no P2P)
2319 GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
2324 * Start search for content.
2326 * @param h handle to the file sharing subsystem
2327 * @param uri specifies the search parameters; can be
2328 * a KSK URI or an SKS URI.
2329 * @param anonymity desired level of anonymity
2330 * @param options options for the search
2331 * @param cctx initial value for the client context
2332 * @return context that can be used to control the search
2334 struct GNUNET_FS_SearchContext *GNUNET_FS_search_start (struct GNUNET_FS_Handle
2340 GNUNET_FS_SearchOptions
2341 options, void *cctx);
2347 * @param sc context for the search that should be paused
2349 void GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2353 * Continue paused search.
2355 * @param sc context for the search that should be resumed
2357 void GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2361 * Stop search for content.
2363 * @param sc context for the search that should be stopped
2365 void GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2371 * Options for downloading. Compatible options
2372 * can be OR'ed together.
2374 enum GNUNET_FS_DownloadOptions
2377 * No options (use defaults for everything).
2379 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2382 * Only download from the local host, do not access remote systems (no P2P)
2384 GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
2387 * Do a recursive download (that is, automatically trigger the
2388 * download of files in directories).
2390 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
2393 * Do not append temporary data to
2394 * the target file (for the IBlocks).
2396 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
2399 * Internal option used to flag this download as a 'probe' for a
2400 * search result. Impacts the priority with which the download is
2401 * run and causes signalling callbacks to be done differently.
2402 * Also, probe downloads are not serialized on suspension. Normal
2403 * clients should not use this!
2405 GNUNET_FS_DOWNLOAD_IS_PROBE = (1 << 31)
2411 * Download parts of a file. Note that this will store
2412 * the blocks at the respective offset in the given file. Also, the
2413 * download is still using the blocking of the underlying FS
2414 * encoding. As a result, the download may *write* outside of the
2415 * given boundaries (if offset and length do not match the 32k FS
2416 * block boundaries). <p>
2418 * The given range can be used to focus a download towards a
2419 * particular portion of the file (optimization), not to strictly
2420 * limit the download to exactly those bytes.
2422 * @param h handle to the file sharing subsystem
2423 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2424 * @param meta known metadata for the file (can be NULL)
2425 * @param filename where to store the file, maybe NULL (then no file is
2426 * created on disk and data must be grabbed from the callbacks)
2427 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2428 * can be NULL (in which case we will pick a name if needed); the temporary file
2429 * may already exist, in which case we will try to use the data that is there and
2430 * if it is not what is desired, will overwrite it
2431 * @param offset at what offset should we start the download (typically 0)
2432 * @param length how many bytes should be downloaded starting at offset
2433 * @param anonymity anonymity level to use for the download
2434 * @param options various download options
2435 * @param cctx initial value for the client context for this download
2436 * @param parent parent download to associate this download with (use NULL
2437 * for top-level downloads; useful for manually-triggered recursive downloads)
2438 * @return context that can be used to control this download
2440 struct GNUNET_FS_DownloadContext *GNUNET_FS_download_start (struct
2441 GNUNET_FS_Handle *h,
2445 GNUNET_CONTAINER_MetaData
2455 GNUNET_FS_DownloadOptions
2456 options, void *cctx,
2458 GNUNET_FS_DownloadContext
2463 * Download parts of a file based on a search result. The download
2464 * will be associated with the search result (and the association
2465 * will be preserved when serializing/deserializing the state).
2466 * If the search is stopped, the download will not be aborted but
2467 * be 'promoted' to a stand-alone download.
2469 * As with the other download function, this will store
2470 * the blocks at the respective offset in the given file. Also, the
2471 * download is still using the blocking of the underlying FS
2472 * encoding. As a result, the download may *write* outside of the
2473 * given boundaries (if offset and length do not match the 32k FS
2474 * block boundaries). <p>
2476 * The given range can be used to focus a download towards a
2477 * particular portion of the file (optimization), not to strictly
2478 * limit the download to exactly those bytes.
2480 * @param h handle to the file sharing subsystem
2481 * @param sr the search result to use for the download (determines uri and
2482 * meta data and associations)
2483 * @param filename where to store the file, maybe NULL (then no file is
2484 * created on disk and data must be grabbed from the callbacks)
2485 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2486 * can be NULL (in which case we will pick a name if needed); the temporary file
2487 * may already exist, in which case we will try to use the data that is there and
2488 * if it is not what is desired, will overwrite it
2489 * @param offset at what offset should we start the download (typically 0)
2490 * @param length how many bytes should be downloaded starting at offset
2491 * @param anonymity anonymity level to use for the download
2492 * @param options various download options
2493 * @param cctx initial value for the client context for this download
2494 * @return context that can be used to control this download
2496 struct GNUNET_FS_DownloadContext *GNUNET_FS_download_start_from_search (struct
2500 GNUNET_FS_SearchResult
2515 GNUNET_FS_DownloadOptions
2522 * Stop a download (aborts if download is incomplete).
2524 * @param dc handle for the download
2525 * @param do_delete delete files of incomplete downloads
2527 void GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
2532 /* ******************** Directory API *********************** */
2535 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2536 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2537 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2540 * Does the meta-data claim that this is a directory?
2541 * Checks if the mime-type is that of a GNUnet directory.
2543 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2544 * we have no mime-type information (treat as 'GNUNET_NO')
2546 int GNUNET_FS_meta_data_test_for_directory (const struct
2547 GNUNET_CONTAINER_MetaData *md);
2551 * Set the MIMETYPE information for the given
2552 * metadata to "application/gnunet-directory".
2554 * @param md metadata to add mimetype to
2556 void GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2560 * Suggest a filename based on given metadata.
2562 * @param md given meta data
2563 * @return NULL if meta data is useless for suggesting a filename
2565 char *GNUNET_FS_meta_data_suggest_filename (const struct
2566 GNUNET_CONTAINER_MetaData *md);
2570 * Function used to process entries in a directory.
2572 * @param cls closure
2573 * @param filename name of the file in the directory
2574 * @param uri URI of the file
2575 * @param metadata metadata for the file; metadata for
2576 * the directory if everything else is NULL/zero
2577 * @param length length of the available data for the file
2578 * (of type size_t since data must certainly fit
2579 * into memory; if files are larger than size_t
2580 * permits, then they will certainly not be
2581 * embedded with the directory itself).
2582 * @param data data available for the file (length bytes)
2584 typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
2585 const char *filename,
2586 const struct GNUNET_FS_Uri *
2589 GNUNET_CONTAINER_MetaData *
2590 meta, size_t length,
2595 * Iterate over all entries in a directory. Note that directories
2596 * are structured such that it is possible to iterate over the
2597 * individual blocks as well as over the entire directory. Thus
2598 * a client can call this function on the buffer in the
2599 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2600 * include the contents of (small) files embedded in the directory
2601 * itself; for those files, the processor may be given the
2602 * contents of the file directly by this function.
2604 * @param size number of bytes in data
2605 * @param data pointer to the beginning of the directory
2606 * @param offset offset of data in the directory
2607 * @param dep function to call on each entry
2608 * @param dep_cls closure for dep
2609 * @return GNUNET_OK if this could be a block in a directory,
2610 * GNUNET_NO if this could be part of a directory (but not 100% OK)
2611 * GNUNET_SYSERR if 'data' does not represent a directory
2613 int GNUNET_FS_directory_list_contents (size_t size, const void *data,
2615 GNUNET_FS_DirectoryEntryProcessor dep,
2620 * Opaque handle to a directory builder.
2622 struct GNUNET_FS_DirectoryBuilder;
2625 * Create a directory builder.
2627 * @param mdir metadata for the directory
2629 struct GNUNET_FS_DirectoryBuilder *GNUNET_FS_directory_builder_create (const
2631 GNUNET_CONTAINER_MetaData
2636 * Add an entry to a directory.
2638 * @param bld directory to extend
2639 * @param uri uri of the entry (must not be a KSK)
2640 * @param md metadata of the entry
2641 * @param data raw data of the entry, can be NULL, otherwise
2642 * data must point to exactly the number of bytes specified
2645 void GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2646 const struct GNUNET_FS_Uri *uri,
2647 const struct GNUNET_CONTAINER_MetaData
2648 *md, const void *data);
2652 * Finish building the directory. Frees the
2653 * builder context and returns the directory
2656 * @param bld directory to finish
2657 * @param rsize set to the number of bytes needed
2658 * @param rdata set to the encoded directory
2659 * @return GNUNET_OK on success
2661 int GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2662 size_t * rsize, void **rdata);
2665 #if 0 /* keep Emacsens' auto-indent happy */