fs.h 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386
  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.h
  19. * @brief definitions for the entire fs module
  20. * @author Igor Wronsky, Christian Grothoff
  21. */
  22. #ifndef FS_H
  23. #define FS_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. /**
  31. * Maximum number of outgoing messages we queue per peer.
  32. *
  33. * Performance measurements for 2 peer setup for 50 MB file
  34. * (with MAX_DATASTORE_QUEUE = 1 and RETRY_PROBABILITY_INV = 1):
  35. *
  36. * 2: 1700 kb/s, 1372 kb/s
  37. * 8: 2117 kb/s, 1284 kb/s, 1112 kb/s
  38. * 16: 3500 kb/s, 3200 kb/s, 3388 kb/s
  39. * 32: 3441 kb/s, 3163 kb/s, 3277 kb/s
  40. * 128: 1700 kb/s; 2010 kb/s, 3383 kb/s, 1156 kb/s
  41. *
  42. * Conclusion: 16 seems to be a pretty good value (stable
  43. * and high performance, no excessive memory use).
  44. */
  45. #define MAX_QUEUE_PER_PEER 16
  46. /**
  47. * Maximum size of the datastore queue for P2P operations.
  48. * Needs to be large enough to queue MAX_QUEUE_PER_PEER
  49. * operations for roughly the number of active (connected)
  50. * peers.
  51. */
  52. #define MAX_DATASTORE_QUEUE (16 * MAX_QUEUE_PER_PEER)
  53. /**
  54. * Maximum number of blocks we keep in memory for migration.
  55. */
  56. #define MAX_MIGRATION_QUEUE 8
  57. /**
  58. * Blocks are at most migrated to this number of peers
  59. * plus one, each time they are fetched from the database.
  60. */
  61. #define MIGRATION_LIST_SIZE 2
  62. /**
  63. * To how many peers do we forward each migration block ultimately?
  64. * This number must be smaller or equal to MIGRATION_LIST_SIZE. Using
  65. * a smaller value allows for variation in available bandwidth (for
  66. * migration) between the peers.
  67. */
  68. #define MIGRATION_TARGET_COUNT 2
  69. /**
  70. * Ratio for moving average delay calculation. The previous
  71. * average goes in with a factor of (n-1) into the calculation.
  72. * Must be > 0.
  73. */
  74. #define RUNAVG_DELAY_N 16
  75. /**
  76. * Size of the individual blocks used for file-sharing.
  77. */
  78. #define DBLOCK_SIZE (32*1024)
  79. /**
  80. * Maximum legal size for a kblock.
  81. */
  82. #define MAX_KBLOCK_SIZE (60 * 1024)
  83. /**
  84. * Maximum legal size for an sblock.
  85. */
  86. #define MAX_SBLOCK_SIZE (60 * 1024)
  87. /**
  88. * Maximum legal size for an nblock.
  89. */
  90. #define MAX_NBLOCK_SIZE (60 * 1024)
  91. /**
  92. * Pick a multiple of 2 here to achive 8-byte alignment!
  93. * We also probably want DBlocks to have (roughly) the
  94. * same size as IBlocks. With SHA-512, the optimal
  95. * value is 32768 byte / 128 byte = 256
  96. * (128 byte = 2 * 512 bits). DO NOT CHANGE!
  97. */
  98. #define CHK_PER_INODE 256
  99. /**
  100. * Maximum size for a file to be considered for
  101. * inlining in a directory.
  102. */
  103. #define MAX_INLINE_SIZE 65536
  104. /**
  105. * Blocksize to use when hashing files
  106. * for indexing (blocksize for IO, not for
  107. * the DBlocks). Larger blocksizes can
  108. * be more efficient but will be more disruptive
  109. * as far as the scheduler is concerned.
  110. */
  111. #define HASHING_BLOCKSIZE (1024 * 128)
  112. /**
  113. * Number of bits we set per entry in the bloomfilter.
  114. * Do not change!
  115. */
  116. #define BLOOMFILTER_K GNUNET_DHT_GET_BLOOMFILTER_K
  117. /**
  118. * Number of availability trials we perform per search result.
  119. */
  120. #define AVAILABILITY_TRIALS_MAX 8
  121. /**
  122. * Length of the P2P success tracker. Note that
  123. * having a very long list can also hurt performance.
  124. */
  125. #define P2P_SUCCESS_LIST_SIZE 8
  126. /**
  127. * Length of the CS-2-P success tracker. Note that
  128. * having a very long list can also hurt performance.
  129. */
  130. #define CS2P_SUCCESS_LIST_SIZE 8
  131. /**
  132. * How long are we willing to wait for the datastore to be ready to
  133. * process a request for a query without priority?
  134. */
  135. #define BASIC_DATASTORE_REQUEST_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
  136. /**
  137. * How long are we willing to wait for the core to be ready to
  138. * transmit a reply to the target peer (if we can not transmit
  139. * until then, we will discard the reply).
  140. */
  141. #define ACCEPTABLE_REPLY_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
  142. /**
  143. * Bandwidth value of an (effectively) 0-priority query.
  144. */
  145. #define QUERY_BANDWIDTH_VALUE 1
  146. /**
  147. * Bandwidth value of a 0-priority content (must be
  148. * fairly high compared to query since content is
  149. * typically significantly larger -- and more valueable
  150. * since it can take many queries to get one piece of
  151. * content).
  152. */
  153. #define CONTENT_BANDWIDTH_VALUE 800
  154. /**
  155. * By which amount do we decrement the TTL for simple forwarding /
  156. * indirection of the query; in milli-seconds. Set somewhat in
  157. * accordance to your network latency (above the time it'll take you
  158. * to send a packet and get a reply).
  159. */
  160. #define TTL_DECREMENT 5000
  161. /**
  162. * Until which load do we consider the peer idle and do not
  163. * charge at all? (should be larger than GNUNET_IDLE_LOAD_THRESHOLD used
  164. * by the rest of the code)!
  165. */
  166. #define IDLE_LOAD_THRESHOLD ((100 + GNUNET_CONSTANTS_IDLE_LOAD_THRESHOLD) / 2)
  167. /**
  168. * Name of the directory with top-level searches.
  169. */
  170. #define GNUNET_FS_SYNC_PATH_MASTER_SEARCH "search"
  171. /**
  172. * Name of the directory with sub-searches (namespace-updates).
  173. */
  174. #define GNUNET_FS_SYNC_PATH_CHILD_SEARCH "search-child"
  175. /**
  176. * Name of the directory with master downloads (not associated
  177. * with search or part of another download).
  178. */
  179. #define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD "download"
  180. /**
  181. * Name of the directory with downloads that are part of another
  182. * download or a search.
  183. */
  184. #define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD "download-child"
  185. /**
  186. * Name of the directory with publishing operations.
  187. */
  188. #define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH "publish"
  189. /**
  190. * Name of the directory with files that are being published
  191. */
  192. #define GNUNET_FS_SYNC_PATH_FILE_INFO "publish-file"
  193. /**
  194. * Name of the directory with unindex operations.
  195. */
  196. #define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX "unindex"
  197. /**
  198. * @brief content hash key
  199. */
  200. struct ContentHashKey
  201. {
  202. /**
  203. * Hash of the original content, used for encryption.
  204. */
  205. GNUNET_HashCode key;
  206. /**
  207. * Hash of the encrypted content, used for querying.
  208. */
  209. GNUNET_HashCode query;
  210. };
  211. /**
  212. * @brief complete information needed
  213. * to download a file.
  214. */
  215. struct FileIdentifier
  216. {
  217. /**
  218. * Total size of the file in bytes. (network byte order (!))
  219. */
  220. uint64_t file_length;
  221. /**
  222. * Query and key of the top GNUNET_EC_IBlock.
  223. */
  224. struct ContentHashKey chk;
  225. };
  226. /**
  227. * Information about a file and its location
  228. * (peer claiming to share the file).
  229. */
  230. struct Location
  231. {
  232. /**
  233. * Information about the shared file.
  234. */
  235. struct FileIdentifier fi;
  236. /**
  237. * Identity of the peer sharing the file.
  238. */
  239. struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
  240. /**
  241. * Time when this location URI expires.
  242. */
  243. struct GNUNET_TIME_Absolute expirationTime;
  244. /**
  245. * RSA signature over the GNUNET_EC_FileIdentifier,
  246. * GNUNET_hash of the peer and expiration time.
  247. */
  248. struct GNUNET_CRYPTO_RsaSignature contentSignature;
  249. };
  250. /**
  251. * Types of URIs.
  252. */
  253. enum uri_types
  254. {
  255. /**
  256. * Content-hash-key (simple file).
  257. */
  258. chk,
  259. /**
  260. * Signed key space (file in namespace).
  261. */
  262. sks,
  263. /**
  264. * Keyword search key (query with keywords).
  265. */
  266. ksk,
  267. /**
  268. * Location (chk with identity of hosting peer).
  269. */
  270. loc
  271. };
  272. /**
  273. * A Universal Resource Identifier (URI), opaque.
  274. */
  275. struct GNUNET_FS_Uri
  276. {
  277. /**
  278. * Type of the URI.
  279. */
  280. enum uri_types type;
  281. union
  282. {
  283. struct
  284. {
  285. /**
  286. * Keywords start with a '+' if they are
  287. * mandatory (in which case the '+' is NOT
  288. * part of the keyword) and with a
  289. * simple space if they are optional
  290. * (in which case the space is ALSO not
  291. * part of the actual keyword).
  292. *
  293. * Double-quotes to protect spaces and
  294. * %-encoding are NOT used internally
  295. * (only in URI-strings).
  296. */
  297. char **keywords;
  298. /**
  299. * Size of the keywords array.
  300. */
  301. unsigned int keywordCount;
  302. } ksk;
  303. struct
  304. {
  305. /**
  306. * Hash of the public key for the namespace.
  307. */
  308. GNUNET_HashCode namespace;
  309. /**
  310. * Human-readable identifier chosen for this
  311. * entry in the namespace.
  312. */
  313. char *identifier;
  314. } sks;
  315. /**
  316. * Information needed to retrieve a file (content-hash-key
  317. * plus file size).
  318. */
  319. struct FileIdentifier chk;
  320. /**
  321. * Information needed to retrieve a file including signed
  322. * location (identity of a peer) of the content.
  323. */
  324. struct Location loc;
  325. } data;
  326. };
  327. /**
  328. * Information for a file or directory that is
  329. * about to be published.
  330. */
  331. struct GNUNET_FS_FileInformation
  332. {
  333. /**
  334. * Files in a directory are kept as a linked list.
  335. */
  336. struct GNUNET_FS_FileInformation *next;
  337. /**
  338. * If this is a file in a directory, "dir" refers to
  339. * the directory; otherwise NULL.
  340. */
  341. struct GNUNET_FS_FileInformation *dir;
  342. /**
  343. * Handle to the master context.
  344. */
  345. struct GNUNET_FS_Handle *h;
  346. /**
  347. * Pointer kept for the client.
  348. */
  349. void *client_info;
  350. /**
  351. * Metadata to use for the file.
  352. */
  353. struct GNUNET_CONTAINER_MetaData *meta;
  354. /**
  355. * Keywords to use for KBlocks.
  356. */
  357. struct GNUNET_FS_Uri *keywords;
  358. /**
  359. * CHK for this file or directory. NULL if
  360. * we have not yet computed it.
  361. */
  362. struct GNUNET_FS_Uri *chk_uri;
  363. /**
  364. * Block options for the file.
  365. */
  366. struct GNUNET_FS_BlockOptions bo;
  367. /**
  368. * At what time did we start this upload?
  369. */
  370. struct GNUNET_TIME_Absolute start_time;
  371. /**
  372. * Under what filename is this struct serialized
  373. * (for operational persistence). Should be determined
  374. * using 'mktemp'.
  375. */
  376. char *serialization;
  377. /**
  378. * Encoder being used to publish this file.
  379. */
  380. struct GNUNET_FS_TreeEncoder *te;
  381. /**
  382. * Error message (non-NULL if this operation failed).
  383. */
  384. char *emsg;
  385. /**
  386. * Name of the file or directory (must be an absolute path).
  387. */
  388. char *filename;
  389. /**
  390. * Data describing either the file or the directory.
  391. */
  392. union
  393. {
  394. /**
  395. * Data for a file.
  396. */
  397. struct
  398. {
  399. /**
  400. * Function that can be used to read the data for the file.
  401. */
  402. GNUNET_FS_DataReader reader;
  403. /**
  404. * Closure for reader.
  405. */
  406. void *reader_cls;
  407. /**
  408. * If this file is being indexed, this value is set to the hash
  409. * over the entire file (when the indexing process is started).
  410. * Otherwise this field is not used.
  411. */
  412. GNUNET_HashCode file_id;
  413. /**
  414. * Size of the file (in bytes).
  415. */
  416. uint64_t file_size;
  417. /**
  418. * Should the file be indexed or inserted?
  419. */
  420. int do_index;
  421. /**
  422. * Is "file_id" already valid? Set to GNUNET_YES once the hash
  423. * has been calculated.
  424. */
  425. int have_hash;
  426. /**
  427. * Has the service confirmed our INDEX_START request?
  428. * GNUNET_YES if this step has been completed.
  429. */
  430. int index_start_confirmed;
  431. } file;
  432. /**
  433. * Data for a directory.
  434. */
  435. struct
  436. {
  437. /**
  438. * Linked list of entries in the directory.
  439. */
  440. struct GNUNET_FS_FileInformation *entries;
  441. /**
  442. * Size of the directory itself (in bytes); 0 if the
  443. * size has not yet been calculated.
  444. */
  445. size_t dir_size;
  446. /**
  447. * Pointer to the data for the directory (or NULL if not
  448. * available).
  449. */
  450. void *dir_data;
  451. } dir;
  452. } data;
  453. /**
  454. * Is this struct for a file or directory?
  455. */
  456. int is_directory;
  457. /**
  458. * Are we done publishing this file?
  459. */
  460. int is_published;
  461. };
  462. /**
  463. * The job is now ready to run and should use the given client
  464. * handle to communicate with the FS service.
  465. *
  466. * @param cls closure
  467. * @param client handle to use for FS communication
  468. */
  469. typedef void (*GNUNET_FS_QueueStart) (void *cls,
  470. struct GNUNET_CLIENT_Connection * client);
  471. /**
  472. * The job must now stop to run and should destry the client handle as
  473. * soon as possible (ideally prior to returning).
  474. */
  475. typedef void (*GNUNET_FS_QueueStop) (void *cls);
  476. /**
  477. * Entry in the job queue.
  478. */
  479. struct GNUNET_FS_QueueEntry
  480. {
  481. /**
  482. * This is a linked list.
  483. */
  484. struct GNUNET_FS_QueueEntry *next;
  485. /**
  486. * This is a linked list.
  487. */
  488. struct GNUNET_FS_QueueEntry *prev;
  489. /**
  490. * Function to call when the job is started.
  491. */
  492. GNUNET_FS_QueueStart start;
  493. /**
  494. * Function to call when the job needs to stop (or is done / dequeued).
  495. */
  496. GNUNET_FS_QueueStop stop;
  497. /**
  498. * Closure for start and stop.
  499. */
  500. void *cls;
  501. /**
  502. * Handle to FS primary context.
  503. */
  504. struct GNUNET_FS_Handle *h;
  505. /**
  506. * Client handle, or NULL if job is not running.
  507. */
  508. struct GNUNET_CLIENT_Connection *client;
  509. /**
  510. * Time the job was originally queued.
  511. */
  512. struct GNUNET_TIME_Absolute queue_time;
  513. /**
  514. * Time the job was started last.
  515. */
  516. struct GNUNET_TIME_Absolute start_time;
  517. /**
  518. * Total amount of time the job has been running (except for the
  519. * current run).
  520. */
  521. struct GNUNET_TIME_Relative run_time;
  522. /**
  523. * How many blocks do the active downloads have?
  524. */
  525. unsigned int blocks;
  526. /**
  527. * How often have we (re)started this download?
  528. */
  529. unsigned int start_times;
  530. };
  531. /**
  532. * Information we store for each search result.
  533. */
  534. struct GNUNET_FS_SearchResult
  535. {
  536. /**
  537. * Search context this result belongs to.
  538. */
  539. struct GNUNET_FS_SearchContext *sc;
  540. /**
  541. * URI to which this search result refers to.
  542. */
  543. struct GNUNET_FS_Uri *uri;
  544. /**
  545. * Metadata for the search result.
  546. */
  547. struct GNUNET_CONTAINER_MetaData *meta;
  548. /**
  549. * Client info for this search result.
  550. */
  551. void *client_info;
  552. /**
  553. * ID of a job that is currently probing this results' availability
  554. * (NULL if we are not currently probing).
  555. */
  556. struct GNUNET_FS_DownloadContext *probe_ctx;
  557. /**
  558. * ID of an associated download based on this search result (or
  559. * NULL for none).
  560. */
  561. struct GNUNET_FS_DownloadContext *download;
  562. /**
  563. * If this search result triggered an update search, this field
  564. * links to the update search.
  565. */
  566. struct GNUNET_FS_SearchContext *update_search;
  567. /**
  568. * Name under which this search result is stored on disk.
  569. */
  570. char *serialization;
  571. /**
  572. * Key for the search result
  573. */
  574. GNUNET_HashCode key;
  575. /**
  576. * ID of the task that will clean up the probe_ctx should it not
  577. * complete on time (and that will need to be cancelled if we clean
  578. * up the search result before then).
  579. */
  580. GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
  581. /**
  582. * When did the current probe become active?
  583. */
  584. struct GNUNET_TIME_Absolute probe_active_time;
  585. /**
  586. * How much longer should we run the current probe before giving up?
  587. */
  588. struct GNUNET_TIME_Relative remaining_probe_time;
  589. /**
  590. * Number of mandatory keywords for which we have NOT yet found the
  591. * search result; when this value hits zero, the search result is
  592. * given to the callback.
  593. */
  594. uint32_t mandatory_missing;
  595. /**
  596. * Number of optional keywords under which this result was also
  597. * found.
  598. */
  599. uint32_t optional_support;
  600. /**
  601. * Number of availability tests that have succeeded for this result.
  602. */
  603. uint32_t availability_success;
  604. /**
  605. * Number of availability trials that we have performed for this
  606. * search result.
  607. */
  608. uint32_t availability_trials;
  609. };
  610. /**
  611. * Add a job to the queue.
  612. *
  613. * @param h handle to the overall FS state
  614. * @param start function to call to begin the job
  615. * @param stop function to call to pause the job, or on dequeue (if the job was running)
  616. * @param cls closure for start and stop
  617. * @param blocks number of blocks this download has
  618. * @return queue handle
  619. */
  620. struct GNUNET_FS_QueueEntry *
  621. GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, GNUNET_FS_QueueStart start,
  622. GNUNET_FS_QueueStop stop, void *cls, unsigned int blocks);
  623. /**
  624. * Dequeue a job from the queue.
  625. * @param qh handle for the job
  626. */
  627. void
  628. GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
  629. /**
  630. * Function that provides data by reading from a file.
  631. *
  632. * @param cls closure (points to the file information)
  633. * @param offset offset to read from; it is possible
  634. * that the caller might need to go backwards
  635. * a bit at times
  636. * @param max maximum number of bytes that should be
  637. * copied to buf; readers are not allowed
  638. * to provide less data unless there is an error;
  639. * a value of "0" will be used at the end to allow
  640. * the reader to clean up its internal state
  641. * @param buf where the reader should write the data
  642. * @param emsg location for the reader to store an error message
  643. * @return number of bytes written, usually "max", 0 on error
  644. */
  645. size_t
  646. GNUNET_FS_data_reader_file_ (void *cls, uint64_t offset, size_t max, void *buf,
  647. char **emsg);
  648. /**
  649. * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
  650. *
  651. * @param filename file to read
  652. * @return closure to use
  653. */
  654. void *
  655. GNUNET_FS_make_file_reader_context_ (const char *filename);
  656. /**
  657. * Function that provides data by copying from a buffer.
  658. *
  659. * @param cls closure (points to the buffer)
  660. * @param offset offset to read from; it is possible
  661. * that the caller might need to go backwards
  662. * a bit at times
  663. * @param max maximum number of bytes that should be
  664. * copied to buf; readers are not allowed
  665. * to provide less data unless there is an error;
  666. * a value of "0" will be used at the end to allow
  667. * the reader to clean up its internal state
  668. * @param buf where the reader should write the data
  669. * @param emsg location for the reader to store an error message
  670. * @return number of bytes written, usually "max", 0 on error
  671. */
  672. size_t
  673. GNUNET_FS_data_reader_copy_ (void *cls, uint64_t offset, size_t max, void *buf,
  674. char **emsg);
  675. /**
  676. * Notification of FS that a search probe has made progress.
  677. * This function is used INSTEAD of the client's event handler
  678. * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
  679. *
  680. * @param cls closure, always NULL (!), actual closure
  681. * is in the client-context of the info struct
  682. * @param info details about the event, specifying the event type
  683. * and various bits about the event
  684. * @return client-context (for the next progress call
  685. * for this operation; should be set to NULL for
  686. * SUSPEND and STOPPED events). The value returned
  687. * will be passed to future callbacks in the respective
  688. * field in the GNUNET_FS_ProgressInfo struct.
  689. */
  690. void *
  691. GNUNET_FS_search_probe_progress_ (void *cls,
  692. const struct GNUNET_FS_ProgressInfo *info);
  693. /**
  694. * Main function that performs the upload.
  695. *
  696. * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
  697. * @param tc task context
  698. */
  699. void
  700. GNUNET_FS_publish_main_ (void *cls,
  701. const struct GNUNET_SCHEDULER_TaskContext *tc);
  702. /**
  703. * Function called once the hash of the file
  704. * that is being unindexed has been computed.
  705. *
  706. * @param cls closure, unindex context
  707. * @param file_id computed hash, NULL on error
  708. */
  709. void
  710. GNUNET_FS_unindex_process_hash_ (void *cls, const GNUNET_HashCode * file_id);
  711. /**
  712. * Fill in all of the generic fields for a publish event and call the
  713. * callback.
  714. *
  715. * @param pi structure to fill in
  716. * @param sc overall publishing context
  717. * @param p file information for the file being published
  718. * @param offset where in the file are we so far
  719. * @return value returned from callback
  720. */
  721. void *
  722. GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
  723. struct GNUNET_FS_PublishContext *sc,
  724. const struct GNUNET_FS_FileInformation *p,
  725. uint64_t offset);
  726. /**
  727. * Fill in all of the generic fields for a download event and call the
  728. * callback.
  729. *
  730. * @param pi structure to fill in
  731. * @param dc overall download context
  732. */
  733. void
  734. GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
  735. struct GNUNET_FS_DownloadContext *dc);
  736. /**
  737. * Task that creates the initial (top-level) download
  738. * request for the file.
  739. *
  740. * @param cls the 'struct GNUNET_FS_DownloadContext'
  741. * @param tc scheduler context
  742. */
  743. void
  744. GNUNET_FS_download_start_task_ (void *cls,
  745. const struct GNUNET_SCHEDULER_TaskContext *tc);
  746. /**
  747. * Fill in all of the generic fields for
  748. * an unindex event and call the callback.
  749. *
  750. * @param pi structure to fill in
  751. * @param uc overall unindex context
  752. * @param offset where we are in the file (for progress)
  753. */
  754. void
  755. GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
  756. struct GNUNET_FS_UnindexContext *uc,
  757. uint64_t offset);
  758. /**
  759. * Fill in all of the generic fields for a search event and
  760. * call the callback.
  761. *
  762. * @param pi structure to fill in
  763. * @param sc overall search context
  764. * @return value returned by the callback
  765. */
  766. void *
  767. GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
  768. struct GNUNET_FS_SearchContext *sc);
  769. /**
  770. * Connect to the datastore and remove the blocks.
  771. *
  772. * @param uc context for the unindex operation.
  773. */
  774. void
  775. GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
  776. /**
  777. * Build the request and actually initiate the search using the
  778. * GNUnet FS service.
  779. *
  780. * @param sc search context
  781. * @return GNUNET_OK on success, GNUNET_SYSERR on error
  782. */
  783. int
  784. GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
  785. /**
  786. * Start the downloading process (by entering the queue).
  787. *
  788. * @param dc our download context
  789. */
  790. void
  791. GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
  792. /**
  793. * Start download probes for the given search result.
  794. *
  795. * @param sr the search result
  796. */
  797. void
  798. GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
  799. /**
  800. * Remove serialization/deserialization file from disk.
  801. *
  802. * @param h master context
  803. * @param ext component of the path
  804. * @param ent entity identifier
  805. */
  806. void
  807. GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, const char *ext,
  808. const char *ent);
  809. /**
  810. * Remove serialization/deserialization directory from disk.
  811. *
  812. * @param h master context
  813. * @param ext component of the path
  814. * @param uni unique name of parent
  815. */
  816. void
  817. GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, const char *ext,
  818. const char *uni);
  819. /**
  820. * Synchronize this file-information struct with its mirror
  821. * on disk. Note that all internal FS-operations that change
  822. * file information data should already call "sync" internally,
  823. * so this function is likely not useful for clients.
  824. *
  825. * @param fi the struct to sync
  826. */
  827. void
  828. GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
  829. /**
  830. * Synchronize this publishing struct with its mirror
  831. * on disk. Note that all internal FS-operations that change
  832. * publishing structs should already call "sync" internally,
  833. * so this function is likely not useful for clients.
  834. *
  835. * @param pc the struct to sync
  836. */
  837. void
  838. GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
  839. /**
  840. * Synchronize this unindex struct with its mirror
  841. * on disk. Note that all internal FS-operations that change
  842. * publishing structs should already call "sync" internally,
  843. * so this function is likely not useful for clients.
  844. *
  845. * @param uc the struct to sync
  846. */
  847. void
  848. GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
  849. /**
  850. * Synchronize this search struct with its mirror
  851. * on disk. Note that all internal FS-operations that change
  852. * publishing structs should already call "sync" internally,
  853. * so this function is likely not useful for clients.
  854. *
  855. * @param sc the struct to sync
  856. */
  857. void
  858. GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
  859. /**
  860. * Synchronize this search result with its mirror
  861. * on disk. Note that all internal FS-operations that change
  862. * publishing structs should already call "sync" internally,
  863. * so this function is likely not useful for clients.
  864. *
  865. * @param sr the struct to sync
  866. */
  867. void
  868. GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
  869. /**
  870. * Synchronize this download struct with its mirror
  871. * on disk. Note that all internal FS-operations that change
  872. * publishing structs should already call "sync" internally,
  873. * so this function is likely not useful for clients.
  874. *
  875. * @param dc the struct to sync
  876. */
  877. void
  878. GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
  879. /**
  880. * Create SUSPEND event for the given publish operation
  881. * and then clean up our state (without stop signal).
  882. *
  883. * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
  884. */
  885. void
  886. GNUNET_FS_publish_signal_suspend_ (void *cls);
  887. /**
  888. * Create SUSPEND event for the given search operation
  889. * and then clean up our state (without stop signal).
  890. *
  891. * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
  892. */
  893. void
  894. GNUNET_FS_search_signal_suspend_ (void *cls);
  895. /**
  896. * Create SUSPEND event for the given download operation
  897. * and then clean up our state (without stop signal).
  898. *
  899. * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
  900. */
  901. void
  902. GNUNET_FS_download_signal_suspend_ (void *cls);
  903. /**
  904. * Create SUSPEND event for the given unindex operation
  905. * and then clean up our state (without stop signal).
  906. *
  907. * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
  908. */
  909. void
  910. GNUNET_FS_unindex_signal_suspend_ (void *cls);
  911. /**
  912. * Function signature of the functions that can be called
  913. * to trigger suspend signals and clean-up for top-level
  914. * activities.
  915. *
  916. * @param cls closure
  917. */
  918. typedef void (*SuspendSignalFunction) (void *cls);
  919. /**
  920. * We track all of the top-level activities of FS
  921. * so that we can signal 'suspend' on shutdown.
  922. */
  923. struct TopLevelActivity
  924. {
  925. /**
  926. * This is a doubly-linked list.
  927. */
  928. struct TopLevelActivity *next;
  929. /**
  930. * This is a doubly-linked list.
  931. */
  932. struct TopLevelActivity *prev;
  933. /**
  934. * Function to call for suspend-signalling and clean up.
  935. */
  936. SuspendSignalFunction ssf;
  937. /**
  938. * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
  939. */
  940. void *ssf_cls;
  941. };
  942. /**
  943. * Create a top-level activity entry.
  944. *
  945. * @param h global fs handle
  946. * @param ssf suspend signal function to use
  947. * @param ssf_cls closure for ssf
  948. * @return fresh top-level activity handle
  949. */
  950. struct TopLevelActivity *
  951. GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, SuspendSignalFunction ssf,
  952. void *ssf_cls);
  953. /**
  954. * Destroy a top-level activity entry.
  955. *
  956. * @param h global fs handle
  957. * @param top top level activity entry
  958. */
  959. void
  960. GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top);
  961. /**
  962. * Master context for most FS operations.
  963. */
  964. struct GNUNET_FS_Handle
  965. {
  966. /**
  967. * Configuration to use.
  968. */
  969. const struct GNUNET_CONFIGURATION_Handle *cfg;
  970. /**
  971. * Name of our client.
  972. */
  973. char *client_name;
  974. /**
  975. * Function to call with updates on our progress.
  976. */
  977. GNUNET_FS_ProgressCallback upcb;
  978. /**
  979. * Closure for upcb.
  980. */
  981. void *upcb_cls;
  982. /**
  983. * Head of DLL of top-level activities.
  984. */
  985. struct TopLevelActivity *top_head;
  986. /**
  987. * Tail of DLL of top-level activities.
  988. */
  989. struct TopLevelActivity *top_tail;
  990. /**
  991. * Head of DLL of running jobs.
  992. */
  993. struct GNUNET_FS_QueueEntry *running_head;
  994. /**
  995. * Tail of DLL of running jobs.
  996. */
  997. struct GNUNET_FS_QueueEntry *running_tail;
  998. /**
  999. * Head of DLL of pending jobs.
  1000. */
  1001. struct GNUNET_FS_QueueEntry *pending_head;
  1002. /**
  1003. * Tail of DLL of pending jobs.
  1004. */
  1005. struct GNUNET_FS_QueueEntry *pending_tail;
  1006. /**
  1007. * Task that processes the jobs in the running and pending queues
  1008. * (and moves jobs around as needed).
  1009. */
  1010. GNUNET_SCHEDULER_TaskIdentifier queue_job;
  1011. /**
  1012. * Average time we take for a single request to be satisfied.
  1013. * FIXME: not yet calcualted properly...
  1014. */
  1015. struct GNUNET_TIME_Relative avg_block_latency;
  1016. /**
  1017. * How many actual downloads do we have running right now?
  1018. */
  1019. unsigned int active_downloads;
  1020. /**
  1021. * How many blocks do the active downloads have?
  1022. */
  1023. unsigned int active_blocks;
  1024. /**
  1025. * General flags.
  1026. */
  1027. enum GNUNET_FS_Flags flags;
  1028. /**
  1029. * Maximum number of parallel downloads.
  1030. */
  1031. unsigned int max_parallel_downloads;
  1032. /**
  1033. * Maximum number of parallel requests.
  1034. */
  1035. unsigned int max_parallel_requests;
  1036. };
  1037. /**
  1038. * Handle for controlling a publication process.
  1039. */
  1040. struct GNUNET_FS_PublishContext
  1041. {
  1042. /**
  1043. * Handle to the global fs context.
  1044. */
  1045. struct GNUNET_FS_Handle *h;
  1046. /**
  1047. * Our top-level activity entry (if we are top-level, otherwise NULL).
  1048. */
  1049. struct TopLevelActivity *top;
  1050. /**
  1051. * File-structure that is being shared.
  1052. */
  1053. struct GNUNET_FS_FileInformation *fi;
  1054. /**
  1055. * Namespace that we are publishing in, NULL if we have no namespace.
  1056. */
  1057. struct GNUNET_FS_Namespace *namespace;
  1058. /**
  1059. * ID of the content in the namespace, NULL if we have no namespace.
  1060. */
  1061. char *nid;
  1062. /**
  1063. * ID for future updates, NULL if we have no namespace or no updates.
  1064. */
  1065. char *nuid;
  1066. /**
  1067. * Filename used for serializing information about this operation
  1068. * (should be determined using 'mktemp').
  1069. */
  1070. char *serialization;
  1071. /**
  1072. * Our own client handle for the FS service; only briefly used when
  1073. * we start to index a file, otherwise NULL.
  1074. */
  1075. struct GNUNET_CLIENT_Connection *client;
  1076. /**
  1077. * Current position in the file-tree for the upload.
  1078. */
  1079. struct GNUNET_FS_FileInformation *fi_pos;
  1080. /**
  1081. * Non-null if we are currently hashing a file.
  1082. */
  1083. struct GNUNET_CRYPTO_FileHashContext *fhc;
  1084. /**
  1085. * Connection to the datastore service.
  1086. */
  1087. struct GNUNET_DATASTORE_Handle *dsh;
  1088. /**
  1089. * Queue entry for reservation/unreservation.
  1090. */
  1091. struct GNUNET_DATASTORE_QueueEntry *qre;
  1092. /**
  1093. * ID of the task performing the upload. NO_TASK if the upload has
  1094. * completed.
  1095. */
  1096. GNUNET_SCHEDULER_TaskIdentifier upload_task;
  1097. /**
  1098. * Storage space to reserve for the operation.
  1099. */
  1100. uint64_t reserve_space;
  1101. /**
  1102. * Overall number of entries to reserve for the
  1103. * publish operation.
  1104. */
  1105. uint32_t reserve_entries;
  1106. /**
  1107. * Typically GNUNET_NO. Set to GNUNET_YES if "upload_task" is
  1108. * GNUNET_SCHEDULER_NO_TASK and we're waiting for a response from
  1109. * the datastore service (in which case this struct must not be
  1110. * freed until we have that response). If someone tries to stop the
  1111. * download for good during this period, "in_network_wait" is set to
  1112. * GNUNET_SYSERR which will cause the struct to be destroyed right
  1113. * after we have the reply (or timeout) from the datastore service.
  1114. */
  1115. int in_network_wait;
  1116. /**
  1117. * Options for publishing.
  1118. */
  1119. enum GNUNET_FS_PublishOptions options;
  1120. /**
  1121. * Space reservation ID with datastore service
  1122. * for this upload.
  1123. */
  1124. int rid;
  1125. /**
  1126. * Set to GNUNET_YES if all processing has completed.
  1127. */
  1128. int all_done;
  1129. };
  1130. /**
  1131. * Phases of unindex processing (state machine).
  1132. */
  1133. enum UnindexState
  1134. {
  1135. /**
  1136. * We're currently hashing the file.
  1137. */
  1138. UNINDEX_STATE_HASHING = 0,
  1139. /**
  1140. * We're telling the datastore to delete
  1141. * the respective entries.
  1142. */
  1143. UNINDEX_STATE_DS_REMOVE = 1,
  1144. /**
  1145. * We're notifying the FS service about
  1146. * the unindexing.
  1147. */
  1148. UNINDEX_STATE_FS_NOTIFY = 2,
  1149. /**
  1150. * We're done.
  1151. */
  1152. UNINDEX_STATE_COMPLETE = 3,
  1153. /**
  1154. * We've encountered a fatal error.
  1155. */
  1156. UNINDEX_STATE_ERROR = 4
  1157. };
  1158. /**
  1159. * Handle for controlling an unindexing operation.
  1160. */
  1161. struct GNUNET_FS_UnindexContext
  1162. {
  1163. /**
  1164. * Global FS context.
  1165. */
  1166. struct GNUNET_FS_Handle *h;
  1167. /**
  1168. * Our top-level activity entry.
  1169. */
  1170. struct TopLevelActivity *top;
  1171. /**
  1172. * Name of the file that we are unindexing.
  1173. */
  1174. char *filename;
  1175. /**
  1176. * Short name under which we are serializing the state of this operation.
  1177. */
  1178. char *serialization;
  1179. /**
  1180. * Connection to the FS service, only valid during the
  1181. * UNINDEX_STATE_FS_NOTIFY phase.
  1182. */
  1183. struct GNUNET_CLIENT_Connection *client;
  1184. /**
  1185. * Connection to the datastore service, only valid during the
  1186. * UNINDEX_STATE_DS_NOTIFY phase.
  1187. */
  1188. struct GNUNET_DATASTORE_Handle *dsh;
  1189. /**
  1190. * Pointer kept for the client.
  1191. */
  1192. void *client_info;
  1193. /**
  1194. * Merkle-ish tree encoder context.
  1195. */
  1196. struct GNUNET_FS_TreeEncoder *tc;
  1197. /**
  1198. * Handle used to read the file.
  1199. */
  1200. struct GNUNET_DISK_FileHandle *fh;
  1201. /**
  1202. * Error message, NULL on success.
  1203. */
  1204. char *emsg;
  1205. /**
  1206. * Context for hashing of the file.
  1207. */
  1208. struct GNUNET_CRYPTO_FileHashContext *fhc;
  1209. /**
  1210. * Overall size of the file.
  1211. */
  1212. uint64_t file_size;
  1213. /**
  1214. * When did we start?
  1215. */
  1216. struct GNUNET_TIME_Absolute start_time;
  1217. /**
  1218. * Hash of the file's contents (once computed).
  1219. */
  1220. GNUNET_HashCode file_id;
  1221. /**
  1222. * Current operatinonal phase.
  1223. */
  1224. enum UnindexState state;
  1225. };
  1226. /**
  1227. * Information we keep for each keyword in
  1228. * a keyword search.
  1229. */
  1230. struct SearchRequestEntry
  1231. {
  1232. /**
  1233. * Hash of the original keyword, also known as the
  1234. * key (for decrypting the KBlock).
  1235. */
  1236. GNUNET_HashCode key;
  1237. /**
  1238. * Hash of the public key, also known as the query.
  1239. */
  1240. GNUNET_HashCode query;
  1241. /**
  1242. * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
  1243. * was found under this keyword. Note that the entries will point
  1244. * to the same locations as those in the master result map (in
  1245. * "struct GNUNET_FS_SearchContext"), so they should not be freed.
  1246. * The key for each entry is the XOR of the key and query in the CHK
  1247. * URI (as a unique identifier for the search result).
  1248. */
  1249. struct GNUNET_CONTAINER_MultiHashMap *results;
  1250. /**
  1251. * Is this keyword a mandatory keyword
  1252. * (started with '+')?
  1253. */
  1254. int mandatory;
  1255. };
  1256. /**
  1257. * Handle for controlling a search.
  1258. */
  1259. struct GNUNET_FS_SearchContext
  1260. {
  1261. /**
  1262. * Handle to the global FS context.
  1263. */
  1264. struct GNUNET_FS_Handle *h;
  1265. /**
  1266. * Our top-level activity entry (if we are top-level, otherwise NULL).
  1267. */
  1268. struct TopLevelActivity *top;
  1269. /**
  1270. * List of keywords that we're looking for.
  1271. */
  1272. struct GNUNET_FS_Uri *uri;
  1273. /**
  1274. * For update-searches, link to the search result that triggered
  1275. * the update search; otherwise NULL.
  1276. */
  1277. struct GNUNET_FS_SearchResult *psearch_result;
  1278. /**
  1279. * Connection to the FS service.
  1280. */
  1281. struct GNUNET_CLIENT_Connection *client;
  1282. /**
  1283. * Pointer we keep for the client.
  1284. */
  1285. void *client_info;
  1286. /**
  1287. * Name of the file on disk we use for persistence.
  1288. */
  1289. char *serialization;
  1290. /**
  1291. * Error message (non-NULL if this operation failed).
  1292. */
  1293. char *emsg;
  1294. /**
  1295. * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
  1296. * was found in the search. The key for each entry is the XOR of
  1297. * the key and query in the CHK URI (as a unique identifier for the
  1298. * search result).
  1299. */
  1300. struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
  1301. /**
  1302. * Per-keyword information for a keyword search. This array will
  1303. * have exactly as many entries as there were keywords.
  1304. */
  1305. struct SearchRequestEntry *requests;
  1306. /**
  1307. * When did we start?
  1308. */
  1309. struct GNUNET_TIME_Absolute start_time;
  1310. /**
  1311. * ID of a task that is using this struct and that must be cancelled
  1312. * when the search is being stopped (if not
  1313. * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
  1314. * artificial delay when trying to reconnect to the FS service.
  1315. */
  1316. GNUNET_SCHEDULER_TaskIdentifier task;
  1317. /**
  1318. * How many of the entries in the search request
  1319. * map have been passed to the service so far?
  1320. */
  1321. unsigned int search_request_map_offset;
  1322. /**
  1323. * How many of the keywords in the KSK
  1324. * map have been passed to the service so far?
  1325. */
  1326. unsigned int keyword_offset;
  1327. /**
  1328. * Anonymity level for the search.
  1329. */
  1330. uint32_t anonymity;
  1331. /**
  1332. * Number of mandatory keywords in this query.
  1333. */
  1334. uint32_t mandatory_count;
  1335. /**
  1336. * Options for the search.
  1337. */
  1338. enum GNUNET_FS_SearchOptions options;
  1339. };
  1340. /**
  1341. * FSM for possible states a block can go through. The typical
  1342. * order of progression is linear through the states, alternatives
  1343. * are documented in the comments.
  1344. */
  1345. enum BlockRequestState
  1346. {
  1347. /**
  1348. * Initial state, block has only been allocated (since it is
  1349. * relevant to the overall download request).
  1350. */
  1351. BRS_INIT = 0,
  1352. /**
  1353. * We've checked the block on the path down the tree, and the
  1354. * content on disk did match the desired CHK, but not all
  1355. * the way down, so at the bottom some blocks will still
  1356. * need to be reconstructed).
  1357. */
  1358. BRS_RECONSTRUCT_DOWN = 1,
  1359. /**
  1360. * We've calculated the CHK bottom-up based on the meta data.
  1361. * This may work, but if it did we have to write the meta data to
  1362. * disk at the end (and we still need to check against the
  1363. * CHK set on top).
  1364. */
  1365. BRS_RECONSTRUCT_META_UP = 2,
  1366. /**
  1367. * We've calculated the CHK bottom-up based on what we have on
  1368. * disk, which may not be what the desired CHK is. If the
  1369. * reconstructed CHKs match whatever comes from above, we're
  1370. * done with the respective subtree.
  1371. */
  1372. BRS_RECONSTRUCT_UP = 3,
  1373. /**
  1374. * We've determined the real, desired CHK for this block
  1375. * (full tree reconstruction failed), request is now pending.
  1376. * If the CHK that bubbled up through reconstruction did match
  1377. * the top-level request, the state machine for the subtree
  1378. * would have moved to BRS_DOWNLOAD_UP.
  1379. */
  1380. BRS_CHK_SET = 4,
  1381. /**
  1382. * We've successfully downloaded this block, but the children
  1383. * still need to be either downloaded or verified (download
  1384. * request propagates down). If the download fails, the
  1385. * state machine for this block may move to
  1386. * BRS_DOWNLOAD_ERROR instead.
  1387. */
  1388. BRS_DOWNLOAD_DOWN = 5,
  1389. /**
  1390. * This block and all of its children have been downloaded
  1391. * successfully (full completion propagates up).
  1392. */
  1393. BRS_DOWNLOAD_UP = 6,
  1394. /**
  1395. * We got a block back that matched the query but did not hash to
  1396. * the key (malicious publisher or hash collision); this block
  1397. * can never be downloaded (error propagates up).
  1398. */
  1399. BRS_ERROR = 7
  1400. };
  1401. /**
  1402. * Information about an active download request.
  1403. */
  1404. struct DownloadRequest
  1405. {
  1406. /**
  1407. * While pending, we keep all download requests in a doubly-linked list.
  1408. */
  1409. struct DownloadRequest *next;
  1410. /**
  1411. * While pending, we keep all download requests in a doubly-linked list.
  1412. */
  1413. struct DownloadRequest *prev;
  1414. /**
  1415. * Parent in the CHK-tree.
  1416. */
  1417. struct DownloadRequest *parent;
  1418. /**
  1419. * Array (!) of child-requests, or NULL for the bottom of the tree.
  1420. */
  1421. struct DownloadRequest **children;
  1422. /**
  1423. * CHK for the request for this block (set during reconstruction
  1424. * to what we have on disk, later to what we want to have).
  1425. */
  1426. struct ContentHashKey chk;
  1427. /**
  1428. * Offset of the corresponding block. Specifically, first (!) byte of
  1429. * the first DBLOCK in the subtree induced by block represented by
  1430. * this request.
  1431. */
  1432. uint64_t offset;
  1433. /**
  1434. * Number of entries in 'children' array.
  1435. */
  1436. unsigned int num_children;
  1437. /**
  1438. * Depth of the corresponding block in the tree. 0==DBLOCKs.
  1439. */
  1440. unsigned int depth;
  1441. /**
  1442. * State in the FSM.
  1443. */
  1444. enum BlockRequestState state;
  1445. /**
  1446. * GNUNET_YES if this entry is in the pending list.
  1447. */
  1448. int is_pending;
  1449. };
  1450. /**
  1451. * (recursively) free download request structure
  1452. *
  1453. * @param dr request to free
  1454. */
  1455. void
  1456. GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
  1457. /**
  1458. * Context for controlling a download.
  1459. */
  1460. struct GNUNET_FS_DownloadContext
  1461. {
  1462. /**
  1463. * Global FS context.
  1464. */
  1465. struct GNUNET_FS_Handle *h;
  1466. /**
  1467. * Our top-level activity entry (if we are top-level, otherwise NULL).
  1468. */
  1469. struct TopLevelActivity *top;
  1470. /**
  1471. * Connection to the FS service.
  1472. */
  1473. struct GNUNET_CLIENT_Connection *client;
  1474. /**
  1475. * Parent download (used when downloading files
  1476. * in directories).
  1477. */
  1478. struct GNUNET_FS_DownloadContext *parent;
  1479. /**
  1480. * Associated search (used when downloading files
  1481. * based on search results), or NULL for none.
  1482. */
  1483. struct GNUNET_FS_SearchResult *search;
  1484. /**
  1485. * Head of list of child downloads.
  1486. */
  1487. struct GNUNET_FS_DownloadContext *child_head;
  1488. /**
  1489. * Tail of list of child downloads.
  1490. */
  1491. struct GNUNET_FS_DownloadContext *child_tail;
  1492. /**
  1493. * Previous download belonging to the same parent.
  1494. */
  1495. struct GNUNET_FS_DownloadContext *prev;
  1496. /**
  1497. * Next download belonging to the same parent.
  1498. */
  1499. struct GNUNET_FS_DownloadContext *next;
  1500. /**
  1501. * Context kept for the client.
  1502. */
  1503. void *client_info;
  1504. /**
  1505. * URI that identifies the file that we are downloading.
  1506. */
  1507. struct GNUNET_FS_Uri *uri;
  1508. /**
  1509. * Known meta-data for the file (can be NULL).
  1510. */
  1511. struct GNUNET_CONTAINER_MetaData *meta;
  1512. /**
  1513. * Error message, NULL if we're doing OK.
  1514. */
  1515. char *emsg;
  1516. /**
  1517. * Random portion of filename we use for syncing state of this
  1518. * download.
  1519. */
  1520. char *serialization;
  1521. /**
  1522. * Where are we writing the data (name of the
  1523. * file, can be NULL!).
  1524. */
  1525. char *filename;
  1526. /**
  1527. * Where are we writing the data temporarily (name of the
  1528. * file, can be NULL!); used if we do not have a permanent
  1529. * name and we are a directory and we do a recursive download.
  1530. */
  1531. char *temp_filename;
  1532. /**
  1533. * Our entry in the job queue.
  1534. */
  1535. struct GNUNET_FS_QueueEntry *job_queue;
  1536. /**
  1537. * Non-NULL if we are currently having a request for
  1538. * transmission pending with the client handle.
  1539. */
  1540. struct GNUNET_CLIENT_TransmitHandle *th;
  1541. /**
  1542. * Tree encoder used for the reconstruction.
  1543. */
  1544. struct GNUNET_FS_TreeEncoder *te;
  1545. /**
  1546. * File handle for reading data from an existing file
  1547. * (to pass to tree encoder).
  1548. */
  1549. struct GNUNET_DISK_FileHandle *rfh;
  1550. /**
  1551. * Map of active requests (those waiting for a response). The key
  1552. * is the hash of the encryped block (aka query).
  1553. */
  1554. struct GNUNET_CONTAINER_MultiHashMap *active;
  1555. /**
  1556. * Head of linked list of pending requests.
  1557. */
  1558. struct DownloadRequest *pending_head;
  1559. /**
  1560. * Head of linked list of pending requests.
  1561. */
  1562. struct DownloadRequest *pending_tail;
  1563. /**
  1564. * Top-level download request.
  1565. */
  1566. struct DownloadRequest *top_request;
  1567. /**
  1568. * Identity of the peer having the content, or all-zeros
  1569. * if we don't know of such a peer.
  1570. */
  1571. struct GNUNET_PeerIdentity target;
  1572. /**
  1573. * ID of a task that is using this struct and that must be cancelled
  1574. * when the download is being stopped (if not
  1575. * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
  1576. * artificial delay when trying to reconnect to the FS service or
  1577. * the task processing incrementally the data on disk, or the
  1578. * task requesting blocks, etc.
  1579. */
  1580. GNUNET_SCHEDULER_TaskIdentifier task;
  1581. /**
  1582. * What is the first offset that we're interested
  1583. * in?
  1584. */
  1585. uint64_t offset;
  1586. /**
  1587. * How many bytes starting from offset are desired?
  1588. * This is NOT the overall length of the file!
  1589. */
  1590. uint64_t length;
  1591. /**
  1592. * How many bytes have we already received within
  1593. * the specified range (DBlocks only).
  1594. */
  1595. uint64_t completed;
  1596. /**
  1597. * What was the size of the file on disk that we're downloading
  1598. * before we started? Used to detect if there is a point in
  1599. * checking an existing block on disk for matching the desired
  1600. * content. 0 if the file did not exist already.
  1601. */
  1602. uint64_t old_file_size;
  1603. /**
  1604. * Time download was started.
  1605. */
  1606. struct GNUNET_TIME_Absolute start_time;
  1607. /**
  1608. * Desired level of anonymity.
  1609. */
  1610. uint32_t anonymity;
  1611. /**
  1612. * The depth of the file-tree.
  1613. */
  1614. unsigned int treedepth;
  1615. /**
  1616. * Options for the download.
  1617. */
  1618. enum GNUNET_FS_DownloadOptions options;
  1619. /**
  1620. * Flag set upon transitive completion (includes child downloads).
  1621. * This flag is only set to GNUNET_YES for directories where all
  1622. * child-downloads have also completed (and signalled completion).
  1623. */
  1624. int has_finished;
  1625. /**
  1626. * Have we started the receive continuation yet?
  1627. */
  1628. int in_receive;
  1629. };
  1630. /**
  1631. * Information about an (updateable) node in the
  1632. * namespace.
  1633. */
  1634. struct NamespaceUpdateNode
  1635. {
  1636. /**
  1637. * Identifier for this node.
  1638. */
  1639. char *id;
  1640. /**
  1641. * Identifier of children of this node.
  1642. */
  1643. char *update;
  1644. /**
  1645. * Metadata for this entry.
  1646. */
  1647. struct GNUNET_CONTAINER_MetaData *md;
  1648. /**
  1649. * URI of this entry in the namespace.
  1650. */
  1651. struct GNUNET_FS_Uri *uri;
  1652. /**
  1653. * Namespace update generation ID. Used to ensure
  1654. * freshness of the tree_id.
  1655. */
  1656. unsigned int nug;
  1657. /**
  1658. * TREE this entry belongs to (if nug is current).
  1659. */
  1660. unsigned int tree_id;
  1661. };
  1662. struct GNUNET_FS_Namespace
  1663. {
  1664. /**
  1665. * Handle to the FS service context.
  1666. */
  1667. struct GNUNET_FS_Handle *h;
  1668. /**
  1669. * Array with information about nodes in the namespace.
  1670. */
  1671. struct NamespaceUpdateNode **update_nodes;
  1672. /**
  1673. * Private key for the namespace.
  1674. */
  1675. struct GNUNET_CRYPTO_RsaPrivateKey *key;
  1676. /**
  1677. * Hash map mapping identifiers of update nodes
  1678. * to the update nodes (initialized on-demand).
  1679. */
  1680. struct GNUNET_CONTAINER_MultiHashMap *update_map;
  1681. /**
  1682. * Name of the file with the private key.
  1683. */
  1684. char *filename;
  1685. /**
  1686. * Name of the namespace.
  1687. */
  1688. char *name;
  1689. /**
  1690. * Size of the update nodes array.
  1691. */
  1692. unsigned int update_node_count;
  1693. /**
  1694. * Reference counter.
  1695. */
  1696. unsigned int rc;
  1697. /**
  1698. * Generator for unique nug numbers.
  1699. */
  1700. unsigned int nug_gen;
  1701. };
  1702. /**
  1703. * Message sent from a GNUnet (fs) publishing activity to the
  1704. * gnunet-fs-service to initiate indexing of a file. The service is
  1705. * supposed to check if the specified file is available and has the
  1706. * same cryptographic hash. It should then respond with either a
  1707. * confirmation or a denial.
  1708. *
  1709. * On OSes where this works, it is considered acceptable if the
  1710. * service only checks that the path, device and inode match (it can
  1711. * then be assumed that the hash will also match without actually
  1712. * computing it; this is an optimization that should be safe given
  1713. * that the client is not our adversary).
  1714. */
  1715. struct IndexStartMessage
  1716. {
  1717. /**
  1718. * Message type will be GNUNET_MESSAGE_TYPE_FS_INDEX_START.
  1719. */
  1720. struct GNUNET_MessageHeader header;
  1721. /**
  1722. * For alignment.
  1723. */
  1724. uint32_t reserved GNUNET_PACKED;
  1725. /**
  1726. * ID of device containing the file, as seen by the client. This
  1727. * device ID is obtained using a call like "statvfs" (and converting
  1728. * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
  1729. * OS does not support this, in which case the service must do a
  1730. * full hash recomputation.
  1731. */
  1732. uint64_t device GNUNET_PACKED;
  1733. /**
  1734. * Inode of the file on the given device, as seen by the client
  1735. * ("st_ino" field from "struct stat"). Use 0 if the OS does not
  1736. * support this, in which case the service must do a full hash
  1737. * recomputation.
  1738. */
  1739. uint64_t inode GNUNET_PACKED;
  1740. /**
  1741. * Hash of the file that we would like to index.
  1742. */
  1743. GNUNET_HashCode file_id;
  1744. /* this is followed by a 0-terminated
  1745. * filename of a file with the hash
  1746. * "file_id" as seen by the client */
  1747. };
  1748. /**
  1749. * Message send by FS service in response to a request
  1750. * asking for a list of all indexed files.
  1751. */
  1752. struct IndexInfoMessage
  1753. {
  1754. /**
  1755. * Message type will be
  1756. * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
  1757. */
  1758. struct GNUNET_MessageHeader header;
  1759. /**
  1760. * Always zero.
  1761. */
  1762. uint32_t reserved GNUNET_PACKED;
  1763. /**
  1764. * Hash of the indexed file.
  1765. */
  1766. GNUNET_HashCode file_id;
  1767. /* this is followed by a 0-terminated
  1768. * filename of a file with the hash
  1769. * "file_id" as seen by the client */
  1770. };
  1771. /**
  1772. * Message sent from a GNUnet (fs) unindexing activity to the
  1773. * gnunet-service-fs to indicate that a file will be unindexed. The
  1774. * service is supposed to remove the file from the list of indexed
  1775. * files and response with a confirmation message (even if the file
  1776. * was already not on the list).
  1777. */
  1778. struct UnindexMessage
  1779. {
  1780. /**
  1781. * Message type will be
  1782. * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
  1783. */
  1784. struct GNUNET_MessageHeader header;
  1785. /**
  1786. * Always zero.
  1787. */
  1788. uint32_t reserved GNUNET_PACKED;
  1789. /**
  1790. * Hash of the file that we will unindex.
  1791. */
  1792. GNUNET_HashCode file_id;
  1793. };
  1794. /**
  1795. * Message sent from a GNUnet (fs) search activity to the
  1796. * gnunet-service-fs to start a search.
  1797. */
  1798. struct SearchMessage
  1799. {
  1800. /**
  1801. * Message type will be
  1802. * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
  1803. */
  1804. struct GNUNET_MessageHeader header;
  1805. /**
  1806. * Bitmask with options. Zero for no options, one for loopback-only.
  1807. * Other bits are currently not defined.
  1808. */
  1809. int32_t options GNUNET_PACKED;
  1810. /**
  1811. * Type of the content that we're looking for.
  1812. */
  1813. uint32_t type GNUNET_PACKED;
  1814. /**
  1815. * Desired anonymity level, big-endian.
  1816. */
  1817. uint32_t anonymity_level GNUNET_PACKED;
  1818. /**
  1819. * If the request is for a DBLOCK or IBLOCK, this is the identity of
  1820. * the peer that is known to have a response. Set to all-zeros if
  1821. * such a target is not known (note that even if OUR anonymity
  1822. * level is >0 we may happen to know the responder's identity;
  1823. * nevertheless, we should probably not use it for a DHT-lookup
  1824. * or similar blunt actions in order to avoid exposing ourselves).
  1825. * <p>
  1826. * If the request is for an SBLOCK, this is the identity of the
  1827. * pseudonym to which the SBLOCK belongs.
  1828. * <p>
  1829. * If the request is for a KBLOCK, "target" must be all zeros.
  1830. */
  1831. GNUNET_HashCode target;
  1832. /**
  1833. * Hash of the keyword (aka query) for KBLOCKs; Hash of
  1834. * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
  1835. * and hash of the identifier XORed with the target for
  1836. * SBLOCKS (aka query).
  1837. */
  1838. GNUNET_HashCode query;
  1839. /* this is followed by the hash codes of already-known
  1840. * results (which should hence be excluded from what
  1841. * the service returns); naturally, this only applies
  1842. * to queries that can have multiple results, such as
  1843. * those for KBLOCKS (KSK) and SBLOCKS (SKS) */
  1844. };
  1845. /**
  1846. * Only the (mandatory) query is included.
  1847. */
  1848. #define GET_MESSAGE_BIT_QUERY_ONLY 0
  1849. /**
  1850. * The peer identity of a peer waiting for the
  1851. * reply is included (used if the response
  1852. * should be transmitted to someone other than
  1853. * the sender of the GET).
  1854. */
  1855. #define GET_MESSAGE_BIT_RETURN_TO 1
  1856. /**
  1857. * The hash of the public key of the target
  1858. * namespace is included (for SKS queries).
  1859. */
  1860. #define GET_MESSAGE_BIT_SKS_NAMESPACE 2
  1861. /**
  1862. * The peer identity of a peer that had claimed to have the content
  1863. * previously is included (can be used if responder-anonymity is not
  1864. * desired; note that the precursor presumably lacked a direct
  1865. * connection to the specified peer; still, the receiver is in no way
  1866. * required to limit forwarding only to the specified peer, it should
  1867. * only prefer it somewhat if possible).
  1868. */
  1869. #define GET_MESSAGE_BIT_TRANSMIT_TO 4
  1870. /**
  1871. * Message sent between peers asking for FS-content.
  1872. */
  1873. struct GetMessage
  1874. {
  1875. /**
  1876. * Message type will be GNUNET_MESSAGE_TYPE_FS_GET.
  1877. */
  1878. struct GNUNET_MessageHeader header;
  1879. /**
  1880. * Type of the query (block type).
  1881. */
  1882. uint32_t type GNUNET_PACKED;
  1883. /**
  1884. * How important is this request (network byte order)
  1885. */
  1886. uint32_t priority GNUNET_PACKED;
  1887. /**
  1888. * Relative time to live in MILLISECONDS (network byte order)
  1889. */
  1890. int32_t ttl GNUNET_PACKED;
  1891. /**
  1892. * The content hash should be mutated using this value
  1893. * before checking against the bloomfilter (used to
  1894. * get many different filters for the same hash codes).
  1895. * The number should be in big-endian format when used
  1896. * for mingling.
  1897. */
  1898. uint32_t filter_mutator GNUNET_PACKED;
  1899. /**
  1900. * Which of the optional hash codes are present at the end of the
  1901. * message? See GET_MESSAGE_BIT_xx constants. For each bit that is
  1902. * set, an additional GNUNET_HashCode with the respective content
  1903. * (in order of the bits) will be appended to the end of the GET
  1904. * message.
  1905. */
  1906. uint32_t hash_bitmap GNUNET_PACKED;
  1907. /**
  1908. * Hashcodes of the file(s) we're looking for.
  1909. * Details depend on the query type.
  1910. */
  1911. GNUNET_HashCode query GNUNET_PACKED;
  1912. /* this is followed by hash codes
  1913. * as specified in the "hash_bitmap";
  1914. * after that, an optional bloomfilter
  1915. * (with bits set for replies that should
  1916. * be suppressed) can be present */
  1917. };
  1918. /**
  1919. * Response from FS service with a result for a previous FS search.
  1920. * Note that queries for DBLOCKS and IBLOCKS that have received a
  1921. * single response are considered done. This message is transmitted
  1922. * between peers as well as between the service and a client.
  1923. */
  1924. struct PutMessage
  1925. {
  1926. /**
  1927. * Message type will be GNUNET_MESSAGE_TYPE_FS_PUT.
  1928. */
  1929. struct GNUNET_MessageHeader header;
  1930. /**
  1931. * Type of the block (in big endian). Should never be zero.
  1932. */
  1933. uint32_t type GNUNET_PACKED;
  1934. /**
  1935. * When does this result expire?
  1936. */
  1937. struct GNUNET_TIME_AbsoluteNBO expiration;
  1938. /* this is followed by the actual encrypted content */
  1939. };
  1940. /**
  1941. * Message send by a peer that wants to be excluded
  1942. * from migration for a while.
  1943. */
  1944. struct MigrationStopMessage
  1945. {
  1946. /**
  1947. * Message type will be
  1948. * GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP.
  1949. */
  1950. struct GNUNET_MessageHeader header;
  1951. /**
  1952. * Always zero.
  1953. */
  1954. uint32_t reserved GNUNET_PACKED;
  1955. /**
  1956. * How long should the block last?
  1957. */
  1958. struct GNUNET_TIME_RelativeNBO duration;
  1959. };
  1960. #endif
  1961. /* end of fs.h */