gnunet_namecache_service.h 4.8 KB

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