fs.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2003--2012 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file fs/fs.h
  18. * @brief definitions for the entire fs module
  19. * @author Igor Wronsky, Christian Grothoff
  20. */
  21. #ifndef FS_H
  22. #define FS_H
  23. #include "gnunet_constants.h"
  24. #include "gnunet_datastore_service.h"
  25. #include "gnunet_dht_service.h"
  26. #include "gnunet_fs_service.h"
  27. #include "gnunet_block_lib.h"
  28. #include "block_fs.h"
  29. /**
  30. * Size of the individual blocks used for file-sharing.
  31. */
  32. #define DBLOCK_SIZE (32 * 1024)
  33. /**
  34. * Blocksize to use when hashing files for indexing (blocksize for IO,
  35. * not for the DBlocks). Larger blocksizes can be more efficient but
  36. * will be more disruptive as far as the scheduler is concerned.
  37. */
  38. #define HASHING_BLOCKSIZE (1024 * 128)
  39. /**
  40. * @brief content hash key
  41. */
  42. struct ContentHashKey
  43. {
  44. /**
  45. * Hash of the original content, used for encryption.
  46. */
  47. struct GNUNET_HashCode key;
  48. /**
  49. * Hash of the encrypted content, used for querying.
  50. */
  51. struct GNUNET_HashCode query;
  52. };
  53. GNUNET_NETWORK_STRUCT_BEGIN
  54. /**
  55. * Message sent from a GNUnet (fs) publishing activity to sign
  56. * a LOC URI.
  57. */
  58. struct RequestLocSignatureMessage
  59. {
  60. /**
  61. * Message type will be #GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN.
  62. */
  63. struct GNUNET_MessageHeader header;
  64. /**
  65. * Requested signature purpose. For now, always
  66. * #GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT.
  67. */
  68. uint32_t purpose GNUNET_PACKED;
  69. /**
  70. * Requested expiration time.
  71. */
  72. struct GNUNET_TIME_AbsoluteNBO expiration_time;
  73. /**
  74. * Information about the shared file (to be signed).
  75. */
  76. struct ContentHashKey chk;
  77. /**
  78. * Size of the shared file (to be signed).
  79. */
  80. uint64_t file_length;
  81. };
  82. /**
  83. * Message sent from the service with the signed LOC URI.
  84. */
  85. struct ResponseLocSignatureMessage
  86. {
  87. /**
  88. * Message type will be
  89. * #GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE.
  90. */
  91. struct GNUNET_MessageHeader header;
  92. /**
  93. * Purpose of the generated signature. For now, always
  94. * #GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT.
  95. */
  96. uint32_t purpose GNUNET_PACKED;
  97. /**
  98. * Expiration time that was actually used (rounded!).
  99. */
  100. struct GNUNET_TIME_AbsoluteNBO expiration_time;
  101. /**
  102. * The requested signature.
  103. */
  104. struct GNUNET_CRYPTO_EddsaSignature signature;
  105. /**
  106. * Identity of the peer sharing the file.
  107. */
  108. struct GNUNET_PeerIdentity peer;
  109. };
  110. /**
  111. * Message sent from a GNUnet (fs) publishing activity to the
  112. * gnunet-fs-service to initiate indexing of a file. The service is
  113. * supposed to check if the specified file is available and has the
  114. * same cryptographic hash. It should then respond with either a
  115. * confirmation or a denial.
  116. *
  117. * On OSes where this works, it is considered acceptable if the
  118. * service only checks that the path, device and inode match (it can
  119. * then be assumed that the hash will also match without actually
  120. * computing it; this is an optimization that should be safe given
  121. * that the client is not our adversary).
  122. */
  123. struct IndexStartMessage
  124. {
  125. /**
  126. * Message type will be #GNUNET_MESSAGE_TYPE_FS_INDEX_START.
  127. */
  128. struct GNUNET_MessageHeader header;
  129. /**
  130. * For alignment.
  131. */
  132. uint32_t reserved GNUNET_PACKED;
  133. /**
  134. * ID of device containing the file, as seen by the client. This
  135. * device ID is obtained using a call like "statvfs" (and converting
  136. * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
  137. * OS does not support this, in which case the service must do a
  138. * full hash recomputation.
  139. */
  140. uint64_t device GNUNET_PACKED;
  141. /**
  142. * Inode of the file on the given device, as seen by the client
  143. * ("st_ino" field from "struct stat"). Use 0 if the OS does not
  144. * support this, in which case the service must do a full hash
  145. * recomputation.
  146. */
  147. uint64_t inode GNUNET_PACKED;
  148. /**
  149. * Hash of the file that we would like to index.
  150. */
  151. struct GNUNET_HashCode file_id;
  152. /* this is followed by a 0-terminated
  153. * filename of a file with the hash
  154. * "file_id" as seen by the client */
  155. };
  156. /**
  157. * Message send by FS service in response to a request
  158. * asking for a list of all indexed files.
  159. */
  160. struct IndexInfoMessage
  161. {
  162. /**
  163. * Message type will be
  164. * #GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
  165. */
  166. struct GNUNET_MessageHeader header;
  167. /**
  168. * Always zero.
  169. */
  170. uint32_t reserved GNUNET_PACKED;
  171. /**
  172. * Hash of the indexed file.
  173. */
  174. struct GNUNET_HashCode file_id;
  175. /* this is followed by a 0-terminated
  176. * filename of a file with the hash
  177. * "file_id" as seen by the client */
  178. };
  179. /**
  180. * Message sent from a GNUnet (fs) unindexing activity to the
  181. * gnunet-service-fs to indicate that a file will be unindexed. The
  182. * service is supposed to remove the file from the list of indexed
  183. * files and response with a confirmation message (even if the file
  184. * was already not on the list).
  185. */
  186. struct UnindexMessage
  187. {
  188. /**
  189. * Message type will be #GNUNET_MESSAGE_TYPE_FS_UNINDEX.
  190. */
  191. struct GNUNET_MessageHeader header;
  192. /**
  193. * Always zero.
  194. */
  195. uint32_t reserved GNUNET_PACKED;
  196. /**
  197. * Hash of the file that we will unindex.
  198. */
  199. struct GNUNET_HashCode file_id;
  200. };
  201. /**
  202. * No options.
  203. */
  204. #define SEARCH_MESSAGE_OPTION_NONE 0
  205. /**
  206. * Only search the local datastore (no network)
  207. */
  208. #define SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY 1
  209. /**
  210. * Request is too large to fit in 64k format. The list of
  211. * already-known search results will be continued in another message
  212. * for the same type/query/target and additional already-known results
  213. * following this one).
  214. */
  215. #define SEARCH_MESSAGE_OPTION_CONTINUED 2
  216. /**
  217. * Message sent from a GNUnet (fs) search activity to the
  218. * gnunet-service-fs to start a search.
  219. */
  220. struct SearchMessage
  221. {
  222. /**
  223. * Message type will be #GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
  224. */
  225. struct GNUNET_MessageHeader header;
  226. /**
  227. * Bitmask with options. Zero for no options, one for
  228. * loopback-only, two for 'to be continued' (with a second search
  229. * message for the same type/query/target and additional
  230. * already-known results following this one). See
  231. * SEARCH_MESSAGE_OPTION_ defines.
  232. *
  233. * Other bits are currently not defined.
  234. */
  235. uint32_t options GNUNET_PACKED;
  236. /**
  237. * Type of the content that we're looking for.
  238. */
  239. uint32_t type GNUNET_PACKED;
  240. /**
  241. * Desired anonymity level, big-endian.
  242. */
  243. uint32_t anonymity_level GNUNET_PACKED;
  244. /**
  245. * If the request is for a DBLOCK or IBLOCK, this is the identity of
  246. * the peer that is known to have a response. Set to all-zeros if
  247. * such a target is not known (note that even if OUR anonymity
  248. * level is >0 we may happen to know the responder's identity;
  249. * nevertheless, we should probably not use it for a DHT-lookup
  250. * or similar blunt actions in order to avoid exposing ourselves).
  251. * <p>
  252. * Otherwise, "target" must be all zeros.
  253. */
  254. struct GNUNET_PeerIdentity target;
  255. /**
  256. * Hash of the public key for UBLOCKs; Hash of
  257. * the CHK-encoded block for DBLOCKS and IBLOCKS.
  258. */
  259. struct GNUNET_HashCode query;
  260. /* this is followed by the hash codes of already-known
  261. * results (which should hence be excluded from what
  262. * the service returns); naturally, this only applies
  263. * to queries that can have multiple results (UBLOCKS).
  264. */
  265. };
  266. /**
  267. * Response from FS service with a result for a previous FS search.
  268. * Note that queries for DBLOCKS and IBLOCKS that have received a
  269. * single response are considered done. This message is transmitted
  270. * between peers.
  271. */
  272. struct PutMessage
  273. {
  274. /**
  275. * Message type will be #GNUNET_MESSAGE_TYPE_FS_PUT.
  276. */
  277. struct GNUNET_MessageHeader header;
  278. /**
  279. * Type of the block (in big endian). Should never be zero.
  280. */
  281. uint32_t type GNUNET_PACKED;
  282. /**
  283. * When does this result expire?
  284. */
  285. struct GNUNET_TIME_AbsoluteNBO expiration;
  286. /* this is followed by the actual encrypted content */
  287. };
  288. /**
  289. * Response from FS service with a result for a previous FS search.
  290. * Note that queries for DBLOCKS and IBLOCKS that have received a
  291. * single response are considered done. This message is transmitted
  292. * between the service and a client.
  293. */
  294. struct ClientPutMessage
  295. {
  296. /**
  297. * Message type will be #GNUNET_MESSAGE_TYPE_FS_PUT.
  298. */
  299. struct GNUNET_MessageHeader header;
  300. /**
  301. * Type of the block (in big endian). Should never be zero.
  302. */
  303. uint32_t type GNUNET_PACKED;
  304. /**
  305. * When does this result expire?
  306. */
  307. struct GNUNET_TIME_AbsoluteNBO expiration;
  308. /**
  309. * When was the last time we've tried to download this block?
  310. * (FOREVER if unknown/not relevant)
  311. */
  312. struct GNUNET_TIME_AbsoluteNBO last_transmission;
  313. /**
  314. * How often did we transmit this query before getting an
  315. * answer (estimate).
  316. */
  317. uint32_t num_transmissions;
  318. /**
  319. * How much respect did we offer (in total) before getting an
  320. * answer (estimate).
  321. */
  322. uint32_t respect_offered;
  323. /* this is followed by the actual encrypted content */
  324. };
  325. GNUNET_NETWORK_STRUCT_END
  326. #endif
  327. /* end of fs.h */