distributed-hash-table.tm 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <TeXmacs|2.1>
  2. <project|scheme-gnunet.tm>
  3. <style|tmmanual>
  4. <\body>
  5. GNUnet has a service that maintains a <em|distributed hash
  6. table><index|distributed hash table><index|DHT><index|R5N>, mapping keys to
  7. values. The module <scm|(gnu gnunet dht client)><index|(gnu gnunet dht
  8. client)> can be used to interact with the service. The connection can be
  9. made with the procedure <scm|connect>. It returns a <em|DHT server
  10. object><index|DHT server object><subindex|server object|DHT>.
  11. <\explain>
  12. <scm|(connect <var|config> <var|#:connected> <var|#:disconnected>
  13. <var|#:spawn>)><subindex|connect|DHT>
  14. <|explain>
  15. Connect to the DHT service, using the configuration <var|config>. The
  16. connection is made asynchronuously; the optional thunk <var|connected> is
  17. called when the connection has been made. The connection can break; the
  18. optional thunk <var|disconnected> is called when it does. If the
  19. connection breaks, the client code automatically tries to reconnect, so
  20. <var|connected> can be called after <var|disconnected>.
  21. </explain>
  22. <\explain>
  23. <scm|(disconnect! <var|server>)><subindex|disconnect!|DHT>
  24. <|explain>
  25. Asynchronuously disconnect from the DHT service and stop reconnecting,
  26. even if not connected. This is an idempotent operation.
  27. </explain>
  28. Some time after the returned server object becomes unreachable, it will
  29. automatically be disconnected. Active lingering operations and reachable
  30. operations keeps the server object reachable. <todo|test this!>
  31. <section|Data in the DHT>
  32. To insert data into the DHT, the DHT service needs various information \U
  33. the key and the value, but also some other information. Likewise, when the
  34. DHT service has found the datum, this information is available as well. A
  35. datum in the DHT is represented as a <em|datum object><index|datum object>.
  36. The object holding the information required for inserting something in the
  37. DHT is called an <em|insertion object><index|insertion object>. Likewise,
  38. the information of searching for something in the DHT is in a <em|query
  39. object><index|query object>. The result of a query is a <em|search result
  40. object><index|search result object>.
  41. These objects only hold information; creating them does not have any side
  42. effects.
  43. <\explain>
  44. <scm|(make-datum <var|type> <var|key> <var|value>
  45. <var|#:expiration>)><index|make-datum>
  46. <|explain>
  47. Make a datum object of block type <var|type> (or its corresponding
  48. numeric value), with key <var|key> (a readable <scm|/hashcode:512>
  49. bytevector slice), value <var|value> (a readable bytevector slice) and
  50. expiring at <var|expiration> (<todo|type, epoch>). The keyword argument
  51. <var|expiration> is optional, see <reference|???>.
  52. The numeric value of the block type can be retrieved with the accessor
  53. <scm|datum-type>. The accessors <scm|datum-key><index|datum-key>,
  54. <scm|datum-value><index|datum-value> and
  55. <scm|datum-expiration><index|datum-expiration> return the key, value and
  56. expiration time respectively. It can be tested if an object is a datum
  57. object with the predicate <scm|datum?><index|datum?>.
  58. The length of <var|value> may be at most
  59. <scm|%max-datum-value-length><index|%max-datum-value-length>. If this
  60. bound is exceeded, an appropriate <scm|&overly-large-datum><index|&overly-large-datum>
  61. and <scm|&who> condition is raised.
  62. </explain>
  63. <\explain>
  64. <scm|(datum-\<gtr\>insertion <var|datum>
  65. #:desired-replication-level)><index|datum-\<gtr\>insertion>
  66. <|explain>
  67. Make an insertion object for inserting the datum <var|datum>, desiring a
  68. replication level <var|desired-replication-level> (see
  69. <reference|replication levels???>)<todo|various options>.
  70. The datum and desired replication level can be recovered with the
  71. accessors <scm|insertion-\<gtr\>datum><index|insertion-\<gtr\>datum> and
  72. <var|insertion-desired-replication-level><index|insertion-desired-replication-level>.
  73. It can be tested if an object is an insertion object with the predicate
  74. <scm|insertion?><index|insertion?>.
  75. </explain>
  76. <\explain>
  77. <scm|(make-query <var|type> <var|key>
  78. #:desired-replication-level)><index|make-query>
  79. <|explain>
  80. Make a query object for searching for a value of block type <var|type>
  81. (or its corresponding numeric value), with key <var|key> (a readable
  82. <scm|/hashcode:512> bytevector slice), at desired replication level
  83. <scm|desired-replication-level> (see <reference|replication levels???>).
  84. <todo|various options, xquery>
  85. The numeric value of the block type, the key and the desired replication
  86. level can be recovered with the accessors
  87. <scm|query-type><index|query-type>, <scm|query-key><index|query-key> and
  88. <scm|query-desired-replication-level><index|query-desired-replication-level>.
  89. It can be tested if an object is a query object with the predicate
  90. <scm|query?><index|query?>.
  91. </explain>
  92. <\explain>
  93. <scm|(datum-\<gtr\>search-result <var|datum> #:get-path
  94. #:put-path)><index|datum-\<gtr\>search-result>
  95. <|explain>
  96. Make a search result object for the datum <var|datum>. The datum can be
  97. recovered with the accessor <scm|search-result-\<gtr\>datum><index|search-result-\<gtr\>datum>.
  98. It can be tested if an object is a search result with the predicate
  99. <scm|search-result?><index|search-result?>. The optional arguments
  100. <var|get-path> and <var|put-path>, when not false, are bytevector slices
  101. consisting of a list of <scm|/dht:path-element><index|/dht:path-element><index|path
  102. element>.
  103. The <var|get-path><index|get path> , if any, is the path from the storage
  104. location to the current peer. Conversely, the <var|put-path><index|put
  105. path>, if any, is a path from the peer that inserted the datum into the
  106. DHT to the storage location. The <var|get-path> and <var|put-path> can be
  107. accessed with <scm|search-result-get-path><index|search-result-get-path>
  108. and <scm|search-result-put-path><index|search-result-put-path>
  109. respectively.
  110. When the datum, get path and put path together are too large, a
  111. <scm|&overly-large-paths><index|&overly-large-paths> condition is raised.
  112. When the bytevector slice length of <var|get-path> or <var|put-path> is
  113. not a multiple of the size of a path element, then a
  114. <scm|&malformed-path><index|&malformed-path> condition is raised.
  115. </explain>
  116. <section|Accessing data in the DHT>
  117. To insert a datum into the DHT, the procedure <scm|put!> is used. To find
  118. data matching a query, the procedure <scm|start-get!> is
  119. used.<index|searching the DHT><index|inserting data into the DHT>
  120. <\explain>
  121. <scm|(start-get! <var|server> <var|query> <var|found>
  122. <var|#:linger?>=#false)><index|start-get!>
  123. <|explain>
  124. Search for data matching <var|query> in the DHT. When a datum is found,
  125. call the unary procedure <var|found> on the search result. It is possible
  126. to find multiple data matching a query. In that case, <var|found> is
  127. called multiple times. Searching happens asynchronuously; to stop the
  128. search, a fresh <em|search object><index|search object> for controlling
  129. the search is returned.
  130. The procedure <var|found> is run from the context of <var|server>. As
  131. such, if <var|found> blocks, then all operations on <var|server> might
  132. block. As such, it is recommended for <var|found> to do as little as
  133. possible by itself and instead delegate any work to a separate fiber.
  134. To avoid expensive copies, the implementation can choose to reuse
  135. internal buffers for the slices passed to <var|found>, which could be
  136. overwritten after the call to <var|found>. As such, it might be necessary
  137. to make a copy of the search result, using <scm|copy-search-result>.
  138. When the boolean <var|linger?> is false (this is the default), the search
  139. is automatically cancelled when the search object becomes unreachable
  140. according to the GC.
  141. <\warning>
  142. Guile currently (3.0.8) uses a conservative GC, so it cannot always
  143. detect unreachability when it should.
  144. </warning>
  145. </explain>
  146. <\explain>
  147. <scm|(stop-get! <var|search>)><index|stop-get!>
  148. </explain|Cancel the get operation described by the search object
  149. <var|search>. This is an asynchronuous operation; it does not have an
  150. immediate effect. This is an idempotent operation: cancelling a search does
  151. not have any additional effect.>
  152. <\explain>
  153. <scm|(put! <var|server> <var|insertion> <var|#:confirmed>)><index|put!>
  154. <|explain>
  155. Perform the insertion <var|insertion>. When the datum has been inserted,
  156. the optional thunk <var|confirmed> is called. A <em|put object> is
  157. returned which can be used to cancel the insertion.
  158. <todo|TODO: actually call <var|confirmed>>
  159. </explain>
  160. <\explain>
  161. <scm|(copy-query <var|old>)><index|copy-query>
  162. <scm|(copy-datum <var|old>)><index|copy-datum>
  163. <scm|(copy-insertion <var|old>)><index|copy-insertion>
  164. <scm|(copy-search-result <var|old>)><index|copy-search-result>
  165. <|explain>
  166. Make a copy of the object <var|old> (a query, datum, insertion or search
  167. result object, depending on the procedure), such that modifications to
  168. the slices in <var|old> do not impact the new object.
  169. </explain>
  170. <todo|cancellation>
  171. <section|Constructing and analysing network messages>
  172. The DHT client and service communicate by sending <em|messages>. Usually,
  173. only the implementation of the client and service need to construct and
  174. analyse these messages, but nothing prevents other uses of the procedures
  175. in <scm|(gnu gnunet dht network)><index|(gnu gnunet dht network)>, e.g. for
  176. learning, in a tool like Wireshark or for tests.
  177. The <em|analysis> procedures<index|analysis procedures> assume that the
  178. message is well-formed and avoid constructing new bytevector slices by
  179. taking subslices. The <em|construction> procedures<index|construction
  180. procedures> create fresh well-formed read-write bytevector slices.
  181. <\warning>
  182. Possibly the type of <var|options> will change and possibly the options
  183. will be moved into the query object and insertion object.
  184. </warning>
  185. <\explain>
  186. <scm|(construct-client-get <var|query> <var|unique-id> #:optional
  187. (<var|options> 0))><index|construct-client-get>
  188. <|explain>
  189. Create a new <scm|/:msg:dht:client:get><index|/:msg:dht:client:get>
  190. message for the query object <var|query>, with <var|unique-id> as
  191. \<#2018\>unique id\<#2019\> and <var|options> as options.
  192. </explain>
  193. <\explain>
  194. <scm|(construct-client-get-stop <var|key>
  195. <var|unique-id>)><index|construct-client-get-stop>
  196. </explain|Create a new <scm|/:msg:dht:client:get:stop> message for
  197. cancelling a get request.>
  198. <\explain>
  199. <scm|(construct-client-put <var|insertion> #:optional (options
  200. 0))><index|construct-client-put>
  201. <|explain>
  202. Create a new <scm|/:msg:dht:client:put><index|/:msg:dht:client:put>
  203. message for the insertion object <var|insertion> with <var|options> as
  204. options.
  205. </explain>
  206. <\explain>
  207. <scm|(construct-client-result <var|search-result>
  208. <var|unique-id>)><index|construct-client-result>
  209. <|explain>
  210. Create a new <scm|/:msg:dht:client:result><index|/:msg:dht:client:result>
  211. message for the search result object <var|search-result>, with
  212. <var|unique-id> as \<#2018\>unique id\<#2019\> .
  213. </explain>
  214. <\explain>
  215. <scm|(analyse-client-get <var|message>)><index|analyse-client-get>
  216. <|explain>
  217. Return the query object, the unique id and the options corresponding to
  218. the <scm|/:msg:dht:client:result><index|/:msg:dht:client:result> message
  219. <var|message>. Xqueries are currently unsupported.
  220. </explain>
  221. <\explain>
  222. <scm|(analyse-client-get-stop <var|message>)><index|analyse-client-get-stop>
  223. </explain|Return the unique id and the key corresponding to the
  224. <scm|/:msg:dht:client:stop> message <var|message>.>
  225. <\explain>
  226. <scm|(analyse-client-put <var|message>)><index|analyse-client-put>
  227. <|explain>
  228. Return the insertion object and options corresponding to the
  229. <scm|/:msg:dht:client:put><index|/:msg:dht:client:put> message
  230. <var|message>.
  231. </explain>
  232. <\explain>
  233. <scm|(analyse-client-result <var|message>)><index|analyse-client-result>
  234. <|explain>
  235. Return search result object and unique id for the
  236. <scm|/:msg:dht:client:result><index|/:msg:dht:client:result> message
  237. <var|message>.
  238. </explain>
  239. <todo|monitoring messages>
  240. <section|How to handle invalid data>
  241. <todo|todo!>
  242. <section|Monitoring: spying on what other applications and peers are doing>
  243. <todo|todo!>
  244. </body>
  245. <\initial>
  246. <\collection>
  247. <associate|page-medium|paper>
  248. <associate|save-aux|false>
  249. </collection>
  250. </initial>