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).
87 struct GNUNET_PseudonymIdentifier
90 * Q consists of an x- and a y-value, each mod p (256 bits),
91 * given here in affine coordinates.
93 unsigned char q_x[256 / 8];
96 * Q consists of an x- and a y-value, each mod p (256 bits),
97 * given here in affine coordinates.
99 unsigned char q_y[256 / 8];
105 * Handle for a pseudonym (private key).
107 struct GNUNET_PseudonymHandle;
111 * Signature made with a pseudonym (includes the full public key).
112 * The ECDSA signature is a pair (r,s) with r = x1 mod n where
113 * (x1,y1) = kG for "random" k and s = k^{-1}(z + rd) mod n,
114 * where z is derived from the hash of the message that is being
117 struct GNUNET_PseudonymSignature
121 * Who created the signature? (public key of the signer), 'd' value in NIST P-256.
123 struct GNUNET_PseudonymIdentifier signer;
126 * Binary ECDSA signature data, r-value. Value is mod n, and n is 256 bits.
128 unsigned char sig_r[256 / 8];
131 * Binary ECDSA signature data, s-value. Value is mod n, and n is 256 bits.
133 unsigned char sig_s[256 / 8];
138 * Purpose for signature made with a pseudonym.
140 struct GNUNET_PseudonymSignaturePurpose
143 * How many bytes are being signed (including this header)?
148 * What is the context/purpose of the signature?
155 * Iterator over keywords
158 * @param keyword the keyword
159 * @param is_mandatory is the keyword mandatory (in a search)
160 * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
162 typedef int (*GNUNET_FS_KeywordIterator) (void *cls, const char *keyword,
169 * Create a pseudonym.
171 * @param filename name of the file to use for storage, NULL for in-memory only
172 * @return handle to the private key of the pseudonym
174 struct GNUNET_PseudonymHandle *
175 GNUNET_PSEUDONYM_create (const char *filename);
179 * Create a pseudonym, from a file that must already exist.
181 * @param filename name of the file to use for storage, NULL for in-memory only
182 * @return handle to the private key of the pseudonym
184 struct GNUNET_PseudonymHandle *
185 GNUNET_PSEUDONYM_create_from_existing_file (const char *filename);
189 * Get the handle for the 'anonymous' pseudonym shared by all users.
190 * That pseudonym uses a fixed 'secret' for the private key; this
191 * construction is useful to make anonymous and pseudonymous APIs
192 * (and packets) indistinguishable on the network. See #2564.
194 * @return handle to the (non-secret) private key of the 'anonymous' pseudonym
196 struct GNUNET_PseudonymHandle *
197 GNUNET_PSEUDONYM_get_anonymous_pseudonym_handle (void);
201 * Destroy a pseudonym handle. Does NOT remove the private key from
204 * @param ph pseudonym handle to destroy
207 GNUNET_PSEUDONYM_destroy (struct GNUNET_PseudonymHandle *ph);
211 * Cryptographically sign some data with the pseudonym.
213 * @param ph private key used for signing (corresponds to 'x' in #2564)
214 * @param purpose data to sign
215 * @param seed hash of the plaintext of the data that we are signing,
216 * used for deterministic PRNG for anonymous signing;
217 * corresponds to 'k' in section 2.7 of #2564
218 * @param signing_key modifier to apply to the private key for signing;
219 * corresponds to 'h' in section 2.3 of #2564.
220 * @param signature where to store the signature
221 * @return GNUNET_SYSERR on failure
224 GNUNET_PSEUDONYM_sign (struct GNUNET_PseudonymHandle *ph,
225 const struct GNUNET_PseudonymSignaturePurpose *purpose,
226 const struct GNUNET_HashCode *seed,
227 const struct GNUNET_HashCode *signing_key,
228 struct GNUNET_PseudonymSignature *signature);
232 * Given a pseudonym and a signing key, derive the corresponding public
233 * key that would be used to verify the resulting signature.
235 * @param pseudonym the public key (g^x in DSA, dQ in ECDSA)
236 * @param signing_key input to derive 'h' (see section 2.4 of #2564)
237 * @param verification_key resulting public key to verify the signature
238 * created from the 'ph' of 'pseudonym' and the 'signing_key';
239 * the value stored here can then be given to GNUNET_PSEUDONYM_verify.
240 * @return GNUNET_OK on success, GNUNET_SYSERR on error
243 GNUNET_PSEUDONYM_derive_verification_key (struct GNUNET_PseudonymIdentifier *pseudonym,
244 const struct GNUNET_HashCode *signing_key,
245 struct GNUNET_PseudonymIdentifier *verification_key);
249 * Verify a signature made with a pseudonym.
251 * @param purpose data that was signed
252 * @param signature signature to verify
253 * @param verification_key public key to use for checking the signature;
254 * corresponds to 'g^(x+h)' in section 2.4 of #2564.
255 * @return GNUNET_OK on success (signature valid, 'pseudonym' set),
256 * GNUNET_SYSERR if the signature is invalid
259 GNUNET_PSEUDONYM_verify (const struct GNUNET_PseudonymSignaturePurpose *purpose,
260 const struct GNUNET_PseudonymSignature *signature,
261 const struct GNUNET_PseudonymIdentifier *verification_key);
265 * Get the identifier (public key) of a pseudonym.
267 * @param ph pseudonym handle with the private key
268 * @param pseudonym pseudonym identifier (set based on 'ph')
271 GNUNET_PSEUDONYM_get_identifier (struct GNUNET_PseudonymHandle *ph,
272 struct GNUNET_PseudonymIdentifier *pseudonym);
277 * Iterator over all known pseudonyms.
280 * @param pseudonym hash code of public key of pseudonym
281 * @param name name of the pseudonym (might be NULL)
282 * @param unique_name unique name of the pseudonym (might be NULL)
283 * @param md meta data known about the pseudonym
284 * @param rating the local rating of the pseudonym
285 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
287 typedef int (*GNUNET_PSEUDONYM_Iterator) (void *cls,
288 const struct GNUNET_PseudonymIdentifier *pseudonym,
290 const char *unique_name,
291 const struct GNUNET_CONTAINER_MetaData *md,
296 * Change the rank of a pseudonym.
298 * @param cfg overall configuration
299 * @param pseudonym identity of the pseudonym
300 * @param delta by how much should the rating be changed?
301 * @return new rating of the pseudonym
304 GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg,
305 const struct GNUNET_PseudonymIdentifier *pseudonym,
310 * Add a pseudonym to the set of known pseudonyms.
311 * For all pseudonym advertisements that we discover
312 * FS should automatically call this function.
314 * @param cfg overall configuration
315 * @param pseudonym the pseudonym identifier
316 * @param meta metadata for the pseudonym
317 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
320 GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg,
321 const struct GNUNET_PseudonymIdentifier *pseudonym,
322 const struct GNUNET_CONTAINER_MetaData *meta);
326 * List all known pseudonyms.
328 * @param cfg overall configuration
329 * @param iterator function to call for each pseudonym
330 * @param iterator_cls closure for iterator
331 * @return number of pseudonyms found
334 GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg,
335 GNUNET_PSEUDONYM_Iterator iterator,
340 * Handle for a discovery callback registration.
342 struct GNUNET_PSEUDONYM_DiscoveryHandle;
346 * Register callback to be invoked whenever we discover
349 * @param cfg our configuration
350 * @param iterator function to invoke on discovery
351 * @param iterator_cls closure for iterator
352 * @return registration handle
354 struct GNUNET_PSEUDONYM_DiscoveryHandle *
355 GNUNET_PSEUDONYM_discovery_callback_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
356 GNUNET_PSEUDONYM_Iterator iterator,
361 * Unregister pseudonym discovery callback.
363 * @param dh registration to unregister
366 GNUNET_PSEUDONYM_discovery_callback_unregister (struct GNUNET_PSEUDONYM_DiscoveryHandle *dh);
370 * Return unique variant of the pseudonym name. Use after
371 * GNUNET_PSEUDONYM_id_to_name() to make sure that name is unique.
373 * @param cfg configuration
374 * @param pseudonym cryptographic ID of the pseudonym
375 * @param name name to uniquify
376 * @param suffix if not NULL, filled with the suffix value
377 * @return NULL on failure (should never happen), name on success.
378 * Free the name with GNUNET_free().
381 GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg,
382 const struct GNUNET_PseudonymIdentifier *pseudonym,
384 unsigned int *suffix);
388 * Get pseudonym name, metadata and rank. This is a wrapper around
389 * internal read_info() call, and ensures that returned data is not
390 * invalid (not NULL). Writing back information returned by this
391 * function will give a name "no-name" to pseudonyms that have no
392 * name. This side-effect is unavoidable, but hardly harmful.
394 * @param cfg configuration
395 * @param pseudonym cryptographic ID of the pseudonym
396 * @param ret_meta a location to store metadata pointer. NULL, if metadata
397 * is not needed. Destroy with GNUNET_CONTAINER_meta_data_destroy().
398 * @param ret_rank a location to store rank. NULL, if rank not needed.
399 * @param ret_name a location to store human-readable name. Name is not unique.
400 * NULL, if name is not needed. Free with GNUNET_free().
401 * @param name_is_a_dup is set to GNUNET_YES, if ret_name was filled with
402 * a duplicate of a "no-name" placeholder
403 * @return GNUNET_OK on success. GNUENT_SYSERR if the data was
404 * unobtainable (in that case ret_* are filled with placeholders -
405 * empty metadata container, rank -1 and a "no-name" name).
408 GNUNET_PSEUDONYM_get_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
409 const struct GNUNET_PseudonymIdentifier *pseudonym,
410 struct GNUNET_CONTAINER_MetaData **ret_meta,
417 * Get the pseudonym ID belonging to the given pseudonym name.
419 * @param cfg configuration to use
420 * @param ns_uname unique (!) human-readable name for the pseudonym
421 * @param pseudonym set to pseudonym ID based on 'ns_uname'
422 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
425 GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg,
426 const char *ns_uname,
427 struct GNUNET_PseudonymIdentifier *pseudonym);
431 * Set the pseudonym metadata, rank and name.
433 * @param cfg overall configuration
434 * @param pseudonym id of the pseudonym
435 * @param name name to set. Must be the non-unique version of it.
436 * May be NULL, in which case it erases pseudonym's name!
437 * @param md metadata to set
438 * May be NULL, in which case it erases pseudonym's metadata!
439 * @param rank rank to assign
440 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
443 GNUNET_PSEUDONYM_set_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
444 const struct GNUNET_PseudonymIdentifier *pseudonym,
446 const struct GNUNET_CONTAINER_MetaData *md,
451 * Remove pseudonym from the set of known pseudonyms.
453 * @param cfg overall configuration
454 * @param id the pseudonym identifier
455 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
458 GNUNET_PSEUDONYM_remove (const struct GNUNET_CONFIGURATION_Handle *cfg,
459 const struct GNUNET_PseudonymIdentifier *id);
463 * Get a unique key from a URI. This is for putting URIs
464 * into HashMaps. The key may change between FS implementations.
466 * @param uri uri to convert to a unique key
467 * @param key wherer to store the unique key
470 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, struct GNUNET_HashCode * key);
474 * Convert a URI to a UTF-8 String.
476 * @param uri uri to convert to a string
477 * @return the UTF-8 string
480 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
484 * Convert keyword URI to a human readable format
485 * (i.e. the search query that was used in the first place)
487 * @param uri ksk uri to convert to a string
488 * @return string with the keywords
491 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
495 * Add the given keyword to the set of keywords represented by the URI.
496 * Does nothing if the keyword is already present.
498 * @param uri ksk uri to modify
499 * @param keyword keyword to add
500 * @param is_mandatory is this keyword mandatory?
503 GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, const char *keyword,
508 * Remove the given keyword from the set of keywords represented by the URI.
509 * Does nothing if the keyword is not present.
511 * @param uri ksk uri to modify
512 * @param keyword keyword to add
515 GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
516 const char *keyword);
520 * Convert a UTF-8 String to a URI.
522 * @param uri string to parse
523 * @param emsg where to store the parser error message (if any)
524 * @return NULL on error
526 struct GNUNET_FS_Uri *
527 GNUNET_FS_uri_parse (const char *uri, char **emsg);
532 * @param uri uri to free
535 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
539 * How many keywords are ANDed in this keyword URI?
541 * @param uri ksk uri to get the number of keywords from
542 * @return 0 if this is not a keyword URI
545 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
549 * Iterate over all keywords in this keyword URI.
551 * @param uri ksk uri to get the keywords from
552 * @param iterator function to call on each keyword
553 * @param iterator_cls closure for iterator
554 * @return -1 if this is not a keyword URI, otherwise number of
555 * keywords iterated over until iterator aborted
558 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
559 GNUNET_FS_KeywordIterator iterator,
564 * Obtain the identity of the peer offering the data
566 * @param uri the location URI to inspect
567 * @param peer where to store the identify of the peer (presumably) offering the content
568 * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK
571 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
572 struct GNUNET_PeerIdentity *peer);
576 * Obtain the URI of the content itself.
578 * @param uri location URI to get the content URI from
579 * @return NULL if argument is not a location URI
581 struct GNUNET_FS_Uri *
582 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
586 * Obtain the expiration of the LOC URI.
588 * @param uri location URI to get the expiration from
589 * @return expiration time of the URI
591 struct GNUNET_TIME_Absolute
592 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
596 * Construct a location URI (this peer will be used for the location).
598 * @param baseUri content offered by the sender
599 * @param cfg configuration information (used to find our hostkey)
600 * @param expiration_time how long will the content be offered?
601 * @return the location URI, NULL on error
603 struct GNUNET_FS_Uri *
604 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
605 const struct GNUNET_CONFIGURATION_Handle *cfg,
606 struct GNUNET_TIME_Absolute expiration_time);
610 * Merge the sets of keywords from two KSK URIs.
612 * @param u1 first uri
613 * @param u2 second uri
614 * @return merged URI, NULL on error
616 struct GNUNET_FS_Uri *
617 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
618 const struct GNUNET_FS_Uri *u2);
624 * @param uri the URI to duplicate
625 * @return copy of the URI
627 struct GNUNET_FS_Uri *
628 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
632 * Create an FS URI from a single user-supplied string of keywords.
633 * The string is broken up at spaces into individual keywords.
634 * Keywords that start with "+" are mandatory. Double-quotes can
635 * be used to prevent breaking up strings at spaces (and also
636 * to specify non-mandatory keywords starting with "+").
638 * Keywords must contain a balanced number of double quotes and
639 * double quotes can not be used in the actual keywords (for
640 * example, the string '""foo bar""' will be turned into two
641 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
643 * @param keywords the keyword string
644 * @param emsg where to store an error message
645 * @return an FS URI for the given keywords, NULL
646 * if keywords is not legal (i.e. empty).
648 struct GNUNET_FS_Uri *
649 GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg);
653 * Create an FS URI from a user-supplied command line of keywords.
654 * Arguments should start with "+" to indicate mandatory
657 * @param argc number of keywords
658 * @param argv keywords (double quotes are not required for
659 * keywords containing spaces; however, double
660 * quotes are required for keywords starting with
661 * "+"); there is no mechanism for having double
662 * quotes in the actual keywords (if the user
663 * did specifically specify double quotes, the
664 * caller should convert each double quote
665 * into two single quotes).
666 * @return an FS URI for the given keywords, NULL
667 * if keywords is not legal (i.e. empty).
669 struct GNUNET_FS_Uri *
670 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv);
674 * Test if two URIs are equal.
676 * @param u1 one of the URIs
677 * @param u2 the other URI
678 * @return GNUNET_YES if the URIs are equal
681 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
682 const struct GNUNET_FS_Uri *u2);
686 * Is this a namespace URI?
688 * @param uri the uri to check
689 * @return GNUNET_YES if this is an SKS uri
692 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
696 * Handle to one of our namespaces.
698 struct GNUNET_FS_Namespace;
702 * Create an SKS URI from a namespace and an identifier.
704 * @param ns namespace
705 * @param id identifier
706 * @param emsg where to store an error message
707 * @return an FS URI for the given namespace and identifier
709 struct GNUNET_FS_Uri *
710 GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id,
715 * Create an SKS URI from a namespace ID and an identifier.
717 * @param pseudonym pseudonym to use
718 * @param id identifier
719 * @return an FS URI for the given namespace and identifier
721 struct GNUNET_FS_Uri *
722 GNUNET_FS_uri_sks_create_from_nsid (struct GNUNET_PseudonymIdentifier *pseudonym,
727 * Get the public key of a namespace from the given
730 * @param uri the uri to get the namespace ID from
731 * @param pseudonym where to store the public key of the namespace
732 * @return GNUNET_OK on success
735 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
736 struct GNUNET_PseudonymIdentifier *pseudonym);
740 * Get the content identifier of an SKS URI.
742 * @param uri the sks uri
743 * @return NULL on error (not a valid SKS URI)
746 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
750 * Convert namespace URI to a human readable format
751 * (using the namespace description, if available).
753 * @param cfg configuration to use
754 * @param uri SKS uri to convert
755 * @return NULL on error (not an SKS URI)
758 GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
759 const struct GNUNET_FS_Uri *uri);
763 * Is this a keyword URI?
766 * @return GNUNET_YES if this is a KSK uri
769 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
773 * Is this a file (or directory) URI?
775 * @param uri the uri to check
776 * @return GNUNET_YES if this is a CHK uri
779 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
783 * What is the size of the file that this URI
786 * @param uri the CHK (or LOC) URI to inspect
787 * @return size of the file as specified in the CHK URI
790 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
794 * Is this a location URI?
796 * @param uri the uri to check
797 * @return GNUNET_YES if this is a LOC uri
800 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
804 * Construct a keyword-URI from meta-data (take all entries
805 * in the meta-data and construct one large keyword URI
806 * that lists all keywords that can be found in the meta-data).
808 * @param md metadata to use
809 * @return NULL on error, otherwise a KSK URI
811 struct GNUNET_FS_Uri *
812 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
816 /* ******************** command-line option parsing API *********************** */
819 * Command-line option parser function that allows the user
820 * to specify one or more '-k' options with keywords. Each
821 * specified keyword will be added to the URI. A pointer to
822 * the URI must be passed as the "scls" argument.
824 * @param ctx command line processor context
825 * @param scls must be of type "struct GNUNET_FS_Uri **"
826 * @param option name of the option (typically 'k')
827 * @param value command line argument given
828 * @return GNUNET_OK on success
831 GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext
832 *ctx, void *scls, const char *option,
837 * Command-line option parser function that allows the user to specify
838 * one or more '-m' options with metadata. Each specified entry of
839 * the form "type=value" will be added to the metadata. A pointer to
840 * the metadata must be passed as the "scls" argument.
842 * @param ctx command line processor context
843 * @param scls must be of type "struct GNUNET_CONTAINER_MetaData **"
844 * @param option name of the option (typically 'k')
845 * @param value command line argument given
846 * @return GNUNET_OK on success
849 GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext
850 *ctx, void *scls, const char *option,
855 /* ************************* sharing API ***************** */
859 * Possible status codes used in the callback for the
860 * various file-sharing operations. On each file (or search),
861 * the callback is guaranteed to be called once with "START"
862 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
863 * are optional and depend on the circumstances; parent operations
864 * will be STARTED before child-operations and STOPPED after
865 * their respective child-operations. START and STOP signals
866 * are typically generated either due to explicit client requests
867 * or because of suspend/resume operations.
869 enum GNUNET_FS_Status
872 * Notification that we have started to publish a file structure.
874 GNUNET_FS_STATUS_PUBLISH_START = 0,
877 * Notification that we have resumed sharing a file structure.
879 GNUNET_FS_STATUS_PUBLISH_RESUME = 1,
882 * Notification that we have suspended sharing a file structure.
884 GNUNET_FS_STATUS_PUBLISH_SUSPEND = 2,
887 * Notification that we are making progress sharing a file structure.
889 GNUNET_FS_STATUS_PUBLISH_PROGRESS = 3,
892 * Notification that an error was encountered sharing a file structure.
893 * The application will continue to receive resume/suspend events for
894 * this structure until "GNUNET_FS_publish_stop" is called.
896 GNUNET_FS_STATUS_PUBLISH_ERROR = 4,
899 * Notification that we completed sharing a file structure.
900 * The application will continue to receive resume/suspend events for
901 * this structure until "GNUNET_FS_publish_stop" is called.
903 GNUNET_FS_STATUS_PUBLISH_COMPLETED = 5,
906 * Notification that we have stopped
907 * the process of uploading a file structure; no
908 * futher events will be generated for this action.
910 GNUNET_FS_STATUS_PUBLISH_STOPPED = 6,
913 * Notification that we have started this download.
915 GNUNET_FS_STATUS_DOWNLOAD_START = 7,
918 * Notification that this download is being resumed.
920 GNUNET_FS_STATUS_DOWNLOAD_RESUME = 8,
923 * Notification that this download was suspended.
925 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND = 9,
928 * Notification about progress with this download.
930 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS = 10,
933 * Notification that this download encountered an error.
935 GNUNET_FS_STATUS_DOWNLOAD_ERROR = 11,
938 * Notification that this download completed. Note that for
939 * directories, completion does not imply completion of all files in
942 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED = 12,
945 * Notification that this download was stopped
946 * (final event with respect to this action).
948 GNUNET_FS_STATUS_DOWNLOAD_STOPPED = 13,
951 * Notification that this download is now actively being
952 * pursued (as opposed to waiting in the queue).
954 GNUNET_FS_STATUS_DOWNLOAD_ACTIVE = 14,
957 * Notification that this download is no longer actively
958 * being pursued (back in the queue).
960 GNUNET_FS_STATUS_DOWNLOAD_INACTIVE = 15,
963 * Notification that this download is no longer part of a
964 * recursive download or search but now a 'stand-alone'
965 * download (and may thus need to be moved in the GUI
966 * into a different category).
968 GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT = 16,
971 * First event generated when a client requests
972 * a search to begin or when a namespace result
973 * automatically triggers the search for updates.
975 GNUNET_FS_STATUS_SEARCH_START = 17,
978 * Last event when a search is being resumed;
979 * note that "GNUNET_FS_SEARCH_START" will not
980 * be generated in this case.
982 GNUNET_FS_STATUS_SEARCH_RESUME = 18,
985 * Event generated for each search result
986 * when the respective search is resumed.
988 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT = 19,
991 * Last event when a search is being suspended;
992 * note that "GNUNET_FS_SEARCH_STOPPED" will not
993 * be generated in this case.
995 GNUNET_FS_STATUS_SEARCH_SUSPEND = 20,
998 * This search has yielded a result.
1000 GNUNET_FS_STATUS_SEARCH_RESULT = 21,
1003 * We have discovered a new namespace.
1005 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE = 22,
1008 * We have additional data about the quality
1009 * or availability of a search result.
1011 GNUNET_FS_STATUS_SEARCH_UPDATE = 23,
1014 * Signals a problem with this search.
1016 GNUNET_FS_STATUS_SEARCH_ERROR = 24,
1019 * Signals that this search was paused.
1021 GNUNET_FS_STATUS_SEARCH_PAUSED = 25,
1024 * Signals that this search was continued (unpaused).
1026 GNUNET_FS_STATUS_SEARCH_CONTINUED = 26,
1029 * Event generated for each search result
1030 * when the respective search is stopped.
1032 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED = 27,
1035 * Event generated for each search result
1036 * when the respective search is suspended.
1038 GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND = 28,
1041 * Last message from a search; this signals
1042 * that there will be no further events associated
1045 GNUNET_FS_STATUS_SEARCH_STOPPED = 29,
1048 * Notification that we started to unindex a file.
1050 GNUNET_FS_STATUS_UNINDEX_START = 30,
1053 * Notification that we resumed unindexing of a file.
1055 GNUNET_FS_STATUS_UNINDEX_RESUME = 31,
1058 * Notification that we suspended unindexing a file.
1060 GNUNET_FS_STATUS_UNINDEX_SUSPEND = 32,
1063 * Notification that we made progress unindexing a file.
1065 GNUNET_FS_STATUS_UNINDEX_PROGRESS = 33,
1068 * Notification that we encountered an error unindexing
1071 GNUNET_FS_STATUS_UNINDEX_ERROR = 34,
1074 * Notification that the unindexing of this file
1077 GNUNET_FS_STATUS_UNINDEX_COMPLETED = 35,
1080 * Notification that the unindexing of this file
1081 * was stopped (final event for this action).
1083 GNUNET_FS_STATUS_UNINDEX_STOPPED = 36
1088 * Handle for controlling an upload.
1090 struct GNUNET_FS_PublishContext;
1094 * Handle for controlling an unindexing operation.
1096 struct GNUNET_FS_UnindexContext;
1100 * Handle for controlling a search.
1102 struct GNUNET_FS_SearchContext;
1106 * Result from a search. Opaque handle to refer to the search
1107 * (typically used when starting a download associated with the search
1110 struct GNUNET_FS_SearchResult;
1114 * Context for controlling a download.
1116 struct GNUNET_FS_DownloadContext;
1120 * Handle for detail information about a file that is being publishd.
1121 * Specifies metadata, keywords, how to get the contents of the file
1122 * (i.e. data-buffer in memory, filename on disk) and other options.
1124 struct GNUNET_FS_FileInformation;
1128 * Argument given to the progress callback with
1129 * information about what is going on.
1131 struct GNUNET_FS_ProgressInfo
1135 * Values that depend on the event type.
1141 * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
1147 * Context for controlling the upload.
1149 struct GNUNET_FS_PublishContext *pc;
1152 * Information about the file that is being publishd.
1154 const struct GNUNET_FS_FileInformation *fi;
1157 * Client context pointer (set the last time by the client for
1158 * this operation; initially NULL on START/RESUME events).
1163 * Client context pointer for the parent operation
1164 * (if this is a file in a directory or a subdirectory).
1169 * Name of the file being published; can be NULL.
1171 const char *filename;
1174 * How large is the file overall? For directories,
1175 * this is only the size of the directory itself,
1176 * not of the other files contained within the
1182 * At what time do we expect to finish the upload?
1183 * (will be a value in the past for completed
1186 struct GNUNET_TIME_Relative eta;
1189 * How long has this upload been actively running
1190 * (excludes times where the upload was suspended).
1192 struct GNUNET_TIME_Relative duration;
1195 * How many bytes have we completed?
1200 * What anonymity level is used for this upload?
1205 * Additional values for specific events.
1211 * These values are only valid for
1212 * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
1218 * Data block we just published.
1223 * At what offset in the file is "data"?
1228 * Length of the data block.
1233 * Depth of the given block in the tree;
1234 * 0 would be the lowest level (DBLOCKs).
1241 * These values are only valid for
1242 * GNUNET_FS_STATUS_PUBLISH_RESUME events.
1248 * Error message, NULL if no error was encountered so far.
1250 const char *message;
1253 * URI of the file (if the download had been completed)
1255 const struct GNUNET_FS_Uri *chk_uri;
1260 * These values are only valid for
1261 * GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
1269 const struct GNUNET_FS_Uri *chk_uri;
1274 * These values are only valid for
1275 * GNUNET_FS_STATUS_PUBLISH_ERROR events.
1281 * Error message, never NULL.
1283 const char *message;
1293 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
1299 * Context for controlling the download.
1301 struct GNUNET_FS_DownloadContext *dc;
1304 * Client context pointer (set the last time
1305 * by the client for this operation; initially
1306 * NULL on START/RESUME events).
1311 * Client context pointer for the parent operation
1312 * (if this is a file in a directory or a subdirectory).
1317 * Client context pointer for the associated search operation
1318 * (specifically, context pointer for the specific search
1319 * result, not the overall search); only set if this
1320 * download was started from a search result.
1325 * URI used for this download.
1327 const struct GNUNET_FS_Uri *uri;
1330 * Name of the file that we are downloading.
1332 const char *filename;
1335 * How large is the download overall? This
1336 * is NOT necessarily the size from the
1337 * URI since we may be doing a partial download.
1342 * At what time do we expect to finish the download?
1343 * (will be a value in the past for completed
1346 struct GNUNET_TIME_Relative eta;
1349 * How long has this download been active?
1351 struct GNUNET_TIME_Relative duration;
1354 * How many bytes have we completed?
1359 * What anonymity level is used for this download?
1364 * Is the download currently active.
1369 * Additional values for specific events.
1375 * These values are only valid for
1376 * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
1382 * Data block we just obtained, can be NULL (even if
1383 * data_len > 0) if we found the entire block 'intact' on
1384 * disk. In this case, it is also possible for 'data_len'
1385 * to be larger than an individual (32k) block.
1390 * At what offset in the file is "data"?
1395 * Length of the data block.
1400 * How much time passed between us asking for this block and
1401 * actually getting it? GNUNET_TIME_UNIT_FOREVER_REL if unknown.
1403 struct GNUNET_TIME_Relative block_download_duration;
1406 * Depth of the given block in the tree;
1407 * 0 would be the lowest level (DBLOCKS).
1412 * How much respect did we offer for downloading this block? (estimate,
1413 * because we might have the same request pending for multiple clients,
1414 * and of course because a transmission may have failed at a lower
1417 uint32_t respect_offered;
1420 * How often did we transmit the request? (estimate,
1421 * because we might have the same request pending for multiple clients,
1422 * and of course because a transmission may have failed at a lower
1425 uint32_t num_transmissions;
1430 * These values are only valid for
1431 * GNUNET_FS_STATUS_DOWNLOAD_START events.
1437 * Known metadata for the download.
1439 const struct GNUNET_CONTAINER_MetaData *meta;
1444 * These values are only valid for
1445 * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
1451 * Known metadata for the download.
1453 const struct GNUNET_CONTAINER_MetaData *meta;
1456 * Error message, NULL if we have not encountered any error yet.
1458 const char *message;
1463 * These values are only valid for
1464 * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1472 const char *message;
1481 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1487 * Context for controlling the search, NULL for
1488 * searches that were not explicitly triggered
1489 * by the client (i.e., searches for updates in
1492 struct GNUNET_FS_SearchContext *sc;
1495 * Client context pointer (set the last time by the client for
1496 * this operation; initially NULL on START/RESUME events). Note
1497 * that this value can only be set on START/RESUME; returning
1498 * non-NULL on RESULT/RESUME_RESULT will actually update the
1499 * private context for "UPDATE" events.
1504 * Client parent-context pointer; NULL for top-level searches,
1505 * refers to the client context of the associated search result
1506 * for automatically triggered searches for updates in
1507 * namespaces. In this case, 'presult' refers to that search
1513 * What query is used for this search
1514 * (list of keywords or SKS identifier).
1516 const struct GNUNET_FS_Uri *query;
1519 * How long has this search been actively running
1520 * (excludes times where the search was paused or
1523 struct GNUNET_TIME_Relative duration;
1526 * What anonymity level is used for this search?
1531 * Additional values for specific events.
1537 * These values are only valid for
1538 * GNUNET_FS_STATUS_SEARCH_RESULT events.
1544 * Metadata for the search result.
1546 const struct GNUNET_CONTAINER_MetaData *meta;
1549 * URI for the search result.
1551 const struct GNUNET_FS_Uri *uri;
1554 * Handle to the result (for starting downloads).
1556 struct GNUNET_FS_SearchResult *result;
1559 * Applicability rank (the larger, the better the result
1560 * fits the search criteria).
1562 uint32_t applicability_rank;
1567 * These values are only valid for
1568 * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1574 * Metadata for the search result.
1576 const struct GNUNET_CONTAINER_MetaData *meta;
1579 * URI for the search result.
1581 const struct GNUNET_FS_Uri *uri;
1584 * Handle to the result (for starting downloads).
1586 struct GNUNET_FS_SearchResult *result;
1589 * Current availability rank (negative:
1590 * unavailable, positive: available)
1592 int32_t availability_rank;
1595 * On how many total queries is the given
1596 * availability_rank based?
1598 uint32_t availability_certainty;
1601 * Updated applicability rank (the larger,
1602 * the better the result fits the search
1605 uint32_t applicability_rank;
1610 * These values are only valid for
1611 * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1617 * Private context set for for this result
1618 * during the "RESULT" event.
1623 * Metadata for the search result.
1625 const struct GNUNET_CONTAINER_MetaData *meta;
1628 * URI for the search result.
1630 const struct GNUNET_FS_Uri *uri;
1633 * Current availability rank (negative:
1634 * unavailable, positive: available)
1636 int32_t availability_rank;
1639 * On how many total queries is the given
1640 * availability_rank based?
1642 uint32_t availability_certainty;
1645 * Updated applicability rank (the larger,
1646 * the better the result fits the search
1649 uint32_t applicability_rank;
1652 * How long has the current probe been active?
1654 struct GNUNET_TIME_Relative current_probe_time;
1659 * These values are only valid for
1660 * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1661 * These events are automatically triggered for
1662 * each search result before the
1663 * GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1664 * happens primarily to give the client a chance
1665 * to clean up the "cctx" (if needed).
1671 * Private context set for for this result
1672 * during the "RESULT" event.
1677 * Metadata for the search result.
1679 const struct GNUNET_CONTAINER_MetaData *meta;
1682 * URI for the search result.
1684 const struct GNUNET_FS_Uri *uri;
1689 * These values are only valid for
1690 * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1691 * These events are automatically triggered for
1692 * each search result before the
1693 * GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1694 * happens primarily to give the client a chance
1695 * to clean up the "cctx" (if needed).
1701 * Private context set for for this result
1702 * during the "RESULT" event.
1707 * Metadata for the search result.
1709 const struct GNUNET_CONTAINER_MetaData *meta;
1712 * URI for the search result.
1714 const struct GNUNET_FS_Uri *uri;
1719 * These values are only valid for
1720 * GNUNET_FS_STATUS_SEARCH_RESUME events.
1726 * Error message, NULL if we have not encountered any error yet.
1728 const char *message;
1731 * Is this search currently paused?
1738 * These values are only valid for
1739 * GNUNET_FS_STATUS_SEARCH_ERROR events.
1747 const char *message;
1752 * Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events.
1758 * Handle to the namespace (NULL if it is not a local
1761 struct GNUNET_FS_Namespace *ns;
1764 * Short, human-readable name of the namespace.
1769 * Root identifier for the namespace, can be NULL.
1774 * Metadata for the namespace.
1776 const struct GNUNET_CONTAINER_MetaData *meta;
1779 * Public key of the namespace.
1781 struct GNUNET_PseudonymIdentifier pseudonym;
1790 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1796 * Context for controlling the unindexing.
1798 struct GNUNET_FS_UnindexContext *uc;
1801 * Client context pointer (set the last time
1802 * by the client for this operation; initially
1803 * NULL on START/RESUME events).
1808 * Name of the file that is being unindexed.
1810 const char *filename;
1813 * How large is the file overall?
1818 * At what time do we expect to finish unindexing?
1819 * (will be a value in the past for completed
1820 * unindexing opeations).
1822 struct GNUNET_TIME_Relative eta;
1825 * How long has this upload been actively running
1826 * (excludes times where the upload was suspended).
1828 struct GNUNET_TIME_Relative duration;
1831 * How many bytes have we completed?
1836 * Additional values for specific events.
1842 * These values are only valid for
1843 * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1849 * Data block we just unindexed.
1854 * At what offset in the file is "data"?
1859 * Length of the data block.
1864 * Depth of the given block in the tree;
1865 * 0 would be the lowest level (DBLOCKS).
1872 * These values are only valid for
1873 * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1879 * Error message, NULL if we have not encountered any error yet.
1881 const char *message;
1886 * These values are only valid for
1887 * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1895 const char *message;
1906 * Specific status code (determines the event type).
1908 enum GNUNET_FS_Status status;
1914 * Notification of FS to a client about the progress of an
1915 * operation. Callbacks of this type will be used for uploads,
1916 * downloads and searches. Some of the arguments depend a bit
1917 * in their meaning on the context in which the callback is used.
1919 * @param cls closure
1920 * @param info details about the event, specifying the event type
1921 * and various bits about the event
1922 * @return client-context (for the next progress call
1923 * for this operation; should be set to NULL for
1924 * SUSPEND and STOPPED events). The value returned
1925 * will be passed to future callbacks in the respective
1926 * field in the GNUNET_FS_ProgressInfo struct.
1928 typedef void *(*GNUNET_FS_ProgressCallback) (void *cls,
1929 const struct GNUNET_FS_ProgressInfo *info);
1933 * General (global) option flags for file-sharing.
1935 enum GNUNET_FS_Flags
1938 * No special flags set.
1940 GNUNET_FS_FLAGS_NONE = 0,
1943 * Is persistence of operations desired?
1944 * (will create SUSPEND/RESUME events).
1946 GNUNET_FS_FLAGS_PERSISTENCE = 1,
1949 * Should we automatically trigger probes for search results
1950 * to determine availability?
1951 * (will create GNUNET_FS_STATUS_SEARCH_UPDATE events).
1953 GNUNET_FS_FLAGS_DO_PROBES = 2
1958 * Options specified in the VARARGs portion of GNUNET_FS_start.
1960 enum GNUNET_FS_OPTIONS
1964 * Last option in the VARARG list.
1966 GNUNET_FS_OPTIONS_END = 0,
1969 * Select the desired amount of parallelism (this option should be
1970 * followed by an "unsigned int" giving the desired maximum number
1971 * of parallel downloads).
1973 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
1976 * Maximum number of requests that should be pending at a given
1977 * point in time (invidivual downloads may go above this, but
1978 * if we are above this threshold, we should not activate any
1979 * additional downloads.
1981 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
1986 * Settings for publishing a block (which may of course also
1987 * apply to an entire directory or file).
1989 struct GNUNET_FS_BlockOptions
1993 * At what time should the block expire? Data blocks (DBLOCKS and
1994 * IBLOCKS) may still be used even if they are expired (however,
1995 * they'd be removed quickly from the datastore if we are short on
1996 * space), all other types of blocks will no longer be returned
1997 * after they expire.
1999 struct GNUNET_TIME_Absolute expiration_time;
2002 * At which anonymity level should the block be shared?
2003 * (0: no anonymity, 1: normal GAP, >1: with cover traffic).
2005 uint32_t anonymity_level;
2008 * How important is it for us to store the block? If we run
2009 * out of space, the highest-priority, non-expired blocks will
2012 uint32_t content_priority;
2015 * How often should we try to migrate the block to other peers?
2016 * Only used if "CONTENT_PUSHING" is set to YES, in which case we
2017 * first push each block to other peers according to their
2018 * replication levels. Once each block has been pushed that many
2019 * times to other peers, blocks are chosen for migration at random.
2020 * Naturally, there is no guarantee that the other peers will keep
2021 * these blocks for any period of time (since they won't have any
2022 * priority or might be too busy to even store the block in the
2025 uint32_t replication_level;
2031 * Return the current year (i.e. '2011').
2034 GNUNET_FS_get_current_year (void);
2038 * Convert a year to an expiration time of January 1st of that year.
2040 * @param year a year (after 1970, please ;-)).
2041 * @return absolute time for January 1st of that year.
2043 struct GNUNET_TIME_Absolute
2044 GNUNET_FS_year_to_time (unsigned int year);
2048 * Convert an expiration time to the respective year (rounds)
2050 * @param at absolute time
2051 * @return year a year (after 1970), 0 on error
2054 GNUNET_FS_time_to_year (struct GNUNET_TIME_Absolute at);
2058 * Handle to the file-sharing service.
2060 struct GNUNET_FS_Handle;
2064 * Setup a connection to the file-sharing service.
2066 * @param cfg configuration to use
2067 * @param client_name unique identifier for this client
2068 * @param upcb function to call to notify about FS actions
2069 * @param upcb_cls closure for upcb
2070 * @param flags specific attributes for fs-operations
2071 * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
2072 * @return NULL on error
2074 struct GNUNET_FS_Handle *
2075 GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
2076 const char *client_name, GNUNET_FS_ProgressCallback upcb,
2077 void *upcb_cls, enum GNUNET_FS_Flags flags, ...);
2081 * Close our connection with the file-sharing service.
2082 * The callback given to GNUNET_FS_start will no longer be
2083 * called after this function returns.
2085 * @param h handle that was returned from GNUNET_FS_start
2088 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
2092 * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
2094 * @param cls closure
2095 * @param fi the entry in the publish-structure
2096 * @param length length of the file or directory
2097 * @param meta metadata for the file or directory (can be modified)
2098 * @param uri pointer to the keywords that will be used for this entry (can be modified)
2099 * @param bo block options (can be modified)
2100 * @param do_index should we index (can be modified)
2101 * @param client_info pointer to client context set upon creation (can be modified)
2102 * @return GNUNET_OK to continue, GNUNET_NO to remove
2103 * this entry from the directory, GNUNET_SYSERR
2104 * to abort the iteration
2106 typedef int (*GNUNET_FS_FileInformationProcessor) (void *cls,
2108 GNUNET_FS_FileInformation *
2109 fi, uint64_t length,
2111 GNUNET_CONTAINER_MetaData *
2113 struct GNUNET_FS_Uri ** uri,
2114 struct GNUNET_FS_BlockOptions
2115 * bo, int *do_index,
2116 void **client_info);
2120 * Obtain the name under which this file information
2121 * structure is stored on disk. Only works for top-level
2122 * file information structures.
2124 * @param s structure to get the filename for
2125 * @return NULL on error, otherwise filename that
2126 * can be passed to "GNUNET_FS_file_information_recover"
2127 * to read this fi-struct from disk.
2130 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
2134 * Obtain the filename from the file information structure.
2136 * @param s structure to get the filename for
2137 * @return "filename" field of the structure (can be NULL)
2140 GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s);
2144 * Set the filename in the file information structure.
2145 * If filename was already set, frees it before setting the new one.
2146 * Makes a copy of the argument.
2148 * @param s structure to get the filename for
2149 * @param filename filename to set
2152 GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s,
2153 const char *filename);
2157 * Create an entry for a file in a publish-structure.
2159 * @param h handle to the file sharing subsystem
2160 * @param client_info initial client-info value for this entry
2161 * @param filename name of the file or directory to publish
2162 * @param keywords under which keywords should this file be available
2163 * directly; can be NULL
2164 * @param meta metadata for the file
2165 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
2166 * GNUNET_SYSERR for simulation
2167 * @param bo block options
2168 * @return publish structure entry for the file
2170 struct GNUNET_FS_FileInformation *
2171 GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
2173 const char *filename,
2174 const struct GNUNET_FS_Uri
2177 GNUNET_CONTAINER_MetaData *meta,
2179 const struct GNUNET_FS_BlockOptions
2184 * Create an entry for a file in a publish-structure.
2186 * @param h handle to the file sharing subsystem
2187 * @param client_info initial client-info value for this entry
2188 * @param length length of the file
2189 * @param data data for the file (should not be used afterwards by
2190 * the caller; callee will "free")
2191 * @param keywords under which keywords should this file be available
2192 * directly; can be NULL
2193 * @param meta metadata for the file
2194 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
2195 * GNUNET_SYSERR for simulation
2196 * @param bo block options
2197 * @return publish structure entry for the file
2199 struct GNUNET_FS_FileInformation *
2200 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
2201 void *client_info, uint64_t length,
2203 const struct GNUNET_FS_Uri
2206 GNUNET_CONTAINER_MetaData *meta,
2208 const struct GNUNET_FS_BlockOptions
2213 * Function that provides data.
2215 * @param cls closure
2216 * @param offset offset to read from; it is possible
2217 * that the caller might need to go backwards
2218 * a bit at times; set to UINT64_MAX to tell
2219 * the reader that we won't be reading for a while
2220 * (used to close the file descriptor but NOT fully
2221 * clean up the reader's state); in this case,
2222 * a value of '0' for max should be ignored
2223 * @param max maximum number of bytes that should be
2224 * copied to buf; readers are not allowed
2225 * to provide less data unless there is an error;
2226 * a value of "0" will be used at the end to allow
2227 * the reader to clean up its internal state
2228 * @param buf where the reader should write the data
2229 * @param emsg location for the reader to store an error message
2230 * @return number of bytes written, usually "max", 0 on error
2232 typedef size_t (*GNUNET_FS_DataReader) (void *cls, uint64_t offset, size_t max,
2233 void *buf, char **emsg);
2237 * Create an entry for a file in a publish-structure.
2239 * @param h handle to the file sharing subsystem
2240 * @param client_info initial client-info value for this entry
2241 * @param length length of the file
2242 * @param reader function that can be used to obtain the data for the file
2243 * @param reader_cls closure for "reader"
2244 * @param keywords under which keywords should this file be available
2245 * directly; can be NULL
2246 * @param meta metadata for the file
2247 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
2248 * GNUNET_SYSERR for simulation
2249 * @param bo block options
2250 * @return publish structure entry for the file
2252 struct GNUNET_FS_FileInformation *
2253 GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
2256 GNUNET_FS_DataReader reader,
2258 const struct GNUNET_FS_Uri
2261 GNUNET_CONTAINER_MetaData *meta,
2264 GNUNET_FS_BlockOptions *bo);
2268 * Create an entry for an empty directory in a publish-structure.
2269 * This function should be used by applications for which the
2270 * use of "GNUNET_FS_file_information_create_from_directory"
2271 * is not appropriate.
2273 * @param h handle to the file sharing subsystem
2274 * @param client_info initial client-info value for this entry
2275 * @param keywords under which keywords should this directory be available
2276 * directly; can be NULL
2277 * @param meta metadata for the directory
2278 * @param bo block options
2279 * @param filename name of the directory; can be NULL
2280 * @return publish structure entry for the directory , NULL on error
2282 struct GNUNET_FS_FileInformation *
2283 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
2285 const struct GNUNET_FS_Uri
2288 GNUNET_CONTAINER_MetaData
2291 GNUNET_FS_BlockOptions *bo,
2292 const char *filename);
2296 * Test if a given entry represents a directory.
2298 * @param ent check if this FI represents a directory
2299 * @return GNUNET_YES if so, GNUNET_NO if not
2302 GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
2307 * Add an entry to a directory in a publish-structure. Clients
2308 * should never modify publish structures that were passed to
2309 * "GNUNET_FS_publish_start" already.
2311 * @param dir the directory
2312 * @param ent the entry to add; the entry must not have been
2313 * added to any other directory at this point and
2314 * must not include "dir" in its structure
2315 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2318 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
2319 struct GNUNET_FS_FileInformation *ent);
2323 * Inspect a file or directory in a publish-structure. Clients
2324 * should never modify publish structures that were passed to
2325 * "GNUNET_FS_publish_start" already. When called on a directory,
2326 * this function will FIRST call "proc" with information about
2327 * the directory itself and then for each of the files in the
2328 * directory (but not for files in subdirectories). When called
2329 * on a file, "proc" will be called exactly once (with information
2330 * about the specific file).
2332 * @param dir the directory
2333 * @param proc function to call on each entry
2334 * @param proc_cls closure for proc
2337 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
2338 GNUNET_FS_FileInformationProcessor proc,
2343 * Destroy publish-structure. Clients should never destroy publish
2344 * structures that were passed to "GNUNET_FS_publish_start" already.
2346 * @param fi structure to destroy
2347 * @param cleaner function to call on each entry in the structure
2348 * (useful to clean up client_info); can be NULL; return
2349 * values are ignored
2350 * @param cleaner_cls closure for cleaner
2353 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
2354 GNUNET_FS_FileInformationProcessor cleaner,
2359 * Options for publishing. Compatible options
2360 * can be OR'ed together.
2362 enum GNUNET_FS_PublishOptions
2365 * No options (use defaults for everything).
2367 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
2370 * Simulate publishing. With this option, no data will be stored
2371 * in the datastore. Useful for computing URIs from files.
2373 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
2377 * Publish a file or directory.
2379 * @param h handle to the file sharing subsystem
2380 * @param fi information about the file or directory structure to publish
2381 * @param ns namespace to publish the file in, NULL for no namespace
2382 * @param nid identifier to use for the publishd content in the namespace
2383 * (can be NULL, must be NULL if namespace is NULL)
2384 * @param nuid update-identifier that will be used for future updates
2385 * (can be NULL, must be NULL if namespace or nid is NULL)
2386 * @param options options for the publication
2387 * @return context that can be used to control the publish operation
2389 struct GNUNET_FS_PublishContext *
2390 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
2391 struct GNUNET_FS_FileInformation *fi,
2392 struct GNUNET_FS_Namespace *ns, const char *nid,
2394 enum GNUNET_FS_PublishOptions options);
2398 * Stop a publication. Will abort incomplete publications (but
2399 * not remove blocks that have already been published) or
2400 * simply clean up the state for completed publications.
2401 * Must NOT be called from within the event callback!
2403 * @param pc context for the publication to stop
2406 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
2410 * Signature of a function called as the continuation of a KBlock or
2411 * SBlock publication.
2413 * @param cls closure
2414 * @param uri URI under which the block is now available, NULL on error
2415 * @param emsg error message, NULL on success
2417 typedef void (*GNUNET_FS_PublishContinuation) (void *cls,
2418 const struct GNUNET_FS_Uri * uri,
2423 * Handle to cancel publish KSK operation.
2425 struct GNUNET_FS_PublishKskContext;
2429 * Publish a KBlock on GNUnet.
2431 * @param h handle to the file sharing subsystem
2432 * @param ksk_uri keywords to use
2433 * @param meta metadata to use
2434 * @param uri URI to refer to in the KBlock
2435 * @param bo block options
2436 * @param options publication options
2437 * @param cont continuation
2438 * @param cont_cls closure for cont
2439 * @return NULL on error ('cont' will still be called)
2441 struct GNUNET_FS_PublishKskContext *
2442 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2443 const struct GNUNET_FS_Uri *ksk_uri,
2444 const struct GNUNET_CONTAINER_MetaData *meta,
2445 const struct GNUNET_FS_Uri *uri,
2446 const struct GNUNET_FS_BlockOptions *bo,
2447 enum GNUNET_FS_PublishOptions options,
2448 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2452 * Abort the KSK publishing operation.
2454 * @param pkc context of the operation to abort.
2457 GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc);
2461 * Handle to cancel publish SKS operation.
2463 struct GNUNET_FS_PublishSksContext;
2467 * Publish an SBlock on GNUnet.
2469 * @param h handle to the file sharing subsystem
2470 * @param ns namespace to publish in
2471 * @param identifier identifier to use
2472 * @param update update identifier to use
2473 * @param meta metadata to use
2474 * @param uri URI to refer to in the SBlock
2475 * @param bo block options
2476 * @param options publication options
2477 * @param cont continuation
2478 * @param cont_cls closure for cont
2479 * @return NULL on error ('cont' will still be called)
2481 struct GNUNET_FS_PublishSksContext *
2482 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2483 struct GNUNET_FS_Namespace *ns,
2484 const char *identifier, const char *update,
2485 const struct GNUNET_CONTAINER_MetaData *meta,
2486 const struct GNUNET_FS_Uri *uri,
2487 const struct GNUNET_FS_BlockOptions *bo,
2488 enum GNUNET_FS_PublishOptions options,
2489 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2493 * Abort the SKS publishing operation.
2495 * @param psc context of the operation to abort.
2498 GNUNET_FS_publish_sks_cancel (struct GNUNET_FS_PublishSksContext *psc);
2502 * Type of a function called by "GNUNET_FS_get_indexed_files".
2504 * @param cls closure
2505 * @param filename the name of the file, NULL for end of list
2506 * @param file_id hash of the contents of the indexed file
2507 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
2509 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls, const char *filename,
2510 const struct GNUNET_HashCode * file_id);
2514 * Handle to cancel 'GNUNET_FS_get_indexed_files'.
2516 struct GNUNET_FS_GetIndexedContext;
2520 * Iterate over all indexed files.
2522 * @param h handle to the file sharing subsystem
2523 * @param iterator function to call on each indexed file
2524 * @param iterator_cls closure for iterator
2525 * @return NULL on error ('iter' is not called)
2527 struct GNUNET_FS_GetIndexedContext *
2528 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2529 GNUNET_FS_IndexedFileProcessor iterator,
2530 void *iterator_cls);
2534 * Cancel iteration over all indexed files.
2536 * @param gic operation to cancel
2539 GNUNET_FS_get_indexed_files_cancel (struct GNUNET_FS_GetIndexedContext *gic);
2545 * @param h handle to the file sharing subsystem
2546 * @param filename file to unindex
2547 * @param cctx initial value for the client context
2548 * @return NULL on error, otherwise handle
2550 struct GNUNET_FS_UnindexContext *
2551 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, const char *filename,
2556 * Clean up after completion of an unindex operation.
2561 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2565 * Create a namespace with the given name; if one already
2566 * exists, return a handle to the existing namespace.
2568 * @param h handle to the file sharing subsystem
2569 * @param name name to use for the namespace
2570 * @return handle to the namespace, NULL on error (i.e. invalid filename)
2572 struct GNUNET_FS_Namespace *
2573 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, const char *name);
2577 * Open the namespace with the given name; if it does not exist,
2578 * or the key file is corrupted, the function fails.
2580 * @param h handle to the file sharing subsystem
2581 * @param name name of the namespace
2582 * @return handle to the namespace,
2583 * NULL on error (i.e. invalid filename, non-existent filename)
2585 struct GNUNET_FS_Namespace *
2586 GNUNET_FS_namespace_open_existing (struct GNUNET_FS_Handle *h, const char *name);
2590 * Rename a local namespace.
2592 * @param h handle to the file sharing subsystem
2593 * @param old_name old name of the namespace
2594 * @param new_name new name of the namespace
2595 * @return GNUNET_OK on success, GNUNET_SYSERR on error (see errno for details)
2598 GNUNET_FS_namespace_rename (struct GNUNET_FS_Handle *h, const char *old_name,
2599 const char *new_name);
2603 * Duplicate a namespace handle.
2605 * @param ns namespace handle
2606 * @return duplicated handle to the namespace
2608 struct GNUNET_FS_Namespace *
2609 GNUNET_FS_namespace_dup (struct GNUNET_FS_Namespace *ns);
2613 * Get hash of the public key of a namespace.
2615 * @param ns namespace
2616 * @param id buffer to store the key in
2617 * @return GNUNET_OK on success
2618 * GNUNET_SYSERR on failure (contents of id remain intact)
2621 GNUNET_FS_namespace_get_public_identifier (struct GNUNET_FS_Namespace *ns,
2622 struct GNUNET_PseudonymIdentifier *id);
2626 * Delete a namespace handle. Can be used for a clean shutdown (free
2627 * memory) or also to freeze the namespace to prevent further
2628 * insertions by anyone.
2630 * @param ns handle to the namespace that should be deleted / freed
2631 * @param freeze prevents future insertions; creating a namespace
2632 * with the same name again will create a fresh namespace instead
2634 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2637 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *ns, int freeze);
2641 * Callback with information about local (!) namespaces.
2642 * Contains the names of the local namespace and the global
2645 * @param cls closure
2646 * @param name human-readable identifier of the namespace
2647 * @param id identifier for the namespace
2649 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls, const char *name,
2650 const struct GNUNET_PseudonymIdentifier *id);
2654 * Build a list of all available local (!) namespaces The returned
2655 * names are only the nicknames since we only iterate over the local
2658 * @param h handle to the file sharing subsystem
2659 * @param cb function to call on each known namespace
2660 * @param cb_cls closure for cb
2663 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2664 GNUNET_FS_NamespaceInfoProcessor cb, void *cb_cls);
2668 * Function called on updateable identifiers.
2670 * @param cls closure
2671 * @param last_id last identifier
2672 * @param last_uri uri used for the content published under the last_id
2673 * @param last_meta metadata associated with last_uri
2674 * @param next_id identifier that should be used for updates
2676 typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls, const char *last_id,
2677 const struct GNUNET_FS_Uri *
2680 GNUNET_CONTAINER_MetaData *
2681 last_meta, const char *next_id);
2685 * List all of the identifiers in the namespace for which we could
2686 * produce an update. Namespace updates form a graph where each node
2687 * has a name. Each node can have any number of URI/meta-data entries
2688 * which can each be linked to other nodes. Cycles are possible.
2690 * Calling this function with "next_id" NULL will cause the library to
2691 * call "ip" with a root for each strongly connected component of the
2692 * graph (a root being a node from which all other nodes in the Scc
2695 * Calling this function with "next_id" being the name of a node will
2696 * cause the library to call "ip" with all children of the node. Note
2697 * that cycles within an SCC are possible (including self-loops).
2699 * @param ns namespace to inspect for updateable content
2700 * @param next_id ID to look for; use NULL to look for SCC roots
2701 * @param ip function to call on each updateable identifier
2702 * @param ip_cls closure for ip
2705 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *ns,
2706 const char *next_id,
2707 GNUNET_FS_IdentifierProcessor ip,
2712 * Options for searching. Compatible options
2713 * can be OR'ed together.
2715 enum GNUNET_FS_SearchOptions
2718 * No options (use defaults for everything).
2720 GNUNET_FS_SEARCH_OPTION_NONE = 0,
2723 * Only search the local host, do not search remote systems (no P2P)
2725 GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
2730 * Start search for content.
2732 * @param h handle to the file sharing subsystem
2733 * @param uri specifies the search parameters; can be
2734 * a KSK URI or an SKS URI.
2735 * @param anonymity desired level of anonymity
2736 * @param options options for the search
2737 * @param cctx initial value for the client context
2738 * @return context that can be used to control the search
2740 struct GNUNET_FS_SearchContext *
2741 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2742 const struct GNUNET_FS_Uri *uri, uint32_t anonymity,
2743 enum GNUNET_FS_SearchOptions options, void *cctx);
2749 * @param sc context for the search that should be paused
2752 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2756 * Continue paused search.
2758 * @param sc context for the search that should be resumed
2761 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2765 * Stop search for content.
2767 * @param sc context for the search that should be stopped
2770 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2776 * Options for downloading. Compatible options
2777 * can be OR'ed together.
2779 enum GNUNET_FS_DownloadOptions
2782 * No options (use defaults for everything).
2784 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2787 * Only download from the local host, do not access remote systems (no P2P)
2789 GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
2792 * Do a recursive download (that is, automatically trigger the
2793 * download of files in directories).
2795 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
2798 * Do not append temporary data to
2799 * the target file (for the IBlocks).
2801 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
2804 * Internal option used to flag this download as a 'probe' for a
2805 * search result. Impacts the priority with which the download is
2806 * run and causes signalling callbacks to be done differently.
2807 * Also, probe downloads are not serialized on suspension. Normal
2808 * clients should not use this!
2810 GNUNET_FS_DOWNLOAD_IS_PROBE = (1 << 31)
2816 * Download parts of a file. Note that this will store
2817 * the blocks at the respective offset in the given file. Also, the
2818 * download is still using the blocking of the underlying FS
2819 * encoding. As a result, the download may *write* outside of the
2820 * given boundaries (if offset and length do not match the 32k FS
2821 * block boundaries). <p>
2823 * The given range can be used to focus a download towards a
2824 * particular portion of the file (optimization), not to strictly
2825 * limit the download to exactly those bytes.
2827 * @param h handle to the file sharing subsystem
2828 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2829 * @param meta known metadata for the file (can be NULL)
2830 * @param filename where to store the file, maybe NULL (then no file is
2831 * created on disk and data must be grabbed from the callbacks)
2832 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2833 * can be NULL (in which case we will pick a name if needed); the temporary file
2834 * may already exist, in which case we will try to use the data that is there and
2835 * if it is not what is desired, will overwrite it
2836 * @param offset at what offset should we start the download (typically 0)
2837 * @param length how many bytes should be downloaded starting at offset
2838 * @param anonymity anonymity level to use for the download
2839 * @param options various download options
2840 * @param cctx initial value for the client context for this download
2841 * @param parent parent download to associate this download with (use NULL
2842 * for top-level downloads; useful for manually-triggered recursive downloads)
2843 * @return context that can be used to control this download
2845 struct GNUNET_FS_DownloadContext *
2846 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2847 const struct GNUNET_FS_Uri *uri,
2848 const struct GNUNET_CONTAINER_MetaData *meta,
2849 const char *filename, const char *tempname,
2850 uint64_t offset, uint64_t length, uint32_t anonymity,
2851 enum GNUNET_FS_DownloadOptions options, void *cctx,
2852 struct GNUNET_FS_DownloadContext *parent);
2856 * Download parts of a file based on a search result. The download
2857 * will be associated with the search result (and the association
2858 * will be preserved when serializing/deserializing the state).
2859 * If the search is stopped, the download will not be aborted but
2860 * be 'promoted' to a stand-alone download.
2862 * As with the other download function, this will store
2863 * the blocks at the respective offset in the given file. Also, the
2864 * download is still using the blocking of the underlying FS
2865 * encoding. As a result, the download may *write* outside of the
2866 * given boundaries (if offset and length do not match the 32k FS
2867 * block boundaries). <p>
2869 * The given range can be used to focus a download towards a
2870 * particular portion of the file (optimization), not to strictly
2871 * limit the download to exactly those bytes.
2873 * @param h handle to the file sharing subsystem
2874 * @param sr the search result to use for the download (determines uri and
2875 * meta data and associations)
2876 * @param filename where to store the file, maybe NULL (then no file is
2877 * created on disk and data must be grabbed from the callbacks)
2878 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2879 * can be NULL (in which case we will pick a name if needed); the temporary file
2880 * may already exist, in which case we will try to use the data that is there and
2881 * if it is not what is desired, will overwrite it
2882 * @param offset at what offset should we start the download (typically 0)
2883 * @param length how many bytes should be downloaded starting at offset
2884 * @param anonymity anonymity level to use for the download
2885 * @param options various download options
2886 * @param cctx initial value for the client context for this download
2887 * @return context that can be used to control this download
2889 struct GNUNET_FS_DownloadContext *
2890 GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2891 struct GNUNET_FS_SearchResult *sr,
2892 const char *filename,
2893 const char *tempname, uint64_t offset,
2894 uint64_t length, uint32_t anonymity,
2895 enum GNUNET_FS_DownloadOptions options,
2900 * Stop a download (aborts if download is incomplete).
2902 * @param dc handle for the download
2903 * @param do_delete delete files of incomplete downloads
2906 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete);
2910 /* ******************** Directory API *********************** */
2913 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2914 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2915 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2918 * Does the meta-data claim that this is a directory?
2919 * Checks if the mime-type is that of a GNUnet directory.
2921 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2922 * we have no mime-type information (treat as 'GNUNET_NO')
2925 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
2930 * Set the MIMETYPE information for the given
2931 * metadata to "application/gnunet-directory".
2933 * @param md metadata to add mimetype to
2936 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2940 * Suggest a filename based on given metadata.
2942 * @param md given meta data
2943 * @return NULL if meta data is useless for suggesting a filename
2946 GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData
2951 * Function used to process entries in a directory.
2953 * @param cls closure
2954 * @param filename name of the file in the directory
2955 * @param uri URI of the file
2956 * @param metadata metadata for the file; metadata for
2957 * the directory if everything else is NULL/zero
2958 * @param length length of the available data for the file
2959 * (of type size_t since data must certainly fit
2960 * into memory; if files are larger than size_t
2961 * permits, then they will certainly not be
2962 * embedded with the directory itself).
2963 * @param data data available for the file (length bytes)
2965 typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
2966 const char *filename,
2967 const struct GNUNET_FS_Uri *
2970 GNUNET_CONTAINER_MetaData *
2971 meta, size_t length,
2976 * Iterate over all entries in a directory. Note that directories
2977 * are structured such that it is possible to iterate over the
2978 * individual blocks as well as over the entire directory. Thus
2979 * a client can call this function on the buffer in the
2980 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2981 * include the contents of (small) files embedded in the directory
2982 * itself; for those files, the processor may be given the
2983 * contents of the file directly by this function.
2985 * @param size number of bytes in data
2986 * @param data pointer to the beginning of the directory
2987 * @param offset offset of data in the directory
2988 * @param dep function to call on each entry
2989 * @param dep_cls closure for dep
2990 * @return GNUNET_OK if this could be a block in a directory,
2991 * GNUNET_NO if this could be part of a directory (but not 100% OK)
2992 * GNUNET_SYSERR if 'data' does not represent a directory
2995 GNUNET_FS_directory_list_contents (size_t size, const void *data,
2997 GNUNET_FS_DirectoryEntryProcessor dep,
3002 * Opaque handle to a directory builder.
3004 struct GNUNET_FS_DirectoryBuilder;
3007 * Create a directory builder.
3009 * @param mdir metadata for the directory
3011 struct GNUNET_FS_DirectoryBuilder *
3012 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
3017 * Add an entry to a directory.
3019 * @param bld directory to extend
3020 * @param uri uri of the entry (must not be a KSK)
3021 * @param md metadata of the entry
3022 * @param data raw data of the entry, can be NULL, otherwise
3023 * data must point to exactly the number of bytes specified
3027 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
3028 const struct GNUNET_FS_Uri *uri,
3029 const struct GNUNET_CONTAINER_MetaData *md,
3034 * Finish building the directory. Frees the
3035 * builder context and returns the directory
3038 * @param bld directory to finish
3039 * @param rsize set to the number of bytes needed
3040 * @param rdata set to the encoded directory
3041 * @return GNUNET_OK on success
3044 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
3045 size_t * rsize, void **rdata);
3048 /* ******************** DirScanner API *********************** */
3051 * Progress reasons of the directory scanner.
3053 enum GNUNET_FS_DirScannerProgressUpdateReason
3057 * We've started processing a file or directory.
3059 GNUNET_FS_DIRSCANNER_FILE_START = 0,
3062 * We're having trouble accessing a file (soft-error); it will
3065 GNUNET_FS_DIRSCANNER_FILE_IGNORED,
3068 * We've found all files (in the pre-pass).
3070 GNUNET_FS_DIRSCANNER_ALL_COUNTED,
3073 * We've finished extracting meta data from a file.
3075 GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED,
3078 * Last call to the progress function: we have finished scanning
3081 GNUNET_FS_DIRSCANNER_FINISHED,
3084 * There was an internal error. Application should abort the scan.
3086 GNUNET_FS_DIRSCANNER_INTERNAL_ERROR
3092 * Function called over time as the directory scanner makes
3093 * progress on the job at hand.
3095 * @param cls closure
3096 * @param filename which file we are making progress on
3097 * @param is_directory GNUNET_YES if this is a directory,
3098 * GNUNET_NO if this is a file
3099 * GNUNET_SYSERR if it is neither (or unknown)
3100 * @param reason kind of progress we are making
3102 typedef void (*GNUNET_FS_DirScannerProgressCallback) (void *cls,
3103 const char *filename,
3105 enum GNUNET_FS_DirScannerProgressUpdateReason reason);
3109 * A node of a directory tree (produced by dirscanner)
3111 struct GNUNET_FS_ShareTreeItem
3114 * This is a doubly-linked list
3116 struct GNUNET_FS_ShareTreeItem *prev;
3119 * This is a doubly-linked list
3121 struct GNUNET_FS_ShareTreeItem *next;
3124 * This is a doubly-linked tree
3125 * NULL for top-level entries.
3127 struct GNUNET_FS_ShareTreeItem *parent;
3130 * This is a doubly-linked tree
3131 * NULL for files and empty directories
3133 struct GNUNET_FS_ShareTreeItem *children_head;
3136 * This is a doubly-linked tree
3137 * NULL for files and empty directories
3139 struct GNUNET_FS_ShareTreeItem *children_tail;
3142 * Metadata for this file or directory
3144 struct GNUNET_CONTAINER_MetaData *meta;
3147 * Keywords for this file or directory (derived from metadata).
3149 struct GNUNET_FS_Uri *ksk_uri;
3152 * Name of the file/directory
3157 * Base name of the file/directory.
3159 char *short_filename;
3162 * GNUNET_YES if this is a directory
3170 * Opaqe handle to an asynchronous directory scanning activity.
3172 struct GNUNET_FS_DirScanner;
3176 * Start a directory scanner.
3178 * @param filename name of the directory to scan
3179 * @param disable_extractor GNUNET_YES to not to run libextractor on files (only build a tree)
3180 * @param ex if not NULL, must be a list of extra plugins for extractor
3181 * @param cb the callback to call when there are scanning progress messages
3182 * @param cb_cls closure for 'cb'
3183 * @return directory scanner object to be used for controlling the scanner
3185 struct GNUNET_FS_DirScanner *
3186 GNUNET_FS_directory_scan_start (const char *filename,
3187 int disable_extractor,
3189 GNUNET_FS_DirScannerProgressCallback cb,
3194 * Abort the scan. Must not be called from within the progress_callback
3197 * @param ds directory scanner structure
3200 GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds);
3204 * Obtain the result of the scan after the scan has signalled
3205 * completion. Must not be called prior to completion. The 'ds' is
3206 * freed as part of this call.
3208 * @param ds directory scanner structure
3209 * @return the results of the scan (a directory tree)
3211 struct GNUNET_FS_ShareTreeItem *
3212 GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds);
3216 * Process a share item tree, moving frequent keywords up and
3217 * copying frequent metadata up.
3219 * @param toplevel toplevel directory in the tree, returned by the scanner
3222 GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel);
3226 * Release memory of a share item tree.
3228 * @param toplevel toplevel of the tree to be freed
3231 GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
3234 #if 0 /* keep Emacsens' auto-indent happy */