gnunet_datacache_lib.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. This file is part of GNUnet
  3. (C) 2006, 2009 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 2, 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 include/gnunet_datacache_lib.h
  19. * @brief datacache is a simple, transient hash table
  20. * of bounded size with content expiration.
  21. * In contrast to the sqstore there is
  22. * no prioritization, deletion or iteration.
  23. * All of the data is discarded when the peer shuts down!
  24. * @author Christian Grothoff
  25. */
  26. #ifndef GNUNET_DATACACHE_LIB_H
  27. #define GNUNET_DATACACHE_LIB_H
  28. #include "gnunet_util_lib.h"
  29. #include "gnunet_block_lib.h"
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #if 0 /* keep Emacsens' auto-indent happy */
  34. }
  35. #endif
  36. #endif
  37. /**
  38. * Handle to the cache.
  39. */
  40. struct GNUNET_DATACACHE_Handle;
  41. /**
  42. * Create a data cache.
  43. *
  44. * @param cfg configuration to use
  45. * @param section section in the configuration that contains our options
  46. * @return handle to use to access the service
  47. */
  48. struct GNUNET_DATACACHE_Handle *
  49. GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
  50. const char *section);
  51. /**
  52. * Destroy a data cache (and free associated resources).
  53. *
  54. * @param h handle to the datastore
  55. */
  56. void
  57. GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h);
  58. /**
  59. * An iterator over a set of items stored in the datacache.
  60. *
  61. * @param cls closure
  62. * @param exp when will the content expire?
  63. * @param key key for the content
  64. * @param size number of bytes in data
  65. * @param data content stored
  66. * @param type type of the content
  67. * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort
  68. */
  69. typedef int (*GNUNET_DATACACHE_Iterator) (void *cls,
  70. struct GNUNET_TIME_Absolute exp,
  71. const GNUNET_HashCode * key,
  72. size_t size, const char *data,
  73. enum GNUNET_BLOCK_Type type);
  74. /**
  75. * Store an item in the datacache.
  76. *
  77. * @param h handle to the datacache
  78. * @param key key to store data under
  79. * @param size number of bytes in data
  80. * @param data data to store
  81. * @param type type of the value
  82. * @param discard_time when to discard the value in any case
  83. * @return GNUNET_OK on success, GNUNET_SYSERR on error (full, etc.)
  84. */
  85. int
  86. GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
  87. const GNUNET_HashCode * key, size_t size,
  88. const char *data, enum GNUNET_BLOCK_Type type,
  89. struct GNUNET_TIME_Absolute discard_time);
  90. /**
  91. * Iterate over the results for a particular key
  92. * in the datacache.
  93. *
  94. * @param h handle to the datacache
  95. * @param key what to look up
  96. * @param type entries of which type are relevant?
  97. * @param iter maybe NULL (to just count)
  98. * @param iter_cls closure for iter
  99. * @return the number of results found
  100. */
  101. unsigned int
  102. GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
  103. const GNUNET_HashCode * key, enum GNUNET_BLOCK_Type type,
  104. GNUNET_DATACACHE_Iterator iter, void *iter_cls);
  105. #if 0 /* keep Emacsens' auto-indent happy */
  106. {
  107. #endif
  108. #ifdef __cplusplus
  109. }
  110. #endif
  111. /* end of gnunet_datacache_lib.h */
  112. #endif