2 This file is part of GNUnet
3 (C) 2004--2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file include/gnunet_fs_service.h
22 * @brief API for file-sharing via GNUnet
23 * @author Christian Grothoff
25 #ifndef GNUNET_FS_LIB_H
26 #define GNUNET_FS_LIB_H
28 #include "gnunet_util_lib.h"
29 #include "gnunet_scheduler_lib.h"
34 #if 0 /* keep Emacsens' auto-indent happy */
40 * Version number of the implementation.
43 * 1.x.x: initial version with triple GNUNET_hash and merkle tree
44 * 2.x.x: root node with mime-type, filename and version number
45 * 2.1.x: combined GNUNET_EC_ContentHashKey/3HASH encoding with 25:1 super-nodes
46 * 2.2.x: with directories
47 * 3.0.x: with namespaces
48 * 3.1.x: with namespace meta-data
49 * 3.2.x: with collections
50 * 4.0.x: with expiration, variable meta-data, kblocks
51 * 4.1.x: with new error and configuration handling
52 * 5.0.x: with location URIs
53 * 6.0.0: with support for OR in KSKs
54 * 6.1.x: with simplified namespace support
55 * 9.0.0: CPS-style integrated API
56 * 9.1.1: asynchronous directory scanning
57 * 9.2.0: unified K-Block and S-block format (#2564)
59 #define GNUNET_FS_VERSION 0x00090200
62 /* ******************** URI API *********************** */
64 #define GNUNET_FS_URI_PREFIX "gnunet://fs/"
65 #define GNUNET_FS_URI_KSK_INFIX "ksk/"
66 #define GNUNET_FS_URI_SKS_INFIX "sks/"
67 #define GNUNET_FS_URI_CHK_INFIX "chk/"
68 #define GNUNET_FS_URI_LOC_INFIX "loc/"
72 * How often do we signal applications that a probe for a particular
73 * search result is running? (used to visualize probes).
75 #define GNUNET_FS_PROBE_UPDATE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
78 * A Universal Resource Identifier (URI), opaque.
84 * Identifier for a GNUnet pseudonym (the public key). Q-point, Q=dp.
85 * Note that we (ab)use an identifier of 'all zeros' to mean the
86 * 'anonymous' pseudonym, where the value is actually the point at
87 * infinity; however, that value cannot be represented here. We do
88 * not handle the case where the actual q-Value of some pseudonym
89 * happens to be all zeros as well (as the chance of that is
92 struct GNUNET_FS_PseudonymIdentifier
95 * Q consists of an x- and a y-value, each mod p (256 bits),
96 * given here in affine coordinates.
98 unsigned char q_x[256 / 8];
101 * Q consists of an x- and a y-value, each mod p (256 bits),
102 * given here in affine coordinates.
104 unsigned char q_y[256 / 8];
110 * Handle for a pseudonym (private key).
112 struct GNUNET_FS_PseudonymHandle;
116 * Signature made with a pseudonym (includes the full public key).
117 * The ECDSA signature is a pair (r,s) with r = x1 mod n where
118 * (x1,y1) = kG for "random" k and s = k^{-1}(z + rd) mod n,
119 * where z is derived from the hash of the message that is being
122 struct GNUNET_FS_PseudonymSignature
126 * Who created the signature? (public key of the signer), 'd' value in NIST P-256.
128 struct GNUNET_FS_PseudonymIdentifier signer;
131 * Binary ECDSA signature data, r-value. Value is mod n, and n is 256 bits.
133 unsigned char sig_r[256 / 8];
136 * Binary ECDSA signature data, s-value. Value is mod n, and n is 256 bits.
138 unsigned char sig_s[256 / 8];
143 * Purpose for signature made with a pseudonym.
145 struct GNUNET_FS_PseudonymSignaturePurpose
148 * How many bytes are being signed (including this header)?
153 * What is the context/purpose of the signature?
160 * Iterator over keywords
163 * @param keyword the keyword
164 * @param is_mandatory is the keyword mandatory (in a search)
165 * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
167 typedef int (*GNUNET_FS_KeywordIterator) (void *cls, const char *keyword,
174 * Create a pseudonym.
176 * @param filename name of the file to use for storage, NULL for in-memory only
177 * @return handle to the private key of the pseudonym
179 struct GNUNET_FS_PseudonymHandle *
180 GNUNET_FS_pseudonym_create (const char *filename);
184 * Create a pseudonym, from a file that must already exist.
186 * @param filename name of the file to use for storage, NULL for in-memory only
187 * @return handle to the private key of the pseudonym
189 struct GNUNET_FS_PseudonymHandle *
190 GNUNET_FS_pseudonym_create_from_existing_file (const char *filename);
194 * Get the handle for the 'anonymous' pseudonym shared by all users.
195 * That pseudonym uses a fixed 'secret' for the private key; this
196 * construction is useful to make anonymous and pseudonymous APIs
197 * (and packets) indistinguishable on the network. See #2564.
199 * @return handle to the (non-secret) private key of the 'anonymous' pseudonym
201 struct GNUNET_FS_PseudonymHandle *
202 GNUNET_FS_pseudonym_get_anonymous_pseudonym_handle (void);
206 * Destroy a pseudonym handle. Does NOT remove the private key from
209 * @param ph pseudonym handle to destroy
212 GNUNET_FS_pseudonym_destroy (struct GNUNET_FS_PseudonymHandle *ph);
216 * Cryptographically sign some data with the pseudonym.
218 * @param ph private key used for signing (corresponds to 'x' in #2564)
219 * @param purpose data to sign
220 * @param seed hash of the plaintext of the data that we are signing,
221 * used for deterministic PRNG for anonymous signing;
222 * corresponds to 'k' in section 2.7 of #2564
223 * @param signing_key modifier to apply to the private key for signing;
224 * corresponds to 'h' in section 2.3 of #2564.
225 * @param signature where to store the signature
226 * @return GNUNET_SYSERR on failure
229 GNUNET_FS_pseudonym_sign (struct GNUNET_FS_PseudonymHandle *ph,
230 const struct GNUNET_FS_PseudonymSignaturePurpose *purpose,
231 const struct GNUNET_HashCode *seed,
232 const struct GNUNET_HashCode *signing_key,
233 struct GNUNET_FS_PseudonymSignature *signature);
237 * Given a pseudonym and a signing key, derive the corresponding public
238 * key that would be used to verify the resulting signature.
240 * @param pseudonym the public key (g^x in DSA, dQ in ECDSA)
241 * @param signing_key input to derive 'h' (see section 2.4 of #2564)
242 * @param verification_key resulting public key to verify the signature
243 * created from the 'ph' of 'pseudonym' and the 'signing_key';
244 * the value stored here can then be given to GNUNET_FS_pseudonym_verify.
245 * @return GNUNET_OK on success, GNUNET_SYSERR on error
248 GNUNET_FS_pseudonym_derive_verification_key (struct GNUNET_FS_PseudonymIdentifier *pseudonym,
249 const struct GNUNET_HashCode *signing_key,
250 struct GNUNET_FS_PseudonymIdentifier *verification_key);
254 * Verify a signature made with a pseudonym.
256 * @param purpose data that was signed
257 * @param signature signature to verify
258 * @param verification_key public key to use for checking the signature;
259 * corresponds to 'g^(x+h)' in section 2.4 of #2564.
260 * @return GNUNET_OK on success (signature valid, 'pseudonym' set),
261 * GNUNET_SYSERR if the signature is invalid
264 GNUNET_FS_pseudonym_verify (const struct GNUNET_FS_PseudonymSignaturePurpose *purpose,
265 const struct GNUNET_FS_PseudonymSignature *signature,
266 const struct GNUNET_FS_PseudonymIdentifier *verification_key);
270 * Get the identifier (public key) of a pseudonym.
272 * @param ph pseudonym handle with the private key
273 * @param pseudonym pseudonym identifier (set based on 'ph')
276 GNUNET_FS_pseudonym_get_identifier (struct GNUNET_FS_PseudonymHandle *ph,
277 struct GNUNET_FS_PseudonymIdentifier *pseudonym);
282 * Iterator over all known pseudonyms.
285 * @param pseudonym hash code of public key of pseudonym
286 * @param name name of the pseudonym (might be NULL)
287 * @param unique_name unique name of the pseudonym (might be NULL)
288 * @param md meta data known about the pseudonym
289 * @param rating the local rating of the pseudonym
290 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
292 typedef int (*GNUNET_FS_PseudonymIterator) (void *cls,
293 const struct GNUNET_FS_PseudonymIdentifier *pseudonym,
295 const char *unique_name,
296 const struct GNUNET_CONTAINER_MetaData *md,
301 * Change the rank of a pseudonym.
303 * @param cfg overall configuration
304 * @param pseudonym identity of the pseudonym
305 * @param delta by how much should the rating be changed?
306 * @return new rating of the pseudonym
309 GNUNET_FS_pseudonym_rank (const struct GNUNET_CONFIGURATION_Handle *cfg,
310 const struct GNUNET_FS_PseudonymIdentifier *pseudonym,
315 * Add a pseudonym to the set of known pseudonyms.
316 * For all pseudonym advertisements that we discover
317 * FS should automatically call this function.
319 * @param cfg overall configuration
320 * @param pseudonym the pseudonym identifier
321 * @param meta metadata for the pseudonym
322 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
325 GNUNET_FS_pseudonym_add (const struct GNUNET_CONFIGURATION_Handle *cfg,
326 const struct GNUNET_FS_PseudonymIdentifier *pseudonym,
327 const struct GNUNET_CONTAINER_MetaData *meta);
331 * List all known pseudonyms.
333 * @param cfg overall configuration
334 * @param iterator function to call for each pseudonym
335 * @param iterator_cls closure for iterator
336 * @return number of pseudonyms found
339 GNUNET_FS_pseudonym_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg,
340 GNUNET_FS_PseudonymIterator iterator,
345 * Handle for a discovery callback registration.
347 struct GNUNET_FS_pseudonym_DiscoveryHandle;
351 * Register callback to be invoked whenever we discover
354 * @param cfg our configuration
355 * @param iterator function to invoke on discovery
356 * @param iterator_cls closure for iterator
357 * @return registration handle
359 struct GNUNET_FS_pseudonym_DiscoveryHandle *
360 GNUNET_FS_pseudonym_discovery_callback_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
361 GNUNET_FS_PseudonymIterator iterator,
366 * Unregister pseudonym discovery callback.
368 * @param dh registration to unregister
371 GNUNET_FS_pseudonym_discovery_callback_unregister (struct GNUNET_FS_pseudonym_DiscoveryHandle *dh);
375 * Return unique variant of the pseudonym name. Use after
376 * GNUNET_FS_pseudonym_id_to_name() to make sure that name is unique.
378 * @param cfg configuration
379 * @param pseudonym cryptographic ID of the pseudonym
380 * @param name name to uniquify
381 * @param suffix if not NULL, filled with the suffix value
382 * @return NULL on failure (should never happen), name on success.
383 * Free the name with GNUNET_free().
386 GNUNET_FS_pseudonym_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg,
387 const struct GNUNET_FS_PseudonymIdentifier *pseudonym,
389 unsigned int *suffix);
393 * Get pseudonym name, metadata and rank. This is a wrapper around
394 * internal read_info() call, and ensures that returned data is not
395 * invalid (not NULL). Writing back information returned by this
396 * function will give a name "no-name" to pseudonyms that have no
397 * name. This side-effect is unavoidable, but hardly harmful.
399 * @param cfg configuration
400 * @param pseudonym cryptographic ID of the pseudonym
401 * @param ret_meta a location to store metadata pointer. NULL, if metadata
402 * is not needed. Destroy with GNUNET_CONTAINER_meta_data_destroy().
403 * @param ret_rank a location to store rank. NULL, if rank not needed.
404 * @param ret_name a location to store human-readable name. Name is not unique.
405 * NULL, if name is not needed. Free with GNUNET_free().
406 * @param name_is_a_dup is set to GNUNET_YES, if ret_name was filled with
407 * a duplicate of a "no-name" placeholder
408 * @return GNUNET_OK on success. GNUENT_SYSERR if the data was
409 * unobtainable (in that case ret_* are filled with placeholders -
410 * empty metadata container, rank -1 and a "no-name" name).
413 GNUNET_FS_pseudonym_get_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
414 const struct GNUNET_FS_PseudonymIdentifier *pseudonym,
415 struct GNUNET_CONTAINER_MetaData **ret_meta,
422 * Get the pseudonym ID belonging to the given pseudonym name.
424 * @param cfg configuration to use
425 * @param ns_uname unique (!) human-readable name for the pseudonym
426 * @param pseudonym set to pseudonym ID based on 'ns_uname'
427 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
430 GNUNET_FS_pseudonym_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg,
431 const char *ns_uname,
432 struct GNUNET_FS_PseudonymIdentifier *pseudonym);
436 * Set the pseudonym metadata, rank and name.
438 * @param cfg overall configuration
439 * @param pseudonym id of the pseudonym
440 * @param name name to set. Must be the non-unique version of it.
441 * May be NULL, in which case it erases pseudonym's name!
442 * @param md metadata to set
443 * May be NULL, in which case it erases pseudonym's metadata!
444 * @param rank rank to assign
445 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
448 GNUNET_FS_pseudonym_set_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
449 const struct GNUNET_FS_PseudonymIdentifier *pseudonym,
451 const struct GNUNET_CONTAINER_MetaData *md,
456 * Remove pseudonym from the set of known pseudonyms.
458 * @param cfg overall configuration
459 * @param id the pseudonym identifier
460 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
463 GNUNET_FS_pseudonym_remove (const struct GNUNET_CONFIGURATION_Handle *cfg,
464 const struct GNUNET_FS_PseudonymIdentifier *id);
468 * Get a unique key from a URI. This is for putting URIs
469 * into HashMaps. The key may change between FS implementations.
471 * @param uri uri to convert to a unique key
472 * @param key wherer to store the unique key
475 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, struct GNUNET_HashCode * key);
479 * Convert a URI to a UTF-8 String.
481 * @param uri uri to convert to a string
482 * @return the UTF-8 string
485 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
489 * Convert keyword URI to a human readable format
490 * (i.e. the search query that was used in the first place)
492 * @param uri ksk uri to convert to a string
493 * @return string with the keywords
496 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
500 * Add the given keyword to the set of keywords represented by the URI.
501 * Does nothing if the keyword is already present.
503 * @param uri ksk uri to modify
504 * @param keyword keyword to add
505 * @param is_mandatory is this keyword mandatory?
508 GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, const char *keyword,
513 * Remove the given keyword from the set of keywords represented by the URI.
514 * Does nothing if the keyword is not present.
516 * @param uri ksk uri to modify
517 * @param keyword keyword to add
520 GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
521 const char *keyword);
525 * Convert a UTF-8 String to a URI.
527 * @param uri string to parse
528 * @param emsg where to store the parser error message (if any)
529 * @return NULL on error
531 struct GNUNET_FS_Uri *
532 GNUNET_FS_uri_parse (const char *uri, char **emsg);
537 * @param uri uri to free
540 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
544 * How many keywords are ANDed in this keyword URI?
546 * @param uri ksk uri to get the number of keywords from
547 * @return 0 if this is not a keyword URI
550 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
554 * Iterate over all keywords in this keyword URI.
556 * @param uri ksk uri to get the keywords from
557 * @param iterator function to call on each keyword
558 * @param iterator_cls closure for iterator
559 * @return -1 if this is not a keyword URI, otherwise number of
560 * keywords iterated over until iterator aborted
563 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
564 GNUNET_FS_KeywordIterator iterator,
569 * Obtain the identity of the peer offering the data
571 * @param uri the location URI to inspect
572 * @param peer where to store the identify of the peer (presumably) offering the content
573 * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK
576 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
577 struct GNUNET_PeerIdentity *peer);
581 * Obtain the URI of the content itself.
583 * @param uri location URI to get the content URI from
584 * @return NULL if argument is not a location URI
586 struct GNUNET_FS_Uri *
587 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
591 * Obtain the expiration of the LOC URI.
593 * @param uri location URI to get the expiration from
594 * @return expiration time of the URI
596 struct GNUNET_TIME_Absolute
597 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
601 * Construct a location URI (this peer will be used for the location).
603 * @param baseUri content offered by the sender
604 * @param cfg configuration information (used to find our hostkey)
605 * @param expiration_time how long will the content be offered?
606 * @return the location URI, NULL on error
608 struct GNUNET_FS_Uri *
609 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
610 const struct GNUNET_CONFIGURATION_Handle *cfg,
611 struct GNUNET_TIME_Absolute expiration_time);
615 * Merge the sets of keywords from two KSK URIs.
617 * @param u1 first uri
618 * @param u2 second uri
619 * @return merged URI, NULL on error
621 struct GNUNET_FS_Uri *
622 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
623 const struct GNUNET_FS_Uri *u2);
629 * @param uri the URI to duplicate
630 * @return copy of the URI
632 struct GNUNET_FS_Uri *
633 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
637 * Create an FS URI from a single user-supplied string of keywords.
638 * The string is broken up at spaces into individual keywords.
639 * Keywords that start with "+" are mandatory. Double-quotes can
640 * be used to prevent breaking up strings at spaces (and also
641 * to specify non-mandatory keywords starting with "+").
643 * Keywords must contain a balanced number of double quotes and
644 * double quotes can not be used in the actual keywords (for
645 * example, the string '""foo bar""' will be turned into two
646 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
648 * @param keywords the keyword string
649 * @param emsg where to store an error message
650 * @return an FS URI for the given keywords, NULL
651 * if keywords is not legal (i.e. empty).
653 struct GNUNET_FS_Uri *
654 GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg);
658 * Create an FS URI from a user-supplied command line of keywords.
659 * Arguments should start with "+" to indicate mandatory
662 * @param argc number of keywords
663 * @param argv keywords (double quotes are not required for
664 * keywords containing spaces; however, double
665 * quotes are required for keywords starting with
666 * "+"); there is no mechanism for having double
667 * quotes in the actual keywords (if the user
668 * did specifically specify double quotes, the
669 * caller should convert each double quote
670 * into two single quotes).
671 * @return an FS URI for the given keywords, NULL
672 * if keywords is not legal (i.e. empty).
674 struct GNUNET_FS_Uri *
675 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv);
679 * Test if two URIs are equal.
681 * @param u1 one of the URIs
682 * @param u2 the other URI
683 * @return GNUNET_YES if the URIs are equal
686 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
687 const struct GNUNET_FS_Uri *u2);
691 * Is this a namespace URI?
693 * @param uri the uri to check
694 * @return GNUNET_YES if this is an SKS uri
697 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
701 * Handle to one of our namespaces.
703 struct GNUNET_FS_Namespace;
707 * Create an SKS URI from a namespace and an identifier.
709 * @param ns namespace
710 * @param id identifier
711 * @param emsg where to store an error message
712 * @return an FS URI for the given namespace and identifier
714 struct GNUNET_FS_Uri *
715 GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id,
720 * Create an SKS URI from a namespace ID and an identifier.
722 * @param pseudonym pseudonym to use
723 * @param id identifier
724 * @return an FS URI for the given namespace and identifier
726 struct GNUNET_FS_Uri *
727 GNUNET_FS_uri_sks_create_from_nsid (struct GNUNET_FS_PseudonymIdentifier *pseudonym,
732 * Get the public key of a namespace from the given
735 * @param uri the uri to get the namespace ID from
736 * @param pseudonym where to store the public key of the namespace
737 * @return GNUNET_OK on success
740 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
741 struct GNUNET_FS_PseudonymIdentifier *pseudonym);
745 * Get the content identifier of an SKS URI.
747 * @param uri the sks uri
748 * @return NULL on error (not a valid SKS URI)
751 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
755 * Convert namespace URI to a human readable format
756 * (using the namespace description, if available).
758 * @param cfg configuration to use
759 * @param uri SKS uri to convert
760 * @return NULL on error (not an SKS URI)
763 GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
764 const struct GNUNET_FS_Uri *uri);
768 * Is this a keyword URI?
771 * @return GNUNET_YES if this is a KSK uri
774 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
778 * Is this a file (or directory) URI?
780 * @param uri the uri to check
781 * @return GNUNET_YES if this is a CHK uri
784 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
788 * What is the size of the file that this URI
791 * @param uri the CHK (or LOC) URI to inspect
792 * @return size of the file as specified in the CHK URI
795 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
799 * Is this a location URI?
801 * @param uri the uri to check
802 * @return GNUNET_YES if this is a LOC uri
805 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
809 * Construct a keyword-URI from meta-data (take all entries
810 * in the meta-data and construct one large keyword URI
811 * that lists all keywords that can be found in the meta-data).
813 * @param md metadata to use
814 * @return NULL on error, otherwise a KSK URI
816 struct GNUNET_FS_Uri *
817 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
821 /* ******************** command-line option parsing API *********************** */
824 * Command-line option parser function that allows the user
825 * to specify one or more '-k' options with keywords. Each
826 * specified keyword will be added to the URI. A pointer to
827 * the URI must be passed as the "scls" argument.
829 * @param ctx command line processor context
830 * @param scls must be of type "struct GNUNET_FS_Uri **"
831 * @param option name of the option (typically 'k')
832 * @param value command line argument given
833 * @return GNUNET_OK on success
836 GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext
837 *ctx, void *scls, const char *option,
842 * Command-line option parser function that allows the user to specify
843 * one or more '-m' options with metadata. Each specified entry of
844 * the form "type=value" will be added to the metadata. A pointer to
845 * the metadata must be passed as the "scls" argument.
847 * @param ctx command line processor context
848 * @param scls must be of type "struct GNUNET_CONTAINER_MetaData **"
849 * @param option name of the option (typically 'k')
850 * @param value command line argument given
851 * @return GNUNET_OK on success
854 GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext
855 *ctx, void *scls, const char *option,
860 /* ************************* sharing API ***************** */
864 * Possible status codes used in the callback for the
865 * various file-sharing operations. On each file (or search),
866 * the callback is guaranteed to be called once with "START"
867 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
868 * are optional and depend on the circumstances; parent operations
869 * will be STARTED before child-operations and STOPPED after
870 * their respective child-operations. START and STOP signals
871 * are typically generated either due to explicit client requests
872 * or because of suspend/resume operations.
874 enum GNUNET_FS_Status
877 * Notification that we have started to publish a file structure.
879 GNUNET_FS_STATUS_PUBLISH_START = 0,
882 * Notification that we have resumed sharing a file structure.
884 GNUNET_FS_STATUS_PUBLISH_RESUME = 1,
887 * Notification that we have suspended sharing a file structure.
889 GNUNET_FS_STATUS_PUBLISH_SUSPEND = 2,
892 * Notification that we are making progress sharing a file structure.
894 GNUNET_FS_STATUS_PUBLISH_PROGRESS = 3,
897 * Notification that an error was encountered sharing a file structure.
898 * The application will continue to receive resume/suspend events for
899 * this structure until "GNUNET_FS_publish_stop" is called.
901 GNUNET_FS_STATUS_PUBLISH_ERROR = 4,
904 * Notification that we completed sharing a file structure.
905 * The application will continue to receive resume/suspend events for
906 * this structure until "GNUNET_FS_publish_stop" is called.
908 GNUNET_FS_STATUS_PUBLISH_COMPLETED = 5,
911 * Notification that we have stopped
912 * the process of uploading a file structure; no
913 * futher events will be generated for this action.
915 GNUNET_FS_STATUS_PUBLISH_STOPPED = 6,
918 * Notification that we have started this download.
920 GNUNET_FS_STATUS_DOWNLOAD_START = 7,
923 * Notification that this download is being resumed.
925 GNUNET_FS_STATUS_DOWNLOAD_RESUME = 8,
928 * Notification that this download was suspended.
930 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND = 9,
933 * Notification about progress with this download.
935 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS = 10,
938 * Notification that this download encountered an error.
940 GNUNET_FS_STATUS_DOWNLOAD_ERROR = 11,
943 * Notification that this download completed. Note that for
944 * directories, completion does not imply completion of all files in
947 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED = 12,
950 * Notification that this download was stopped
951 * (final event with respect to this action).
953 GNUNET_FS_STATUS_DOWNLOAD_STOPPED = 13,
956 * Notification that this download is now actively being
957 * pursued (as opposed to waiting in the queue).
959 GNUNET_FS_STATUS_DOWNLOAD_ACTIVE = 14,
962 * Notification that this download is no longer actively
963 * being pursued (back in the queue).
965 GNUNET_FS_STATUS_DOWNLOAD_INACTIVE = 15,
968 * Notification that this download is no longer part of a
969 * recursive download or search but now a 'stand-alone'
970 * download (and may thus need to be moved in the GUI
971 * into a different category).
973 GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT = 16,
976 * First event generated when a client requests
977 * a search to begin or when a namespace result
978 * automatically triggers the search for updates.
980 GNUNET_FS_STATUS_SEARCH_START = 17,
983 * Last event when a search is being resumed;
984 * note that "GNUNET_FS_SEARCH_START" will not
985 * be generated in this case.
987 GNUNET_FS_STATUS_SEARCH_RESUME = 18,
990 * Event generated for each search result
991 * when the respective search is resumed.
993 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT = 19,
996 * Last event when a search is being suspended;
997 * note that "GNUNET_FS_SEARCH_STOPPED" will not
998 * be generated in this case.
1000 GNUNET_FS_STATUS_SEARCH_SUSPEND = 20,
1003 * This search has yielded a result.
1005 GNUNET_FS_STATUS_SEARCH_RESULT = 21,
1008 * We have discovered a new namespace.
1010 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE = 22,
1013 * We have additional data about the quality
1014 * or availability of a search result.
1016 GNUNET_FS_STATUS_SEARCH_UPDATE = 23,
1019 * Signals a problem with this search.
1021 GNUNET_FS_STATUS_SEARCH_ERROR = 24,
1024 * Signals that this search was paused.
1026 GNUNET_FS_STATUS_SEARCH_PAUSED = 25,
1029 * Signals that this search was continued (unpaused).
1031 GNUNET_FS_STATUS_SEARCH_CONTINUED = 26,
1034 * Event generated for each search result
1035 * when the respective search is stopped.
1037 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED = 27,
1040 * Event generated for each search result
1041 * when the respective search is suspended.
1043 GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND = 28,
1046 * Last message from a search; this signals
1047 * that there will be no further events associated
1050 GNUNET_FS_STATUS_SEARCH_STOPPED = 29,
1053 * Notification that we started to unindex a file.
1055 GNUNET_FS_STATUS_UNINDEX_START = 30,
1058 * Notification that we resumed unindexing of a file.
1060 GNUNET_FS_STATUS_UNINDEX_RESUME = 31,
1063 * Notification that we suspended unindexing a file.
1065 GNUNET_FS_STATUS_UNINDEX_SUSPEND = 32,
1068 * Notification that we made progress unindexing a file.
1070 GNUNET_FS_STATUS_UNINDEX_PROGRESS = 33,
1073 * Notification that we encountered an error unindexing
1076 GNUNET_FS_STATUS_UNINDEX_ERROR = 34,
1079 * Notification that the unindexing of this file
1082 GNUNET_FS_STATUS_UNINDEX_COMPLETED = 35,
1085 * Notification that the unindexing of this file
1086 * was stopped (final event for this action).
1088 GNUNET_FS_STATUS_UNINDEX_STOPPED = 36
1093 * Handle for controlling an upload.
1095 struct GNUNET_FS_PublishContext;
1099 * Handle for controlling an unindexing operation.
1101 struct GNUNET_FS_UnindexContext;
1105 * Handle for controlling a search.
1107 struct GNUNET_FS_SearchContext;
1111 * Result from a search. Opaque handle to refer to the search
1112 * (typically used when starting a download associated with the search
1115 struct GNUNET_FS_SearchResult;
1119 * Context for controlling a download.
1121 struct GNUNET_FS_DownloadContext;
1125 * Handle for detail information about a file that is being publishd.
1126 * Specifies metadata, keywords, how to get the contents of the file
1127 * (i.e. data-buffer in memory, filename on disk) and other options.
1129 struct GNUNET_FS_FileInformation;
1133 * Argument given to the progress callback with
1134 * information about what is going on.
1136 struct GNUNET_FS_ProgressInfo
1140 * Values that depend on the event type.
1146 * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
1152 * Context for controlling the upload.
1154 struct GNUNET_FS_PublishContext *pc;
1157 * Information about the file that is being publishd.
1159 const struct GNUNET_FS_FileInformation *fi;
1162 * Client context pointer (set the last time by the client for
1163 * this operation; initially NULL on START/RESUME events).
1168 * Client context pointer for the parent operation
1169 * (if this is a file in a directory or a subdirectory).
1174 * Name of the file being published; can be NULL.
1176 const char *filename;
1179 * How large is the file overall? For directories,
1180 * this is only the size of the directory itself,
1181 * not of the other files contained within the
1187 * At what time do we expect to finish the upload?
1188 * (will be a value in the past for completed
1191 struct GNUNET_TIME_Relative eta;
1194 * How long has this upload been actively running
1195 * (excludes times where the upload was suspended).
1197 struct GNUNET_TIME_Relative duration;
1200 * How many bytes have we completed?
1205 * What anonymity level is used for this upload?
1210 * Additional values for specific events.
1216 * These values are only valid for
1217 * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
1223 * Data block we just published.
1228 * At what offset in the file is "data"?
1233 * Length of the data block.
1238 * Depth of the given block in the tree;
1239 * 0 would be the lowest level (DBLOCKs).
1246 * These values are only valid for
1247 * GNUNET_FS_STATUS_PUBLISH_RESUME events.
1253 * Error message, NULL if no error was encountered so far.
1255 const char *message;
1258 * URI of the file (if the download had been completed)
1260 const struct GNUNET_FS_Uri *chk_uri;
1265 * These values are only valid for
1266 * GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
1274 const struct GNUNET_FS_Uri *chk_uri;
1279 * These values are only valid for
1280 * GNUNET_FS_STATUS_PUBLISH_ERROR events.
1286 * Error message, never NULL.
1288 const char *message;
1298 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
1304 * Context for controlling the download.
1306 struct GNUNET_FS_DownloadContext *dc;
1309 * Client context pointer (set the last time
1310 * by the client for this operation; initially
1311 * NULL on START/RESUME events).
1316 * Client context pointer for the parent operation
1317 * (if this is a file in a directory or a subdirectory).
1322 * Client context pointer for the associated search operation
1323 * (specifically, context pointer for the specific search
1324 * result, not the overall search); only set if this
1325 * download was started from a search result.
1330 * URI used for this download.
1332 const struct GNUNET_FS_Uri *uri;
1335 * Name of the file that we are downloading.
1337 const char *filename;
1340 * How large is the download overall? This
1341 * is NOT necessarily the size from the
1342 * URI since we may be doing a partial download.
1347 * At what time do we expect to finish the download?
1348 * (will be a value in the past for completed
1351 struct GNUNET_TIME_Relative eta;
1354 * How long has this download been active?
1356 struct GNUNET_TIME_Relative duration;
1359 * How many bytes have we completed?
1364 * What anonymity level is used for this download?
1369 * Is the download currently active.
1374 * Additional values for specific events.
1380 * These values are only valid for
1381 * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
1387 * Data block we just obtained, can be NULL (even if
1388 * data_len > 0) if we found the entire block 'intact' on
1389 * disk. In this case, it is also possible for 'data_len'
1390 * to be larger than an individual (32k) block.
1395 * At what offset in the file is "data"?
1400 * Length of the data block.
1405 * How much time passed between us asking for this block and
1406 * actually getting it? GNUNET_TIME_UNIT_FOREVER_REL if unknown.
1408 struct GNUNET_TIME_Relative block_download_duration;
1411 * Depth of the given block in the tree;
1412 * 0 would be the lowest level (DBLOCKS).
1417 * How much respect did we offer for downloading this block? (estimate,
1418 * because we might have the same request pending for multiple clients,
1419 * and of course because a transmission may have failed at a lower
1422 uint32_t respect_offered;
1425 * How often did we transmit the request? (estimate,
1426 * because we might have the same request pending for multiple clients,
1427 * and of course because a transmission may have failed at a lower
1430 uint32_t num_transmissions;
1435 * These values are only valid for
1436 * GNUNET_FS_STATUS_DOWNLOAD_START events.
1442 * Known metadata for the download.
1444 const struct GNUNET_CONTAINER_MetaData *meta;
1449 * These values are only valid for
1450 * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
1456 * Known metadata for the download.
1458 const struct GNUNET_CONTAINER_MetaData *meta;
1461 * Error message, NULL if we have not encountered any error yet.
1463 const char *message;
1468 * These values are only valid for
1469 * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1477 const char *message;
1486 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1492 * Context for controlling the search, NULL for
1493 * searches that were not explicitly triggered
1494 * by the client (i.e., searches for updates in
1497 struct GNUNET_FS_SearchContext *sc;
1500 * Client context pointer (set the last time by the client for
1501 * this operation; initially NULL on START/RESUME events). Note
1502 * that this value can only be set on START/RESUME; returning
1503 * non-NULL on RESULT/RESUME_RESULT will actually update the
1504 * private context for "UPDATE" events.
1509 * Client parent-context pointer; NULL for top-level searches,
1510 * refers to the client context of the associated search result
1511 * for automatically triggered searches for updates in
1512 * namespaces. In this case, 'presult' refers to that search
1518 * What query is used for this search
1519 * (list of keywords or SKS identifier).
1521 const struct GNUNET_FS_Uri *query;
1524 * How long has this search been actively running
1525 * (excludes times where the search was paused or
1528 struct GNUNET_TIME_Relative duration;
1531 * What anonymity level is used for this search?
1536 * Additional values for specific events.
1542 * These values are only valid for
1543 * GNUNET_FS_STATUS_SEARCH_RESULT events.
1549 * Metadata for the search result.
1551 const struct GNUNET_CONTAINER_MetaData *meta;
1554 * URI for the search result.
1556 const struct GNUNET_FS_Uri *uri;
1559 * Handle to the result (for starting downloads).
1561 struct GNUNET_FS_SearchResult *result;
1564 * Applicability rank (the larger, the better the result
1565 * fits the search criteria).
1567 uint32_t applicability_rank;
1572 * These values are only valid for
1573 * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1579 * Metadata for the search result.
1581 const struct GNUNET_CONTAINER_MetaData *meta;
1584 * URI for the search result.
1586 const struct GNUNET_FS_Uri *uri;
1589 * Handle to the result (for starting downloads).
1591 struct GNUNET_FS_SearchResult *result;
1594 * Current availability rank (negative:
1595 * unavailable, positive: available)
1597 int32_t availability_rank;
1600 * On how many total queries is the given
1601 * availability_rank based?
1603 uint32_t availability_certainty;
1606 * Updated applicability rank (the larger,
1607 * the better the result fits the search
1610 uint32_t applicability_rank;
1615 * These values are only valid for
1616 * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1622 * Private context set for for this result
1623 * during the "RESULT" event.
1628 * Metadata for the search result.
1630 const struct GNUNET_CONTAINER_MetaData *meta;
1633 * URI for the search result.
1635 const struct GNUNET_FS_Uri *uri;
1638 * Current availability rank (negative:
1639 * unavailable, positive: available)
1641 int32_t availability_rank;
1644 * On how many total queries is the given
1645 * availability_rank based?
1647 uint32_t availability_certainty;
1650 * Updated applicability rank (the larger,
1651 * the better the result fits the search
1654 uint32_t applicability_rank;
1657 * How long has the current probe been active?
1659 struct GNUNET_TIME_Relative current_probe_time;
1664 * These values are only valid for
1665 * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1666 * These events are automatically triggered for
1667 * each search result before the
1668 * GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1669 * happens primarily to give the client a chance
1670 * to clean up the "cctx" (if needed).
1676 * Private context set for for this result
1677 * during the "RESULT" event.
1682 * Metadata for the search result.
1684 const struct GNUNET_CONTAINER_MetaData *meta;
1687 * URI for the search result.
1689 const struct GNUNET_FS_Uri *uri;
1694 * These values are only valid for
1695 * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1696 * These events are automatically triggered for
1697 * each search result before the
1698 * GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1699 * happens primarily to give the client a chance
1700 * to clean up the "cctx" (if needed).
1706 * Private context set for for this result
1707 * during the "RESULT" event.
1712 * Metadata for the search result.
1714 const struct GNUNET_CONTAINER_MetaData *meta;
1717 * URI for the search result.
1719 const struct GNUNET_FS_Uri *uri;
1724 * These values are only valid for
1725 * GNUNET_FS_STATUS_SEARCH_RESUME events.
1731 * Error message, NULL if we have not encountered any error yet.
1733 const char *message;
1736 * Is this search currently paused?
1743 * These values are only valid for
1744 * GNUNET_FS_STATUS_SEARCH_ERROR events.
1752 const char *message;
1757 * Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events.
1763 * Handle to the namespace (NULL if it is not a local
1766 struct GNUNET_FS_Namespace *ns;
1769 * Short, human-readable name of the namespace.
1774 * Root identifier for the namespace, can be NULL.
1779 * Metadata for the namespace.
1781 const struct GNUNET_CONTAINER_MetaData *meta;
1784 * Public key of the namespace.
1786 struct GNUNET_FS_PseudonymIdentifier pseudonym;
1795 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1801 * Context for controlling the unindexing.
1803 struct GNUNET_FS_UnindexContext *uc;
1806 * Client context pointer (set the last time
1807 * by the client for this operation; initially
1808 * NULL on START/RESUME events).
1813 * Name of the file that is being unindexed.
1815 const char *filename;
1818 * How large is the file overall?
1823 * At what time do we expect to finish unindexing?
1824 * (will be a value in the past for completed
1825 * unindexing opeations).
1827 struct GNUNET_TIME_Relative eta;
1830 * How long has this upload been actively running
1831 * (excludes times where the upload was suspended).
1833 struct GNUNET_TIME_Relative duration;
1836 * How many bytes have we completed?
1841 * Additional values for specific events.
1847 * These values are only valid for
1848 * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1854 * Data block we just unindexed.
1859 * At what offset in the file is "data"?
1864 * Length of the data block.
1869 * Depth of the given block in the tree;
1870 * 0 would be the lowest level (DBLOCKS).
1877 * These values are only valid for
1878 * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1884 * Error message, NULL if we have not encountered any error yet.
1886 const char *message;
1891 * These values are only valid for
1892 * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1900 const char *message;
1911 * Specific status code (determines the event type).
1913 enum GNUNET_FS_Status status;
1919 * Notification of FS to a client about the progress of an
1920 * operation. Callbacks of this type will be used for uploads,
1921 * downloads and searches. Some of the arguments depend a bit
1922 * in their meaning on the context in which the callback is used.
1924 * @param cls closure
1925 * @param info details about the event, specifying the event type
1926 * and various bits about the event
1927 * @return client-context (for the next progress call
1928 * for this operation; should be set to NULL for
1929 * SUSPEND and STOPPED events). The value returned
1930 * will be passed to future callbacks in the respective
1931 * field in the GNUNET_FS_ProgressInfo struct.
1933 typedef void *(*GNUNET_FS_ProgressCallback) (void *cls,
1934 const struct GNUNET_FS_ProgressInfo *info);
1938 * General (global) option flags for file-sharing.
1940 enum GNUNET_FS_Flags
1943 * No special flags set.
1945 GNUNET_FS_FLAGS_NONE = 0,
1948 * Is persistence of operations desired?
1949 * (will create SUSPEND/RESUME events).
1951 GNUNET_FS_FLAGS_PERSISTENCE = 1,
1954 * Should we automatically trigger probes for search results
1955 * to determine availability?
1956 * (will create GNUNET_FS_STATUS_SEARCH_UPDATE events).
1958 GNUNET_FS_FLAGS_DO_PROBES = 2
1963 * Options specified in the VARARGs portion of GNUNET_FS_start.
1965 enum GNUNET_FS_OPTIONS
1969 * Last option in the VARARG list.
1971 GNUNET_FS_OPTIONS_END = 0,
1974 * Select the desired amount of parallelism (this option should be
1975 * followed by an "unsigned int" giving the desired maximum number
1976 * of parallel downloads).
1978 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
1981 * Maximum number of requests that should be pending at a given
1982 * point in time (invidivual downloads may go above this, but
1983 * if we are above this threshold, we should not activate any
1984 * additional downloads.
1986 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
1991 * Settings for publishing a block (which may of course also
1992 * apply to an entire directory or file).
1994 struct GNUNET_FS_BlockOptions
1998 * At what time should the block expire? Data blocks (DBLOCKS and
1999 * IBLOCKS) may still be used even if they are expired (however,
2000 * they'd be removed quickly from the datastore if we are short on
2001 * space), all other types of blocks will no longer be returned
2002 * after they expire.
2004 struct GNUNET_TIME_Absolute expiration_time;
2007 * At which anonymity level should the block be shared?
2008 * (0: no anonymity, 1: normal GAP, >1: with cover traffic).
2010 uint32_t anonymity_level;
2013 * How important is it for us to store the block? If we run
2014 * out of space, the highest-priority, non-expired blocks will
2017 uint32_t content_priority;
2020 * How often should we try to migrate the block to other peers?
2021 * Only used if "CONTENT_PUSHING" is set to YES, in which case we
2022 * first push each block to other peers according to their
2023 * replication levels. Once each block has been pushed that many
2024 * times to other peers, blocks are chosen for migration at random.
2025 * Naturally, there is no guarantee that the other peers will keep
2026 * these blocks for any period of time (since they won't have any
2027 * priority or might be too busy to even store the block in the
2030 uint32_t replication_level;
2036 * Return the current year (i.e. '2011').
2039 GNUNET_FS_get_current_year (void);
2043 * Convert a year to an expiration time of January 1st of that year.
2045 * @param year a year (after 1970, please ;-)).
2046 * @return absolute time for January 1st of that year.
2048 struct GNUNET_TIME_Absolute
2049 GNUNET_FS_year_to_time (unsigned int year);
2053 * Convert an expiration time to the respective year (rounds)
2055 * @param at absolute time
2056 * @return year a year (after 1970), 0 on error
2059 GNUNET_FS_time_to_year (struct GNUNET_TIME_Absolute at);
2063 * Handle to the file-sharing service.
2065 struct GNUNET_FS_Handle;
2069 * Setup a connection to the file-sharing service.
2071 * @param cfg configuration to use
2072 * @param client_name unique identifier for this client
2073 * @param upcb function to call to notify about FS actions
2074 * @param upcb_cls closure for upcb
2075 * @param flags specific attributes for fs-operations
2076 * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
2077 * @return NULL on error
2079 struct GNUNET_FS_Handle *
2080 GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
2081 const char *client_name, GNUNET_FS_ProgressCallback upcb,
2082 void *upcb_cls, enum GNUNET_FS_Flags flags, ...);
2086 * Close our connection with the file-sharing service.
2087 * The callback given to GNUNET_FS_start will no longer be
2088 * called after this function returns.
2090 * @param h handle that was returned from GNUNET_FS_start
2093 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
2097 * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
2099 * @param cls closure
2100 * @param fi the entry in the publish-structure
2101 * @param length length of the file or directory
2102 * @param meta metadata for the file or directory (can be modified)
2103 * @param uri pointer to the keywords that will be used for this entry (can be modified)
2104 * @param bo block options (can be modified)
2105 * @param do_index should we index (can be modified)
2106 * @param client_info pointer to client context set upon creation (can be modified)
2107 * @return GNUNET_OK to continue, GNUNET_NO to remove
2108 * this entry from the directory, GNUNET_SYSERR
2109 * to abort the iteration
2111 typedef int (*GNUNET_FS_FileInformationProcessor) (void *cls,
2113 GNUNET_FS_FileInformation *
2114 fi, uint64_t length,
2116 GNUNET_CONTAINER_MetaData *
2118 struct GNUNET_FS_Uri ** uri,
2119 struct GNUNET_FS_BlockOptions
2120 * bo, int *do_index,
2121 void **client_info);
2125 * Obtain the name under which this file information
2126 * structure is stored on disk. Only works for top-level
2127 * file information structures.
2129 * @param s structure to get the filename for
2130 * @return NULL on error, otherwise filename that
2131 * can be passed to "GNUNET_FS_file_information_recover"
2132 * to read this fi-struct from disk.
2135 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
2139 * Obtain the filename from the file information structure.
2141 * @param s structure to get the filename for
2142 * @return "filename" field of the structure (can be NULL)
2145 GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s);
2149 * Set the filename in the file information structure.
2150 * If filename was already set, frees it before setting the new one.
2151 * Makes a copy of the argument.
2153 * @param s structure to get the filename for
2154 * @param filename filename to set
2157 GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s,
2158 const char *filename);
2162 * Create an entry for a file in a publish-structure.
2164 * @param h handle to the file sharing subsystem
2165 * @param client_info initial client-info value for this entry
2166 * @param filename name of the file or directory to publish
2167 * @param keywords under which keywords should this file be available
2168 * directly; can be NULL
2169 * @param meta metadata for the file
2170 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
2171 * GNUNET_SYSERR for simulation
2172 * @param bo block options
2173 * @return publish structure entry for the file
2175 struct GNUNET_FS_FileInformation *
2176 GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
2178 const char *filename,
2179 const struct GNUNET_FS_Uri
2182 GNUNET_CONTAINER_MetaData *meta,
2184 const struct GNUNET_FS_BlockOptions
2189 * Create an entry for a file in a publish-structure.
2191 * @param h handle to the file sharing subsystem
2192 * @param client_info initial client-info value for this entry
2193 * @param length length of the file
2194 * @param data data for the file (should not be used afterwards by
2195 * the caller; callee will "free")
2196 * @param keywords under which keywords should this file be available
2197 * directly; can be NULL
2198 * @param meta metadata for the file
2199 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
2200 * GNUNET_SYSERR for simulation
2201 * @param bo block options
2202 * @return publish structure entry for the file
2204 struct GNUNET_FS_FileInformation *
2205 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
2206 void *client_info, uint64_t length,
2208 const struct GNUNET_FS_Uri
2211 GNUNET_CONTAINER_MetaData *meta,
2213 const struct GNUNET_FS_BlockOptions
2218 * Function that provides data.
2220 * @param cls closure
2221 * @param offset offset to read from; it is possible
2222 * that the caller might need to go backwards
2223 * a bit at times; set to UINT64_MAX to tell
2224 * the reader that we won't be reading for a while
2225 * (used to close the file descriptor but NOT fully
2226 * clean up the reader's state); in this case,
2227 * a value of '0' for max should be ignored
2228 * @param max maximum number of bytes that should be
2229 * copied to buf; readers are not allowed
2230 * to provide less data unless there is an error;
2231 * a value of "0" will be used at the end to allow
2232 * the reader to clean up its internal state
2233 * @param buf where the reader should write the data
2234 * @param emsg location for the reader to store an error message
2235 * @return number of bytes written, usually "max", 0 on error
2237 typedef size_t (*GNUNET_FS_DataReader) (void *cls, uint64_t offset, size_t max,
2238 void *buf, char **emsg);
2242 * Create an entry for a file in a publish-structure.
2244 * @param h handle to the file sharing subsystem
2245 * @param client_info initial client-info value for this entry
2246 * @param length length of the file
2247 * @param reader function that can be used to obtain the data for the file
2248 * @param reader_cls closure for "reader"
2249 * @param keywords under which keywords should this file be available
2250 * directly; can be NULL
2251 * @param meta metadata for the file
2252 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
2253 * GNUNET_SYSERR for simulation
2254 * @param bo block options
2255 * @return publish structure entry for the file
2257 struct GNUNET_FS_FileInformation *
2258 GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
2261 GNUNET_FS_DataReader reader,
2263 const struct GNUNET_FS_Uri
2266 GNUNET_CONTAINER_MetaData *meta,
2269 GNUNET_FS_BlockOptions *bo);
2273 * Create an entry for an empty directory in a publish-structure.
2274 * This function should be used by applications for which the
2275 * use of "GNUNET_FS_file_information_create_from_directory"
2276 * is not appropriate.
2278 * @param h handle to the file sharing subsystem
2279 * @param client_info initial client-info value for this entry
2280 * @param keywords under which keywords should this directory be available
2281 * directly; can be NULL
2282 * @param meta metadata for the directory
2283 * @param bo block options
2284 * @param filename name of the directory; can be NULL
2285 * @return publish structure entry for the directory , NULL on error
2287 struct GNUNET_FS_FileInformation *
2288 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
2290 const struct GNUNET_FS_Uri
2293 GNUNET_CONTAINER_MetaData
2296 GNUNET_FS_BlockOptions *bo,
2297 const char *filename);
2301 * Test if a given entry represents a directory.
2303 * @param ent check if this FI represents a directory
2304 * @return GNUNET_YES if so, GNUNET_NO if not
2307 GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
2312 * Add an entry to a directory in a publish-structure. Clients
2313 * should never modify publish structures that were passed to
2314 * "GNUNET_FS_publish_start" already.
2316 * @param dir the directory
2317 * @param ent the entry to add; the entry must not have been
2318 * added to any other directory at this point and
2319 * must not include "dir" in its structure
2320 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2323 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
2324 struct GNUNET_FS_FileInformation *ent);
2328 * Inspect a file or directory in a publish-structure. Clients
2329 * should never modify publish structures that were passed to
2330 * "GNUNET_FS_publish_start" already. When called on a directory,
2331 * this function will FIRST call "proc" with information about
2332 * the directory itself and then for each of the files in the
2333 * directory (but not for files in subdirectories). When called
2334 * on a file, "proc" will be called exactly once (with information
2335 * about the specific file).
2337 * @param dir the directory
2338 * @param proc function to call on each entry
2339 * @param proc_cls closure for proc
2342 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
2343 GNUNET_FS_FileInformationProcessor proc,
2348 * Destroy publish-structure. Clients should never destroy publish
2349 * structures that were passed to "GNUNET_FS_publish_start" already.
2351 * @param fi structure to destroy
2352 * @param cleaner function to call on each entry in the structure
2353 * (useful to clean up client_info); can be NULL; return
2354 * values are ignored
2355 * @param cleaner_cls closure for cleaner
2358 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
2359 GNUNET_FS_FileInformationProcessor cleaner,
2364 * Options for publishing. Compatible options
2365 * can be OR'ed together.
2367 enum GNUNET_FS_PublishOptions
2370 * No options (use defaults for everything).
2372 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
2375 * Simulate publishing. With this option, no data will be stored
2376 * in the datastore. Useful for computing URIs from files.
2378 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
2382 * Publish a file or directory.
2384 * @param h handle to the file sharing subsystem
2385 * @param fi information about the file or directory structure to publish
2386 * @param ns namespace to publish the file in, NULL for no namespace
2387 * @param nid identifier to use for the publishd content in the namespace
2388 * (can be NULL, must be NULL if namespace is NULL)
2389 * @param nuid update-identifier that will be used for future updates
2390 * (can be NULL, must be NULL if namespace or nid is NULL)
2391 * @param options options for the publication
2392 * @return context that can be used to control the publish operation
2394 struct GNUNET_FS_PublishContext *
2395 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
2396 struct GNUNET_FS_FileInformation *fi,
2397 struct GNUNET_FS_Namespace *ns, const char *nid,
2399 enum GNUNET_FS_PublishOptions options);
2403 * Stop a publication. Will abort incomplete publications (but
2404 * not remove blocks that have already been published) or
2405 * simply clean up the state for completed publications.
2406 * Must NOT be called from within the event callback!
2408 * @param pc context for the publication to stop
2411 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
2415 * Signature of a function called as the continuation of a KBlock or
2416 * SBlock publication.
2418 * @param cls closure
2419 * @param uri URI under which the block is now available, NULL on error
2420 * @param emsg error message, NULL on success
2422 typedef void (*GNUNET_FS_PublishContinuation) (void *cls,
2423 const struct GNUNET_FS_Uri * uri,
2428 * Handle to cancel publish KSK operation.
2430 struct GNUNET_FS_PublishKskContext;
2434 * Publish a KBlock on GNUnet.
2436 * @param h handle to the file sharing subsystem
2437 * @param ksk_uri keywords to use
2438 * @param meta metadata to use
2439 * @param uri URI to refer to in the KBlock
2440 * @param bo block options
2441 * @param options publication options
2442 * @param cont continuation
2443 * @param cont_cls closure for cont
2444 * @return NULL on error ('cont' will still be called)
2446 struct GNUNET_FS_PublishKskContext *
2447 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2448 const struct GNUNET_FS_Uri *ksk_uri,
2449 const struct GNUNET_CONTAINER_MetaData *meta,
2450 const struct GNUNET_FS_Uri *uri,
2451 const struct GNUNET_FS_BlockOptions *bo,
2452 enum GNUNET_FS_PublishOptions options,
2453 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2457 * Abort the KSK publishing operation.
2459 * @param pkc context of the operation to abort.
2462 GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc);
2466 * Handle to cancel publish SKS operation.
2468 struct GNUNET_FS_PublishSksContext;
2472 * Publish an SBlock on GNUnet.
2474 * @param h handle to the file sharing subsystem
2475 * @param ns namespace to publish in
2476 * @param identifier identifier to use
2477 * @param update update identifier to use
2478 * @param meta metadata to use
2479 * @param uri URI to refer to in the SBlock
2480 * @param bo block options
2481 * @param options publication options
2482 * @param cont continuation
2483 * @param cont_cls closure for cont
2484 * @return NULL on error ('cont' will still be called)
2486 struct GNUNET_FS_PublishSksContext *
2487 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2488 struct GNUNET_FS_Namespace *ns,
2489 const char *identifier, const char *update,
2490 const struct GNUNET_CONTAINER_MetaData *meta,
2491 const struct GNUNET_FS_Uri *uri,
2492 const struct GNUNET_FS_BlockOptions *bo,
2493 enum GNUNET_FS_PublishOptions options,
2494 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2498 * Abort the SKS publishing operation.
2500 * @param psc context of the operation to abort.
2503 GNUNET_FS_publish_sks_cancel (struct GNUNET_FS_PublishSksContext *psc);
2507 * Type of a function called by "GNUNET_FS_get_indexed_files".
2509 * @param cls closure
2510 * @param filename the name of the file, NULL for end of list
2511 * @param file_id hash of the contents of the indexed file
2512 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
2514 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls, const char *filename,
2515 const struct GNUNET_HashCode * file_id);
2519 * Handle to cancel 'GNUNET_FS_get_indexed_files'.
2521 struct GNUNET_FS_GetIndexedContext;
2525 * Iterate over all indexed files.
2527 * @param h handle to the file sharing subsystem
2528 * @param iterator function to call on each indexed file
2529 * @param iterator_cls closure for iterator
2530 * @return NULL on error ('iter' is not called)
2532 struct GNUNET_FS_GetIndexedContext *
2533 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2534 GNUNET_FS_IndexedFileProcessor iterator,
2535 void *iterator_cls);
2539 * Cancel iteration over all indexed files.
2541 * @param gic operation to cancel
2544 GNUNET_FS_get_indexed_files_cancel (struct GNUNET_FS_GetIndexedContext *gic);
2550 * @param h handle to the file sharing subsystem
2551 * @param filename file to unindex
2552 * @param cctx initial value for the client context
2553 * @return NULL on error, otherwise handle
2555 struct GNUNET_FS_UnindexContext *
2556 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, const char *filename,
2561 * Clean up after completion of an unindex operation.
2566 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2570 * Create a namespace with the given name; if one already
2571 * exists, return a handle to the existing namespace.
2573 * @param h handle to the file sharing subsystem
2574 * @param name name to use for the namespace
2575 * @return handle to the namespace, NULL on error (i.e. invalid filename)
2577 struct GNUNET_FS_Namespace *
2578 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, const char *name);
2582 * Open the namespace with the given name; if it does not exist,
2583 * or the key file is corrupted, the function fails.
2585 * @param h handle to the file sharing subsystem
2586 * @param name name of the namespace
2587 * @return handle to the namespace,
2588 * NULL on error (i.e. invalid filename, non-existent filename)
2590 struct GNUNET_FS_Namespace *
2591 GNUNET_FS_namespace_open_existing (struct GNUNET_FS_Handle *h, const char *name);
2595 * Rename a local namespace.
2597 * @param h handle to the file sharing subsystem
2598 * @param old_name old name of the namespace
2599 * @param new_name new name of the namespace
2600 * @return GNUNET_OK on success, GNUNET_SYSERR on error (see errno for details)
2603 GNUNET_FS_namespace_rename (struct GNUNET_FS_Handle *h, const char *old_name,
2604 const char *new_name);
2608 * Duplicate a namespace handle.
2610 * @param ns namespace handle
2611 * @return duplicated handle to the namespace
2613 struct GNUNET_FS_Namespace *
2614 GNUNET_FS_namespace_dup (struct GNUNET_FS_Namespace *ns);
2618 * Get hash of the public key of a namespace.
2620 * @param ns namespace
2621 * @param id buffer to store the key in
2622 * @return GNUNET_OK on success
2623 * GNUNET_SYSERR on failure (contents of id remain intact)
2626 GNUNET_FS_namespace_get_public_identifier (struct GNUNET_FS_Namespace *ns,
2627 struct GNUNET_FS_PseudonymIdentifier *id);
2631 * Delete a namespace handle. Can be used for a clean shutdown (free
2632 * memory) or also to freeze the namespace to prevent further
2633 * insertions by anyone.
2635 * @param ns handle to the namespace that should be deleted / freed
2636 * @param freeze prevents future insertions; creating a namespace
2637 * with the same name again will create a fresh namespace instead
2639 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2642 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *ns, int freeze);
2646 * Callback with information about local (!) namespaces.
2647 * Contains the names of the local namespace and the global
2650 * @param cls closure
2651 * @param name human-readable identifier of the namespace
2652 * @param id identifier for the namespace
2654 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls, const char *name,
2655 const struct GNUNET_FS_PseudonymIdentifier *id);
2659 * Build a list of all available local (!) namespaces The returned
2660 * names are only the nicknames since we only iterate over the local
2663 * @param h handle to the file sharing subsystem
2664 * @param cb function to call on each known namespace
2665 * @param cb_cls closure for cb
2668 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2669 GNUNET_FS_NamespaceInfoProcessor cb, void *cb_cls);
2673 * Function called on updateable identifiers.
2675 * @param cls closure
2676 * @param last_id last identifier
2677 * @param last_uri uri used for the content published under the last_id
2678 * @param last_meta metadata associated with last_uri
2679 * @param next_id identifier that should be used for updates
2681 typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls, const char *last_id,
2682 const struct GNUNET_FS_Uri *
2685 GNUNET_CONTAINER_MetaData *
2686 last_meta, const char *next_id);
2690 * List all of the identifiers in the namespace for which we could
2691 * produce an update. Namespace updates form a graph where each node
2692 * has a name. Each node can have any number of URI/meta-data entries
2693 * which can each be linked to other nodes. Cycles are possible.
2695 * Calling this function with "next_id" NULL will cause the library to
2696 * call "ip" with a root for each strongly connected component of the
2697 * graph (a root being a node from which all other nodes in the Scc
2700 * Calling this function with "next_id" being the name of a node will
2701 * cause the library to call "ip" with all children of the node. Note
2702 * that cycles within an SCC are possible (including self-loops).
2704 * @param ns namespace to inspect for updateable content
2705 * @param next_id ID to look for; use NULL to look for SCC roots
2706 * @param ip function to call on each updateable identifier
2707 * @param ip_cls closure for ip
2710 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *ns,
2711 const char *next_id,
2712 GNUNET_FS_IdentifierProcessor ip,
2717 * Options for searching. Compatible options
2718 * can be OR'ed together.
2720 enum GNUNET_FS_SearchOptions
2723 * No options (use defaults for everything).
2725 GNUNET_FS_SEARCH_OPTION_NONE = 0,
2728 * Only search the local host, do not search remote systems (no P2P)
2730 GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
2735 * Start search for content.
2737 * @param h handle to the file sharing subsystem
2738 * @param uri specifies the search parameters; can be
2739 * a KSK URI or an SKS URI.
2740 * @param anonymity desired level of anonymity
2741 * @param options options for the search
2742 * @param cctx initial value for the client context
2743 * @return context that can be used to control the search
2745 struct GNUNET_FS_SearchContext *
2746 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2747 const struct GNUNET_FS_Uri *uri, uint32_t anonymity,
2748 enum GNUNET_FS_SearchOptions options, void *cctx);
2754 * @param sc context for the search that should be paused
2757 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2761 * Continue paused search.
2763 * @param sc context for the search that should be resumed
2766 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2770 * Stop search for content.
2772 * @param sc context for the search that should be stopped
2775 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2781 * Options for downloading. Compatible options
2782 * can be OR'ed together.
2784 enum GNUNET_FS_DownloadOptions
2787 * No options (use defaults for everything).
2789 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2792 * Only download from the local host, do not access remote systems (no P2P)
2794 GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
2797 * Do a recursive download (that is, automatically trigger the
2798 * download of files in directories).
2800 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
2803 * Do not append temporary data to
2804 * the target file (for the IBlocks).
2806 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
2809 * Internal option used to flag this download as a 'probe' for a
2810 * search result. Impacts the priority with which the download is
2811 * run and causes signalling callbacks to be done differently.
2812 * Also, probe downloads are not serialized on suspension. Normal
2813 * clients should not use this!
2815 GNUNET_FS_DOWNLOAD_IS_PROBE = (1 << 31)
2821 * Download parts of a file. Note that this will store
2822 * the blocks at the respective offset in the given file. Also, the
2823 * download is still using the blocking of the underlying FS
2824 * encoding. As a result, the download may *write* outside of the
2825 * given boundaries (if offset and length do not match the 32k FS
2826 * block boundaries). <p>
2828 * The given range can be used to focus a download towards a
2829 * particular portion of the file (optimization), not to strictly
2830 * limit the download to exactly those bytes.
2832 * @param h handle to the file sharing subsystem
2833 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2834 * @param meta known metadata for the file (can be NULL)
2835 * @param filename where to store the file, maybe NULL (then no file is
2836 * created on disk and data must be grabbed from the callbacks)
2837 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2838 * can be NULL (in which case we will pick a name if needed); the temporary file
2839 * may already exist, in which case we will try to use the data that is there and
2840 * if it is not what is desired, will overwrite it
2841 * @param offset at what offset should we start the download (typically 0)
2842 * @param length how many bytes should be downloaded starting at offset
2843 * @param anonymity anonymity level to use for the download
2844 * @param options various download options
2845 * @param cctx initial value for the client context for this download
2846 * @param parent parent download to associate this download with (use NULL
2847 * for top-level downloads; useful for manually-triggered recursive downloads)
2848 * @return context that can be used to control this download
2850 struct GNUNET_FS_DownloadContext *
2851 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2852 const struct GNUNET_FS_Uri *uri,
2853 const struct GNUNET_CONTAINER_MetaData *meta,
2854 const char *filename, const char *tempname,
2855 uint64_t offset, uint64_t length, uint32_t anonymity,
2856 enum GNUNET_FS_DownloadOptions options, void *cctx,
2857 struct GNUNET_FS_DownloadContext *parent);
2861 * Download parts of a file based on a search result. The download
2862 * will be associated with the search result (and the association
2863 * will be preserved when serializing/deserializing the state).
2864 * If the search is stopped, the download will not be aborted but
2865 * be 'promoted' to a stand-alone download.
2867 * As with the other download function, this will store
2868 * the blocks at the respective offset in the given file. Also, the
2869 * download is still using the blocking of the underlying FS
2870 * encoding. As a result, the download may *write* outside of the
2871 * given boundaries (if offset and length do not match the 32k FS
2872 * block boundaries). <p>
2874 * The given range can be used to focus a download towards a
2875 * particular portion of the file (optimization), not to strictly
2876 * limit the download to exactly those bytes.
2878 * @param h handle to the file sharing subsystem
2879 * @param sr the search result to use for the download (determines uri and
2880 * meta data and associations)
2881 * @param filename where to store the file, maybe NULL (then no file is
2882 * created on disk and data must be grabbed from the callbacks)
2883 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2884 * can be NULL (in which case we will pick a name if needed); the temporary file
2885 * may already exist, in which case we will try to use the data that is there and
2886 * if it is not what is desired, will overwrite it
2887 * @param offset at what offset should we start the download (typically 0)
2888 * @param length how many bytes should be downloaded starting at offset
2889 * @param anonymity anonymity level to use for the download
2890 * @param options various download options
2891 * @param cctx initial value for the client context for this download
2892 * @return context that can be used to control this download
2894 struct GNUNET_FS_DownloadContext *
2895 GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2896 struct GNUNET_FS_SearchResult *sr,
2897 const char *filename,
2898 const char *tempname, uint64_t offset,
2899 uint64_t length, uint32_t anonymity,
2900 enum GNUNET_FS_DownloadOptions options,
2905 * Stop a download (aborts if download is incomplete).
2907 * @param dc handle for the download
2908 * @param do_delete delete files of incomplete downloads
2911 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete);
2915 /* ******************** Directory API *********************** */
2918 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2919 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2920 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2923 * Does the meta-data claim that this is a directory?
2924 * Checks if the mime-type is that of a GNUnet directory.
2926 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2927 * we have no mime-type information (treat as 'GNUNET_NO')
2930 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
2935 * Set the MIMETYPE information for the given
2936 * metadata to "application/gnunet-directory".
2938 * @param md metadata to add mimetype to
2941 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2945 * Suggest a filename based on given metadata.
2947 * @param md given meta data
2948 * @return NULL if meta data is useless for suggesting a filename
2951 GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData
2956 * Function used to process entries in a directory.
2958 * @param cls closure
2959 * @param filename name of the file in the directory
2960 * @param uri URI of the file
2961 * @param metadata metadata for the file; metadata for
2962 * the directory if everything else is NULL/zero
2963 * @param length length of the available data for the file
2964 * (of type size_t since data must certainly fit
2965 * into memory; if files are larger than size_t
2966 * permits, then they will certainly not be
2967 * embedded with the directory itself).
2968 * @param data data available for the file (length bytes)
2970 typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
2971 const char *filename,
2972 const struct GNUNET_FS_Uri *
2975 GNUNET_CONTAINER_MetaData *
2976 meta, size_t length,
2981 * Iterate over all entries in a directory. Note that directories
2982 * are structured such that it is possible to iterate over the
2983 * individual blocks as well as over the entire directory. Thus
2984 * a client can call this function on the buffer in the
2985 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2986 * include the contents of (small) files embedded in the directory
2987 * itself; for those files, the processor may be given the
2988 * contents of the file directly by this function.
2990 * @param size number of bytes in data
2991 * @param data pointer to the beginning of the directory
2992 * @param offset offset of data in the directory
2993 * @param dep function to call on each entry
2994 * @param dep_cls closure for dep
2995 * @return GNUNET_OK if this could be a block in a directory,
2996 * GNUNET_NO if this could be part of a directory (but not 100% OK)
2997 * GNUNET_SYSERR if 'data' does not represent a directory
3000 GNUNET_FS_directory_list_contents (size_t size, const void *data,
3002 GNUNET_FS_DirectoryEntryProcessor dep,
3007 * Opaque handle to a directory builder.
3009 struct GNUNET_FS_DirectoryBuilder;
3012 * Create a directory builder.
3014 * @param mdir metadata for the directory
3016 struct GNUNET_FS_DirectoryBuilder *
3017 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
3022 * Add an entry to a directory.
3024 * @param bld directory to extend
3025 * @param uri uri of the entry (must not be a KSK)
3026 * @param md metadata of the entry
3027 * @param data raw data of the entry, can be NULL, otherwise
3028 * data must point to exactly the number of bytes specified
3032 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
3033 const struct GNUNET_FS_Uri *uri,
3034 const struct GNUNET_CONTAINER_MetaData *md,
3039 * Finish building the directory. Frees the
3040 * builder context and returns the directory
3043 * @param bld directory to finish
3044 * @param rsize set to the number of bytes needed
3045 * @param rdata set to the encoded directory
3046 * @return GNUNET_OK on success
3049 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
3050 size_t * rsize, void **rdata);
3053 /* ******************** DirScanner API *********************** */
3056 * Progress reasons of the directory scanner.
3058 enum GNUNET_FS_DirScannerProgressUpdateReason
3062 * We've started processing a file or directory.
3064 GNUNET_FS_DIRSCANNER_FILE_START = 0,
3067 * We're having trouble accessing a file (soft-error); it will
3070 GNUNET_FS_DIRSCANNER_FILE_IGNORED,
3073 * We've found all files (in the pre-pass).
3075 GNUNET_FS_DIRSCANNER_ALL_COUNTED,
3078 * We've finished extracting meta data from a file.
3080 GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED,
3083 * Last call to the progress function: we have finished scanning
3086 GNUNET_FS_DIRSCANNER_FINISHED,
3089 * There was an internal error. Application should abort the scan.
3091 GNUNET_FS_DIRSCANNER_INTERNAL_ERROR
3097 * Function called over time as the directory scanner makes
3098 * progress on the job at hand.
3100 * @param cls closure
3101 * @param filename which file we are making progress on
3102 * @param is_directory GNUNET_YES if this is a directory,
3103 * GNUNET_NO if this is a file
3104 * GNUNET_SYSERR if it is neither (or unknown)
3105 * @param reason kind of progress we are making
3107 typedef void (*GNUNET_FS_DirScannerProgressCallback) (void *cls,
3108 const char *filename,
3110 enum GNUNET_FS_DirScannerProgressUpdateReason reason);
3114 * A node of a directory tree (produced by dirscanner)
3116 struct GNUNET_FS_ShareTreeItem
3119 * This is a doubly-linked list
3121 struct GNUNET_FS_ShareTreeItem *prev;
3124 * This is a doubly-linked list
3126 struct GNUNET_FS_ShareTreeItem *next;
3129 * This is a doubly-linked tree
3130 * NULL for top-level entries.
3132 struct GNUNET_FS_ShareTreeItem *parent;
3135 * This is a doubly-linked tree
3136 * NULL for files and empty directories
3138 struct GNUNET_FS_ShareTreeItem *children_head;
3141 * This is a doubly-linked tree
3142 * NULL for files and empty directories
3144 struct GNUNET_FS_ShareTreeItem *children_tail;
3147 * Metadata for this file or directory
3149 struct GNUNET_CONTAINER_MetaData *meta;
3152 * Keywords for this file or directory (derived from metadata).
3154 struct GNUNET_FS_Uri *ksk_uri;
3157 * Name of the file/directory
3162 * Base name of the file/directory.
3164 char *short_filename;
3167 * GNUNET_YES if this is a directory
3175 * Opaqe handle to an asynchronous directory scanning activity.
3177 struct GNUNET_FS_DirScanner;
3181 * Start a directory scanner.
3183 * @param filename name of the directory to scan
3184 * @param disable_extractor GNUNET_YES to not to run libextractor on files (only build a tree)
3185 * @param ex if not NULL, must be a list of extra plugins for extractor
3186 * @param cb the callback to call when there are scanning progress messages
3187 * @param cb_cls closure for 'cb'
3188 * @return directory scanner object to be used for controlling the scanner
3190 struct GNUNET_FS_DirScanner *
3191 GNUNET_FS_directory_scan_start (const char *filename,
3192 int disable_extractor,
3194 GNUNET_FS_DirScannerProgressCallback cb,
3199 * Abort the scan. Must not be called from within the progress_callback
3202 * @param ds directory scanner structure
3205 GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds);
3209 * Obtain the result of the scan after the scan has signalled
3210 * completion. Must not be called prior to completion. The 'ds' is
3211 * freed as part of this call.
3213 * @param ds directory scanner structure
3214 * @return the results of the scan (a directory tree)
3216 struct GNUNET_FS_ShareTreeItem *
3217 GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds);
3221 * Process a share item tree, moving frequent keywords up and
3222 * copying frequent metadata up.
3224 * @param toplevel toplevel directory in the tree, returned by the scanner
3227 GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel);
3231 * Release memory of a share item tree.
3233 * @param toplevel toplevel of the tree to be freed
3236 GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
3239 #if 0 /* keep Emacsens' auto-indent happy */