fs.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2003--2012 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. * Size of the individual blocks used for file-sharing.
  32. */
  33. #define DBLOCK_SIZE (32 * 1024)
  34. /**
  35. * Blocksize to use when hashing files for indexing (blocksize for IO,
  36. * not for the DBlocks). Larger blocksizes can be more efficient but
  37. * will be more disruptive as far as the scheduler is concerned.
  38. */
  39. #define HASHING_BLOCKSIZE (1024 * 128)
  40. /**
  41. * @brief content hash key
  42. */
  43. struct ContentHashKey
  44. {
  45. /**
  46. * Hash of the original content, used for encryption.
  47. */
  48. struct GNUNET_HashCode key;
  49. /**
  50. * Hash of the encrypted content, used for querying.
  51. */
  52. struct GNUNET_HashCode query;
  53. };
  54. GNUNET_NETWORK_STRUCT_BEGIN
  55. /**
  56. * Message sent from a GNUnet (fs) publishing activity to the
  57. * gnunet-fs-service to initiate indexing of a file. The service is
  58. * supposed to check if the specified file is available and has the
  59. * same cryptographic hash. It should then respond with either a
  60. * confirmation or a denial.
  61. *
  62. * On OSes where this works, it is considered acceptable if the
  63. * service only checks that the path, device and inode match (it can
  64. * then be assumed that the hash will also match without actually
  65. * computing it; this is an optimization that should be safe given
  66. * that the client is not our adversary).
  67. */
  68. struct IndexStartMessage
  69. {
  70. /**
  71. * Message type will be #GNUNET_MESSAGE_TYPE_FS_INDEX_START.
  72. */
  73. struct GNUNET_MessageHeader header;
  74. /**
  75. * For alignment.
  76. */
  77. uint32_t reserved GNUNET_PACKED;
  78. /**
  79. * ID of device containing the file, as seen by the client. This
  80. * device ID is obtained using a call like "statvfs" (and converting
  81. * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
  82. * OS does not support this, in which case the service must do a
  83. * full hash recomputation.
  84. */
  85. uint64_t device GNUNET_PACKED;
  86. /**
  87. * Inode of the file on the given device, as seen by the client
  88. * ("st_ino" field from "struct stat"). Use 0 if the OS does not
  89. * support this, in which case the service must do a full hash
  90. * recomputation.
  91. */
  92. uint64_t inode GNUNET_PACKED;
  93. /**
  94. * Hash of the file that we would like to index.
  95. */
  96. struct GNUNET_HashCode file_id;
  97. /* this is followed by a 0-terminated
  98. * filename of a file with the hash
  99. * "file_id" as seen by the client */
  100. };
  101. /**
  102. * Message send by FS service in response to a request
  103. * asking for a list of all indexed files.
  104. */
  105. struct IndexInfoMessage
  106. {
  107. /**
  108. * Message type will be
  109. * #GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
  110. */
  111. struct GNUNET_MessageHeader header;
  112. /**
  113. * Always zero.
  114. */
  115. uint32_t reserved GNUNET_PACKED;
  116. /**
  117. * Hash of the indexed file.
  118. */
  119. struct GNUNET_HashCode file_id;
  120. /* this is followed by a 0-terminated
  121. * filename of a file with the hash
  122. * "file_id" as seen by the client */
  123. };
  124. /**
  125. * Message sent from a GNUnet (fs) unindexing activity to the
  126. * gnunet-service-fs to indicate that a file will be unindexed. The
  127. * service is supposed to remove the file from the list of indexed
  128. * files and response with a confirmation message (even if the file
  129. * was already not on the list).
  130. */
  131. struct UnindexMessage
  132. {
  133. /**
  134. * Message type will be #GNUNET_MESSAGE_TYPE_FS_UNINDEX.
  135. */
  136. struct GNUNET_MessageHeader header;
  137. /**
  138. * Always zero.
  139. */
  140. uint32_t reserved GNUNET_PACKED;
  141. /**
  142. * Hash of the file that we will unindex.
  143. */
  144. struct GNUNET_HashCode file_id;
  145. };
  146. /**
  147. * No options.
  148. */
  149. #define SEARCH_MESSAGE_OPTION_NONE 0
  150. /**
  151. * Only search the local datastore (no network)
  152. */
  153. #define SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY 1
  154. /**
  155. * Request is too large to fit in 64k format. The list of
  156. * already-known search results will be continued in another message
  157. * for the same type/query/target and additional already-known results
  158. * following this one).
  159. */
  160. #define SEARCH_MESSAGE_OPTION_CONTINUED 2
  161. /**
  162. * Message sent from a GNUnet (fs) search activity to the
  163. * gnunet-service-fs to start a search.
  164. */
  165. struct SearchMessage
  166. {
  167. /**
  168. * Message type will be #GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
  169. */
  170. struct GNUNET_MessageHeader header;
  171. /**
  172. * Bitmask with options. Zero for no options, one for
  173. * loopback-only, two for 'to be continued' (with a second search
  174. * message for the same type/query/target and additional
  175. * already-known results following this one). See
  176. * SEARCH_MESSAGE_OPTION_ defines.
  177. *
  178. * Other bits are currently not defined.
  179. */
  180. uint32_t options GNUNET_PACKED;
  181. /**
  182. * Type of the content that we're looking for.
  183. */
  184. uint32_t type GNUNET_PACKED;
  185. /**
  186. * Desired anonymity level, big-endian.
  187. */
  188. uint32_t anonymity_level GNUNET_PACKED;
  189. /**
  190. * If the request is for a DBLOCK or IBLOCK, this is the identity of
  191. * the peer that is known to have a response. Set to all-zeros if
  192. * such a target is not known (note that even if OUR anonymity
  193. * level is >0 we may happen to know the responder's identity;
  194. * nevertheless, we should probably not use it for a DHT-lookup
  195. * or similar blunt actions in order to avoid exposing ourselves).
  196. * <p>
  197. * Otherwise, "target" must be all zeros.
  198. */
  199. struct GNUNET_PeerIdentity target;
  200. /**
  201. * Hash of the public key for UBLOCKs; Hash of
  202. * the CHK-encoded block for DBLOCKS and IBLOCKS.
  203. */
  204. struct GNUNET_HashCode query;
  205. /* this is followed by the hash codes of already-known
  206. * results (which should hence be excluded from what
  207. * the service returns); naturally, this only applies
  208. * to queries that can have multiple results (UBLOCKS).
  209. */
  210. };
  211. /**
  212. * Response from FS service with a result for a previous FS search.
  213. * Note that queries for DBLOCKS and IBLOCKS that have received a
  214. * single response are considered done. This message is transmitted
  215. * between peers.
  216. */
  217. struct PutMessage
  218. {
  219. /**
  220. * Message type will be #GNUNET_MESSAGE_TYPE_FS_PUT.
  221. */
  222. struct GNUNET_MessageHeader header;
  223. /**
  224. * Type of the block (in big endian). Should never be zero.
  225. */
  226. uint32_t type GNUNET_PACKED;
  227. /**
  228. * When does this result expire?
  229. */
  230. struct GNUNET_TIME_AbsoluteNBO expiration;
  231. /* this is followed by the actual encrypted content */
  232. };
  233. /**
  234. * Response from FS service with a result for a previous FS search.
  235. * Note that queries for DBLOCKS and IBLOCKS that have received a
  236. * single response are considered done. This message is transmitted
  237. * between the service and a client.
  238. */
  239. struct ClientPutMessage
  240. {
  241. /**
  242. * Message type will be #GNUNET_MESSAGE_TYPE_FS_PUT.
  243. */
  244. struct GNUNET_MessageHeader header;
  245. /**
  246. * Type of the block (in big endian). Should never be zero.
  247. */
  248. uint32_t type GNUNET_PACKED;
  249. /**
  250. * When does this result expire?
  251. */
  252. struct GNUNET_TIME_AbsoluteNBO expiration;
  253. /**
  254. * When was the last time we've tried to download this block?
  255. * (FOREVER if unknown/not relevant)
  256. */
  257. struct GNUNET_TIME_AbsoluteNBO last_transmission;
  258. /**
  259. * How often did we transmit this query before getting an
  260. * answer (estimate).
  261. */
  262. uint32_t num_transmissions;
  263. /**
  264. * How much respect did we offer (in total) before getting an
  265. * answer (estimate).
  266. */
  267. uint32_t respect_offered;
  268. /* this is followed by the actual encrypted content */
  269. };
  270. GNUNET_NETWORK_STRUCT_END
  271. #endif
  272. /* end of fs.h */