dht.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2001, 2002, 2003, 2004, 2009, 2011 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. * @author Christian Grothoff
  19. * @author Nathan Evans
  20. * @file dht/dht.h
  21. */
  22. #ifndef DHT_H
  23. #define DHT_H
  24. /**
  25. * Size of the bloom filter the DHT uses to filter peers.
  26. */
  27. #define DHT_BLOOM_SIZE 128
  28. GNUNET_NETWORK_STRUCT_BEGIN
  29. /**
  30. * Message which indicates the DHT should cancel outstanding
  31. * requests and discard any state.
  32. */
  33. struct GNUNET_DHT_ClientGetStopMessage
  34. {
  35. /**
  36. * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP
  37. */
  38. struct GNUNET_MessageHeader header;
  39. /**
  40. * Always zero.
  41. */
  42. uint32_t reserved GNUNET_PACKED;
  43. /**
  44. * Unique ID identifying this request
  45. */
  46. uint64_t unique_id GNUNET_PACKED;
  47. /**
  48. * Key of this request
  49. */
  50. struct GNUNET_HashCode key;
  51. };
  52. /**
  53. * DHT GET message sent from clients to service. Indicates that a GET
  54. * request should be issued.
  55. */
  56. struct GNUNET_DHT_ClientGetMessage
  57. {
  58. /**
  59. * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET
  60. */
  61. struct GNUNET_MessageHeader header;
  62. /**
  63. * Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
  64. */
  65. uint32_t options GNUNET_PACKED;
  66. /**
  67. * Replication level for this message
  68. */
  69. uint32_t desired_replication_level GNUNET_PACKED;
  70. /**
  71. * The type for the data for the GET request; actually an 'enum
  72. * GNUNET_BLOCK_Type'.
  73. */
  74. uint32_t type GNUNET_PACKED;
  75. /**
  76. * The key to search for
  77. */
  78. struct GNUNET_HashCode key GNUNET_PACKED;
  79. /**
  80. * Unique ID identifying this request, if 0 then
  81. * the client will not expect a response
  82. */
  83. uint64_t unique_id GNUNET_PACKED;
  84. /* Possibly followed by xquery, copied to end of this dealy do */
  85. };
  86. /**
  87. * DHT GET RESULTS KNOWN message sent from clients to service. Indicates that a GET
  88. * request should exclude certain results which are already known.
  89. */
  90. struct GNUNET_DHT_ClientGetResultSeenMessage
  91. {
  92. /**
  93. * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN
  94. */
  95. struct GNUNET_MessageHeader header;
  96. /**
  97. * Reserved, always 0.
  98. */
  99. uint32_t reserved GNUNET_PACKED;
  100. /**
  101. * The key we are searching for (to make it easy to find the corresponding
  102. * GET inside the service).
  103. */
  104. struct GNUNET_HashCode key GNUNET_PACKED;
  105. /**
  106. * Unique ID identifying this request.
  107. */
  108. uint64_t unique_id GNUNET_PACKED;
  109. /* Followed by an array of the hash codes of known results */
  110. };
  111. /**
  112. * Reply to a GET send from the service to a client.
  113. */
  114. struct GNUNET_DHT_ClientResultMessage
  115. {
  116. /**
  117. * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT
  118. */
  119. struct GNUNET_MessageHeader header;
  120. /**
  121. * The type for the data.
  122. */
  123. uint32_t type GNUNET_PACKED;
  124. /**
  125. * Number of peers recorded in the outgoing path from source to the
  126. * storgage location of this message.
  127. */
  128. uint32_t put_path_length GNUNET_PACKED;
  129. /**
  130. * The number of peer identities recorded from the storage location
  131. * to this peer.
  132. */
  133. uint32_t get_path_length GNUNET_PACKED;
  134. /**
  135. * Unique ID of the matching GET request.
  136. */
  137. uint64_t unique_id GNUNET_PACKED;
  138. /**
  139. * When does this entry expire?
  140. */
  141. struct GNUNET_TIME_AbsoluteNBO expiration;
  142. /**
  143. * The key that was searched for
  144. */
  145. struct GNUNET_HashCode key GNUNET_PACKED;
  146. /* put path, get path and actual data are copied to end of this dealy do */
  147. };
  148. /**
  149. * Message to insert data into the DHT, sent from clients to DHT service.
  150. */
  151. struct GNUNET_DHT_ClientPutMessage
  152. {
  153. /**
  154. * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT
  155. */
  156. struct GNUNET_MessageHeader header;
  157. /**
  158. * The type of data to insert.
  159. */
  160. uint32_t type GNUNET_PACKED;
  161. /**
  162. * Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
  163. */
  164. uint32_t options GNUNET_PACKED;
  165. /**
  166. * Replication level for this message
  167. */
  168. uint32_t desired_replication_level GNUNET_PACKED;
  169. /**
  170. * Unique ID for the PUT message.
  171. */
  172. uint64_t unique_id GNUNET_PACKED;
  173. /**
  174. * How long should this data persist?
  175. */
  176. struct GNUNET_TIME_AbsoluteNBO expiration;
  177. /**
  178. * The key to store the value under.
  179. */
  180. struct GNUNET_HashCode key GNUNET_PACKED;
  181. /* DATA copied to end of this message */
  182. };
  183. /**
  184. * Message to confirming receipt of PUT, sent from DHT service to clients.
  185. */
  186. struct GNUNET_DHT_ClientPutConfirmationMessage
  187. {
  188. /**
  189. * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT_OK
  190. */
  191. struct GNUNET_MessageHeader header;
  192. /**
  193. * Always zero.
  194. */
  195. uint32_t reserved GNUNET_PACKED;
  196. /**
  197. * Unique ID from the PUT message that is being confirmed.
  198. */
  199. uint64_t unique_id GNUNET_PACKED;
  200. };
  201. /**
  202. * Message to monitor put requests going through peer, DHT service -> clients.
  203. */
  204. struct GNUNET_DHT_MonitorPutMessage
  205. {
  206. /**
  207. * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT
  208. */
  209. struct GNUNET_MessageHeader header;
  210. /**
  211. * Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
  212. */
  213. uint32_t options GNUNET_PACKED;
  214. /**
  215. * The type of data in the request.
  216. */
  217. uint32_t type GNUNET_PACKED;
  218. /**
  219. * Hop count so far.
  220. */
  221. uint32_t hop_count GNUNET_PACKED;
  222. /**
  223. * Replication level for this message
  224. */
  225. uint32_t desired_replication_level GNUNET_PACKED;
  226. /**
  227. * Number of peers recorded in the outgoing path from source to the
  228. * storage location of this message.
  229. */
  230. uint32_t put_path_length GNUNET_PACKED;
  231. /**
  232. * How long should this data persist?
  233. */
  234. struct GNUNET_TIME_AbsoluteNBO expiration_time;
  235. /**
  236. * The key to store the value under.
  237. */
  238. struct GNUNET_HashCode key GNUNET_PACKED;
  239. /* put path (if tracked) */
  240. /* Payload */
  241. };
  242. /**
  243. * Message to request monitoring messages, clients -> DHT service.
  244. */
  245. struct GNUNET_DHT_MonitorStartStopMessage
  246. {
  247. /**
  248. * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_START or
  249. * #GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP
  250. */
  251. struct GNUNET_MessageHeader header;
  252. /**
  253. * The type of data desired, GNUNET_BLOCK_TYPE_ANY for all.
  254. */
  255. uint32_t type GNUNET_PACKED;
  256. /**
  257. * Flag whether to notify about GET messages.
  258. */
  259. int16_t get GNUNET_PACKED;
  260. /**
  261. * Flag whether to notify about GET_REPONSE messages.
  262. */
  263. int16_t get_resp GNUNET_PACKED;
  264. /**
  265. * Flag whether to notify about PUT messages.
  266. */
  267. int16_t put GNUNET_PACKED;
  268. /**
  269. * Flag whether to use the provided key to filter messages.
  270. */
  271. int16_t filter_key GNUNET_PACKED;
  272. /**
  273. * The key to filter messages by.
  274. */
  275. struct GNUNET_HashCode key GNUNET_PACKED;
  276. };
  277. /**
  278. * Message to monitor get requests going through peer, DHT service -> clients.
  279. */
  280. struct GNUNET_DHT_MonitorGetMessage
  281. {
  282. /**
  283. * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET
  284. */
  285. struct GNUNET_MessageHeader header;
  286. /**
  287. * Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
  288. */
  289. uint32_t options GNUNET_PACKED;
  290. /**
  291. * The type of data in the request.
  292. */
  293. uint32_t type GNUNET_PACKED;
  294. /**
  295. * Hop count
  296. */
  297. uint32_t hop_count GNUNET_PACKED;
  298. /**
  299. * Replication level for this message
  300. */
  301. uint32_t desired_replication_level GNUNET_PACKED;
  302. /**
  303. * Number of peers recorded in the outgoing path from source to the
  304. * storage location of this message.
  305. */
  306. uint32_t get_path_length GNUNET_PACKED;
  307. /**
  308. * The key to store the value under.
  309. */
  310. struct GNUNET_HashCode key GNUNET_PACKED;
  311. /* get path (if tracked) */
  312. };
  313. /**
  314. * Message to monitor get results going through peer, DHT service -> clients.
  315. */
  316. struct GNUNET_DHT_MonitorGetRespMessage
  317. {
  318. /**
  319. * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT
  320. */
  321. struct GNUNET_MessageHeader header;
  322. /**
  323. * Content type.
  324. */
  325. uint32_t type GNUNET_PACKED;
  326. /**
  327. * Length of the PUT path that follows (if tracked).
  328. */
  329. uint32_t put_path_length GNUNET_PACKED;
  330. /**
  331. * Length of the GET path that follows (if tracked).
  332. */
  333. uint32_t get_path_length GNUNET_PACKED;
  334. /**
  335. * When does the content expire?
  336. */
  337. struct GNUNET_TIME_AbsoluteNBO expiration_time;
  338. /**
  339. * The key of the corresponding GET request.
  340. */
  341. struct GNUNET_HashCode key GNUNET_PACKED;
  342. /* put path (if tracked) */
  343. /* get path (if tracked) */
  344. /* Payload */
  345. };
  346. #if ENABLE_MALICIOUS
  347. /**
  348. * Message to confirming receipt of ACT MALICIOUS, sent from DHT service to clients.
  349. */
  350. struct GNUNET_DHT_ClientActMaliciousConfirmationMessage
  351. {
  352. /**
  353. * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT_OK
  354. */
  355. struct GNUNET_MessageHeader header;
  356. };
  357. /**
  358. * Message to turn the service malicious
  359. */
  360. struct GNUNET_DHT_ActMaliciousMessage
  361. {
  362. /**
  363. * Type: #GNUNET_MESSAGE_TYPE_ACT_MALICIOUS
  364. */
  365. struct GNUNET_MessageHeader header;
  366. /**
  367. * If set to 1, act maliciously
  368. */
  369. uint32_t action;
  370. };
  371. #endif
  372. GNUNET_NETWORK_STRUCT_END
  373. #endif