fs_api.h 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. 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. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file fs/fs_api.h
  19. * @brief shared definitions for the FS library
  20. * @author Igor Wronsky, Christian Grothoff
  21. */
  22. #ifndef FS_API_H
  23. #define FS_API_H
  24. #include "gnunet_constants.h"
  25. #include "gnunet_datastore_service.h"
  26. #include "gnunet_dht_service.h"
  27. #include "gnunet_fs_service.h"
  28. #include "gnunet_block_lib.h"
  29. #include "block_fs.h"
  30. #include "fs.h"
  31. /**
  32. * Pick a multiple of 2 here to achive 8-byte alignment! We also
  33. * probably want DBlocks to have (roughly) the same size as IBlocks.
  34. * With SHA-512, the optimal value is 32768 byte / 128 byte = 256 (128
  35. * byte = 2 * 512 bits). DO NOT CHANGE!
  36. */
  37. #define CHK_PER_INODE 256
  38. /**
  39. * Maximum size for a file to be considered for inlining in a
  40. * directory.
  41. */
  42. #define MAX_INLINE_SIZE 65536
  43. /**
  44. * Name of the directory with top-level searches.
  45. */
  46. #define GNUNET_FS_SYNC_PATH_MASTER_SEARCH "search"
  47. /**
  48. * Name of the directory with sub-searches (namespace-updates).
  49. */
  50. #define GNUNET_FS_SYNC_PATH_CHILD_SEARCH "search-child"
  51. /**
  52. * Name of the directory with master downloads (not associated
  53. * with search or part of another download).
  54. */
  55. #define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD "download"
  56. /**
  57. * Name of the directory with downloads that are part of another
  58. * download or a search.
  59. */
  60. #define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD "download-child"
  61. /**
  62. * Name of the directory with publishing operations.
  63. */
  64. #define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH "publish"
  65. /**
  66. * Name of the directory with files that are being published
  67. */
  68. #define GNUNET_FS_SYNC_PATH_FILE_INFO "publish-file"
  69. /**
  70. * Name of the directory with unindex operations.
  71. */
  72. #define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX "unindex"
  73. /**
  74. * @brief complete information needed
  75. * to download a file.
  76. */
  77. struct FileIdentifier
  78. {
  79. /**
  80. * Total size of the file in bytes. (network byte order (!))
  81. */
  82. uint64_t file_length;
  83. /**
  84. * Query and key of the top GNUNET_EC_IBlock.
  85. */
  86. struct ContentHashKey chk;
  87. };
  88. /**
  89. * Information about a file and its location
  90. * (peer claiming to share the file).
  91. */
  92. struct Location
  93. {
  94. /**
  95. * Information about the shared file.
  96. */
  97. struct FileIdentifier fi;
  98. /**
  99. * Identity of the peer sharing the file.
  100. */
  101. struct GNUNET_PeerIdentity peer;
  102. /**
  103. * Time when this location URI expires.
  104. */
  105. struct GNUNET_TIME_Absolute expirationTime;
  106. /**
  107. * Signature over the GNUNET_EC_FileIdentifier,
  108. * peer identity and expiration time.
  109. */
  110. struct GNUNET_CRYPTO_EddsaSignature contentSignature;
  111. };
  112. /**
  113. * Types of URIs.
  114. */
  115. enum GNUNET_FS_UriType
  116. {
  117. /**
  118. * Content-hash-key (simple file).
  119. */
  120. GNUNET_FS_URI_CHK,
  121. /**
  122. * Signed key space (file in namespace).
  123. */
  124. GNUNET_FS_URI_SKS,
  125. /**
  126. * Keyword search key (query with keywords).
  127. */
  128. GNUNET_FS_URI_KSK,
  129. /**
  130. * Location (chk with identity of hosting peer).
  131. */
  132. GNUNET_FS_URI_LOC
  133. };
  134. /**
  135. * A Universal Resource Identifier (URI), opaque.
  136. */
  137. struct GNUNET_FS_Uri
  138. {
  139. /**
  140. * Type of the URI.
  141. */
  142. enum GNUNET_FS_UriType type;
  143. union
  144. {
  145. struct
  146. {
  147. /**
  148. * Keywords start with a '+' if they are mandatory (in which
  149. * case the '+' is NOT part of the keyword) and with a simple
  150. * space if they are optional (in which case the space is ALSO
  151. * not part of the actual keyword).
  152. *
  153. * Double-quotes to protect spaces and %-encoding are NOT used
  154. * internally (only in URI-strings).
  155. */
  156. char **keywords;
  157. /**
  158. * Size of the keywords array.
  159. */
  160. unsigned int keywordCount;
  161. } ksk;
  162. struct
  163. {
  164. /**
  165. * Identifier of the namespace.
  166. */
  167. struct GNUNET_CRYPTO_EcdsaPublicKey ns;
  168. /**
  169. * Human-readable identifier chosen for this entry in the
  170. * namespace.
  171. */
  172. char *identifier;
  173. } sks;
  174. /**
  175. * Information needed to retrieve a file (content-hash-key
  176. * plus file size).
  177. */
  178. struct FileIdentifier chk;
  179. /**
  180. * Information needed to retrieve a file including signed
  181. * location (identity of a peer) of the content.
  182. */
  183. struct Location loc;
  184. } data;
  185. };
  186. /**
  187. * Information for a file or directory that is
  188. * about to be published.
  189. */
  190. struct GNUNET_FS_FileInformation
  191. {
  192. /**
  193. * Files in a directory are kept as a linked list.
  194. */
  195. struct GNUNET_FS_FileInformation *next;
  196. /**
  197. * If this is a file in a directory, "dir" refers to
  198. * the directory; otherwise NULL.
  199. */
  200. struct GNUNET_FS_FileInformation *dir;
  201. /**
  202. * Handle to the master context.
  203. */
  204. struct GNUNET_FS_Handle *h;
  205. /**
  206. * Pointer kept for the client.
  207. */
  208. void *client_info;
  209. /**
  210. * Metadata to use for the file.
  211. */
  212. struct GNUNET_CONTAINER_MetaData *meta;
  213. /**
  214. * Keywords to use for KBlocks.
  215. */
  216. struct GNUNET_FS_Uri *keywords;
  217. /**
  218. * CHK for this file or directory. NULL if
  219. * we have not yet computed it.
  220. */
  221. struct GNUNET_FS_Uri *chk_uri;
  222. /**
  223. * SKS URI for this file or directory. NULL if
  224. * we have not yet computed it.
  225. */
  226. struct GNUNET_FS_Uri *sks_uri;
  227. /**
  228. * Block options for the file.
  229. */
  230. struct GNUNET_FS_BlockOptions bo;
  231. /**
  232. * At what time did we start this upload?
  233. */
  234. struct GNUNET_TIME_Absolute start_time;
  235. /**
  236. * Under what filename is this struct serialized
  237. * (for operational persistence). Should be determined
  238. * using 'mktemp'.
  239. */
  240. char *serialization;
  241. /**
  242. * Encoder being used to publish this file.
  243. */
  244. struct GNUNET_FS_TreeEncoder *te;
  245. /**
  246. * Error message (non-NULL if this operation failed).
  247. */
  248. char *emsg;
  249. /**
  250. * Name of the file or directory (must be an absolute path).
  251. */
  252. char *filename;
  253. /**
  254. * Data describing either the file or the directory.
  255. */
  256. union
  257. {
  258. /**
  259. * Data for a file.
  260. */
  261. struct
  262. {
  263. /**
  264. * Function that can be used to read the data for the file.
  265. */
  266. GNUNET_FS_DataReader reader;
  267. /**
  268. * Closure for reader.
  269. */
  270. void *reader_cls;
  271. /**
  272. * If this file is being indexed, this value is set to the hash
  273. * over the entire file (when the indexing process is started).
  274. * Otherwise this field is not used.
  275. */
  276. struct GNUNET_HashCode file_id;
  277. /**
  278. * Size of the file (in bytes).
  279. */
  280. uint64_t file_size;
  281. /**
  282. * Should the file be indexed or inserted?
  283. */
  284. int do_index;
  285. /**
  286. * Is "file_id" already valid? Set to #GNUNET_YES once the hash
  287. * has been calculated.
  288. */
  289. int have_hash;
  290. /**
  291. * Has the service confirmed our INDEX_START request?
  292. * #GNUNET_YES if this step has been completed.
  293. */
  294. int index_start_confirmed;
  295. } file;
  296. /**
  297. * Data for a directory.
  298. */
  299. struct
  300. {
  301. /**
  302. * Linked list of entries in the directory.
  303. */
  304. struct GNUNET_FS_FileInformation *entries;
  305. /**
  306. * Size of the directory itself (in bytes); 0 if the
  307. * size has not yet been calculated.
  308. */
  309. size_t dir_size;
  310. /**
  311. * Pointer to the data for the directory (or NULL if not
  312. * available).
  313. */
  314. void *dir_data;
  315. /**
  316. * How much of the directory have we published (relative to @e contents_size).
  317. */
  318. uint64_t contents_completed;
  319. /**
  320. * Sum of all of the sizes of all of the files in the directory.
  321. */
  322. uint64_t contents_size;
  323. } dir;
  324. } data;
  325. /**
  326. * Is this struct for a file or directory?
  327. */
  328. int is_directory;
  329. /**
  330. * Are we done publishing this file?
  331. */
  332. int is_published;
  333. };
  334. /**
  335. * The job is now ready to run and should use the given client
  336. * handle to communicate with the FS service.
  337. *
  338. * @param cls closure
  339. * @param client handle to use for FS communication
  340. */
  341. typedef void (*GNUNET_FS_QueueStart) (void *cls,
  342. struct GNUNET_CLIENT_Connection * client);
  343. /**
  344. * The job must now stop to run and should destry the client handle as
  345. * soon as possible (ideally prior to returning).
  346. */
  347. typedef void (*GNUNET_FS_QueueStop) (void *cls);
  348. /**
  349. * Priorities for the queue.
  350. */
  351. enum GNUNET_FS_QueuePriority
  352. {
  353. /**
  354. * This is a probe (low priority).
  355. */
  356. GNUNET_FS_QUEUE_PRIORITY_PROBE,
  357. /**
  358. * Default priority.
  359. */
  360. GNUNET_FS_QUEUE_PRIORITY_NORMAL
  361. };
  362. /**
  363. * Entry in the job queue.
  364. */
  365. struct GNUNET_FS_QueueEntry
  366. {
  367. /**
  368. * This is a linked list.
  369. */
  370. struct GNUNET_FS_QueueEntry *next;
  371. /**
  372. * This is a linked list.
  373. */
  374. struct GNUNET_FS_QueueEntry *prev;
  375. /**
  376. * Function to call when the job is started.
  377. */
  378. GNUNET_FS_QueueStart start;
  379. /**
  380. * Function to call when the job needs to stop (or is done / dequeued).
  381. */
  382. GNUNET_FS_QueueStop stop;
  383. /**
  384. * Closure for start and stop.
  385. */
  386. void *cls;
  387. /**
  388. * Handle to FS primary context.
  389. */
  390. struct GNUNET_FS_Handle *h;
  391. /**
  392. * Client handle, or NULL if job is not running.
  393. */
  394. struct GNUNET_CLIENT_Connection *client;
  395. /**
  396. * Time the job was originally queued.
  397. */
  398. struct GNUNET_TIME_Absolute queue_time;
  399. /**
  400. * Time the job was started last.
  401. */
  402. struct GNUNET_TIME_Absolute start_time;
  403. /**
  404. * Total amount of time the job has been running (except for the
  405. * current run).
  406. */
  407. struct GNUNET_TIME_Relative run_time;
  408. /**
  409. * How many blocks do the active downloads have?
  410. */
  411. unsigned int blocks;
  412. /**
  413. * How important is this download?
  414. */
  415. enum GNUNET_FS_QueuePriority priority;
  416. /**
  417. * How often have we (re)started this download?
  418. */
  419. unsigned int start_times;
  420. };
  421. /**
  422. * Information we store for each search result.
  423. */
  424. struct GNUNET_FS_SearchResult
  425. {
  426. /**
  427. * File-sharing context this result belongs to.
  428. */
  429. struct GNUNET_FS_Handle *h;
  430. /**
  431. * Search context this result belongs to; can be NULL
  432. * for probes that come from a directory result.
  433. */
  434. struct GNUNET_FS_SearchContext *sc;
  435. /**
  436. * URI to which this search result refers to.
  437. */
  438. struct GNUNET_FS_Uri *uri;
  439. /**
  440. * Metadata for the search result.
  441. */
  442. struct GNUNET_CONTAINER_MetaData *meta;
  443. /**
  444. * Client info for this search result.
  445. */
  446. void *client_info;
  447. /**
  448. * ID of a job that is currently probing this results' availability
  449. * (NULL if we are not currently probing).
  450. */
  451. struct GNUNET_FS_DownloadContext *probe_ctx;
  452. /**
  453. * ID of an associated download based on this search result (or
  454. * NULL for none).
  455. */
  456. struct GNUNET_FS_DownloadContext *download;
  457. /**
  458. * If this search result triggered an update search, this field
  459. * links to the update search.
  460. */
  461. struct GNUNET_FS_SearchContext *update_search;
  462. /**
  463. * Name under which this search result is stored on disk.
  464. */
  465. char *serialization;
  466. /**
  467. * Bitmap that specifies precisely which keywords have been matched already.
  468. */
  469. uint8_t *keyword_bitmap;
  470. /**
  471. * Key for the search result based on the URI.
  472. */
  473. struct GNUNET_HashCode key;
  474. /**
  475. * ID of the task that will clean up the probe_ctx should it not
  476. * complete on time (and that will need to be cancelled if we clean
  477. * up the search result before then).
  478. */
  479. GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
  480. /**
  481. * Task we use to report periodically to the application that the
  482. * probe is still running.
  483. */
  484. GNUNET_SCHEDULER_TaskIdentifier probe_ping_task;
  485. /**
  486. * When did the current probe become active?
  487. */
  488. struct GNUNET_TIME_Absolute probe_active_time;
  489. /**
  490. * How much longer should we run the current probe before giving up?
  491. */
  492. struct GNUNET_TIME_Relative remaining_probe_time;
  493. /**
  494. * Anonymity level to use for probes using this search result.
  495. */
  496. uint32_t anonymity;
  497. /**
  498. * Number of mandatory keywords for which we have NOT yet found the
  499. * search result; when this value hits zero, the search result is
  500. * given to the callback.
  501. */
  502. uint32_t mandatory_missing;
  503. /**
  504. * Number of optional keywords under which this result was also
  505. * found.
  506. */
  507. uint32_t optional_support;
  508. /**
  509. * Number of availability tests that have succeeded for this result.
  510. */
  511. uint32_t availability_success;
  512. /**
  513. * Number of availability trials that we have performed for this
  514. * search result.
  515. */
  516. uint32_t availability_trials;
  517. };
  518. /**
  519. * Add a job to the queue.
  520. *
  521. * @param h handle to the overall FS state
  522. * @param start function to call to begin the job
  523. * @param stop function to call to pause the job, or on dequeue (if the job was running)
  524. * @param cls closure for start and stop
  525. * @param blocks number of blocks this download has
  526. * @param priority how important is this download
  527. * @return queue handle
  528. */
  529. struct GNUNET_FS_QueueEntry *
  530. GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, GNUNET_FS_QueueStart start,
  531. GNUNET_FS_QueueStop stop, void *cls, unsigned int blocks,
  532. enum GNUNET_FS_QueuePriority priority);
  533. /**
  534. * Dequeue a job from the queue.
  535. *
  536. * @param qe handle for the job
  537. */
  538. void
  539. GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe);
  540. /**
  541. * Function that provides data by reading from a file.
  542. *
  543. * @param cls closure (points to the file information)
  544. * @param offset offset to read from; it is possible
  545. * that the caller might need to go backwards
  546. * a bit at times
  547. * @param max maximum number of bytes that should be
  548. * copied to buf; readers are not allowed
  549. * to provide less data unless there is an error;
  550. * a value of "0" will be used at the end to allow
  551. * the reader to clean up its internal state
  552. * @param buf where the reader should write the data
  553. * @param emsg location for the reader to store an error message
  554. * @return number of bytes written, usually "max", 0 on error
  555. */
  556. size_t
  557. GNUNET_FS_data_reader_file_ (void *cls, uint64_t offset, size_t max, void *buf,
  558. char **emsg);
  559. /**
  560. * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
  561. *
  562. * @param filename file to read
  563. * @return closure to use
  564. */
  565. void *
  566. GNUNET_FS_make_file_reader_context_ (const char *filename);
  567. /**
  568. * Function that provides data by copying from a buffer.
  569. *
  570. * @param cls closure (points to the buffer)
  571. * @param offset offset to read from; it is possible
  572. * that the caller might need to go backwards
  573. * a bit at times
  574. * @param max maximum number of bytes that should be
  575. * copied to buf; readers are not allowed
  576. * to provide less data unless there is an error;
  577. * a value of "0" will be used at the end to allow
  578. * the reader to clean up its internal state
  579. * @param buf where the reader should write the data
  580. * @param emsg location for the reader to store an error message
  581. * @return number of bytes written, usually "max", 0 on error
  582. */
  583. size_t
  584. GNUNET_FS_data_reader_copy_ (void *cls, uint64_t offset, size_t max, void *buf,
  585. char **emsg);
  586. /**
  587. * Notification of FS that a search probe has made progress.
  588. * This function is used INSTEAD of the client's event handler
  589. * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
  590. *
  591. * @param cls closure, always NULL (!), actual closure
  592. * is in the client-context of the info struct
  593. * @param info details about the event, specifying the event type
  594. * and various bits about the event
  595. * @return client-context (for the next progress call
  596. * for this operation; should be set to NULL for
  597. * SUSPEND and STOPPED events). The value returned
  598. * will be passed to future callbacks in the respective
  599. * field in the GNUNET_FS_ProgressInfo struct.
  600. */
  601. void *
  602. GNUNET_FS_search_probe_progress_ (void *cls,
  603. const struct GNUNET_FS_ProgressInfo *info);
  604. /**
  605. * Main function that performs the upload.
  606. *
  607. * @param cls `struct GNUNET_FS_PublishContext` identifies the upload
  608. * @param tc task context
  609. */
  610. void
  611. GNUNET_FS_publish_main_ (void *cls,
  612. const struct GNUNET_SCHEDULER_TaskContext *tc);
  613. /**
  614. * Function called once the hash of the file
  615. * that is being unindexed has been computed.
  616. *
  617. * @param cls closure, unindex context
  618. * @param file_id computed hash, NULL on error
  619. */
  620. void
  621. GNUNET_FS_unindex_process_hash_ (void *cls, const struct GNUNET_HashCode * file_id);
  622. /**
  623. * Extract the keywords for KBlock removal
  624. *
  625. * @param uc context for the unindex operation.
  626. */
  627. void
  628. GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc);
  629. /**
  630. * If necessary, connect to the datastore and remove the KBlocks.
  631. *
  632. * @param uc context for the unindex operation.
  633. */
  634. void
  635. GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc);
  636. /**
  637. * Fill in all of the generic fields for a publish event and call the
  638. * callback.
  639. *
  640. * @param pi structure to fill in
  641. * @param pc overall publishing context
  642. * @param p file information for the file being published
  643. * @param offset where in the file are we so far
  644. * @return value returned from callback
  645. */
  646. void *
  647. GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
  648. struct GNUNET_FS_PublishContext *pc,
  649. const struct GNUNET_FS_FileInformation *p,
  650. uint64_t offset);
  651. /**
  652. * Fill in all of the generic fields for a download event and call the
  653. * callback.
  654. *
  655. * @param pi structure to fill in
  656. * @param dc overall download context
  657. */
  658. void
  659. GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
  660. struct GNUNET_FS_DownloadContext *dc);
  661. /**
  662. * Task that creates the initial (top-level) download
  663. * request for the file.
  664. *
  665. * @param cls the 'struct GNUNET_FS_DownloadContext'
  666. * @param tc scheduler context
  667. */
  668. void
  669. GNUNET_FS_download_start_task_ (void *cls,
  670. const struct GNUNET_SCHEDULER_TaskContext *tc);
  671. /**
  672. * Fill in all of the generic fields for
  673. * an unindex event and call the callback.
  674. *
  675. * @param pi structure to fill in
  676. * @param uc overall unindex context
  677. * @param offset where we are in the file (for progress)
  678. */
  679. void
  680. GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
  681. struct GNUNET_FS_UnindexContext *uc,
  682. uint64_t offset);
  683. /**
  684. * Fill in all of the generic fields for a search event and
  685. * call the callback.
  686. *
  687. * @param pi structure to fill in
  688. * @param h file-sharing handle
  689. * @param sc overall search context
  690. * @return value returned by the callback
  691. */
  692. void *
  693. GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
  694. struct GNUNET_FS_Handle *h,
  695. struct GNUNET_FS_SearchContext *sc);
  696. /**
  697. * Connect to the datastore and remove the blocks.
  698. *
  699. * @param uc context for the unindex operation.
  700. */
  701. void
  702. GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
  703. /**
  704. * Build the request and actually initiate the search using the
  705. * GNUnet FS service.
  706. *
  707. * @param sc search context
  708. * @return GNUNET_OK on success, GNUNET_SYSERR on error
  709. */
  710. int
  711. GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
  712. /**
  713. * Start the downloading process (by entering the queue).
  714. *
  715. * @param dc our download context
  716. */
  717. void
  718. GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
  719. /**
  720. * Start download probes for the given search result.
  721. *
  722. * @param sr the search result
  723. */
  724. void
  725. GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
  726. /**
  727. * Remove serialization/deserialization file from disk.
  728. *
  729. * @param h master context
  730. * @param ext component of the path
  731. * @param ent entity identifier
  732. */
  733. void
  734. GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, const char *ext,
  735. const char *ent);
  736. /**
  737. * Remove serialization/deserialization directory from disk.
  738. *
  739. * @param h master context
  740. * @param ext component of the path
  741. * @param uni unique name of parent
  742. */
  743. void
  744. GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, const char *ext,
  745. const char *uni);
  746. /**
  747. * Synchronize this file-information struct with its mirror
  748. * on disk. Note that all internal FS-operations that change
  749. * file information data should already call "sync" internally,
  750. * so this function is likely not useful for clients.
  751. *
  752. * @param fi the struct to sync
  753. */
  754. void
  755. GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
  756. /**
  757. * Synchronize this publishing struct with its mirror
  758. * on disk. Note that all internal FS-operations that change
  759. * publishing structs should already call "sync" internally,
  760. * so this function is likely not useful for clients.
  761. *
  762. * @param pc the struct to sync
  763. */
  764. void
  765. GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
  766. /**
  767. * Synchronize this unindex struct with its mirror
  768. * on disk. Note that all internal FS-operations that change
  769. * publishing structs should already call "sync" internally,
  770. * so this function is likely not useful for clients.
  771. *
  772. * @param uc the struct to sync
  773. */
  774. void
  775. GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
  776. /**
  777. * Synchronize this search struct with its mirror
  778. * on disk. Note that all internal FS-operations that change
  779. * publishing structs should already call "sync" internally,
  780. * so this function is likely not useful for clients.
  781. *
  782. * @param sc the struct to sync
  783. */
  784. void
  785. GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
  786. /**
  787. * Synchronize this search result with its mirror
  788. * on disk. Note that all internal FS-operations that change
  789. * publishing structs should already call "sync" internally,
  790. * so this function is likely not useful for clients.
  791. *
  792. * @param sr the struct to sync
  793. */
  794. void
  795. GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
  796. /**
  797. * Synchronize this download struct with its mirror
  798. * on disk. Note that all internal FS-operations that change
  799. * publishing structs should already call "sync" internally,
  800. * so this function is likely not useful for clients.
  801. *
  802. * @param dc the struct to sync
  803. */
  804. void
  805. GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
  806. /**
  807. * Create SUSPEND event for the given publish operation
  808. * and then clean up our state (without stop signal).
  809. *
  810. * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
  811. */
  812. void
  813. GNUNET_FS_publish_signal_suspend_ (void *cls);
  814. /**
  815. * Create SUSPEND event for the given search operation
  816. * and then clean up our state (without stop signal).
  817. *
  818. * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
  819. */
  820. void
  821. GNUNET_FS_search_signal_suspend_ (void *cls);
  822. /**
  823. * Create SUSPEND event for the given download operation
  824. * and then clean up our state (without stop signal).
  825. *
  826. * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
  827. */
  828. void
  829. GNUNET_FS_download_signal_suspend_ (void *cls);
  830. /**
  831. * Create SUSPEND event for the given unindex operation
  832. * and then clean up our state (without stop signal).
  833. *
  834. * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
  835. */
  836. void
  837. GNUNET_FS_unindex_signal_suspend_ (void *cls);
  838. /**
  839. * Function signature of the functions that can be called
  840. * to trigger suspend signals and clean-up for top-level
  841. * activities.
  842. *
  843. * @param cls closure
  844. */
  845. typedef void (*SuspendSignalFunction) (void *cls);
  846. /**
  847. * We track all of the top-level activities of FS
  848. * so that we can signal 'suspend' on shutdown.
  849. */
  850. struct TopLevelActivity
  851. {
  852. /**
  853. * This is a doubly-linked list.
  854. */
  855. struct TopLevelActivity *next;
  856. /**
  857. * This is a doubly-linked list.
  858. */
  859. struct TopLevelActivity *prev;
  860. /**
  861. * Function to call for suspend-signalling and clean up.
  862. */
  863. SuspendSignalFunction ssf;
  864. /**
  865. * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
  866. */
  867. void *ssf_cls;
  868. };
  869. /**
  870. * Create a top-level activity entry.
  871. *
  872. * @param h global fs handle
  873. * @param ssf suspend signal function to use
  874. * @param ssf_cls closure for @a ssf
  875. * @return fresh top-level activity handle
  876. */
  877. struct TopLevelActivity *
  878. GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
  879. SuspendSignalFunction ssf,
  880. void *ssf_cls);
  881. /**
  882. * Destroy a top-level activity entry.
  883. *
  884. * @param h global fs handle
  885. * @param top top level activity entry
  886. */
  887. void
  888. GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
  889. struct TopLevelActivity *top);
  890. /**
  891. * Master context for most FS operations.
  892. */
  893. struct GNUNET_FS_Handle
  894. {
  895. /**
  896. * Configuration to use.
  897. */
  898. const struct GNUNET_CONFIGURATION_Handle *cfg;
  899. /**
  900. * Name of our client.
  901. */
  902. char *client_name;
  903. /**
  904. * Function to call with updates on our progress.
  905. */
  906. GNUNET_FS_ProgressCallback upcb;
  907. /**
  908. * Closure for upcb.
  909. */
  910. void *upcb_cls;
  911. /**
  912. * Head of DLL of top-level activities.
  913. */
  914. struct TopLevelActivity *top_head;
  915. /**
  916. * Tail of DLL of top-level activities.
  917. */
  918. struct TopLevelActivity *top_tail;
  919. /**
  920. * Head of DLL of running jobs.
  921. */
  922. struct GNUNET_FS_QueueEntry *running_head;
  923. /**
  924. * Tail of DLL of running jobs.
  925. */
  926. struct GNUNET_FS_QueueEntry *running_tail;
  927. /**
  928. * Head of DLL of pending jobs.
  929. */
  930. struct GNUNET_FS_QueueEntry *pending_head;
  931. /**
  932. * Tail of DLL of pending jobs.
  933. */
  934. struct GNUNET_FS_QueueEntry *pending_tail;
  935. /**
  936. * Task that processes the jobs in the running and pending queues
  937. * (and moves jobs around as needed).
  938. */
  939. GNUNET_SCHEDULER_TaskIdentifier queue_job;
  940. /**
  941. * Average time we take for a single request to be satisfied.
  942. * FIXME: not yet calcualted properly...
  943. */
  944. struct GNUNET_TIME_Relative avg_block_latency;
  945. /**
  946. * How many actual downloads do we have running right now?
  947. */
  948. unsigned int active_downloads;
  949. /**
  950. * How many blocks do the active downloads have?
  951. */
  952. unsigned int active_blocks;
  953. /**
  954. * General flags.
  955. */
  956. enum GNUNET_FS_Flags flags;
  957. /**
  958. * Maximum number of parallel downloads.
  959. */
  960. unsigned int max_parallel_downloads;
  961. /**
  962. * Maximum number of parallel requests.
  963. */
  964. unsigned int max_parallel_requests;
  965. };
  966. /**
  967. * Handle for controlling a publication process.
  968. */
  969. struct GNUNET_FS_PublishContext
  970. {
  971. /**
  972. * Handle to the global fs context.
  973. */
  974. struct GNUNET_FS_Handle *h;
  975. /**
  976. * Our top-level activity entry (if we are top-level, otherwise NULL).
  977. */
  978. struct TopLevelActivity *top;
  979. /**
  980. * File-structure that is being shared.
  981. */
  982. struct GNUNET_FS_FileInformation *fi;
  983. /**
  984. * Namespace that we are publishing in, NULL if we have no namespace.
  985. */
  986. struct GNUNET_CRYPTO_EcdsaPrivateKey *ns;
  987. /**
  988. * ID of the content in the namespace, NULL if we have no namespace.
  989. */
  990. char *nid;
  991. /**
  992. * ID for future updates, NULL if we have no namespace or no updates.
  993. */
  994. char *nuid;
  995. /**
  996. * Filename used for serializing information about this operation
  997. * (should be determined using 'mktemp').
  998. */
  999. char *serialization;
  1000. /**
  1001. * Our own client handle for the FS service; only briefly used when
  1002. * we start to index a file, otherwise NULL.
  1003. */
  1004. struct GNUNET_CLIENT_Connection *client;
  1005. /**
  1006. * Current position in the file-tree for the upload.
  1007. */
  1008. struct GNUNET_FS_FileInformation *fi_pos;
  1009. /**
  1010. * Non-null if we are currently hashing a file.
  1011. */
  1012. struct GNUNET_CRYPTO_FileHashContext *fhc;
  1013. /**
  1014. * Connection to the datastore service.
  1015. */
  1016. struct GNUNET_DATASTORE_Handle *dsh;
  1017. /**
  1018. * Queue entry for reservation/unreservation.
  1019. */
  1020. struct GNUNET_DATASTORE_QueueEntry *qre;
  1021. /**
  1022. * Context for SKS publishing operation that is part of this publishing operation
  1023. * (NULL if not active).
  1024. */
  1025. struct GNUNET_FS_PublishSksContext *sks_pc;
  1026. /**
  1027. * Context for KSK publishing operation that is part of this publishing operation
  1028. * (NULL if not active).
  1029. */
  1030. struct GNUNET_FS_PublishKskContext *ksk_pc;
  1031. /**
  1032. * ID of the task performing the upload. NO_TASK if the upload has
  1033. * completed.
  1034. */
  1035. GNUNET_SCHEDULER_TaskIdentifier upload_task;
  1036. /**
  1037. * Storage space to reserve for the operation.
  1038. */
  1039. uint64_t reserve_space;
  1040. /**
  1041. * Overall number of entries to reserve for the
  1042. * publish operation.
  1043. */
  1044. uint32_t reserve_entries;
  1045. /**
  1046. * Options for publishing.
  1047. */
  1048. enum GNUNET_FS_PublishOptions options;
  1049. /**
  1050. * Space reservation ID with datastore service
  1051. * for this upload.
  1052. */
  1053. int rid;
  1054. /**
  1055. * Set to #GNUNET_YES if all processing has completed.
  1056. */
  1057. int all_done;
  1058. /**
  1059. * Flag set to #GNUNET_YES if the next callback from
  1060. * #GNUNET_FS_file_information_inspect should be skipped because it
  1061. * is for the directory which was already processed with the parent.
  1062. */
  1063. int skip_next_fi_callback;
  1064. };
  1065. /**
  1066. * Phases of unindex processing (state machine).
  1067. */
  1068. enum UnindexState
  1069. {
  1070. /**
  1071. * We're currently hashing the file.
  1072. */
  1073. UNINDEX_STATE_HASHING = 0,
  1074. /**
  1075. * We're telling the datastore to delete
  1076. * the respective DBlocks and IBlocks.
  1077. */
  1078. UNINDEX_STATE_DS_REMOVE = 1,
  1079. /**
  1080. * Find out which keywords apply.
  1081. */
  1082. UNINDEX_STATE_EXTRACT_KEYWORDS = 2,
  1083. /**
  1084. * We're telling the datastore to remove KBlocks.
  1085. */
  1086. UNINDEX_STATE_DS_REMOVE_KBLOCKS = 3,
  1087. /**
  1088. * We're notifying the FS service about
  1089. * the unindexing.
  1090. */
  1091. UNINDEX_STATE_FS_NOTIFY = 4,
  1092. /**
  1093. * We're done.
  1094. */
  1095. UNINDEX_STATE_COMPLETE = 5,
  1096. /**
  1097. * We've encountered a fatal error.
  1098. */
  1099. UNINDEX_STATE_ERROR = 6
  1100. };
  1101. /**
  1102. * Handle for controlling an unindexing operation.
  1103. */
  1104. struct GNUNET_FS_UnindexContext
  1105. {
  1106. /**
  1107. * The content hash key of the last block we processed, will in the
  1108. * end be set to the CHK from the URI. Used to remove the KBlocks.
  1109. */
  1110. struct ContentHashKey chk;
  1111. /**
  1112. * Global FS context.
  1113. */
  1114. struct GNUNET_FS_Handle *h;
  1115. /**
  1116. * Our top-level activity entry.
  1117. */
  1118. struct TopLevelActivity *top;
  1119. /**
  1120. * Directory scanner to find keywords (KBlock removal).
  1121. */
  1122. struct GNUNET_FS_DirScanner *dscan;
  1123. /**
  1124. * Keywords found (telling us which KBlocks to remove).
  1125. */
  1126. struct GNUNET_FS_Uri *ksk_uri;
  1127. /**
  1128. * Current offset in KSK removal.
  1129. */
  1130. uint32_t ksk_offset;
  1131. /**
  1132. * Name of the file that we are unindexing.
  1133. */
  1134. char *filename;
  1135. /**
  1136. * Short name under which we are serializing the state of this operation.
  1137. */
  1138. char *serialization;
  1139. /**
  1140. * Connection to the FS service, only valid during the
  1141. * #UNINDEX_STATE_FS_NOTIFY phase.
  1142. */
  1143. struct GNUNET_CLIENT_Connection *client;
  1144. /**
  1145. * Connection to the datastore service, only valid during the
  1146. * UNINDEX_STATE_DS_NOTIFY phase.
  1147. */
  1148. struct GNUNET_DATASTORE_Handle *dsh;
  1149. /**
  1150. * Pointer kept for the client.
  1151. */
  1152. void *client_info;
  1153. /**
  1154. * Merkle-ish tree encoder context.
  1155. */
  1156. struct GNUNET_FS_TreeEncoder *tc;
  1157. /**
  1158. * Handle used to read the file.
  1159. */
  1160. struct GNUNET_DISK_FileHandle *fh;
  1161. /**
  1162. * Handle to datastore 'get_key' operation issued for
  1163. * obtaining KBlocks.
  1164. */
  1165. struct GNUNET_DATASTORE_QueueEntry *dqe;
  1166. /**
  1167. * Current key for decrypting UBLocks from 'get_key' operation.
  1168. */
  1169. struct GNUNET_HashCode ukey;
  1170. /**
  1171. * Current query of 'get_key' operation.
  1172. */
  1173. struct GNUNET_HashCode uquery;
  1174. /**
  1175. * First content UID, 0 for none.
  1176. */
  1177. uint64_t first_uid;
  1178. /**
  1179. * Error message, NULL on success.
  1180. */
  1181. char *emsg;
  1182. /**
  1183. * Context for hashing of the file.
  1184. */
  1185. struct GNUNET_CRYPTO_FileHashContext *fhc;
  1186. /**
  1187. * Overall size of the file.
  1188. */
  1189. uint64_t file_size;
  1190. /**
  1191. * Random offset given to #GNUNET_DATASTORE_get_key.
  1192. */
  1193. uint64_t roff;
  1194. /**
  1195. * When did we start?
  1196. */
  1197. struct GNUNET_TIME_Absolute start_time;
  1198. /**
  1199. * Hash of the file's contents (once computed).
  1200. */
  1201. struct GNUNET_HashCode file_id;
  1202. /**
  1203. * Current operatinonal phase.
  1204. */
  1205. enum UnindexState state;
  1206. };
  1207. /**
  1208. * Information we keep for each keyword in a keyword search.
  1209. */
  1210. struct SearchRequestEntry
  1211. {
  1212. /**
  1213. * Hash of the public key, also known as the query.
  1214. */
  1215. struct GNUNET_HashCode uquery;
  1216. /**
  1217. * Derived public key, hashes to 'uquery'.
  1218. */
  1219. struct GNUNET_CRYPTO_EcdsaPublicKey dpub;
  1220. /**
  1221. * The original keyword, used to derive the
  1222. * key (for decrypting the UBlock).
  1223. */
  1224. char *keyword;
  1225. /**
  1226. * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
  1227. * was found under this keyword. Note that the entries will point
  1228. * to the same locations as those in the master result map (in
  1229. * "struct GNUNET_FS_SearchContext"), so they should not be freed.
  1230. * The key for each entry is the XOR of the key and query in the CHK
  1231. * URI (as a unique identifier for the search result).
  1232. */
  1233. struct GNUNET_CONTAINER_MultiHashMap *results;
  1234. /**
  1235. * Is this keyword a mandatory keyword
  1236. * (started with '+')?
  1237. */
  1238. int mandatory;
  1239. };
  1240. /**
  1241. * Handle for controlling a search.
  1242. */
  1243. struct GNUNET_FS_SearchContext
  1244. {
  1245. /**
  1246. * Handle to the global FS context.
  1247. */
  1248. struct GNUNET_FS_Handle *h;
  1249. /**
  1250. * Our top-level activity entry (if we are top-level, otherwise NULL).
  1251. */
  1252. struct TopLevelActivity *top;
  1253. /**
  1254. * List of keywords that we're looking for.
  1255. */
  1256. struct GNUNET_FS_Uri *uri;
  1257. /**
  1258. * For update-searches, link to the search result that triggered
  1259. * the update search; otherwise NULL.
  1260. */
  1261. struct GNUNET_FS_SearchResult *psearch_result;
  1262. /**
  1263. * Connection to the FS service.
  1264. */
  1265. struct GNUNET_CLIENT_Connection *client;
  1266. /**
  1267. * Pointer we keep for the client.
  1268. */
  1269. void *client_info;
  1270. /**
  1271. * Name of the file on disk we use for persistence.
  1272. */
  1273. char *serialization;
  1274. /**
  1275. * Error message (non-NULL if this operation failed).
  1276. */
  1277. char *emsg;
  1278. /**
  1279. * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
  1280. * was found in the search. The key for each entry is the XOR of
  1281. * the key and query in the CHK URI (as a unique identifier for the
  1282. * search result).
  1283. */
  1284. struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
  1285. /**
  1286. * Per-keyword information for a keyword search. This array will
  1287. * have exactly as many entries as there were keywords.
  1288. */
  1289. struct SearchRequestEntry *requests;
  1290. /**
  1291. * When did we start?
  1292. */
  1293. struct GNUNET_TIME_Absolute start_time;
  1294. /**
  1295. * How long to wait before we try to reconnect to FS service?
  1296. */
  1297. struct GNUNET_TIME_Relative reconnect_backoff;
  1298. /**
  1299. * ID of a task that is using this struct and that must be cancelled
  1300. * when the search is being stopped (if not
  1301. * #GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
  1302. * artificial delay when trying to reconnect to the FS service.
  1303. */
  1304. GNUNET_SCHEDULER_TaskIdentifier task;
  1305. /**
  1306. * How many of the entries in the search request
  1307. * map have been passed to the service so far?
  1308. */
  1309. unsigned int search_request_map_offset;
  1310. /**
  1311. * How many of the keywords in the KSK
  1312. * map have been passed to the service so far?
  1313. */
  1314. unsigned int keyword_offset;
  1315. /**
  1316. * Anonymity level for the search.
  1317. */
  1318. uint32_t anonymity;
  1319. /**
  1320. * Number of mandatory keywords in this query.
  1321. */
  1322. uint32_t mandatory_count;
  1323. /**
  1324. * Options for the search.
  1325. */
  1326. enum GNUNET_FS_SearchOptions options;
  1327. };
  1328. /**
  1329. * FSM for possible states a block can go through. The typical
  1330. * order of progression is linear through the states, alternatives
  1331. * are documented in the comments.
  1332. */
  1333. enum BlockRequestState
  1334. {
  1335. /**
  1336. * Initial state, block has only been allocated (since it is
  1337. * relevant to the overall download request).
  1338. */
  1339. BRS_INIT = 0,
  1340. /**
  1341. * We've checked the block on the path down the tree, and the
  1342. * content on disk did match the desired CHK, but not all
  1343. * the way down, so at the bottom some blocks will still
  1344. * need to be reconstructed).
  1345. */
  1346. BRS_RECONSTRUCT_DOWN = 1,
  1347. /**
  1348. * We've calculated the CHK bottom-up based on the meta data.
  1349. * This may work, but if it did we have to write the meta data to
  1350. * disk at the end (and we still need to check against the
  1351. * CHK set on top).
  1352. */
  1353. BRS_RECONSTRUCT_META_UP = 2,
  1354. /**
  1355. * We've calculated the CHK bottom-up based on what we have on
  1356. * disk, which may not be what the desired CHK is. If the
  1357. * reconstructed CHKs match whatever comes from above, we're
  1358. * done with the respective subtree.
  1359. */
  1360. BRS_RECONSTRUCT_UP = 3,
  1361. /**
  1362. * We've determined the real, desired CHK for this block
  1363. * (full tree reconstruction failed), request is now pending.
  1364. * If the CHK that bubbled up through reconstruction did match
  1365. * the top-level request, the state machine for the subtree
  1366. * would have moved to BRS_DOWNLOAD_UP.
  1367. */
  1368. BRS_CHK_SET = 4,
  1369. /**
  1370. * We've successfully downloaded this block, but the children
  1371. * still need to be either downloaded or verified (download
  1372. * request propagates down). If the download fails, the
  1373. * state machine for this block may move to
  1374. * BRS_DOWNLOAD_ERROR instead.
  1375. */
  1376. BRS_DOWNLOAD_DOWN = 5,
  1377. /**
  1378. * This block and all of its children have been downloaded
  1379. * successfully (full completion propagates up).
  1380. */
  1381. BRS_DOWNLOAD_UP = 6,
  1382. /**
  1383. * We got a block back that matched the query but did not hash to
  1384. * the key (malicious publisher or hash collision); this block
  1385. * can never be downloaded (error propagates up).
  1386. */
  1387. BRS_ERROR = 7
  1388. };
  1389. /**
  1390. * Information about an active download request.
  1391. */
  1392. struct DownloadRequest
  1393. {
  1394. /**
  1395. * While pending, we keep all download requests in a doubly-linked list.
  1396. */
  1397. struct DownloadRequest *next;
  1398. /**
  1399. * While pending, we keep all download requests in a doubly-linked list.
  1400. */
  1401. struct DownloadRequest *prev;
  1402. /**
  1403. * Parent in the CHK-tree.
  1404. */
  1405. struct DownloadRequest *parent;
  1406. /**
  1407. * Array (!) of child-requests, or NULL for the bottom of the tree.
  1408. */
  1409. struct DownloadRequest **children;
  1410. /**
  1411. * CHK for the request for this block (set during reconstruction
  1412. * to what we have on disk, later to what we want to have).
  1413. */
  1414. struct ContentHashKey chk;
  1415. /**
  1416. * Offset of the corresponding block. Specifically, first (!) byte of
  1417. * the first DBLOCK in the subtree induced by block represented by
  1418. * this request.
  1419. */
  1420. uint64_t offset;
  1421. /**
  1422. * Number of entries in 'children' array.
  1423. */
  1424. unsigned int num_children;
  1425. /**
  1426. * Depth of the corresponding block in the tree. 0==DBLOCKs.
  1427. */
  1428. unsigned int depth;
  1429. /**
  1430. * Offset of the CHK for this block in the parent block
  1431. */
  1432. unsigned int chk_idx;
  1433. /**
  1434. * State in the FSM.
  1435. */
  1436. enum BlockRequestState state;
  1437. /**
  1438. * #GNUNET_YES if this entry is in the pending list.
  1439. */
  1440. int is_pending;
  1441. };
  1442. /**
  1443. * (recursively) free download request structure
  1444. *
  1445. * @param dr request to free
  1446. */
  1447. void
  1448. GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
  1449. /**
  1450. * Context for controlling a download.
  1451. */
  1452. struct GNUNET_FS_DownloadContext
  1453. {
  1454. /**
  1455. * Global FS context.
  1456. */
  1457. struct GNUNET_FS_Handle *h;
  1458. /**
  1459. * Our top-level activity entry (if we are top-level, otherwise NULL).
  1460. */
  1461. struct TopLevelActivity *top;
  1462. /**
  1463. * Connection to the FS service.
  1464. */
  1465. struct GNUNET_CLIENT_Connection *client;
  1466. /**
  1467. * Parent download (used when downloading files
  1468. * in directories).
  1469. */
  1470. struct GNUNET_FS_DownloadContext *parent;
  1471. /**
  1472. * Associated search (used when downloading files
  1473. * based on search results), or NULL for none.
  1474. */
  1475. struct GNUNET_FS_SearchResult *search;
  1476. /**
  1477. * Head of list of child downloads.
  1478. */
  1479. struct GNUNET_FS_DownloadContext *child_head;
  1480. /**
  1481. * Tail of list of child downloads.
  1482. */
  1483. struct GNUNET_FS_DownloadContext *child_tail;
  1484. /**
  1485. * Previous download belonging to the same parent.
  1486. */
  1487. struct GNUNET_FS_DownloadContext *prev;
  1488. /**
  1489. * Next download belonging to the same parent.
  1490. */
  1491. struct GNUNET_FS_DownloadContext *next;
  1492. /**
  1493. * Context kept for the client.
  1494. */
  1495. void *client_info;
  1496. /**
  1497. * URI that identifies the file that we are downloading.
  1498. */
  1499. struct GNUNET_FS_Uri *uri;
  1500. /**
  1501. * Known meta-data for the file (can be NULL).
  1502. */
  1503. struct GNUNET_CONTAINER_MetaData *meta;
  1504. /**
  1505. * Error message, NULL if we're doing OK.
  1506. */
  1507. char *emsg;
  1508. /**
  1509. * Random portion of filename we use for syncing state of this
  1510. * download.
  1511. */
  1512. char *serialization;
  1513. /**
  1514. * Where are we writing the data (name of the
  1515. * file, can be NULL!).
  1516. */
  1517. char *filename;
  1518. /**
  1519. * Where are we writing the data temporarily (name of the
  1520. * file, can be NULL!); used if we do not have a permanent
  1521. * name and we are a directory and we do a recursive download.
  1522. */
  1523. char *temp_filename;
  1524. /**
  1525. * Our entry in the job queue.
  1526. */
  1527. struct GNUNET_FS_QueueEntry *job_queue;
  1528. /**
  1529. * Non-NULL if we are currently having a request for
  1530. * transmission pending with the client handle.
  1531. */
  1532. struct GNUNET_CLIENT_TransmitHandle *th;
  1533. /**
  1534. * Tree encoder used for the reconstruction.
  1535. */
  1536. struct GNUNET_FS_TreeEncoder *te;
  1537. /**
  1538. * File handle for reading data from an existing file
  1539. * (to pass to tree encoder).
  1540. */
  1541. struct GNUNET_DISK_FileHandle *rfh;
  1542. /**
  1543. * Map of active requests (those waiting for a response). The key
  1544. * is the hash of the encryped block (aka query).
  1545. */
  1546. struct GNUNET_CONTAINER_MultiHashMap *active;
  1547. /**
  1548. * Head of linked list of pending requests.
  1549. */
  1550. struct DownloadRequest *pending_head;
  1551. /**
  1552. * Head of linked list of pending requests.
  1553. */
  1554. struct DownloadRequest *pending_tail;
  1555. /**
  1556. * Top-level download request.
  1557. */
  1558. struct DownloadRequest *top_request;
  1559. /**
  1560. * Identity of the peer having the content, or all-zeros
  1561. * if we don't know of such a peer.
  1562. */
  1563. struct GNUNET_PeerIdentity target;
  1564. /**
  1565. * ID of a task that is using this struct and that must be cancelled
  1566. * when the download is being stopped (if not
  1567. * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
  1568. * artificial delay when trying to reconnect to the FS service or
  1569. * the task processing incrementally the data on disk, or the
  1570. * task requesting blocks, etc.
  1571. */
  1572. GNUNET_SCHEDULER_TaskIdentifier task;
  1573. /**
  1574. * What is the first offset that we're interested
  1575. * in?
  1576. */
  1577. uint64_t offset;
  1578. /**
  1579. * How many bytes starting from offset are desired?
  1580. * This is NOT the overall length of the file!
  1581. */
  1582. uint64_t length;
  1583. /**
  1584. * How many bytes have we already received within
  1585. * the specified range (DBlocks only).
  1586. */
  1587. uint64_t completed;
  1588. /**
  1589. * What was the size of the file on disk that we're downloading
  1590. * before we started? Used to detect if there is a point in
  1591. * checking an existing block on disk for matching the desired
  1592. * content. 0 if the file did not exist already.
  1593. */
  1594. uint64_t old_file_size;
  1595. /**
  1596. * Time download was started.
  1597. */
  1598. struct GNUNET_TIME_Absolute start_time;
  1599. /**
  1600. * How long to wait before we try to reconnect to FS service?
  1601. */
  1602. struct GNUNET_TIME_Relative reconnect_backoff;
  1603. /**
  1604. * Desired level of anonymity.
  1605. */
  1606. uint32_t anonymity;
  1607. /**
  1608. * The depth of the file-tree.
  1609. */
  1610. unsigned int treedepth;
  1611. /**
  1612. * Options for the download.
  1613. */
  1614. enum GNUNET_FS_DownloadOptions options;
  1615. /**
  1616. * Flag set upon transitive completion (includes child downloads).
  1617. * This flag is only set to #GNUNET_YES for directories where all
  1618. * child-downloads have also completed (and signalled completion).
  1619. */
  1620. int has_finished;
  1621. /**
  1622. * Have we started the receive continuation yet?
  1623. */
  1624. int in_receive;
  1625. /**
  1626. * Are we ready to issue requests (reconstructions are finished)?
  1627. */
  1628. int issue_requests;
  1629. };
  1630. #endif
  1631. /* end of fs_api.h */