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,
87 * Get a unique key from a URI. This is for putting URIs
88 * into HashMaps. The key may change between FS implementations.
90 * @param uri uri to convert to a unique key
91 * @param key wherer to store the unique key
94 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
95 GNUNET_HashCode * key);
98 * Convert a URI to a UTF-8 String.
100 * @param uri uri to convert to a string
101 * @return the UTF-8 string
104 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
107 * Convert keyword URI to a human readable format
108 * (i.e. the search query that was used in the first place)
110 * @param uri ksk uri to convert to a string
111 * @return string with the keywords
114 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
118 * Add the given keyword to the set of keywords represented by the URI.
119 * Does nothing if the keyword is already present.
121 * @param uri ksk uri to modify
122 * @param keyword keyword to add
123 * @param is_mandatory is this keyword mandatory?
126 GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
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,
157 * @param uri uri to free
160 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
164 * How many keywords are ANDed in this keyword URI?
166 * @param uri ksk uri to get the number of keywords from
167 * @return 0 if this is not a keyword URI
170 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
174 * Iterate over all keywords in this keyword URI.
176 * @param uri ksk uri to get the keywords from
177 * @param iterator function to call on each keyword
178 * @param iterator_cls closure for iterator
179 * @return -1 if this is not a keyword URI, otherwise number of
180 * keywords iterated over until iterator aborted
183 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
184 GNUNET_FS_KeywordIterator iterator,
189 * Obtain the identity of the peer offering the data
191 * @param uri the location URI to inspect
192 * @param peer where to store the identify of the peer (presumably) offering the content
193 * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK
196 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
197 struct GNUNET_PeerIdentity * peer);
201 * Obtain the URI of the content itself.
203 * @param uri location URI to get the content URI from
204 * @return NULL if argument is not a location URI
206 struct GNUNET_FS_Uri *
207 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
211 * Obtain the expiration of the LOC URI.
213 * @param uri location URI to get the expiration from
214 * @return expiration time of the URI
216 struct GNUNET_TIME_Absolute
217 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
221 * Construct a location URI (this peer will be used for the location).
223 * @param baseUri content offered by the sender
224 * @param cfg configuration information (used to find our hostkey)
225 * @param expiration_time how long will the content be offered?
226 * @return the location URI, NULL on error
228 struct GNUNET_FS_Uri *
229 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
230 const struct GNUNET_CONFIGURATION_Handle *cfg,
231 struct GNUNET_TIME_Absolute expiration_time);
235 * Canonicalize keyword URI. Performs operations such
236 * as decapitalization and removal of certain characters.
237 * (useful for search).
239 * @param uri the URI to canonicalize
240 * @return canonicalized version of the URI, NULL on error
242 struct GNUNET_FS_Uri *
243 GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri);
247 * Merge the sets of keywords from two KSK URIs.
248 * (useful for merging the canonicalized keywords with
249 * the original keywords for sharing).
251 * @param u1 first uri
252 * @param u2 second uri
253 * @return merged URI, NULL on error
255 struct GNUNET_FS_Uri *
256 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
257 const struct GNUNET_FS_Uri *u2);
263 * @param uri the URI to duplicate
264 * @return copy of the URI
266 struct GNUNET_FS_Uri *
267 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
271 * Create an FS URI from a single user-supplied string of keywords.
272 * The string is broken up at spaces into individual keywords.
273 * Keywords that start with "+" are mandatory. Double-quotes can
274 * be used to prevent breaking up strings at spaces (and also
275 * to specify non-mandatory keywords starting with "+").
277 * Keywords must contain a balanced number of double quotes and
278 * double quotes can not be used in the actual keywords (for
279 * example, the string '""foo bar""' will be turned into two
280 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
282 * @param keywords the keyword string
283 * @param emsg where to store an error message
284 * @return an FS URI for the given keywords, NULL
285 * if keywords is not legal (i.e. empty).
287 struct GNUNET_FS_Uri *
288 GNUNET_FS_uri_ksk_create (const char *keywords,
293 * Create an FS URI from a user-supplied command line of keywords.
294 * Arguments should start with "+" to indicate mandatory
297 * @param argc number of keywords
298 * @param argv keywords (double quotes are not required for
299 * keywords containing spaces; however, double
300 * quotes are required for keywords starting with
301 * "+"); there is no mechanism for having double
302 * quotes in the actual keywords (if the user
303 * did specifically specify double quotes, the
304 * caller should convert each double quote
305 * into two single quotes).
306 * @return an FS URI for the given keywords, NULL
307 * if keywords is not legal (i.e. empty).
309 struct GNUNET_FS_Uri *
310 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
315 * Test if two URIs are equal.
317 * @param u1 one of the URIs
318 * @param u2 the other URI
319 * @return GNUNET_YES if the URIs are equal
322 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
323 const struct GNUNET_FS_Uri *u2);
327 * Is this a namespace URI?
329 * @param uri the uri to check
330 * @return GNUNET_YES if this is an SKS uri
333 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
337 * Handle to one of our namespaces.
339 struct GNUNET_FS_Namespace;
343 * Create an SKS URI from a namespace and an identifier.
345 * @param ns namespace
346 * @param id identifier
347 * @param emsg where to store an error message
348 * @return an FS URI for the given namespace and identifier
350 struct GNUNET_FS_Uri *
351 GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns,
357 * Create an SKS URI from a namespace ID and an identifier.
359 * @param nsid namespace ID
360 * @param id identifier
361 * @return an FS URI for the given namespace and identifier
363 struct GNUNET_FS_Uri *
364 GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode *nsid,
369 * Get the ID of a namespace from the given
372 * @param uri the uri to get the namespace ID from
373 * @param nsid where to store the ID of the namespace
374 * @return GNUNET_OK on success
377 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
378 GNUNET_HashCode * nsid);
382 * Get the content identifier of an SKS URI.
384 * @param uri the sks uri
385 * @return NULL on error (not a valid SKS URI)
388 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
392 * Convert namespace URI to a human readable format
393 * (using the namespace description, if available).
395 * @param cfg configuration to use
396 * @param uri SKS uri to convert
397 * @return NULL on error (not an SKS URI)
400 GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
401 const struct GNUNET_FS_Uri *uri);
405 * Is this a keyword URI?
408 * @return GNUNET_YES if this is a KSK uri
411 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
415 * Is this a file (or directory) URI?
417 * @param uri the uri to check
418 * @return GNUNET_YES if this is a CHK uri
421 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
425 * What is the size of the file that this URI
428 * @param uri the CHK (or LOC) URI to inspect
429 * @return size of the file as specified in the CHK URI
432 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
436 * Is this a location URI?
438 * @param uri the uri to check
439 * @return GNUNET_YES if this is a LOC uri
442 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
446 * Construct a keyword-URI from meta-data (take all entries
447 * in the meta-data and construct one large keyword URI
448 * that lists all keywords that can be found in the meta-data).
450 * @param md metadata to use
451 * @return NULL on error, otherwise a KSK URI
453 struct GNUNET_FS_Uri *
454 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md);
457 /* ******************** command-line option parsing API *********************** */
460 * Command-line option parser function that allows the user
461 * to specify one or more '-k' options with keywords. Each
462 * specified keyword will be added to the URI. A pointer to
463 * the URI must be passed as the "scls" argument.
465 * @param ctx command line processor context
466 * @param scls must be of type "struct GNUNET_FS_Uri **"
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_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx,
479 * Command-line option parser function that allows the user to specify
480 * one or more '-m' options with metadata. Each specified entry of
481 * the form "type=value" will be added to the metadata. A pointer to
482 * the metadata must be passed as the "scls" argument.
484 * @param ctx command line processor context
485 * @param scls must be of type "struct GNUNET_CONTAINER_MetaData **"
486 * @param option name of the option (typically 'k')
487 * @param value command line argument given
488 * @return GNUNET_OK on success
491 GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx,
498 /* ************************* sharing API ***************** */
502 * Possible status codes used in the callback for the
503 * various file-sharing operations. On each file (or search),
504 * the callback is guaranteed to be called once with "START"
505 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
506 * are optional and depend on the circumstances; parent operations
507 * will be STARTED before child-operations and STOPPED after
508 * their respective child-operations. START and STOP signals
509 * are typically generated either due to explicit client requests
510 * or because of suspend/resume operations.
512 enum GNUNET_FS_Status
515 * Notification that we have started to publish a file structure.
517 GNUNET_FS_STATUS_PUBLISH_START,
520 * Notification that we have resumed sharing a file structure.
522 GNUNET_FS_STATUS_PUBLISH_RESUME,
525 * Notification that we have suspended sharing a file structure.
527 GNUNET_FS_STATUS_PUBLISH_SUSPEND,
530 * Notification that we are making progress sharing a file structure.
532 GNUNET_FS_STATUS_PUBLISH_PROGRESS,
535 * Notification that an error was encountered sharing a file structure.
536 * The application will continue to receive resume/suspend events for
537 * this structure until "GNUNET_FS_publish_stop" is called.
539 GNUNET_FS_STATUS_PUBLISH_ERROR,
542 * Notification that we completed sharing a file structure.
543 * The application will continue to receive resume/suspend events for
544 * this structure until "GNUNET_FS_publish_stop" is called.
546 GNUNET_FS_STATUS_PUBLISH_COMPLETED,
549 * Notification that we have stopped
550 * the process of uploading a file structure; no
551 * futher events will be generated for this action.
553 GNUNET_FS_STATUS_PUBLISH_STOPPED,
556 * Notification that we have started this download.
558 GNUNET_FS_STATUS_DOWNLOAD_START,
561 * Notification that this download is being resumed.
563 GNUNET_FS_STATUS_DOWNLOAD_RESUME,
566 * Notification that this download was suspended.
568 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND,
571 * Notification about progress with this download.
573 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS,
576 * Notification that this download encountered an error.
578 GNUNET_FS_STATUS_DOWNLOAD_ERROR,
581 * Notification that this download completed. Note that for
582 * directories, completion does not imply completion of all files in
585 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED,
588 * Notification that this download was stopped
589 * (final event with respect to this action).
591 GNUNET_FS_STATUS_DOWNLOAD_STOPPED,
594 * Notification that this download is now actively being
595 * pursued (as opposed to waiting in the queue).
597 GNUNET_FS_STATUS_DOWNLOAD_ACTIVE,
600 * Notification that this download is no longer actively
601 * being pursued (back in the queue).
603 GNUNET_FS_STATUS_DOWNLOAD_INACTIVE,
606 * Notification that this download is no longer part of a
607 * recursive download or search but now a 'stand-alone'
608 * download (and may thus need to be moved in the GUI
609 * into a different category).
611 GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT,
614 * First event generated when a client requests
615 * a search to begin or when a namespace result
616 * automatically triggers the search for updates.
618 GNUNET_FS_STATUS_SEARCH_START,
621 * Last event when a search is being resumed;
622 * note that "GNUNET_FS_SEARCH_START" will not
623 * be generated in this case.
625 GNUNET_FS_STATUS_SEARCH_RESUME,
628 * Event generated for each search result
629 * when the respective search is resumed.
631 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT,
634 * Last event when a search is being suspended;
635 * note that "GNUNET_FS_SEARCH_STOPPED" will not
636 * be generated in this case.
638 GNUNET_FS_STATUS_SEARCH_SUSPEND,
641 * This search has yielded a result.
643 GNUNET_FS_STATUS_SEARCH_RESULT,
646 * We have discovered a new namespace.
648 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE,
651 * We have additional data about the quality
652 * or availability of a search result.
654 GNUNET_FS_STATUS_SEARCH_UPDATE,
657 * Signals a problem with this search.
659 GNUNET_FS_STATUS_SEARCH_ERROR,
662 * Signals that this search was paused.
664 GNUNET_FS_STATUS_SEARCH_PAUSED,
667 * Signals that this search was continued (unpaused).
669 GNUNET_FS_STATUS_SEARCH_CONTINUED,
672 * Event generated for each search result
673 * when the respective search is stopped.
675 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED,
678 * Event generated for each search result
679 * when the respective search is suspended.
681 GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND,
684 * Last message from a search; this signals
685 * that there will be no further events associated
688 GNUNET_FS_STATUS_SEARCH_STOPPED,
691 * Notification that we started to unindex a file.
693 GNUNET_FS_STATUS_UNINDEX_START,
696 * Notification that we resumed unindexing of a file.
698 GNUNET_FS_STATUS_UNINDEX_RESUME,
701 * Notification that we suspended unindexing a file.
703 GNUNET_FS_STATUS_UNINDEX_SUSPEND,
706 * Notification that we made progress unindexing a file.
708 GNUNET_FS_STATUS_UNINDEX_PROGRESS,
711 * Notification that we encountered an error unindexing
714 GNUNET_FS_STATUS_UNINDEX_ERROR,
717 * Notification that the unindexing of this file
720 GNUNET_FS_STATUS_UNINDEX_COMPLETED,
723 * Notification that the unindexing of this file
724 * was stopped (final event for this action).
726 GNUNET_FS_STATUS_UNINDEX_STOPPED
732 * Handle for controlling an upload.
734 struct GNUNET_FS_PublishContext;
738 * Handle for controlling an unindexing operation.
740 struct GNUNET_FS_UnindexContext;
744 * Handle for controlling a search.
746 struct GNUNET_FS_SearchContext;
750 * Result from a search. Opaque handle to refer to the search
751 * (typically used when starting a download associated with the search
754 struct GNUNET_FS_SearchResult;
758 * Context for controlling a download.
760 struct GNUNET_FS_DownloadContext;
764 * Handle for detail information about a file that is being publishd.
765 * Specifies metadata, keywords, how to get the contents of the file
766 * (i.e. data-buffer in memory, filename on disk) and other options.
768 struct GNUNET_FS_FileInformation;
772 * Argument given to the progress callback with
773 * information about what is going on.
775 struct GNUNET_FS_ProgressInfo
779 * Values that depend on the event type.
784 * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
789 * Context for controlling the upload.
791 struct GNUNET_FS_PublishContext *pc;
794 * Information about the file that is being publishd.
796 const struct GNUNET_FS_FileInformation *fi;
799 * Client context pointer (set the last time by the client for
800 * this operation; initially NULL on START/RESUME events).
805 * Client context pointer for the parent operation
806 * (if this is a file in a directory or a subdirectory).
811 * Name of the file being published; can be NULL.
813 const char *filename;
816 * How large is the file overall? For directories,
817 * this is only the size of the directory itself,
818 * not of the other files contained within the
824 * At what time do we expect to finish the upload?
825 * (will be a value in the past for completed
828 struct GNUNET_TIME_Relative eta;
831 * How long has this upload been actively running
832 * (excludes times where the upload was suspended).
834 struct GNUNET_TIME_Relative duration;
837 * How many bytes have we completed?
842 * What anonymity level is used for this upload?
847 * Additional values for specific events.
852 * These values are only valid for
853 * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
858 * Data block we just published.
863 * At what offset in the file is "data"?
868 * Length of the data block.
873 * Depth of the given block in the tree;
874 * 0 would be the lowest level (DBLOCKs).
881 * These values are only valid for
882 * GNUNET_FS_STATUS_PUBLISH_RESUME events.
887 * Error message, NULL if no error was encountered so far.
892 * URI of the file (if the download had been completed)
894 const struct GNUNET_FS_Uri *chk_uri;
899 * These values are only valid for
900 * GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
907 const struct GNUNET_FS_Uri *chk_uri;
912 * These values are only valid for
913 * GNUNET_FS_STATUS_PUBLISH_ERROR events.
918 * Error message, never NULL.
930 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
935 * Context for controlling the download.
937 struct GNUNET_FS_DownloadContext *dc;
940 * Client context pointer (set the last time
941 * by the client for this operation; initially
942 * NULL on START/RESUME events).
947 * Client context pointer for the parent operation
948 * (if this is a file in a directory or a subdirectory).
953 * Client context pointer for the associated search operation
954 * (specifically, context pointer for the specific search
955 * result, not the overall search); only set if this
956 * download was started from a search result.
961 * URI used for this download.
963 const struct GNUNET_FS_Uri *uri;
966 * Name of the file that we are downloading.
968 const char *filename;
971 * How large is the download overall? This
972 * is NOT necessarily the size from the
973 * URI since we may be doing a partial download.
978 * At what time do we expect to finish the download?
979 * (will be a value in the past for completed
982 struct GNUNET_TIME_Relative eta;
985 * How long has this download been active?
987 struct GNUNET_TIME_Relative duration;
990 * How many bytes have we completed?
995 * What anonymity level is used for this download?
1000 * Is the download currently active.
1005 * Additional values for specific events.
1010 * These values are only valid for
1011 * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
1016 * Data block we just obtained, can be NULL (even if
1017 * data_len > 0) if we found the entire block 'intact' on
1018 * disk. In this case, it is also possible for 'data_len'
1019 * to be larger than an individual (32k) block.
1024 * At what offset in the file is "data"?
1029 * Length of the data block.
1034 * Depth of the given block in the tree;
1035 * 0 would be the lowest level (DBLOCKS).
1042 * These values are only valid for
1043 * GNUNET_FS_STATUS_DOWNLOAD_START events.
1048 * Known metadata for the download.
1050 const struct GNUNET_CONTAINER_MetaData *meta;
1055 * These values are only valid for
1056 * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
1061 * Known metadata for the download.
1063 const struct GNUNET_CONTAINER_MetaData *meta;
1066 * Error message, NULL if we have not encountered any error yet.
1068 const char *message;
1073 * These values are only valid for
1074 * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1081 const char *message;
1090 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1095 * Context for controlling the search, NULL for
1096 * searches that were not explicitly triggered
1097 * by the client (i.e., searches for updates in
1100 struct GNUNET_FS_SearchContext *sc;
1103 * Client context pointer (set the last time by the client for
1104 * this operation; initially NULL on START/RESUME events). Note
1105 * that this value can only be set on START/RESUME; returning
1106 * non-NULL on RESULT/RESUME_RESULT will actually update the
1107 * private context for "UPDATE" events.
1112 * Client parent-context pointer; NULL for top-level searches,
1113 * refers to the client context of the associated search result
1114 * for automatically triggered searches for updates in
1115 * namespaces. In this case, 'presult' refers to that search
1121 * What query is used for this search
1122 * (list of keywords or SKS identifier).
1124 const struct GNUNET_FS_Uri *query;
1127 * How long has this search been actively running
1128 * (excludes times where the search was paused or
1131 struct GNUNET_TIME_Relative duration;
1134 * What anonymity level is used for this search?
1139 * Additional values for specific events.
1144 * These values are only valid for
1145 * GNUNET_FS_STATUS_SEARCH_RESULT events.
1150 * Metadata for the search result.
1152 const struct GNUNET_CONTAINER_MetaData *meta;
1155 * URI for the search result.
1157 const struct GNUNET_FS_Uri *uri;
1160 * Handle to the result (for starting downloads).
1162 struct GNUNET_FS_SearchResult *result;
1165 * Applicability rank (the larger, the better the result
1166 * fits the search criteria).
1168 uint32_t applicability_rank;
1173 * These values are only valid for
1174 * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1179 * Metadata for the search result.
1181 const struct GNUNET_CONTAINER_MetaData *meta;
1184 * URI for the search result.
1186 const struct GNUNET_FS_Uri *uri;
1189 * Handle to the result (for starting downloads).
1191 struct GNUNET_FS_SearchResult *result;
1194 * Current availability rank (negative:
1195 * unavailable, positive: available)
1197 int32_t availability_rank;
1200 * On how many total queries is the given
1201 * availability_rank based?
1203 uint32_t availability_certainty;
1206 * Updated applicability rank (the larger,
1207 * the better the result fits the search
1210 uint32_t applicability_rank;
1215 * These values are only valid for
1216 * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1221 * Private context set for for this result
1222 * during the "RESULT" event.
1227 * Metadata for the search result.
1229 const struct GNUNET_CONTAINER_MetaData *meta;
1232 * URI for the search result.
1234 const struct GNUNET_FS_Uri *uri;
1237 * Current availability rank (negative:
1238 * unavailable, positive: available)
1240 int32_t availability_rank;
1243 * On how many total queries is the given
1244 * availability_rank based?
1246 uint32_t availability_certainty;
1249 * Updated applicability rank (the larger,
1250 * the better the result fits the search
1253 uint32_t applicability_rank;
1258 * These values are only valid for
1259 * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1260 * These events are automatically triggered for
1261 * each search result before the
1262 * GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1263 * happens primarily to give the client a chance
1264 * to clean up the "cctx" (if needed).
1269 * Private context set for for this result
1270 * during the "RESULT" event.
1275 * Metadata for the search result.
1277 const struct GNUNET_CONTAINER_MetaData *meta;
1280 * URI for the search result.
1282 const struct GNUNET_FS_Uri *uri;
1287 * These values are only valid for
1288 * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1289 * These events are automatically triggered for
1290 * each search result before the
1291 * GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1292 * happens primarily to give the client a chance
1293 * to clean up the "cctx" (if needed).
1298 * Private context set for for this result
1299 * during the "RESULT" event.
1304 * Metadata for the search result.
1306 const struct GNUNET_CONTAINER_MetaData *meta;
1309 * URI for the search result.
1311 const struct GNUNET_FS_Uri *uri;
1316 * These values are only valid for
1317 * GNUNET_FS_STATUS_SEARCH_RESUME events.
1322 * Error message, NULL if we have not encountered any error yet.
1324 const char *message;
1327 * Is this search currently paused?
1334 * These values are only valid for
1335 * GNUNET_FS_STATUS_SEARCH_ERROR events.
1342 const char *message;
1347 * Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events.
1352 * Handle to the namespace (NULL if it is not a local
1355 struct GNUNET_FS_Namespace *ns;
1358 * Short, human-readable name of the namespace.
1363 * Root identifier for the namespace, can be NULL.
1368 * Metadata for the namespace.
1370 const struct GNUNET_CONTAINER_MetaData *meta;
1373 * Hash-identifier for the namespace.
1384 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1389 * Context for controlling the unindexing.
1391 struct GNUNET_FS_UnindexContext *uc;
1394 * Client context pointer (set the last time
1395 * by the client for this operation; initially
1396 * NULL on START/RESUME events).
1401 * Name of the file that is being unindexed.
1403 const char *filename;
1406 * How large is the file overall?
1411 * At what time do we expect to finish unindexing?
1412 * (will be a value in the past for completed
1413 * unindexing opeations).
1415 struct GNUNET_TIME_Relative eta;
1418 * How long has this upload been actively running
1419 * (excludes times where the upload was suspended).
1421 struct GNUNET_TIME_Relative duration;
1424 * How many bytes have we completed?
1429 * Additional values for specific events.
1434 * These values are only valid for
1435 * 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.
1469 * Error message, NULL if we have not encountered any error yet.
1471 const char *message;
1476 * These values are only valid for
1477 * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1484 const char *message;
1495 * Specific status code (determines the event type).
1497 enum GNUNET_FS_Status status;
1503 * Notification of FS to a client about the progress of an
1504 * operation. Callbacks of this type will be used for uploads,
1505 * downloads and searches. Some of the arguments depend a bit
1506 * in their meaning on the context in which the callback is used.
1508 * @param cls closure
1509 * @param info details about the event, specifying the event type
1510 * and various bits about the event
1511 * @return client-context (for the next progress call
1512 * for this operation; should be set to NULL for
1513 * SUSPEND and STOPPED events). The value returned
1514 * will be passed to future callbacks in the respective
1515 * field in the GNUNET_FS_ProgressInfo struct.
1517 typedef void* (*GNUNET_FS_ProgressCallback)
1519 const struct GNUNET_FS_ProgressInfo *info);
1523 * General (global) option flags for file-sharing.
1525 enum GNUNET_FS_Flags
1528 * No special flags set.
1530 GNUNET_FS_FLAGS_NONE = 0,
1533 * Is persistence of operations desired?
1534 * (will create SUSPEND/RESUME events).
1536 GNUNET_FS_FLAGS_PERSISTENCE = 1,
1539 * Should we automatically trigger probes for search results
1540 * to determine availability?
1541 * (will create GNUNET_FS_STATUS_SEARCH_UPDATE events).
1543 GNUNET_FS_FLAGS_DO_PROBES = 2
1548 * Options specified in the VARARGs portion of GNUNET_FS_start.
1550 enum GNUNET_FS_OPTIONS
1554 * Last option in the VARARG list.
1556 GNUNET_FS_OPTIONS_END = 0,
1559 * Select the desired amount of parallelism (this option should be
1560 * followed by an "unsigned int" giving the desired maximum number
1561 * of parallel downloads).
1563 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
1566 * Maximum number of requests that should be pending at a given
1567 * point in time (invidivual downloads may go above this, but
1568 * if we are above this threshold, we should not activate any
1569 * additional downloads.
1571 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;
1623 * Handle to the file-sharing service.
1625 struct GNUNET_FS_Handle;
1629 * Setup a connection to the file-sharing service.
1631 * @param cfg configuration to use
1632 * @param client_name unique identifier for this client
1633 * @param upcb function to call to notify about FS actions
1634 * @param upcb_cls closure for upcb
1635 * @param flags specific attributes for fs-operations
1636 * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
1637 * @return NULL on error
1639 struct GNUNET_FS_Handle *
1640 GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1641 const char *client_name,
1642 GNUNET_FS_ProgressCallback upcb,
1644 enum GNUNET_FS_Flags flags,
1649 * Close our connection with the file-sharing service.
1650 * The callback given to GNUNET_FS_start will no longer be
1651 * called after this function returns.
1653 * @param h handle that was returned from GNUNET_FS_start
1656 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1660 * Extract meta-data from a file.
1662 * @param md metadata to set
1663 * @param filename name of file to inspect
1664 * @param extractors plugins to use
1665 * @return GNUNET_SYSERR on error, otherwise the number
1666 * of meta-data items obtained
1669 GNUNET_FS_meta_data_extract_from_file (struct
1670 GNUNET_CONTAINER_MetaData
1671 *md, const char *filename,
1672 struct EXTRACTOR_PluginList *
1677 * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
1679 * @param cls closure
1680 * @param fi the entry in the publish-structure
1681 * @param length length of the file or directory
1682 * @param meta metadata for the file or directory (can be modified)
1683 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1684 * @param bo block options (can be modified)
1685 * @param do_index should we index (can be modified)
1686 * @param client_info pointer to client context set upon creation (can be modified)
1687 * @return GNUNET_OK to continue, GNUNET_NO to remove
1688 * this entry from the directory, GNUNET_SYSERR
1689 * to abort the iteration
1691 typedef int (*GNUNET_FS_FileInformationProcessor)(void *cls,
1692 struct GNUNET_FS_FileInformation *fi,
1694 struct GNUNET_CONTAINER_MetaData *meta,
1695 struct GNUNET_FS_Uri **uri,
1696 struct GNUNET_FS_BlockOptions *bo,
1698 void **client_info);
1702 * Obtain the name under which this file information
1703 * structure is stored on disk. Only works for top-level
1704 * file information structures.
1706 * @param s structure to get the filename for
1707 * @return NULL on error, otherwise filename that
1708 * can be passed to "GNUNET_FS_file_information_recover"
1709 * to read this fi-struct from disk.
1712 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1717 * Create an entry for a file in a publish-structure.
1719 * @param h handle to the file sharing subsystem
1720 * @param client_info initial client-info value for this entry
1721 * @param filename name of the file or directory to publish
1722 * @param keywords under which keywords should this file be available
1723 * directly; can be NULL
1724 * @param meta metadata for the file
1725 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1726 * GNUNET_SYSERR for simulation
1727 * @param bo block options
1728 * @return publish structure entry for the file
1730 struct GNUNET_FS_FileInformation *
1731 GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
1733 const char *filename,
1734 const struct GNUNET_FS_Uri *keywords,
1735 const struct GNUNET_CONTAINER_MetaData *meta,
1737 const struct GNUNET_FS_BlockOptions *bo);
1741 * Create an entry for a file in a publish-structure.
1743 * @param h handle to the file sharing subsystem
1744 * @param client_info initial client-info value for this entry
1745 * @param length length of the file
1746 * @param data data for the file (should not be used afterwards by
1747 * the caller; callee will "free")
1748 * @param keywords under which keywords should this file be available
1749 * directly; can be NULL
1750 * @param meta metadata for the file
1751 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1752 * GNUNET_SYSERR for simulation
1753 * @param bo block options
1754 * @return publish structure entry for the file
1756 struct GNUNET_FS_FileInformation *
1757 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
1761 const struct GNUNET_FS_Uri *keywords,
1762 const struct GNUNET_CONTAINER_MetaData *meta,
1764 const struct GNUNET_FS_BlockOptions *bo);
1768 * Function that provides data.
1770 * @param cls closure
1771 * @param offset offset to read from; it is possible
1772 * that the caller might need to go backwards
1774 * @param max maximum number of bytes that should be
1775 * copied to buf; readers are not allowed
1776 * to provide less data unless there is an error;
1777 * a value of "0" will be used at the end to allow
1778 * the reader to clean up its internal state
1779 * @param buf where the reader should write the data
1780 * @param emsg location for the reader to store an error message
1781 * @return number of bytes written, usually "max", 0 on error
1783 typedef size_t (*GNUNET_FS_DataReader)(void *cls,
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 reader function that can be used to obtain the data for the file
1797 * @param reader_cls closure for "reader"
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_reader (struct GNUNET_FS_Handle *h,
1810 GNUNET_FS_DataReader reader,
1812 const struct GNUNET_FS_Uri *keywords,
1813 const struct GNUNET_CONTAINER_MetaData *meta,
1815 const struct GNUNET_FS_BlockOptions *bo);
1819 * Function that a "GNUNET_FS_DirectoryScanner" should call
1820 * for each entry in the directory.
1822 * @param cls closure
1823 * @param filename name of the file (including path); must end
1824 * in a "/" (even on W32) if this is a directory
1825 * @param fi information about the file (should not be
1826 * used henceforth by the caller)
1828 typedef void (*GNUNET_FS_FileProcessor)(void *cls,
1829 const char *filename,
1830 struct GNUNET_FS_FileInformation *fi);
1834 * Type of a function that will be used to scan a directory.
1836 * @param cls closure
1837 * @param h handle to the file sharing subsystem
1838 * @param dirname name of the directory to scan
1839 * @param do_index should files be indexed or inserted
1840 * @param bo block options
1841 * @param proc function to call on each entry
1842 * @param proc_cls closure for proc
1843 * @param emsg where to store an error message (on errors)
1844 * @return GNUNET_OK on success
1846 typedef int (*GNUNET_FS_DirectoryScanner)(void *cls,
1847 struct GNUNET_FS_Handle *h,
1848 const char *dirname,
1850 const struct GNUNET_FS_BlockOptions *bo,
1851 GNUNET_FS_FileProcessor proc,
1858 * Simple, useful default implementation of a directory scanner
1859 * (GNUNET_FS_DirectoryScanner). This implementation expects to get a
1860 * UNIX filename, will publish all files in the directory except hidden
1861 * files (those starting with a "."). Metadata will be extracted
1862 * using GNU libextractor; the specific list of plugins should be
1863 * specified in "cls", passing NULL will disable (!) metadata
1864 * extraction. Keywords will be derived from the metadata and be
1865 * subject to default canonicalization. This is strictly a
1866 * convenience function.
1868 * @param cls must be of type "struct EXTRACTOR_Extractor*"
1869 * @param h handle to the file sharing subsystem
1870 * @param dirname name of the directory to scan
1871 * @param do_index should files be indexed or inserted
1872 * @param bo block options
1873 * @param proc function called on each entry
1874 * @param proc_cls closure for proc
1875 * @param emsg where to store an error message (on errors)
1876 * @return GNUNET_OK on success
1879 GNUNET_FS_directory_scanner_default (void *cls,
1880 struct GNUNET_FS_Handle *h,
1881 const char *dirname,
1883 const struct GNUNET_FS_BlockOptions *bo,
1884 GNUNET_FS_FileProcessor proc,
1890 * Create a publish-structure from an existing file hierarchy, inferring
1891 * and organizing keywords and metadata as much as possible. This
1892 * function primarily performs the recursive build and re-organizes
1893 * keywords and metadata; for automatically getting metadata
1894 * extraction, scanning of directories and creation of the respective
1895 * GNUNET_FS_FileInformation entries the default scanner should be
1896 * passed (GNUNET_FS_directory_scanner_default). This is strictly a
1897 * convenience function.
1899 * @param h handle to the file sharing subsystem
1900 * @param client_info initial client-info value for this entry
1901 * @param filename name of the top-level file or directory
1902 * @param scanner function used to get a list of files in a directory
1903 * @param scanner_cls closure for scanner
1904 * @param do_index should files in the hierarchy be indexed?
1905 * @param bo block options
1906 * @param emsg where to store an error message
1907 * @return publish structure entry for the directory, NULL on error
1909 struct GNUNET_FS_FileInformation *
1910 GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
1912 const char *filename,
1913 GNUNET_FS_DirectoryScanner scanner,
1916 const struct GNUNET_FS_BlockOptions *bo,
1921 * Create an entry for an empty directory in a publish-structure.
1922 * This function should be used by applications for which the
1923 * use of "GNUNET_FS_file_information_create_from_directory"
1924 * is not appropriate.
1926 * @param h handle to the file sharing subsystem
1927 * @param client_info initial client-info value for this entry
1928 * @param keywords under which keywords should this directory be available
1929 * directly; can be NULL
1930 * @param meta metadata for the directory
1931 * @param bo block options
1932 * @return publish structure entry for the directory , NULL on error
1934 struct GNUNET_FS_FileInformation *
1935 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
1937 const struct GNUNET_FS_Uri *keywords,
1938 const struct GNUNET_CONTAINER_MetaData *meta,
1939 const struct GNUNET_FS_BlockOptions *bo);
1943 * Test if a given entry represents a directory.
1945 * @param ent check if this FI represents a directory
1946 * @return GNUNET_YES if so, GNUNET_NO if not
1949 GNUNET_FS_file_information_is_directory (struct GNUNET_FS_FileInformation *ent);
1953 * Add an entry to a directory in a publish-structure. Clients
1954 * should never modify publish structures that were passed to
1955 * "GNUNET_FS_publish_start" already.
1957 * @param dir the directory
1958 * @param ent the entry to add; the entry must not have been
1959 * added to any other directory at this point and
1960 * must not include "dir" in its structure
1961 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1964 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1965 struct GNUNET_FS_FileInformation *ent);
1969 * Inspect a file or directory in a publish-structure. Clients
1970 * should never modify publish structures that were passed to
1971 * "GNUNET_FS_publish_start" already. When called on a directory,
1972 * this function will FIRST call "proc" with information about
1973 * the directory itself and then for each of the files in the
1974 * directory (but not for files in subdirectories). When called
1975 * on a file, "proc" will be called exactly once (with information
1976 * about the specific file).
1978 * @param dir the directory
1979 * @param proc function to call on each entry
1980 * @param proc_cls closure for proc
1983 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1984 GNUNET_FS_FileInformationProcessor proc,
1989 * Destroy publish-structure. Clients should never destroy publish
1990 * structures that were passed to "GNUNET_FS_publish_start" already.
1992 * @param fi structure to destroy
1993 * @param cleaner function to call on each entry in the structure
1994 * (useful to clean up client_info); can be NULL; return
1995 * values are ignored
1996 * @param cleaner_cls closure for cleaner
1999 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
2000 GNUNET_FS_FileInformationProcessor cleaner,
2005 * Options for publishing. Compatible options
2006 * can be OR'ed together.
2008 enum GNUNET_FS_PublishOptions
2011 * No options (use defaults for everything).
2013 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
2016 * Simulate publishing. With this option, no data will be stored
2017 * in the datastore. Useful for computing URIs from files.
2019 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
2023 * Publish a file or directory.
2025 * @param h handle to the file sharing subsystem
2026 * @param fi information about the file or directory structure to publish
2027 * @param namespace namespace to publish the file in, NULL for no namespace
2028 * @param nid identifier to use for the publishd content in the namespace
2029 * (can be NULL, must be NULL if namespace is NULL)
2030 * @param nuid update-identifier that will be used for future updates
2031 * (can be NULL, must be NULL if namespace or nid is NULL)
2032 * @param options options for the publication
2033 * @return context that can be used to control the publish operation
2035 struct GNUNET_FS_PublishContext *
2036 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
2037 struct GNUNET_FS_FileInformation *fi,
2038 struct GNUNET_FS_Namespace *namespace,
2041 enum GNUNET_FS_PublishOptions options);
2045 * Stop a publication. Will abort incomplete publications (but
2046 * not remove blocks that have already been published) or
2047 * simply clean up the state for completed publications.
2048 * Must NOT be called from within the event callback!
2050 * @param pc context for the publication to stop
2053 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
2057 * Signature of a function called as the continuation of a KBlock or
2058 * SBlock publication.
2060 * @param cls closure
2061 * @param uri URI under which the block is now available, NULL on error
2062 * @param emsg error message, NULL on success
2064 typedef void (*GNUNET_FS_PublishContinuation)(void *cls,
2065 const struct GNUNET_FS_Uri *uri,
2070 * Publish a KBlock on GNUnet.
2072 * @param h handle to the file sharing subsystem
2073 * @param ksk_uri keywords to use
2074 * @param meta metadata to use
2075 * @param uri URI to refer to in the KBlock
2076 * @param bo block options
2077 * @param options publication options
2078 * @param cont continuation
2079 * @param cont_cls closure for cont
2082 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2083 const struct GNUNET_FS_Uri *ksk_uri,
2084 const struct GNUNET_CONTAINER_MetaData *meta,
2085 const struct GNUNET_FS_Uri *uri,
2086 const struct GNUNET_FS_BlockOptions *bo,
2087 enum GNUNET_FS_PublishOptions options,
2088 GNUNET_FS_PublishContinuation cont,
2093 * Publish an SBlock on GNUnet.
2095 * @param h handle to the file sharing subsystem
2096 * @param namespace namespace to publish in
2097 * @param identifier identifier to use
2098 * @param update update identifier to use
2099 * @param meta metadata to use
2100 * @param uri URI to refer to in the SBlock
2101 * @param bo block options
2102 * @param options publication options
2103 * @param cont continuation
2104 * @param cont_cls closure for cont
2107 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2108 struct GNUNET_FS_Namespace *namespace,
2109 const char *identifier,
2111 const struct GNUNET_CONTAINER_MetaData *meta,
2112 const struct GNUNET_FS_Uri *uri,
2113 const struct GNUNET_FS_BlockOptions *bo,
2114 enum GNUNET_FS_PublishOptions options,
2115 GNUNET_FS_PublishContinuation cont,
2120 * Type of a function called by "GNUNET_FS_get_indexed_files".
2122 * @param cls closure
2123 * @param filename the name of the file
2124 * @param file_id hash of the contents of the indexed file
2125 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
2127 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls,
2128 const char *filename,
2129 const GNUNET_HashCode *file_id);
2133 * Iterate over all indexed files.
2135 * @param h handle to the file sharing subsystem
2136 * @param iterator function to call on each indexed file
2137 * @param iterator_cls closure for iterator
2138 * @param cont continuation to call when done;
2139 * reason should be "TIMEOUT" (on
2140 * error) or "PREREQ_DONE" (on success)
2141 * @param cont_cls closure for cont
2144 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2145 GNUNET_FS_IndexedFileProcessor iterator,
2147 GNUNET_SCHEDULER_Task cont,
2154 * @param h handle to the file sharing subsystem
2155 * @param filename file to unindex
2156 * @param cctx initial value for the client context
2157 * @return NULL on error, otherwise handle
2159 struct GNUNET_FS_UnindexContext *
2160 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
2161 const char *filename,
2166 * Clean up after completion of an unindex operation.
2171 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2175 * Publish an advertismement for a namespace.
2177 * @param h handle to the file sharing subsystem
2178 * @param ksk_uri keywords to use for advertisment
2179 * @param namespace handle for the namespace that should be advertised
2180 * @param meta meta-data for the namespace advertisement
2181 * @param bo block options
2182 * @param rootEntry name of the root of the namespace
2183 * @param cont continuation
2184 * @param cont_cls closure for cont
2187 GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
2188 struct GNUNET_FS_Uri *ksk_uri,
2189 struct GNUNET_FS_Namespace *namespace,
2190 const struct GNUNET_CONTAINER_MetaData *meta,
2191 const struct GNUNET_FS_BlockOptions *bo,
2192 const char *rootEntry,
2193 GNUNET_FS_PublishContinuation cont,
2198 * Create a namespace with the given name; if one already
2199 * exists, return a handle to the existing namespace.
2201 * @param h handle to the file sharing subsystem
2202 * @param name name to use for the namespace
2203 * @return handle to the namespace, NULL on error
2205 struct GNUNET_FS_Namespace *
2206 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h,
2211 * Delete a namespace handle. Can be used for a clean shutdown (free
2212 * memory) or also to freeze the namespace to prevent further
2213 * insertions by anyone.
2215 * @param namespace handle to the namespace that should be deleted / freed
2216 * @param freeze prevents future insertions; creating a namespace
2217 * with the same name again will create a fresh namespace instead
2219 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2222 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace,
2227 * Callback with information about local (!) namespaces.
2228 * Contains the names of the local namespace and the global
2231 * @param cls closure
2232 * @param name human-readable identifier of the namespace
2233 * @param id hash identifier for the namespace
2235 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls,
2237 const GNUNET_HashCode *id);
2241 * Build a list of all available local (!) namespaces The returned
2242 * names are only the nicknames since we only iterate over the local
2245 * @param h handle to the file sharing subsystem
2246 * @param cb function to call on each known namespace
2247 * @param cb_cls closure for cb
2250 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2251 GNUNET_FS_NamespaceInfoProcessor cb,
2256 * Function called on updateable identifiers.
2258 * @param cls closure
2259 * @param last_id last identifier
2260 * @param last_uri uri used for the content published under the last_id
2261 * @param last_meta metadata associated with last_uri
2262 * @param next_id identifier that should be used for updates
2265 (*GNUNET_FS_IdentifierProcessor)(void *cls,
2266 const char *last_id,
2267 const struct GNUNET_FS_Uri *last_uri,
2268 const struct GNUNET_CONTAINER_MetaData *last_meta,
2269 const char *next_id);
2273 * List all of the identifiers in the namespace for which we could
2274 * produce an update. Namespace updates form a graph where each node
2275 * has a name. Each node can have any number of URI/meta-data entries
2276 * which can each be linked to other nodes. Cycles are possible.
2278 * Calling this function with "next_id" NULL will cause the library to
2279 * call "ip" with a root for each strongly connected component of the
2280 * graph (a root being a node from which all other nodes in the Scc
2283 * Calling this function with "next_id" being the name of a node will
2284 * cause the library to call "ip" with all children of the node. Note
2285 * that cycles within an SCC are possible (including self-loops).
2287 * @param namespace namespace to inspect for updateable content
2288 * @param next_id ID to look for; use NULL to look for SCC roots
2289 * @param ip function to call on each updateable identifier
2290 * @param ip_cls closure for ip
2293 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
2294 const char *next_id,
2295 GNUNET_FS_IdentifierProcessor ip,
2300 * Options for searching. Compatible options
2301 * can be OR'ed together.
2303 enum GNUNET_FS_SearchOptions
2306 * No options (use defaults for everything).
2308 GNUNET_FS_SEARCH_OPTION_NONE = 0,
2311 * Only search the local host, do not search remote systems (no P2P)
2313 GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
2319 * Start search for content.
2321 * @param h handle to the file sharing subsystem
2322 * @param uri specifies the search parameters; can be
2323 * a KSK URI or an SKS URI.
2324 * @param anonymity desired level of anonymity
2325 * @param options options for the search
2326 * @param cctx initial value for the client context
2327 * @return context that can be used to control the search
2329 struct GNUNET_FS_SearchContext *
2330 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2331 const struct GNUNET_FS_Uri *uri,
2333 enum GNUNET_FS_SearchOptions options,
2340 * @param sc context for the search that should be paused
2343 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2347 * Continue paused search.
2349 * @param sc context for the search that should be resumed
2352 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2356 * Stop search for content.
2358 * @param sc context for the search that should be stopped
2361 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2367 * Options for downloading. Compatible options
2368 * can be OR'ed together.
2370 enum GNUNET_FS_DownloadOptions
2373 * No options (use defaults for everything).
2375 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2378 * Only download from the local host, do not access remote systems (no P2P)
2380 GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
2383 * Do a recursive download (that is, automatically trigger the
2384 * download of files in directories).
2386 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
2389 * Do not append temporary data to
2390 * the target file (for the IBlocks).
2392 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
2395 * Internal option used to flag this download as a 'probe' for a
2396 * search result. Impacts the priority with which the download is
2397 * run and causes signalling callbacks to be done differently.
2398 * Also, probe downloads are not serialized on suspension. Normal
2399 * clients should not use this!
2401 GNUNET_FS_DOWNLOAD_IS_PROBE = (1<<31)
2408 * Download parts of a file. Note that this will store
2409 * the blocks at the respective offset in the given file. Also, the
2410 * download is still using the blocking of the underlying FS
2411 * encoding. As a result, the download may *write* outside of the
2412 * given boundaries (if offset and length do not match the 32k FS
2413 * block boundaries). <p>
2415 * The given range can be used to focus a download towards a
2416 * particular portion of the file (optimization), not to strictly
2417 * limit the download to exactly those bytes.
2419 * @param h handle to the file sharing subsystem
2420 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2421 * @param meta known metadata for the file (can be NULL)
2422 * @param filename where to store the file, maybe NULL (then no file is
2423 * created on disk and data must be grabbed from the callbacks)
2424 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2425 * can be NULL (in which case we will pick a name if needed); the temporary file
2426 * may already exist, in which case we will try to use the data that is there and
2427 * if it is not what is desired, will overwrite it
2428 * @param offset at what offset should we start the download (typically 0)
2429 * @param length how many bytes should be downloaded starting at offset
2430 * @param anonymity anonymity level to use for the download
2431 * @param options various download options
2432 * @param cctx initial value for the client context for this download
2433 * @param parent parent download to associate this download with (use NULL
2434 * for top-level downloads; useful for manually-triggered recursive downloads)
2435 * @return context that can be used to control this download
2437 struct GNUNET_FS_DownloadContext *
2438 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2439 const struct GNUNET_FS_Uri *uri,
2440 const struct GNUNET_CONTAINER_MetaData *meta,
2441 const char *filename,
2442 const char *tempname,
2446 enum GNUNET_FS_DownloadOptions options,
2448 struct GNUNET_FS_DownloadContext *parent);
2452 * Download parts of a file based on a search result. The download
2453 * will be associated with the search result (and the association
2454 * will be preserved when serializing/deserializing the state).
2455 * If the search is stopped, the download will not be aborted but
2456 * be 'promoted' to a stand-alone download.
2458 * As with the other download function, this will store
2459 * the blocks at the respective offset in the given file. Also, the
2460 * download is still using the blocking of the underlying FS
2461 * encoding. As a result, the download may *write* outside of the
2462 * given boundaries (if offset and length do not match the 32k FS
2463 * block boundaries). <p>
2465 * The given range can be used to focus a download towards a
2466 * particular portion of the file (optimization), not to strictly
2467 * limit the download to exactly those bytes.
2469 * @param h handle to the file sharing subsystem
2470 * @param sr the search result to use for the download (determines uri and
2471 * meta data and associations)
2472 * @param filename where to store the file, maybe NULL (then no file is
2473 * created on disk and data must be grabbed from the callbacks)
2474 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2475 * can be NULL (in which case we will pick a name if needed); the temporary file
2476 * may already exist, in which case we will try to use the data that is there and
2477 * if it is not what is desired, will overwrite it
2478 * @param offset at what offset should we start the download (typically 0)
2479 * @param length how many bytes should be downloaded starting at offset
2480 * @param anonymity anonymity level to use for the download
2481 * @param options various download options
2482 * @param cctx initial value for the client context for this download
2483 * @return context that can be used to control this download
2485 struct GNUNET_FS_DownloadContext *
2486 GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2487 struct GNUNET_FS_SearchResult *sr,
2488 const char *filename,
2489 const char *tempname,
2493 enum GNUNET_FS_DownloadOptions options,
2498 * Stop a download (aborts if download is incomplete).
2500 * @param dc handle for the download
2501 * @param do_delete delete files of incomplete downloads
2504 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
2509 /* ******************** Directory API *********************** */
2512 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2513 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2514 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2517 * Does the meta-data claim that this is a directory?
2518 * Checks if the mime-type is that of a GNUnet directory.
2520 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2521 * we have no mime-type information (treat as 'GNUNET_NO')
2524 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData *md);
2528 * Set the MIMETYPE information for the given
2529 * metadata to "application/gnunet-directory".
2531 * @param md metadata to add mimetype to
2534 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2538 * Suggest a filename based on given metadata.
2540 * @param md given meta data
2541 * @return NULL if meta data is useless for suggesting a filename
2544 GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData *md);
2548 * Function used to process entries in a directory.
2550 * @param cls closure
2551 * @param filename name of the file in the directory
2552 * @param uri URI of the file
2553 * @param metadata metadata for the file; metadata for
2554 * the directory if everything else is NULL/zero
2555 * @param length length of the available data for the file
2556 * (of type size_t since data must certainly fit
2557 * into memory; if files are larger than size_t
2558 * permits, then they will certainly not be
2559 * embedded with the directory itself).
2560 * @param data data available for the file (length bytes)
2562 typedef void (*GNUNET_FS_DirectoryEntryProcessor)(void *cls,
2563 const char *filename,
2564 const struct GNUNET_FS_Uri *uri,
2565 const struct GNUNET_CONTAINER_MetaData *meta,
2571 * Iterate over all entries in a directory. Note that directories
2572 * are structured such that it is possible to iterate over the
2573 * individual blocks as well as over the entire directory. Thus
2574 * a client can call this function on the buffer in the
2575 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2576 * include the contents of (small) files embedded in the directory
2577 * itself; for those files, the processor may be given the
2578 * contents of the file directly by this function.
2580 * @param size number of bytes in data
2581 * @param data pointer to the beginning of the directory
2582 * @param offset offset of data in the directory
2583 * @param dep function to call on each entry
2584 * @param dep_cls closure for dep
2585 * @return GNUNET_OK if this could be a block in a directory,
2586 * GNUNET_NO if this could be part of a directory (but not 100% OK)
2587 * GNUNET_SYSERR if 'data' does not represent a directory
2590 GNUNET_FS_directory_list_contents (size_t size,
2593 GNUNET_FS_DirectoryEntryProcessor dep,
2598 * Opaque handle to a directory builder.
2600 struct GNUNET_FS_DirectoryBuilder;
2603 * Create a directory builder.
2605 * @param mdir metadata for the directory
2607 struct GNUNET_FS_DirectoryBuilder *
2608 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData *mdir);
2612 * Add an entry to a directory.
2614 * @param bld directory to extend
2615 * @param uri uri of the entry (must not be a KSK)
2616 * @param md metadata of the entry
2617 * @param data raw data of the entry, can be NULL, otherwise
2618 * data must point to exactly the number of bytes specified
2622 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2623 const struct GNUNET_FS_Uri *uri,
2624 const struct GNUNET_CONTAINER_MetaData *md,
2629 * Finish building the directory. Frees the
2630 * builder context and returns the directory
2633 * @param bld directory to finish
2634 * @param rsize set to the number of bytes needed
2635 * @param rdata set to the encoded directory
2636 * @return GNUNET_OK on success
2639 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2644 #if 0 /* keep Emacsens' auto-indent happy */