gnunet_namecache_service.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2012, 2013, 2016 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. * @author Christian Grothoff
  18. *
  19. * @file
  20. * API that can be used to store naming information on a GNUnet node.
  21. *
  22. * @defgroup namecache Name Cache service
  23. * Store naming information on a GNUnet node.
  24. *
  25. * Naming information can either be records for which this peer/user is
  26. * authoritative, or blocks which are cached, encrypted naming data from other
  27. * peers.
  28. *
  29. * @see [Documentation](https://gnunet.org/namecache-subsystem)
  30. *
  31. * @{
  32. */
  33. #ifndef GNUNET_NAMECACHE_SERVICE_H
  34. #define GNUNET_NAMECACHE_SERVICE_H
  35. #include "gnunet_util_lib.h"
  36. #include "gnunet_block_lib.h"
  37. #include "gnunet_namestore_service.h"
  38. #ifdef __cplusplus
  39. extern "C"
  40. {
  41. #if 0 /* keep Emacsens' auto-indent happy */
  42. }
  43. #endif
  44. #endif
  45. /**
  46. * Entry in the queue.
  47. */
  48. struct GNUNET_NAMECACHE_QueueEntry;
  49. /**
  50. * Handle to the namecache service.
  51. */
  52. struct GNUNET_NAMECACHE_Handle;
  53. /**
  54. * Maximum size of a value that can be stored in the namecache.
  55. */
  56. #define GNUNET_NAMECACHE_MAX_VALUE_SIZE (63 * 1024)
  57. /**
  58. * Connect to the namecache service.
  59. *
  60. * @param cfg configuration to use
  61. * @return handle to use to access the service
  62. */
  63. struct GNUNET_NAMECACHE_Handle *
  64. GNUNET_NAMECACHE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
  65. /**
  66. * Disconnect from the namecache service (and free associated
  67. * resources). Must not be called from within operation callbacks of
  68. * the API.
  69. *
  70. * @param h handle to the namecache
  71. */
  72. void
  73. GNUNET_NAMECACHE_disconnect (struct GNUNET_NAMECACHE_Handle *h);
  74. /**
  75. * Continuation called to notify client about result of the
  76. * operation.
  77. *
  78. * @param cls closure
  79. * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
  80. * #GNUNET_NO if content was already there or not found
  81. * #GNUNET_YES (or other positive value) on success
  82. * @param emsg NULL on success, otherwise an error message
  83. */
  84. typedef void
  85. (*GNUNET_NAMECACHE_ContinuationWithStatus) (void *cls,
  86. int32_t success,
  87. const char *emsg);
  88. /**
  89. * Store an item in the namecache. If the item is already present,
  90. * it is replaced with the new record.
  91. *
  92. * @param h handle to the namecache
  93. * @param block block to store
  94. * @param cont continuation to call when done
  95. * @param cont_cls closure for @a cont
  96. * @return handle to abort the request, NULL on error
  97. */
  98. struct GNUNET_NAMECACHE_QueueEntry *
  99. GNUNET_NAMECACHE_block_cache (struct GNUNET_NAMECACHE_Handle *h,
  100. const struct GNUNET_GNSRECORD_Block *block,
  101. GNUNET_NAMECACHE_ContinuationWithStatus cont,
  102. void *cont_cls);
  103. /**
  104. * Process a record that was stored in the namecache.
  105. *
  106. * @param cls closure
  107. * @param block block that was stored in the namecache
  108. */
  109. typedef void
  110. (*GNUNET_NAMECACHE_BlockProcessor) (void *cls,
  111. const struct GNUNET_GNSRECORD_Block *block);
  112. /**
  113. * Get a result for a particular key from the namecache. The processor
  114. * will only be called once.
  115. *
  116. * @param h handle to the namecache
  117. * @param derived_hash hash of zone key combined with name to lookup
  118. * then at the end once with NULL
  119. * @param proc function to call on the matching block, or with
  120. * NULL if there is no matching block
  121. * @param proc_cls closure for @a proc
  122. * @return a handle that can be used to cancel, NULL on error
  123. */
  124. struct GNUNET_NAMECACHE_QueueEntry *
  125. GNUNET_NAMECACHE_lookup_block (struct GNUNET_NAMECACHE_Handle *h,
  126. const struct GNUNET_HashCode *derived_hash,
  127. GNUNET_NAMECACHE_BlockProcessor proc,
  128. void *proc_cls);
  129. /**
  130. * Cancel a namecache operation. The final callback from the
  131. * operation must not have been done yet. Must be called on any
  132. * namecache operation that has not yet completed prior to calling
  133. * #GNUNET_NAMECACHE_disconnect.
  134. *
  135. * @param qe operation to cancel
  136. */
  137. void
  138. GNUNET_NAMECACHE_cancel (struct GNUNET_NAMECACHE_QueueEntry *qe);
  139. #if 0 /* keep Emacsens' auto-indent happy */
  140. {
  141. #endif
  142. #ifdef __cplusplus
  143. }
  144. #endif
  145. #endif
  146. /** @} */ /* end of group */