gnunet_fs_service.h 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2004--2013 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author Christian Grothoff
  18. *
  19. * @file
  20. * API for file sharing via GNUnet
  21. *
  22. * @defgroup fs FS service
  23. * File sharing
  24. *
  25. * @see [Documentation](https://gnunet.org/file-sharing-service)
  26. *
  27. * @{
  28. */
  29. #ifndef GNUNET_FS_LIB_H
  30. #define GNUNET_FS_LIB_H
  31. #include "gnunet_util_lib.h"
  32. #ifdef __cplusplus
  33. extern "C"
  34. {
  35. #if 0 /* keep Emacsens' auto-indent happy */
  36. }
  37. #endif
  38. #endif
  39. /**
  40. * Version number of the implementation.
  41. * History:
  42. *
  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)
  58. * 9.3.0: base32crockford encoded URLs
  59. */
  60. #define GNUNET_FS_VERSION 0x00090300
  61. /* ******************** URI API *********************** */
  62. #define GNUNET_FS_URI_PREFIX "gnunet://fs/"
  63. #define GNUNET_FS_URI_KSK_INFIX "ksk/"
  64. #define GNUNET_FS_URI_SKS_INFIX "sks/"
  65. #define GNUNET_FS_URI_CHK_INFIX "chk/"
  66. #define GNUNET_FS_URI_LOC_INFIX "loc/"
  67. /**
  68. * How often do we signal applications that a probe for a particular
  69. * search result is running? (used to visualize probes).
  70. */
  71. #define GNUNET_FS_PROBE_UPDATE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
  72. /**
  73. * A Universal Resource Identifier (URI), opaque.
  74. */
  75. struct GNUNET_FS_Uri;
  76. /**
  77. * Iterator over keywords
  78. *
  79. * @param cls closure
  80. * @param keyword the keyword
  81. * @param is_mandatory is the keyword mandatory (in a search)
  82. * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to abort
  83. */
  84. typedef int
  85. (*GNUNET_FS_KeywordIterator) (void *cls,
  86. const char *keyword,
  87. int is_mandatory);
  88. /**
  89. * Get a unique key from a URI. This is for putting URIs
  90. * into HashMaps. The key may change between FS implementations.
  91. *
  92. * @param uri uri to convert to a unique key
  93. * @param key wherer to store the unique key
  94. * @return #GNUNET_OK on success
  95. */
  96. int
  97. GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
  98. struct GNUNET_HashCode *key);
  99. /**
  100. * Convert a URI to a UTF-8 String.
  101. *
  102. * @param uri uri to convert to a string
  103. * @return the UTF-8 string
  104. */
  105. char *
  106. GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
  107. /**
  108. * Convert keyword URI to a human readable format
  109. * (i.e. the search query that was used in the first place)
  110. *
  111. * @param uri ksk uri to convert to a string
  112. * @return string with the keywords
  113. */
  114. char *
  115. GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
  116. /**
  117. * Add the given keyword to the set of keywords represented by the URI.
  118. * Does nothing if the keyword is already present.
  119. *
  120. * @param uri ksk uri to modify
  121. * @param keyword keyword to add
  122. * @param is_mandatory is this keyword mandatory?
  123. */
  124. void
  125. GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
  126. const char *keyword,
  127. int is_mandatory);
  128. /**
  129. * Remove the given keyword from the set of keywords represented by the URI.
  130. * Does nothing if the keyword is not present.
  131. *
  132. * @param uri ksk uri to modify
  133. * @param keyword keyword to add
  134. */
  135. void
  136. GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
  137. const char *keyword);
  138. /**
  139. * Convert a UTF-8 String to a URI.
  140. *
  141. * @param uri string to parse
  142. * @param emsg where to store the parser error message (if any)
  143. * @return NULL on error
  144. */
  145. struct GNUNET_FS_Uri *
  146. GNUNET_FS_uri_parse (const char *uri,
  147. char **emsg);
  148. /**
  149. * Free URI.
  150. *
  151. * @param uri uri to free
  152. */
  153. void
  154. GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
  155. /**
  156. * How many keywords are ANDed in this keyword URI?
  157. *
  158. * @param uri ksk uri to get the number of keywords from
  159. * @return 0 if this is not a keyword URI
  160. */
  161. unsigned int
  162. GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
  163. /**
  164. * Iterate over all keywords in this keyword URI.
  165. *
  166. * @param uri ksk uri to get the keywords from
  167. * @param iterator function to call on each keyword
  168. * @param iterator_cls closure for @a iterator
  169. * @return -1 if this is not a keyword URI, otherwise number of
  170. * keywords iterated over until iterator aborted
  171. */
  172. int
  173. GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
  174. GNUNET_FS_KeywordIterator iterator,
  175. void *iterator_cls);
  176. /**
  177. * Obtain the identity of the peer offering the data
  178. *
  179. * @param uri the location URI to inspect
  180. * @param peer where to store the identify of the peer (presumably) offering the content
  181. * @return #GNUNET_SYSERR if this is not a location URI, otherwise #GNUNET_OK
  182. */
  183. int
  184. GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
  185. struct GNUNET_PeerIdentity *peer);
  186. /**
  187. * Obtain the URI of the content itself.
  188. *
  189. * @param uri location URI to get the content URI from
  190. * @return NULL if argument is not a location URI
  191. */
  192. struct GNUNET_FS_Uri *
  193. GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
  194. /**
  195. * Obtain the expiration of the LOC URI.
  196. *
  197. * @param uri location URI to get the expiration from
  198. * @return expiration time of the URI
  199. */
  200. struct GNUNET_TIME_Absolute
  201. GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
  202. /**
  203. * Construct a location URI (this peer will be used for the location).
  204. * This function should only be called from within gnunet-service-fs,
  205. * as it requires the peer's private key which is generally unavailable
  206. * to processes directly under the user's control. However, for
  207. * testing and as it logically fits under URIs, it is in this API.
  208. *
  209. * @param base_uri content offered by the sender
  210. * @param sign_key private key of the peer
  211. * @param expiration_time how long will the content be offered?
  212. * @return the location URI, NULL on error
  213. */
  214. struct GNUNET_FS_Uri *
  215. GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri,
  216. const struct GNUNET_CRYPTO_EddsaPrivateKey *sign_key,
  217. struct GNUNET_TIME_Absolute expiration_time);
  218. /**
  219. * Merge the sets of keywords from two KSK URIs.
  220. *
  221. * @param u1 first uri
  222. * @param u2 second uri
  223. * @return merged URI, NULL on error
  224. */
  225. struct GNUNET_FS_Uri *
  226. GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
  227. const struct GNUNET_FS_Uri *u2);
  228. /**
  229. * Duplicate URI.
  230. *
  231. * @param uri the URI to duplicate
  232. * @return copy of the URI
  233. */
  234. struct GNUNET_FS_Uri *
  235. GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
  236. /**
  237. * Create an FS URI from a single user-supplied string of keywords.
  238. * The string is broken up at spaces into individual keywords.
  239. * Keywords that start with "+" are mandatory. Double-quotes can
  240. * be used to prevent breaking up strings at spaces (and also
  241. * to specify non-mandatory keywords starting with "+").
  242. *
  243. * Keywords must contain a balanced number of double quotes and
  244. * double quotes can not be used in the actual keywords (for
  245. * example, the string '""foo bar""' will be turned into two
  246. * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
  247. *
  248. * @param keywords the keyword string
  249. * @param emsg where to store an error message
  250. * @return an FS URI for the given keywords, NULL
  251. * if keywords is not legal (i.e. empty).
  252. */
  253. struct GNUNET_FS_Uri *
  254. GNUNET_FS_uri_ksk_create (const char *keywords,
  255. char **emsg);
  256. /**
  257. * Create an FS URI from a user-supplied command line of keywords.
  258. * Arguments should start with "+" to indicate mandatory
  259. * keywords.
  260. *
  261. * @param argc number of keywords
  262. * @param argv keywords (double quotes are not required for
  263. * keywords containing spaces; however, double
  264. * quotes are required for keywords starting with
  265. * "+"); there is no mechanism for having double
  266. * quotes in the actual keywords (if the user
  267. * did specifically specify double quotes, the
  268. * caller should convert each double quote
  269. * into two single quotes).
  270. * @return an FS URI for the given keywords, NULL
  271. * if keywords is not legal (i.e. empty).
  272. */
  273. struct GNUNET_FS_Uri *
  274. GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
  275. const char **argv);
  276. /**
  277. * Test if two URIs are equal.
  278. *
  279. * @param u1 one of the URIs
  280. * @param u2 the other URI
  281. * @return #GNUNET_YES if the URIs are equal
  282. */
  283. int
  284. GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
  285. const struct GNUNET_FS_Uri *u2);
  286. /**
  287. * Is this a namespace URI?
  288. *
  289. * @param uri the uri to check
  290. * @return #GNUNET_YES if this is an SKS uri
  291. */
  292. int
  293. GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
  294. /**
  295. * Create an SKS URI from a namespace ID and an identifier.
  296. *
  297. * @param ns pseudonym to use
  298. * @param id identifier
  299. * @return an FS URI for the given namespace and identifier
  300. */
  301. struct GNUNET_FS_Uri *
  302. GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns,
  303. const char *id);
  304. /**
  305. * Get the public key of a namespace from the given
  306. * namespace URI.
  307. *
  308. * @param uri the uri to get the namespace ID from
  309. * @param pseudonym where to store the public key of the namespace
  310. * @return #GNUNET_OK on success
  311. */
  312. int
  313. GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
  314. struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym);
  315. /**
  316. * Get the content identifier of an SKS URI.
  317. *
  318. * @param uri the sks uri
  319. * @return NULL on error (not a valid SKS URI)
  320. */
  321. char *
  322. GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
  323. /**
  324. * Is this a keyword URI?
  325. *
  326. * @param uri the uri
  327. * @return #GNUNET_YES if this is a KSK uri
  328. */
  329. int
  330. GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
  331. /**
  332. * Is this a file (or directory) URI?
  333. *
  334. * @param uri the uri to check
  335. * @return #GNUNET_YES if this is a CHK uri
  336. */
  337. int
  338. GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
  339. /**
  340. * What is the size of the file that this URI
  341. * refers to?
  342. *
  343. * @param uri the CHK (or LOC) URI to inspect
  344. * @return size of the file as specified in the CHK URI
  345. */
  346. uint64_t
  347. GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
  348. /**
  349. * Is this a location URI?
  350. *
  351. * @param uri the uri to check
  352. * @return #GNUNET_YES if this is a LOC uri
  353. */
  354. int
  355. GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
  356. /**
  357. * Construct a keyword-URI from meta-data (take all entries
  358. * in the meta-data and construct one large keyword URI
  359. * that lists all keywords that can be found in the meta-data).
  360. *
  361. * @param md metadata to use
  362. * @return NULL on error, otherwise a KSK URI
  363. */
  364. struct GNUNET_FS_Uri *
  365. GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
  366. *md);
  367. /* ******************** command-line option parsing API *********************** */
  368. /**
  369. * Allow user to specify keywords.
  370. *
  371. * @param shortName short name of the option
  372. * @param name long name of the option
  373. * @param argumentHelp help text for the option argument
  374. * @param description long help text for the option
  375. * @param[out] topKeywords set to the desired value
  376. */
  377. struct GNUNET_GETOPT_CommandLineOption
  378. GNUNET_FS_GETOPT_KEYWORDS (char shortName,
  379. const char *name,
  380. const char *argumentHelp,
  381. const char *description,
  382. struct GNUNET_FS_Uri **topKeywords);
  383. /**
  384. * Allow user to specify metadata.
  385. *
  386. * @param shortName short name of the option
  387. * @param name long name of the option
  388. * @param argumentHelp help text for the option argument
  389. * @param description long help text for the option
  390. * @param[out] metadata set to the desired value
  391. */
  392. struct GNUNET_GETOPT_CommandLineOption
  393. GNUNET_FS_GETOPT_METADATA (char shortName,
  394. const char *name,
  395. const char *argumentHelp,
  396. const char *description,
  397. struct GNUNET_CONTAINER_MetaData **meta);
  398. /**
  399. * Command-line option parser function that allows the user to specify
  400. * one or more '-m' options with metadata. Each specified entry of
  401. * the form "type=value" will be added to the metadata. A pointer to
  402. * the metadata must be passed as the "scls" argument.
  403. *
  404. * @param ctx command line processor context
  405. * @param scls must be of type `struct GNUNET_CONTAINER_MetaData **`
  406. * @param option name of the option (typically 'k')
  407. * @param value command line argument given
  408. * @return #GNUNET_OK on success
  409. */
  410. int
  411. GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
  412. void *scls,
  413. const char *option,
  414. const char *value);
  415. /* ************************* sharing API ***************** */
  416. /**
  417. * Possible status codes used in the callback for the
  418. * various file-sharing operations. On each file (or search),
  419. * the callback is guaranteed to be called once with "START"
  420. * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
  421. * are optional and depend on the circumstances; parent operations
  422. * will be STARTED before child-operations and STOPPED after
  423. * their respective child-operations. START and STOP signals
  424. * are typically generated either due to explicit client requests
  425. * or because of suspend/resume operations.
  426. */
  427. enum GNUNET_FS_Status
  428. {
  429. /**
  430. * Notification that we have started to publish a file structure.
  431. */
  432. GNUNET_FS_STATUS_PUBLISH_START = 0,
  433. /**
  434. * Notification that we have resumed sharing a file structure.
  435. */
  436. GNUNET_FS_STATUS_PUBLISH_RESUME = 1,
  437. /**
  438. * Notification that we have suspended sharing a file structure.
  439. */
  440. GNUNET_FS_STATUS_PUBLISH_SUSPEND = 2,
  441. /**
  442. * Notification that we are making progress sharing a file structure.
  443. */
  444. GNUNET_FS_STATUS_PUBLISH_PROGRESS = 3,
  445. /**
  446. * Notification that an error was encountered sharing a file structure.
  447. * The application will continue to receive resume/suspend events for
  448. * this structure until "GNUNET_FS_publish_stop" is called.
  449. */
  450. GNUNET_FS_STATUS_PUBLISH_ERROR = 4,
  451. /**
  452. * Notification that we completed sharing a file structure.
  453. * The application will continue to receive resume/suspend events for
  454. * this structure until "GNUNET_FS_publish_stop" is called.
  455. */
  456. GNUNET_FS_STATUS_PUBLISH_COMPLETED = 5,
  457. /**
  458. * Notification that we have stopped
  459. * the process of uploading a file structure; no
  460. * futher events will be generated for this action.
  461. */
  462. GNUNET_FS_STATUS_PUBLISH_STOPPED = 6,
  463. /**
  464. * Notification that we have started this download.
  465. */
  466. GNUNET_FS_STATUS_DOWNLOAD_START = 7,
  467. /**
  468. * Notification that this download is being resumed.
  469. */
  470. GNUNET_FS_STATUS_DOWNLOAD_RESUME = 8,
  471. /**
  472. * Notification that this download was suspended.
  473. */
  474. GNUNET_FS_STATUS_DOWNLOAD_SUSPEND = 9,
  475. /**
  476. * Notification about progress with this download.
  477. */
  478. GNUNET_FS_STATUS_DOWNLOAD_PROGRESS = 10,
  479. /**
  480. * Notification that this download encountered an error.
  481. */
  482. GNUNET_FS_STATUS_DOWNLOAD_ERROR = 11,
  483. /**
  484. * Notification that this download completed. Note that for
  485. * directories, completion does not imply completion of all files in
  486. * the directory.
  487. */
  488. GNUNET_FS_STATUS_DOWNLOAD_COMPLETED = 12,
  489. /**
  490. * Notification that this download was stopped
  491. * (final event with respect to this action).
  492. */
  493. GNUNET_FS_STATUS_DOWNLOAD_STOPPED = 13,
  494. /**
  495. * Notification that this download is now actively being
  496. * pursued (as opposed to waiting in the queue).
  497. */
  498. GNUNET_FS_STATUS_DOWNLOAD_ACTIVE = 14,
  499. /**
  500. * Notification that this download is no longer actively
  501. * being pursued (back in the queue).
  502. */
  503. GNUNET_FS_STATUS_DOWNLOAD_INACTIVE = 15,
  504. /**
  505. * Notification that this download is no longer part of a
  506. * recursive download or search but now a 'stand-alone'
  507. * download (and may thus need to be moved in the GUI
  508. * into a different category).
  509. */
  510. GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT = 16,
  511. /**
  512. * First event generated when a client requests
  513. * a search to begin or when a namespace result
  514. * automatically triggers the search for updates.
  515. */
  516. GNUNET_FS_STATUS_SEARCH_START = 17,
  517. /**
  518. * Last event when a search is being resumed;
  519. * note that "GNUNET_FS_SEARCH_START" will not
  520. * be generated in this case.
  521. */
  522. GNUNET_FS_STATUS_SEARCH_RESUME = 18,
  523. /**
  524. * Event generated for each search result
  525. * when the respective search is resumed.
  526. */
  527. GNUNET_FS_STATUS_SEARCH_RESUME_RESULT = 19,
  528. /**
  529. * Last event when a search is being suspended;
  530. * note that "GNUNET_FS_SEARCH_STOPPED" will not
  531. * be generated in this case.
  532. */
  533. GNUNET_FS_STATUS_SEARCH_SUSPEND = 20,
  534. /**
  535. * This search has yielded a result.
  536. */
  537. GNUNET_FS_STATUS_SEARCH_RESULT = 21,
  538. /**
  539. * We have discovered a new namespace.
  540. */
  541. GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE = 22,
  542. /**
  543. * We have additional data about the quality
  544. * or availability of a search result.
  545. */
  546. GNUNET_FS_STATUS_SEARCH_UPDATE = 23,
  547. /**
  548. * Signals a problem with this search.
  549. */
  550. GNUNET_FS_STATUS_SEARCH_ERROR = 24,
  551. /**
  552. * Signals that this search was paused.
  553. */
  554. GNUNET_FS_STATUS_SEARCH_PAUSED = 25,
  555. /**
  556. * Signals that this search was continued (unpaused).
  557. */
  558. GNUNET_FS_STATUS_SEARCH_CONTINUED = 26,
  559. /**
  560. * Event generated for each search result
  561. * when the respective search is stopped.
  562. */
  563. GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED = 27,
  564. /**
  565. * Event generated for each search result
  566. * when the respective search is suspended.
  567. */
  568. GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND = 28,
  569. /**
  570. * Last message from a search; this signals
  571. * that there will be no further events associated
  572. * with this search.
  573. */
  574. GNUNET_FS_STATUS_SEARCH_STOPPED = 29,
  575. /**
  576. * Notification that we started to unindex a file.
  577. */
  578. GNUNET_FS_STATUS_UNINDEX_START = 30,
  579. /**
  580. * Notification that we resumed unindexing of a file.
  581. */
  582. GNUNET_FS_STATUS_UNINDEX_RESUME = 31,
  583. /**
  584. * Notification that we suspended unindexing a file.
  585. */
  586. GNUNET_FS_STATUS_UNINDEX_SUSPEND = 32,
  587. /**
  588. * Notification that we made progress unindexing a file.
  589. */
  590. GNUNET_FS_STATUS_UNINDEX_PROGRESS = 33,
  591. /**
  592. * Notification that we encountered an error unindexing
  593. * a file.
  594. */
  595. GNUNET_FS_STATUS_UNINDEX_ERROR = 34,
  596. /**
  597. * Notification that the unindexing of this file
  598. * was completed.
  599. */
  600. GNUNET_FS_STATUS_UNINDEX_COMPLETED = 35,
  601. /**
  602. * Notification that the unindexing of this file
  603. * was stopped (final event for this action).
  604. */
  605. GNUNET_FS_STATUS_UNINDEX_STOPPED = 36,
  606. /**
  607. * Notification that we are making progress sharing a directory.
  608. */
  609. GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY = 37
  610. };
  611. /**
  612. * Handle for controlling an upload.
  613. */
  614. struct GNUNET_FS_PublishContext;
  615. /**
  616. * Handle for controlling an unindexing operation.
  617. */
  618. struct GNUNET_FS_UnindexContext;
  619. /**
  620. * Handle for controlling a search.
  621. */
  622. struct GNUNET_FS_SearchContext;
  623. /**
  624. * Result from a search. Opaque handle to refer to the search
  625. * (typically used when starting a download associated with the search
  626. * result).
  627. */
  628. struct GNUNET_FS_SearchResult;
  629. /**
  630. * Context for controlling a download.
  631. */
  632. struct GNUNET_FS_DownloadContext;
  633. /**
  634. * Handle for detail information about a file that is being publishd.
  635. * Specifies metadata, keywords, how to get the contents of the file
  636. * (i.e. data-buffer in memory, filename on disk) and other options.
  637. */
  638. struct GNUNET_FS_FileInformation;
  639. /**
  640. * Argument given to the progress callback with
  641. * information about what is going on.
  642. */
  643. struct GNUNET_FS_ProgressInfo
  644. {
  645. /**
  646. * Values that depend on the event type.
  647. */
  648. union
  649. {
  650. /**
  651. * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
  652. */
  653. struct
  654. {
  655. /**
  656. * Context for controlling the upload.
  657. */
  658. struct GNUNET_FS_PublishContext *pc;
  659. /**
  660. * Information about the file that is being publishd.
  661. */
  662. const struct GNUNET_FS_FileInformation *fi;
  663. /**
  664. * Client context pointer (set the last time by the client for
  665. * this operation; initially NULL on START/RESUME events).
  666. */
  667. void *cctx;
  668. /**
  669. * Client context pointer for the parent operation
  670. * (if this is a file in a directory or a subdirectory).
  671. */
  672. void *pctx;
  673. /**
  674. * Name of the file being published; can be NULL.
  675. */
  676. const char *filename;
  677. /**
  678. * How large is the file overall? For directories,
  679. * this is only the size of the directory itself,
  680. * not of the other files contained within the
  681. * directory.
  682. */
  683. uint64_t size;
  684. /**
  685. * At what time do we expect to finish the upload?
  686. * (will be a value in the past for completed
  687. * uploads).
  688. */
  689. struct GNUNET_TIME_Relative eta;
  690. /**
  691. * How long has this upload been actively running
  692. * (excludes times where the upload was suspended).
  693. */
  694. struct GNUNET_TIME_Relative duration;
  695. /**
  696. * How many bytes have we completed?
  697. */
  698. uint64_t completed;
  699. /**
  700. * What anonymity level is used for this upload?
  701. */
  702. uint32_t anonymity;
  703. /**
  704. * Additional values for specific events.
  705. */
  706. union
  707. {
  708. /**
  709. * These values are only valid for
  710. * #GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
  711. */
  712. struct
  713. {
  714. /**
  715. * Data block we just published.
  716. */
  717. const void *data;
  718. /**
  719. * At what offset in the file is "data"?
  720. */
  721. uint64_t offset;
  722. /**
  723. * Length of the data block.
  724. */
  725. uint64_t data_len;
  726. /**
  727. * Depth of the given block in the tree;
  728. * 0 would be the lowest level (DBLOCKs).
  729. */
  730. unsigned int depth;
  731. } progress;
  732. /**
  733. * These values are only valid for
  734. * #GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY events.
  735. */
  736. struct
  737. {
  738. /**
  739. * How far are we along in the overall directory?
  740. */
  741. uint64_t completed;
  742. /**
  743. * How big do we estimate the entire directory to be?
  744. */
  745. uint64_t total;
  746. /**
  747. * At what time do we expect to finish the upload of the
  748. * CONTENTS of the directory. (The direcory itself will take
  749. * extra time, indicated with the "eta" member at the
  750. * "publish"-level of this struct.)
  751. */
  752. struct GNUNET_TIME_Relative eta;
  753. } progress_directory;
  754. /**
  755. * These values are only valid for
  756. * #GNUNET_FS_STATUS_PUBLISH_RESUME events.
  757. */
  758. struct
  759. {
  760. /**
  761. * Error message, NULL if no error was encountered so far.
  762. */
  763. const char *message;
  764. /**
  765. * URI of the file (if the download had been completed)
  766. */
  767. const struct GNUNET_FS_Uri *chk_uri;
  768. /**
  769. * SKS URI of the file (if the download had been completed)
  770. */
  771. const struct GNUNET_FS_Uri *sks_uri;
  772. } resume;
  773. /**
  774. * These values are only valid for
  775. * #GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
  776. */
  777. struct
  778. {
  779. /**
  780. * CHK URI of the file.
  781. */
  782. const struct GNUNET_FS_Uri *chk_uri;
  783. /**
  784. * SKS URI of the file (if the download had been completed)
  785. */
  786. const struct GNUNET_FS_Uri *sks_uri;
  787. } completed;
  788. /**
  789. * These values are only valid for
  790. * #GNUNET_FS_STATUS_PUBLISH_ERROR events.
  791. */
  792. struct
  793. {
  794. /**
  795. * Error message, never NULL.
  796. */
  797. const char *message;
  798. } error;
  799. } specifics;
  800. } publish;
  801. /**
  802. * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
  803. */
  804. struct
  805. {
  806. /**
  807. * Context for controlling the download.
  808. */
  809. struct GNUNET_FS_DownloadContext *dc;
  810. /**
  811. * Client context pointer (set the last time
  812. * by the client for this operation; initially
  813. * NULL on START/RESUME events).
  814. */
  815. void *cctx;
  816. /**
  817. * Client context pointer for the parent operation
  818. * (if this is a file in a directory or a subdirectory).
  819. */
  820. void *pctx;
  821. /**
  822. * Client context pointer for the associated search operation
  823. * (specifically, context pointer for the specific search
  824. * result, not the overall search); only set if this
  825. * download was started from a search result.
  826. */
  827. void *sctx;
  828. /**
  829. * URI used for this download.
  830. */
  831. const struct GNUNET_FS_Uri *uri;
  832. /**
  833. * Name of the file that we are downloading.
  834. */
  835. const char *filename;
  836. /**
  837. * How large is the download overall? This
  838. * is NOT necessarily the size from the
  839. * URI since we may be doing a partial download.
  840. */
  841. uint64_t size;
  842. /**
  843. * At what time do we expect to finish the download?
  844. * (will be a value in the past for completed
  845. * uploads).
  846. */
  847. struct GNUNET_TIME_Relative eta;
  848. /**
  849. * How long has this download been active?
  850. */
  851. struct GNUNET_TIME_Relative duration;
  852. /**
  853. * How many bytes have we completed?
  854. */
  855. uint64_t completed;
  856. /**
  857. * What anonymity level is used for this download?
  858. */
  859. uint32_t anonymity;
  860. /**
  861. * Is the download currently active.
  862. */
  863. int is_active;
  864. /**
  865. * Additional values for specific events.
  866. */
  867. union
  868. {
  869. /**
  870. * These values are only valid for
  871. * #GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
  872. */
  873. struct
  874. {
  875. /**
  876. * Data block we just obtained, can be NULL (even if
  877. * data_len > 0) if we found the entire block 'intact' on
  878. * disk. In this case, it is also possible for 'data_len'
  879. * to be larger than an individual (32k) block.
  880. */
  881. const void *data;
  882. /**
  883. * At what offset in the file is "data"?
  884. */
  885. uint64_t offset;
  886. /**
  887. * Length of the data block.
  888. */
  889. uint64_t data_len;
  890. /**
  891. * How much time passed between us asking for this block and
  892. * actually getting it? #GNUNET_TIME_UNIT_FOREVER_REL if unknown.
  893. */
  894. struct GNUNET_TIME_Relative block_download_duration;
  895. /**
  896. * Depth of the given block in the tree;
  897. * 0 would be the lowest level (DBLOCKS).
  898. */
  899. unsigned int depth;
  900. /**
  901. * How much respect did we offer for downloading this block? (estimate,
  902. * because we might have the same request pending for multiple clients,
  903. * and of course because a transmission may have failed at a lower
  904. * layer).
  905. */
  906. uint32_t respect_offered;
  907. /**
  908. * How often did we transmit the request? (estimate,
  909. * because we might have the same request pending for multiple clients,
  910. * and of course because a transmission may have failed at a lower
  911. * layer).
  912. */
  913. uint32_t num_transmissions;
  914. } progress;
  915. /**
  916. * These values are only valid for
  917. * #GNUNET_FS_STATUS_DOWNLOAD_START events.
  918. */
  919. struct
  920. {
  921. /**
  922. * Known metadata for the download.
  923. */
  924. const struct GNUNET_CONTAINER_MetaData *meta;
  925. } start;
  926. /**
  927. * These values are only valid for
  928. * #GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
  929. */
  930. struct
  931. {
  932. /**
  933. * Known metadata for the download.
  934. */
  935. const struct GNUNET_CONTAINER_MetaData *meta;
  936. /**
  937. * Error message, NULL if we have not encountered any error yet.
  938. */
  939. const char *message;
  940. } resume;
  941. /**
  942. * These values are only valid for
  943. * #GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
  944. */
  945. struct
  946. {
  947. /**
  948. * Error message.
  949. */
  950. const char *message;
  951. } error;
  952. } specifics;
  953. } download;
  954. /**
  955. * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
  956. */
  957. struct
  958. {
  959. /**
  960. * Context for controlling the search, NULL for
  961. * searches that were not explicitly triggered
  962. * by the client (i.e., searches for updates in
  963. * namespaces).
  964. */
  965. struct GNUNET_FS_SearchContext *sc;
  966. /**
  967. * Client context pointer (set the last time by the client for
  968. * this operation; initially NULL on START/RESUME events). Note
  969. * that this value can only be set on START/RESUME; returning
  970. * non-NULL on RESULT/RESUME_RESULT will actually update the
  971. * private context for "UPDATE" events.
  972. */
  973. void *cctx;
  974. /**
  975. * Client parent-context pointer; NULL for top-level searches,
  976. * refers to the client context of the associated search result
  977. * for automatically triggered searches for updates in
  978. * namespaces. In this case, 'presult' refers to that search
  979. * result.
  980. */
  981. void *pctx;
  982. /**
  983. * What query is used for this search
  984. * (list of keywords or SKS identifier).
  985. */
  986. const struct GNUNET_FS_Uri *query;
  987. /**
  988. * How long has this search been actively running
  989. * (excludes times where the search was paused or
  990. * suspended).
  991. */
  992. struct GNUNET_TIME_Relative duration;
  993. /**
  994. * What anonymity level is used for this search?
  995. */
  996. uint32_t anonymity;
  997. /**
  998. * Additional values for specific events.
  999. */
  1000. union
  1001. {
  1002. /**
  1003. * These values are only valid for
  1004. * #GNUNET_FS_STATUS_SEARCH_RESULT events.
  1005. */
  1006. struct
  1007. {
  1008. /**
  1009. * Metadata for the search result.
  1010. */
  1011. const struct GNUNET_CONTAINER_MetaData *meta;
  1012. /**
  1013. * URI for the search result.
  1014. */
  1015. const struct GNUNET_FS_Uri *uri;
  1016. /**
  1017. * Handle to the result (for starting downloads).
  1018. */
  1019. struct GNUNET_FS_SearchResult *result;
  1020. /**
  1021. * Applicability rank (the larger, the better the result
  1022. * fits the search criteria).
  1023. */
  1024. uint32_t applicability_rank;
  1025. } result;
  1026. /**
  1027. * These values are only valid for
  1028. * #GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
  1029. */
  1030. struct
  1031. {
  1032. /**
  1033. * Metadata for the search result.
  1034. */
  1035. const struct GNUNET_CONTAINER_MetaData *meta;
  1036. /**
  1037. * URI for the search result.
  1038. */
  1039. const struct GNUNET_FS_Uri *uri;
  1040. /**
  1041. * Handle to the result (for starting downloads).
  1042. */
  1043. struct GNUNET_FS_SearchResult *result;
  1044. /**
  1045. * Current availability rank (negative:
  1046. * unavailable, positive: available)
  1047. */
  1048. int32_t availability_rank;
  1049. /**
  1050. * On how many total queries is the given
  1051. * availability_rank based?
  1052. */
  1053. uint32_t availability_certainty;
  1054. /**
  1055. * Updated applicability rank (the larger,
  1056. * the better the result fits the search
  1057. * criteria).
  1058. */
  1059. uint32_t applicability_rank;
  1060. } resume_result;
  1061. /**
  1062. * These values are only valid for
  1063. * #GNUNET_FS_STATUS_SEARCH_UPDATE events.
  1064. */
  1065. struct
  1066. {
  1067. /**
  1068. * Private context set for for this result
  1069. * during the "RESULT" event.
  1070. */
  1071. void *cctx;
  1072. /**
  1073. * Metadata for the search result.
  1074. */
  1075. const struct GNUNET_CONTAINER_MetaData *meta;
  1076. /**
  1077. * URI for the search result.
  1078. */
  1079. const struct GNUNET_FS_Uri *uri;
  1080. /**
  1081. * Current availability rank (negative:
  1082. * unavailable, positive: available)
  1083. */
  1084. int32_t availability_rank;
  1085. /**
  1086. * On how many total queries is the given
  1087. * availability_rank based?
  1088. */
  1089. uint32_t availability_certainty;
  1090. /**
  1091. * Updated applicability rank (the larger,
  1092. * the better the result fits the search
  1093. * criteria).
  1094. */
  1095. uint32_t applicability_rank;
  1096. /**
  1097. * How long has the current probe been active?
  1098. */
  1099. struct GNUNET_TIME_Relative current_probe_time;
  1100. } update;
  1101. /**
  1102. * These values are only valid for
  1103. * #GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
  1104. * These events are automatically triggered for
  1105. * each search result before the
  1106. * #GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
  1107. * happens primarily to give the client a chance
  1108. * to clean up the "cctx" (if needed).
  1109. */
  1110. struct
  1111. {
  1112. /**
  1113. * Private context set for for this result
  1114. * during the "RESULT" event.
  1115. */
  1116. void *cctx;
  1117. /**
  1118. * Metadata for the search result.
  1119. */
  1120. const struct GNUNET_CONTAINER_MetaData *meta;
  1121. /**
  1122. * URI for the search result.
  1123. */
  1124. const struct GNUNET_FS_Uri *uri;
  1125. } result_suspend;
  1126. /**
  1127. * These values are only valid for
  1128. * #GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
  1129. * These events are automatically triggered for
  1130. * each search result before the
  1131. * #GNUNET_FS_STATUS_SEARCH_STOPPED event. This
  1132. * happens primarily to give the client a chance
  1133. * to clean up the "cctx" (if needed).
  1134. */
  1135. struct
  1136. {
  1137. /**
  1138. * Private context set for for this result
  1139. * during the "RESULT" event.
  1140. */
  1141. void *cctx;
  1142. /**
  1143. * Metadata for the search result.
  1144. */
  1145. const struct GNUNET_CONTAINER_MetaData *meta;
  1146. /**
  1147. * URI for the search result.
  1148. */
  1149. const struct GNUNET_FS_Uri *uri;
  1150. } result_stopped;
  1151. /**
  1152. * These values are only valid for
  1153. * #GNUNET_FS_STATUS_SEARCH_RESUME events.
  1154. */
  1155. struct
  1156. {
  1157. /**
  1158. * Error message, NULL if we have not encountered any error yet.
  1159. */
  1160. const char *message;
  1161. /**
  1162. * Is this search currently paused?
  1163. */
  1164. int is_paused;
  1165. } resume;
  1166. /**
  1167. * These values are only valid for
  1168. * #GNUNET_FS_STATUS_SEARCH_ERROR events.
  1169. */
  1170. struct
  1171. {
  1172. /**
  1173. * Error message.
  1174. */
  1175. const char *message;
  1176. } error;
  1177. /**
  1178. * Values for #GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE events.
  1179. */
  1180. struct
  1181. {
  1182. /**
  1183. * Short, human-readable name of the namespace.
  1184. */
  1185. const char *name;
  1186. /**
  1187. * Root identifier for the namespace, can be NULL.
  1188. */
  1189. const char *root;
  1190. /**
  1191. * Metadata for the namespace.
  1192. */
  1193. const struct GNUNET_CONTAINER_MetaData *meta;
  1194. /**
  1195. * Public key of the namespace.
  1196. */
  1197. struct GNUNET_CRYPTO_EcdsaPublicKey pseudonym;
  1198. } ns;
  1199. } specifics;
  1200. } search;
  1201. /**
  1202. * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
  1203. */
  1204. struct
  1205. {
  1206. /**
  1207. * Context for controlling the unindexing.
  1208. */
  1209. struct GNUNET_FS_UnindexContext *uc;
  1210. /**
  1211. * Client context pointer (set the last time
  1212. * by the client for this operation; initially
  1213. * NULL on START/RESUME events).
  1214. */
  1215. void *cctx;
  1216. /**
  1217. * Name of the file that is being unindexed.
  1218. */
  1219. const char *filename;
  1220. /**
  1221. * How large is the file overall?
  1222. */
  1223. uint64_t size;
  1224. /**
  1225. * At what time do we expect to finish unindexing?
  1226. * (will be a value in the past for completed
  1227. * unindexing opeations).
  1228. */
  1229. struct GNUNET_TIME_Relative eta;
  1230. /**
  1231. * How long has this upload been actively running
  1232. * (excludes times where the upload was suspended).
  1233. */
  1234. struct GNUNET_TIME_Relative duration;
  1235. /**
  1236. * How many bytes have we completed?
  1237. */
  1238. uint64_t completed;
  1239. /**
  1240. * Additional values for specific events.
  1241. */
  1242. union
  1243. {
  1244. /**
  1245. * These values are only valid for
  1246. * #GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
  1247. */
  1248. struct
  1249. {
  1250. /**
  1251. * Data block we just unindexed.
  1252. */
  1253. const void *data;
  1254. /**
  1255. * At what offset in the file is "data"?
  1256. */
  1257. uint64_t offset;
  1258. /**
  1259. * Length of the data block.
  1260. */
  1261. uint64_t data_len;
  1262. /**
  1263. * Depth of the given block in the tree;
  1264. * 0 would be the lowest level (DBLOCKS).
  1265. */
  1266. unsigned int depth;
  1267. } progress;
  1268. /**
  1269. * These values are only valid for
  1270. * #GNUNET_FS_STATUS_UNINDEX_RESUME events.
  1271. */
  1272. struct
  1273. {
  1274. /**
  1275. * Error message, NULL if we have not encountered any error yet.
  1276. */
  1277. const char *message;
  1278. } resume;
  1279. /**
  1280. * These values are only valid for
  1281. * #GNUNET_FS_STATUS_UNINDEX_ERROR events.
  1282. */
  1283. struct
  1284. {
  1285. /**
  1286. * Error message.
  1287. */
  1288. const char *message;
  1289. } error;
  1290. } specifics;
  1291. } unindex;
  1292. } value;
  1293. /**
  1294. * Specific status code (determines the event type).
  1295. */
  1296. enum GNUNET_FS_Status status;
  1297. /**
  1298. * File-sharing handle that generated the event.
  1299. */
  1300. struct GNUNET_FS_Handle *fsh;
  1301. };
  1302. /**
  1303. * Notification of FS to a client about the progress of an
  1304. * operation. Callbacks of this type will be used for uploads,
  1305. * downloads and searches. Some of the arguments depend a bit
  1306. * in their meaning on the context in which the callback is used.
  1307. *
  1308. * @param cls closure
  1309. * @param info details about the event, specifying the event type
  1310. * and various bits about the event
  1311. * @return client-context (for the next progress call
  1312. * for this operation; should be set to NULL for
  1313. * SUSPEND and STOPPED events). The value returned
  1314. * will be passed to future callbacks in the respective
  1315. * field in the `struct GNUNET_FS_ProgressInfo`.
  1316. */
  1317. typedef void *
  1318. (*GNUNET_FS_ProgressCallback) (void *cls,
  1319. const struct GNUNET_FS_ProgressInfo *info);
  1320. /**
  1321. * General (global) option flags for file-sharing.
  1322. */
  1323. enum GNUNET_FS_Flags
  1324. {
  1325. /**
  1326. * No special flags set.
  1327. */
  1328. GNUNET_FS_FLAGS_NONE = 0,
  1329. /**
  1330. * Is persistence of operations desired?
  1331. * (will create SUSPEND/RESUME events).
  1332. */
  1333. GNUNET_FS_FLAGS_PERSISTENCE = 1,
  1334. /**
  1335. * Should we automatically trigger probes for search results
  1336. * to determine availability?
  1337. * (will create #GNUNET_FS_STATUS_SEARCH_UPDATE events).
  1338. */
  1339. GNUNET_FS_FLAGS_DO_PROBES = 2
  1340. };
  1341. /**
  1342. * Options specified in the VARARGs portion of GNUNET_FS_start.
  1343. */
  1344. enum GNUNET_FS_OPTIONS
  1345. {
  1346. /**
  1347. * Last option in the VARARG list.
  1348. */
  1349. GNUNET_FS_OPTIONS_END = 0,
  1350. /**
  1351. * Select the desired amount of parallelism (this option should be
  1352. * followed by an "unsigned int" giving the desired maximum number
  1353. * of parallel downloads).
  1354. */
  1355. GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
  1356. /**
  1357. * Maximum number of requests that should be pending at a given
  1358. * point in time (invidivual downloads may go above this, but
  1359. * if we are above this threshold, we should not activate any
  1360. * additional downloads.
  1361. */
  1362. GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
  1363. };
  1364. /**
  1365. * Settings for publishing a block (which may of course also
  1366. * apply to an entire directory or file).
  1367. */
  1368. struct GNUNET_FS_BlockOptions
  1369. {
  1370. /**
  1371. * At what time should the block expire? Data blocks (DBLOCKS and
  1372. * IBLOCKS) may still be used even if they are expired (however,
  1373. * they'd be removed quickly from the datastore if we are short on
  1374. * space), all other types of blocks will no longer be returned
  1375. * after they expire.
  1376. */
  1377. struct GNUNET_TIME_Absolute expiration_time;
  1378. /**
  1379. * At which anonymity level should the block be shared?
  1380. * (0: no anonymity, 1: normal GAP, >1: with cover traffic).
  1381. */
  1382. uint32_t anonymity_level;
  1383. /**
  1384. * How important is it for us to store the block? If we run
  1385. * out of space, the highest-priority, non-expired blocks will
  1386. * be kept.
  1387. */
  1388. uint32_t content_priority;
  1389. /**
  1390. * How often should we try to migrate the block to other peers?
  1391. * Only used if "CONTENT_PUSHING" is set to YES, in which case we
  1392. * first push each block to other peers according to their
  1393. * replication levels. Once each block has been pushed that many
  1394. * times to other peers, blocks are chosen for migration at random.
  1395. * Naturally, there is no guarantee that the other peers will keep
  1396. * these blocks for any period of time (since they won't have any
  1397. * priority or might be too busy to even store the block in the
  1398. * first place).
  1399. */
  1400. uint32_t replication_level;
  1401. };
  1402. /**
  1403. * Handle to the file-sharing service.
  1404. */
  1405. struct GNUNET_FS_Handle;
  1406. /**
  1407. * Setup a connection to the file-sharing service.
  1408. *
  1409. * @param cfg configuration to use
  1410. * @param client_name unique identifier for this client
  1411. * @param upcb function to call to notify about FS actions
  1412. * @param upcb_cls closure for @a upcb
  1413. * @param flags specific attributes for fs-operations
  1414. * @param ... list of optional options, terminated with #GNUNET_FS_OPTIONS_END
  1415. * @return NULL on error
  1416. */
  1417. struct GNUNET_FS_Handle *
  1418. GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
  1419. const char *client_name,
  1420. GNUNET_FS_ProgressCallback upcb,
  1421. void *upcb_cls,
  1422. enum GNUNET_FS_Flags flags,
  1423. ...);
  1424. /**
  1425. * Close our connection with the file-sharing service.
  1426. * The callback given to #GNUNET_FS_start() will no longer be
  1427. * called after this function returns.
  1428. * This function MUST NOT be called from within the
  1429. * callback itself.
  1430. *
  1431. * @param h handle that was returned from #GNUNET_FS_start()
  1432. */
  1433. void
  1434. GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
  1435. /**
  1436. * Function called on entries in a `struct GNUNET_FS_FileInformation` iteration.
  1437. *
  1438. * @param cls closure
  1439. * @param fi the entry in the publish-structure
  1440. * @param length length of the file or directory
  1441. * @param meta metadata for the file or directory (can be modified)
  1442. * @param uri pointer to the keywords that will be used for this entry (can be modified)
  1443. * @param bo block options (can be modified)
  1444. * @param do_index should we index (can be modified)
  1445. * @param client_info pointer to client context set upon creation (can be modified)
  1446. * @return #GNUNET_OK to continue, #GNUNET_NO to remove
  1447. * this entry from the directory, #GNUNET_SYSERR
  1448. * to abort the iteration
  1449. */
  1450. typedef int
  1451. (*GNUNET_FS_FileInformationProcessor) (void *cls,
  1452. struct GNUNET_FS_FileInformation *fi,
  1453. uint64_t length,
  1454. struct GNUNET_CONTAINER_MetaData *meta,
  1455. struct GNUNET_FS_Uri ** uri,
  1456. struct GNUNET_FS_BlockOptions *bo,
  1457. int *do_index,
  1458. void **client_info);
  1459. /**
  1460. * Obtain the name under which this file information
  1461. * structure is stored on disk. Only works for top-level
  1462. * file information structures.
  1463. *
  1464. * @param s structure to get the filename for
  1465. * @return NULL on error, otherwise filename that can be used
  1466. * to read this fi-struct from disk.
  1467. */
  1468. const char *
  1469. GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
  1470. /**
  1471. * Obtain the filename from the file information structure.
  1472. *
  1473. * @param s structure to get the filename for
  1474. * @return "filename" field of the structure (can be NULL)
  1475. */
  1476. const char *
  1477. GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s);
  1478. /**
  1479. * Set the filename in the file information structure.
  1480. * If filename was already set, frees it before setting the new one.
  1481. * Makes a copy of the argument.
  1482. *
  1483. * @param s structure to get the filename for
  1484. * @param filename filename to set
  1485. */
  1486. void
  1487. GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s,
  1488. const char *filename);
  1489. /**
  1490. * Create an entry for a file in a publish-structure.
  1491. *
  1492. * @param h handle to the file sharing subsystem
  1493. * @param client_info initial client-info value for this entry
  1494. * @param filename name of the file or directory to publish
  1495. * @param keywords under which keywords should this file be available
  1496. * directly; can be NULL
  1497. * @param meta metadata for the file
  1498. * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
  1499. * #GNUNET_SYSERR for simulation
  1500. * @param bo block options
  1501. * @return publish structure entry for the file
  1502. */
  1503. struct GNUNET_FS_FileInformation *
  1504. GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
  1505. void *client_info,
  1506. const char *filename,
  1507. const struct GNUNET_FS_Uri *keywords,
  1508. const struct GNUNET_CONTAINER_MetaData *meta,
  1509. int do_index,
  1510. const struct GNUNET_FS_BlockOptions *bo);
  1511. /**
  1512. * Create an entry for a file in a publish-structure.
  1513. *
  1514. * @param h handle to the file sharing subsystem
  1515. * @param client_info initial client-info value for this entry
  1516. * @param length length of the file
  1517. * @param data data for the file (should not be used afterwards by
  1518. * the caller; callee will "free")
  1519. * @param keywords under which keywords should this file be available
  1520. * directly; can be NULL
  1521. * @param meta metadata for the file
  1522. * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
  1523. * #GNUNET_SYSERR for simulation
  1524. * @param bo block options
  1525. * @return publish structure entry for the file
  1526. */
  1527. struct GNUNET_FS_FileInformation *
  1528. GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
  1529. void *client_info,
  1530. uint64_t length,
  1531. void *data,
  1532. const struct GNUNET_FS_Uri *keywords,
  1533. const struct GNUNET_CONTAINER_MetaData *meta,
  1534. int do_index,
  1535. const struct GNUNET_FS_BlockOptions *bo);
  1536. /**
  1537. * Function that provides data.
  1538. *
  1539. * @param cls closure
  1540. * @param offset offset to read from; it is possible
  1541. * that the caller might need to go backwards
  1542. * a bit at times; set to UINT64_MAX to tell
  1543. * the reader that we won't be reading for a while
  1544. * (used to close the file descriptor but NOT fully
  1545. * clean up the reader's state); in this case,
  1546. * a value of '0' for max should be ignored
  1547. * @param max maximum number of bytes that should be
  1548. * copied to buf; readers are not allowed
  1549. * to provide less data unless there is an error;
  1550. * a value of "0" will be used at the end to allow
  1551. * the reader to clean up its internal state
  1552. * @param buf where the reader should write the data
  1553. * @param emsg location for the reader to store an error message
  1554. * @return number of bytes written, usually @a max, 0 on error
  1555. */
  1556. typedef size_t
  1557. (*GNUNET_FS_DataReader) (void *cls,
  1558. uint64_t offset,
  1559. size_t max,
  1560. void *buf,
  1561. char **emsg);
  1562. /**
  1563. * Create an entry for a file in a publish-structure.
  1564. *
  1565. * @param h handle to the file sharing subsystem
  1566. * @param client_info initial client-info value for this entry
  1567. * @param length length of the file
  1568. * @param reader function that can be used to obtain the data for the file
  1569. * @param reader_cls closure for @a reader
  1570. * @param keywords under which keywords should this file be available
  1571. * directly; can be NULL
  1572. * @param meta metadata for the file
  1573. * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
  1574. * #GNUNET_SYSERR for simulation
  1575. * @param bo block options
  1576. * @return publish structure entry for the file
  1577. */
  1578. struct GNUNET_FS_FileInformation *
  1579. GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
  1580. void *client_info,
  1581. uint64_t length,
  1582. GNUNET_FS_DataReader reader,
  1583. void *reader_cls,
  1584. const struct GNUNET_FS_Uri
  1585. *keywords,
  1586. const struct
  1587. GNUNET_CONTAINER_MetaData *meta,
  1588. int do_index,
  1589. const struct
  1590. GNUNET_FS_BlockOptions *bo);
  1591. /**
  1592. * Create an entry for an empty directory in a publish-structure.
  1593. *
  1594. * @param h handle to the file sharing subsystem
  1595. * @param client_info initial client-info value for this entry
  1596. * @param keywords under which keywords should this directory be available
  1597. * directly; can be NULL
  1598. * @param meta metadata for the directory
  1599. * @param bo block options
  1600. * @param filename name of the directory; can be NULL
  1601. * @return publish structure entry for the directory , NULL on error
  1602. */
  1603. struct GNUNET_FS_FileInformation *
  1604. GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
  1605. void *client_info,
  1606. const struct GNUNET_FS_Uri
  1607. *keywords,
  1608. const struct
  1609. GNUNET_CONTAINER_MetaData
  1610. *meta,
  1611. const struct
  1612. GNUNET_FS_BlockOptions *bo,
  1613. const char *filename);
  1614. /**
  1615. * Test if a given entry represents a directory.
  1616. *
  1617. * @param ent check if this FI represents a directory
  1618. * @return #GNUNET_YES if so, #GNUNET_NO if not
  1619. */
  1620. int
  1621. GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
  1622. *ent);
  1623. /**
  1624. * Add an entry to a directory in a publish-structure. Clients
  1625. * should never modify publish structures that were passed to
  1626. * #GNUNET_FS_publish_start() already.
  1627. *
  1628. * @param dir the directory
  1629. * @param ent the entry to add; the entry must not have been
  1630. * added to any other directory at this point and
  1631. * must not include @a dir in its structure
  1632. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  1633. */
  1634. int
  1635. GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
  1636. struct GNUNET_FS_FileInformation *ent);
  1637. /**
  1638. * Inspect a file or directory in a publish-structure. Clients
  1639. * should never modify publish structures that were passed to
  1640. * #GNUNET_FS_publish_start already. When called on a directory,
  1641. * this function will FIRST call @a proc with information about
  1642. * the directory itself and then for each of the files in the
  1643. * directory (but not for files in subdirectories). When called
  1644. * on a file, @a proc will be called exactly once (with information
  1645. * about the specific file).
  1646. *
  1647. * @param dir the directory
  1648. * @param proc function to call on each entry
  1649. * @param proc_cls closure for @a proc
  1650. */
  1651. void
  1652. GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
  1653. GNUNET_FS_FileInformationProcessor proc,
  1654. void *proc_cls);
  1655. /**
  1656. * Destroy publish-structure. Clients should never destroy publish
  1657. * structures that were passed to #GNUNET_FS_publish_start already.
  1658. *
  1659. * @param fi structure to destroy
  1660. * @param cleaner function to call on each entry in the structure
  1661. * (useful to clean up client_info); can be NULL; return
  1662. * values are ignored
  1663. * @param cleaner_cls closure for @a cleaner
  1664. */
  1665. void
  1666. GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
  1667. GNUNET_FS_FileInformationProcessor cleaner,
  1668. void *cleaner_cls);
  1669. /**
  1670. * Options for publishing. Compatible options
  1671. * can be OR'ed together.
  1672. */
  1673. enum GNUNET_FS_PublishOptions
  1674. {
  1675. /**
  1676. * No options (use defaults for everything).
  1677. */
  1678. GNUNET_FS_PUBLISH_OPTION_NONE = 0,
  1679. /**
  1680. * Simulate publishing. With this option, no data will be stored
  1681. * in the datastore. Useful for computing URIs from files.
  1682. */
  1683. GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
  1684. };
  1685. /**
  1686. * Publish a file or directory.
  1687. *
  1688. * @param h handle to the file sharing subsystem
  1689. * @param fi information about the file or directory structure to publish
  1690. * @param ns namespace to publish the file in, NULL for no namespace
  1691. * @param nid identifier to use for the publishd content in the namespace
  1692. * (can be NULL, must be NULL if namespace is NULL)
  1693. * @param nuid update-identifier that will be used for future updates
  1694. * (can be NULL, must be NULL if namespace or nid is NULL)
  1695. * @param options options for the publication
  1696. * @return context that can be used to control the publish operation
  1697. */
  1698. struct GNUNET_FS_PublishContext *
  1699. GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
  1700. struct GNUNET_FS_FileInformation *fi,
  1701. const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
  1702. const char *nid,
  1703. const char *nuid,
  1704. enum GNUNET_FS_PublishOptions options);
  1705. /**
  1706. * Stop a publication. Will abort incomplete publications (but
  1707. * not remove blocks that have already been published) or
  1708. * simply clean up the state for completed publications.
  1709. * Must NOT be called from within the event callback!
  1710. *
  1711. * @param pc context for the publication to stop
  1712. */
  1713. void
  1714. GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
  1715. /**
  1716. * Signature of a function called as the continuation of a KBlock or
  1717. * SBlock publication.
  1718. *
  1719. * @param cls closure
  1720. * @param uri URI under which the block is now available, NULL on error
  1721. * @param emsg error message, NULL on success
  1722. */
  1723. typedef void
  1724. (*GNUNET_FS_PublishContinuation) (void *cls,
  1725. const struct GNUNET_FS_Uri *uri,
  1726. const char *emsg);
  1727. /**
  1728. * Handle to cancel publish KSK operation.
  1729. */
  1730. struct GNUNET_FS_PublishKskContext;
  1731. /**
  1732. * Publish a KBlock on GNUnet.
  1733. *
  1734. * @param h handle to the file sharing subsystem
  1735. * @param ksk_uri keywords to use
  1736. * @param meta metadata to use
  1737. * @param uri URI to refer to in the KBlock
  1738. * @param bo block options
  1739. * @param options publication options
  1740. * @param cont continuation
  1741. * @param cont_cls closure for @a cont
  1742. * @return NULL on error (@a cont will still be called)
  1743. */
  1744. struct GNUNET_FS_PublishKskContext *
  1745. GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
  1746. const struct GNUNET_FS_Uri *ksk_uri,
  1747. const struct GNUNET_CONTAINER_MetaData *meta,
  1748. const struct GNUNET_FS_Uri *uri,
  1749. const struct GNUNET_FS_BlockOptions *bo,
  1750. enum GNUNET_FS_PublishOptions options,
  1751. GNUNET_FS_PublishContinuation cont, void *cont_cls);
  1752. /**
  1753. * Abort the KSK publishing operation.
  1754. *
  1755. * @param pkc context of the operation to abort.
  1756. */
  1757. void
  1758. GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc);
  1759. /**
  1760. * Handle to cancel publish SKS operation.
  1761. */
  1762. struct GNUNET_FS_PublishSksContext;
  1763. /**
  1764. * Publish an SBlock on GNUnet.
  1765. *
  1766. * @param h handle to the file sharing subsystem
  1767. * @param ns namespace to publish in
  1768. * @param identifier identifier to use
  1769. * @param update update identifier to use
  1770. * @param meta metadata to use
  1771. * @param uri URI to refer to in the SBlock
  1772. * @param bo block options
  1773. * @param options publication options
  1774. * @param cont continuation
  1775. * @param cont_cls closure for @a cont
  1776. * @return NULL on error (@a cont will still be called)
  1777. */
  1778. struct GNUNET_FS_PublishSksContext *
  1779. GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
  1780. const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
  1781. const char *identifier,
  1782. const char *update,
  1783. const struct GNUNET_CONTAINER_MetaData *meta,
  1784. const struct GNUNET_FS_Uri *uri,
  1785. const struct GNUNET_FS_BlockOptions *bo,
  1786. enum GNUNET_FS_PublishOptions options,
  1787. GNUNET_FS_PublishContinuation cont, void *cont_cls);
  1788. /**
  1789. * Abort the SKS publishing operation.
  1790. *
  1791. * @param psc context of the operation to abort.
  1792. */
  1793. void
  1794. GNUNET_FS_publish_sks_cancel (struct GNUNET_FS_PublishSksContext *psc);
  1795. /**
  1796. * Type of a function called by #GNUNET_FS_get_indexed_files.
  1797. *
  1798. * @param cls closure
  1799. * @param filename the name of the file, NULL for end of list
  1800. * @param file_id hash of the contents of the indexed file
  1801. * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
  1802. */
  1803. typedef int
  1804. (*GNUNET_FS_IndexedFileProcessor) (void *cls,
  1805. const char *filename,
  1806. const struct GNUNET_HashCode *file_id);
  1807. /**
  1808. * Handle to cancel 'GNUNET_FS_get_indexed_files'.
  1809. */
  1810. struct GNUNET_FS_GetIndexedContext;
  1811. /**
  1812. * Iterate over all indexed files.
  1813. *
  1814. * @param h handle to the file sharing subsystem
  1815. * @param iterator function to call on each indexed file
  1816. * @param iterator_cls closure for @a iterator
  1817. * @return NULL on error (@a iterator is not called)
  1818. */
  1819. struct GNUNET_FS_GetIndexedContext *
  1820. GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
  1821. GNUNET_FS_IndexedFileProcessor iterator,
  1822. void *iterator_cls);
  1823. /**
  1824. * Cancel iteration over all indexed files.
  1825. *
  1826. * @param gic operation to cancel
  1827. */
  1828. void
  1829. GNUNET_FS_get_indexed_files_cancel (struct GNUNET_FS_GetIndexedContext *gic);
  1830. /**
  1831. * Unindex a file.
  1832. *
  1833. * @param h handle to the file sharing subsystem
  1834. * @param filename file to unindex
  1835. * @param cctx initial value for the client context
  1836. * @return NULL on error, otherwise handle
  1837. */
  1838. struct GNUNET_FS_UnindexContext *
  1839. GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
  1840. const char *filename,
  1841. void *cctx);
  1842. /**
  1843. * Clean up after completion of an unindex operation.
  1844. *
  1845. * @param uc handle
  1846. */
  1847. void
  1848. GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
  1849. /**
  1850. * Function called on updateable identifiers.
  1851. *
  1852. * @param cls closure
  1853. * @param last_id last identifier
  1854. * @param last_uri uri used for the content published under the @a last_id
  1855. * @param last_meta metadata associated with @a last_uri
  1856. * @param next_id identifier that should be used for updates
  1857. */
  1858. typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls,
  1859. const char *last_id,
  1860. const struct GNUNET_FS_Uri *last_uri,
  1861. const struct GNUNET_CONTAINER_MetaData *last_meta,
  1862. const char *next_id);
  1863. /**
  1864. * List all of the identifiers in the namespace for which we could
  1865. * produce an update. Namespace updates form a graph where each node
  1866. * has a name. Each node can have any number of URI/meta-data entries
  1867. * which can each be linked to other nodes. Cycles are possible.
  1868. *
  1869. * Calling this function with @a next_id NULL will cause the library to
  1870. * call @a ip with a root for each strongly connected component of the
  1871. * graph (a root being a node from which all other nodes in the Scc
  1872. * are reachable).
  1873. *
  1874. * Calling this function with @a next_id being the name of a node will
  1875. * cause the library to call @a ip with all children of the node. Note
  1876. * that cycles within an SCC are possible (including self-loops).
  1877. *
  1878. * @param h fs handle to use
  1879. * @param ns namespace to inspect for updateable content
  1880. * @param next_id ID to look for; use NULL to look for SCC roots
  1881. * @param ip function to call on each updateable identifier
  1882. * @param ip_cls closure for @a ip
  1883. */
  1884. void
  1885. GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h,
  1886. const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
  1887. const char *next_id,
  1888. GNUNET_FS_IdentifierProcessor ip,
  1889. void *ip_cls);
  1890. /**
  1891. * Options for searching. Compatible options
  1892. * can be OR'ed together.
  1893. */
  1894. enum GNUNET_FS_SearchOptions
  1895. {
  1896. /**
  1897. * No options (use defaults for everything).
  1898. */
  1899. GNUNET_FS_SEARCH_OPTION_NONE = 0,
  1900. /**
  1901. * Only search the local host, do not search remote systems (no P2P)
  1902. */
  1903. GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
  1904. };
  1905. /**
  1906. * Start search for content.
  1907. *
  1908. * @param h handle to the file sharing subsystem
  1909. * @param uri specifies the search parameters; can be
  1910. * a KSK URI or an SKS URI.
  1911. * @param anonymity desired level of anonymity
  1912. * @param options options for the search
  1913. * @param cctx initial value for the client context
  1914. * @return context that can be used to control the search
  1915. */
  1916. struct GNUNET_FS_SearchContext *
  1917. GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
  1918. const struct GNUNET_FS_Uri *uri, uint32_t anonymity,
  1919. enum GNUNET_FS_SearchOptions options, void *cctx);
  1920. /**
  1921. * Pause search.
  1922. *
  1923. * @param sc context for the search that should be paused
  1924. */
  1925. void
  1926. GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
  1927. /**
  1928. * Continue paused search.
  1929. *
  1930. * @param sc context for the search that should be resumed
  1931. */
  1932. void
  1933. GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
  1934. /**
  1935. * Stop search for content.
  1936. *
  1937. * @param sc context for the search that should be stopped
  1938. */
  1939. void
  1940. GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
  1941. /**
  1942. * Start download probes for the given search result.
  1943. *
  1944. * @param h file-sharing handle to use for the operation
  1945. * @param uri URI to probe
  1946. * @param meta meta data associated with the URI
  1947. * @param client_info client info pointer to use for associated events
  1948. * @param anonymity anonymity level to use for the probes
  1949. * @return the search result handle to access the probe activity
  1950. */
  1951. struct GNUNET_FS_SearchResult *
  1952. GNUNET_FS_probe (struct GNUNET_FS_Handle *h,
  1953. const struct GNUNET_FS_Uri *uri,
  1954. const struct GNUNET_CONTAINER_MetaData *meta,
  1955. void *client_info,
  1956. uint32_t anonymity);
  1957. /**
  1958. * Stop probe activity. Must ONLY be used on values
  1959. * returned from #GNUNET_FS_probe.
  1960. *
  1961. * @param sr search result to stop probing for (freed)
  1962. * @return the value of the 'client_info' pointer
  1963. */
  1964. void *
  1965. GNUNET_FS_probe_stop (struct GNUNET_FS_SearchResult *sr);
  1966. /**
  1967. * Options for downloading. Compatible options
  1968. * can be OR'ed together.
  1969. */
  1970. enum GNUNET_FS_DownloadOptions
  1971. {
  1972. /**
  1973. * No options (use defaults for everything).
  1974. */
  1975. GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
  1976. /**
  1977. * Only download from the local host, do not access remote systems (no P2P)
  1978. */
  1979. GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
  1980. /**
  1981. * Do a recursive download (that is, automatically trigger the
  1982. * download of files in directories).
  1983. */
  1984. GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
  1985. /**
  1986. * Do not append temporary data to
  1987. * the target file (for the IBlocks).
  1988. */
  1989. GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
  1990. /**
  1991. * Internal option used to flag this download as a 'probe' for a
  1992. * search result. Impacts the priority with which the download is
  1993. * run and causes signalling callbacks to be done differently.
  1994. * Also, probe downloads are not serialized on suspension. Normal
  1995. * clients should not use this!
  1996. */
  1997. GNUNET_FS_DOWNLOAD_IS_PROBE = (1 << 31)
  1998. };
  1999. /**
  2000. * Download parts of a file. Note that this will store
  2001. * the blocks at the respective offset in the given file. Also, the
  2002. * download is still using the blocking of the underlying FS
  2003. * encoding. As a result, the download may *write* outside of the
  2004. * given boundaries (if offset and length do not match the 32k FS
  2005. * block boundaries).
  2006. *
  2007. * The given range can be used to focus a download towards a
  2008. * particular portion of the file (optimization), not to strictly
  2009. * limit the download to exactly those bytes.
  2010. *
  2011. * @param h handle to the file sharing subsystem
  2012. * @param uri the URI of the file (determines what to download); CHK or LOC URI
  2013. * @param meta known metadata for the file (can be NULL)
  2014. * @param filename where to store the file, maybe NULL (then no file is
  2015. * created on disk and data must be grabbed from the callbacks)
  2016. * @param tempname where to store temporary file data, not used if filename is non-NULL;
  2017. * can be NULL (in which case we will pick a name if needed); the temporary file
  2018. * may already exist, in which case we will try to use the data that is there and
  2019. * if it is not what is desired, will overwrite it
  2020. * @param offset at what offset should we start the download (typically 0)
  2021. * @param length how many bytes should be downloaded starting at offset
  2022. * @param anonymity anonymity level to use for the download
  2023. * @param options various download options
  2024. * @param cctx initial value for the client context for this download
  2025. * @param parent parent download to associate this download with (use NULL
  2026. * for top-level downloads; useful for manually-triggered recursive downloads)
  2027. * @return context that can be used to control this download
  2028. */
  2029. struct GNUNET_FS_DownloadContext *
  2030. GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
  2031. const struct GNUNET_FS_Uri *uri,
  2032. const struct GNUNET_CONTAINER_MetaData *meta,
  2033. const char *filename, const char *tempname,
  2034. uint64_t offset, uint64_t length, uint32_t anonymity,
  2035. enum GNUNET_FS_DownloadOptions options, void *cctx,
  2036. struct GNUNET_FS_DownloadContext *parent);
  2037. /**
  2038. * Download parts of a file based on a search result. The download
  2039. * will be associated with the search result (and the association
  2040. * will be preserved when serializing/deserializing the state).
  2041. * If the search is stopped, the download will not be aborted but
  2042. * be 'promoted' to a stand-alone download.
  2043. *
  2044. * As with the other download function, this will store
  2045. * the blocks at the respective offset in the given file. Also, the
  2046. * download is still using the blocking of the underlying FS
  2047. * encoding. As a result, the download may *write* outside of the
  2048. * given boundaries (if offset and length do not match the 32k FS
  2049. * block boundaries).
  2050. *
  2051. * The given range can be used to focus a download towards a
  2052. * particular portion of the file (optimization), not to strictly
  2053. * limit the download to exactly those bytes.
  2054. *
  2055. * @param h handle to the file sharing subsystem
  2056. * @param sr the search result to use for the download (determines uri and
  2057. * meta data and associations)
  2058. * @param filename where to store the file, maybe NULL (then no file is
  2059. * created on disk and data must be grabbed from the callbacks)
  2060. * @param tempname where to store temporary file data, not used if filename is non-NULL;
  2061. * can be NULL (in which case we will pick a name if needed); the temporary file
  2062. * may already exist, in which case we will try to use the data that is there and
  2063. * if it is not what is desired, will overwrite it
  2064. * @param offset at what offset should we start the download (typically 0)
  2065. * @param length how many bytes should be downloaded starting at offset
  2066. * @param anonymity anonymity level to use for the download
  2067. * @param options various download options
  2068. * @param cctx initial value for the client context for this download
  2069. * @return context that can be used to control this download
  2070. */
  2071. struct GNUNET_FS_DownloadContext *
  2072. GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
  2073. struct GNUNET_FS_SearchResult *sr,
  2074. const char *filename,
  2075. const char *tempname, uint64_t offset,
  2076. uint64_t length, uint32_t anonymity,
  2077. enum GNUNET_FS_DownloadOptions options,
  2078. void *cctx);
  2079. /**
  2080. * Stop a download (aborts if download is incomplete).
  2081. *
  2082. * @param dc handle for the download
  2083. * @param do_delete delete files of incomplete downloads
  2084. */
  2085. void
  2086. GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete);
  2087. /**
  2088. * Suspend a download.
  2089. *
  2090. * @param dc handle for the download
  2091. */
  2092. void
  2093. GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc);
  2094. /**
  2095. * Resume a suspended download.
  2096. *
  2097. * @param dc handle for the download
  2098. */
  2099. void
  2100. GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc);
  2101. /* ******************** Directory API *********************** */
  2102. #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
  2103. #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
  2104. #define GNUNET_FS_DIRECTORY_EXT ".gnd"
  2105. /**
  2106. * Does the meta-data claim that this is a directory?
  2107. * Checks if the mime-type is that of a GNUnet directory.
  2108. *
  2109. * @return #GNUNET_YES if it is, #GNUNET_NO if it is not, #GNUNET_SYSERR if
  2110. * we have no mime-type information (treat as #GNUNET_NO)
  2111. */
  2112. int
  2113. GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
  2114. *md);
  2115. /**
  2116. * Set the MIMETYPE information for the given
  2117. * metadata to "application/gnunet-directory".
  2118. *
  2119. * @param md metadata to add mimetype to
  2120. */
  2121. void
  2122. GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
  2123. /**
  2124. * Suggest a filename based on given metadata.
  2125. *
  2126. * @param md given meta data
  2127. * @return NULL if meta data is useless for suggesting a filename
  2128. */
  2129. char *
  2130. GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData *md);
  2131. /**
  2132. * Function used to process entries in a directory.
  2133. *
  2134. * @param cls closure
  2135. * @param filename name of the file in the directory
  2136. * @param uri URI of the file
  2137. * @param metadata metadata for the file; metadata for
  2138. * the directory if everything else is NULL/zero
  2139. * @param length length of the available data for the file
  2140. * (of type size_t since data must certainly fit
  2141. * into memory; if files are larger than size_t
  2142. * permits, then they will certainly not be
  2143. * embedded with the directory itself).
  2144. * @param data data available for the file (length bytes)
  2145. */
  2146. typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
  2147. const char *filename,
  2148. const struct GNUNET_FS_Uri *
  2149. uri,
  2150. const struct
  2151. GNUNET_CONTAINER_MetaData *
  2152. meta, size_t length,
  2153. const void *data);
  2154. /**
  2155. * Iterate over all entries in a directory. Note that directories
  2156. * are structured such that it is possible to iterate over the
  2157. * individual blocks as well as over the entire directory. Thus
  2158. * a client can call this function on the buffer in the
  2159. * GNUNET_FS_ProgressCallback. Also, directories can optionally
  2160. * include the contents of (small) files embedded in the directory
  2161. * itself; for those files, the processor may be given the
  2162. * contents of the file directly by this function.
  2163. *
  2164. * @param size number of bytes in data
  2165. * @param data pointer to the beginning of the directory
  2166. * @param offset offset of data in the directory
  2167. * @param dep function to call on each entry
  2168. * @param dep_cls closure for @a dep
  2169. * @return #GNUNET_OK if this could be a block in a directory,
  2170. * #GNUNET_NO if this could be part of a directory (but not 100% OK)
  2171. * #GNUNET_SYSERR if 'data' does not represent a directory
  2172. */
  2173. int
  2174. GNUNET_FS_directory_list_contents (size_t size, const void *data,
  2175. uint64_t offset,
  2176. GNUNET_FS_DirectoryEntryProcessor dep,
  2177. void *dep_cls);
  2178. /**
  2179. * Opaque handle to a directory builder.
  2180. */
  2181. struct GNUNET_FS_DirectoryBuilder;
  2182. /**
  2183. * Create a directory builder.
  2184. *
  2185. * @param mdir metadata for the directory
  2186. */
  2187. struct GNUNET_FS_DirectoryBuilder *
  2188. GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
  2189. *mdir);
  2190. /**
  2191. * Add an entry to a directory.
  2192. *
  2193. * @param bld directory to extend
  2194. * @param uri uri of the entry (must not be a KSK)
  2195. * @param md metadata of the entry
  2196. * @param data raw data of the entry, can be NULL, otherwise
  2197. * data must point to exactly the number of bytes specified
  2198. * by the uri
  2199. */
  2200. void
  2201. GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
  2202. const struct GNUNET_FS_Uri *uri,
  2203. const struct GNUNET_CONTAINER_MetaData *md,
  2204. const void *data);
  2205. /**
  2206. * Finish building the directory. Frees the
  2207. * builder context and returns the directory
  2208. * in-memory.
  2209. *
  2210. * @param bld directory to finish
  2211. * @param rsize set to the number of bytes needed
  2212. * @param rdata set to the encoded directory
  2213. * @return #GNUNET_OK on success
  2214. */
  2215. int
  2216. GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
  2217. size_t * rsize, void **rdata);
  2218. /* ******************** DirScanner API *********************** */
  2219. /**
  2220. * Progress reasons of the directory scanner.
  2221. */
  2222. enum GNUNET_FS_DirScannerProgressUpdateReason
  2223. {
  2224. /**
  2225. * We've started processing a file or directory.
  2226. */
  2227. GNUNET_FS_DIRSCANNER_FILE_START = 0,
  2228. /**
  2229. * We're having trouble accessing a file (soft-error); it will
  2230. * be ignored.
  2231. */
  2232. GNUNET_FS_DIRSCANNER_FILE_IGNORED,
  2233. /**
  2234. * We've found all files (in the pre-pass).
  2235. */
  2236. GNUNET_FS_DIRSCANNER_ALL_COUNTED,
  2237. /**
  2238. * We've finished extracting meta data from a file.
  2239. */
  2240. GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED,
  2241. /**
  2242. * Last call to the progress function: we have finished scanning
  2243. * the directory.
  2244. */
  2245. GNUNET_FS_DIRSCANNER_FINISHED,
  2246. /**
  2247. * There was an internal error. Application should abort the scan.
  2248. */
  2249. GNUNET_FS_DIRSCANNER_INTERNAL_ERROR
  2250. };
  2251. /**
  2252. * Function called over time as the directory scanner makes
  2253. * progress on the job at hand.
  2254. *
  2255. * @param cls closure
  2256. * @param filename which file we are making progress on
  2257. * @param is_directory #GNUNET_YES if this is a directory,
  2258. * #GNUNET_NO if this is a file
  2259. * #GNUNET_SYSERR if it is neither (or unknown)
  2260. * @param reason kind of progress we are making
  2261. */
  2262. typedef void (*GNUNET_FS_DirScannerProgressCallback) (void *cls,
  2263. const char *filename,
  2264. int is_directory,
  2265. enum GNUNET_FS_DirScannerProgressUpdateReason reason);
  2266. /**
  2267. * A node of a directory tree (produced by dirscanner)
  2268. */
  2269. struct GNUNET_FS_ShareTreeItem
  2270. {
  2271. /**
  2272. * This is a doubly-linked list
  2273. */
  2274. struct GNUNET_FS_ShareTreeItem *prev;
  2275. /**
  2276. * This is a doubly-linked list
  2277. */
  2278. struct GNUNET_FS_ShareTreeItem *next;
  2279. /**
  2280. * This is a doubly-linked tree
  2281. * NULL for top-level entries.
  2282. */
  2283. struct GNUNET_FS_ShareTreeItem *parent;
  2284. /**
  2285. * This is a doubly-linked tree
  2286. * NULL for files and empty directories
  2287. */
  2288. struct GNUNET_FS_ShareTreeItem *children_head;
  2289. /**
  2290. * This is a doubly-linked tree
  2291. * NULL for files and empty directories
  2292. */
  2293. struct GNUNET_FS_ShareTreeItem *children_tail;
  2294. /**
  2295. * Metadata for this file or directory
  2296. */
  2297. struct GNUNET_CONTAINER_MetaData *meta;
  2298. /**
  2299. * Keywords for this file or directory (derived from metadata).
  2300. */
  2301. struct GNUNET_FS_Uri *ksk_uri;
  2302. /**
  2303. * Name of the file/directory
  2304. */
  2305. char *filename;
  2306. /**
  2307. * Base name of the file/directory.
  2308. */
  2309. char *short_filename;
  2310. /**
  2311. * #GNUNET_YES if this is a directory
  2312. */
  2313. int is_directory;
  2314. };
  2315. /**
  2316. * Opaque handle to an asynchronous directory scanning activity.
  2317. */
  2318. struct GNUNET_FS_DirScanner;
  2319. /**
  2320. * Start a directory scanner.
  2321. *
  2322. * @param filename name of the directory to scan
  2323. * @param disable_extractor #GNUNET_YES to not run libextractor on files (only
  2324. * build a tree)
  2325. * @param ex if not NULL, must be a list of extra plugins for extractor
  2326. * @param cb the callback to call when there are scanning progress messages
  2327. * @param cb_cls closure for @a cb
  2328. * @return directory scanner object to be used for controlling the scanner
  2329. */
  2330. struct GNUNET_FS_DirScanner *
  2331. GNUNET_FS_directory_scan_start (const char *filename,
  2332. int disable_extractor,
  2333. const char *ex,
  2334. GNUNET_FS_DirScannerProgressCallback cb,
  2335. void *cb_cls);
  2336. /**
  2337. * Abort the scan. Must not be called from within the progress_callback
  2338. * function.
  2339. *
  2340. * @param ds directory scanner structure
  2341. */
  2342. void
  2343. GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds);
  2344. /**
  2345. * Obtain the result of the scan after the scan has signalled
  2346. * completion. Must not be called prior to completion. The @a ds is
  2347. * freed as part of this call.
  2348. *
  2349. * @param ds directory scanner structure
  2350. * @return the results of the scan (a directory tree)
  2351. */
  2352. struct GNUNET_FS_ShareTreeItem *
  2353. GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds);
  2354. /**
  2355. * Process a share item tree, moving frequent keywords up and
  2356. * copying frequent metadata up.
  2357. *
  2358. * @param toplevel toplevel directory in the tree, returned by the scanner
  2359. */
  2360. void
  2361. GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel);
  2362. /**
  2363. * Release memory of a share item tree.
  2364. *
  2365. * @param toplevel toplevel of the tree to be freed
  2366. */
  2367. void
  2368. GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
  2369. #if 0 /* keep Emacsens' auto-indent happy */
  2370. {
  2371. #endif
  2372. #ifdef __cplusplus
  2373. }
  2374. #endif
  2375. #endif
  2376. /** @} */ /* end of group */