gnunet_regex_service.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 Maximilian Szengel
  19. * @author Christian Grothoff
  20. *
  21. * @file
  22. * API to access regex service to advertise capabilities via regex and discover
  23. * respective peers using matching strings
  24. *
  25. * @defgroup regex RegEx service
  26. * Advertise capabilities via RegEx and discover
  27. * respective peers using matching strings.
  28. *
  29. * @{
  30. */
  31. #ifndef GNUNET_REGEX_SERVICE_H
  32. #define GNUNET_REGEX_SERVICE_H
  33. #include "gnunet_util_lib.h"
  34. #ifdef __cplusplus
  35. extern "C"
  36. {
  37. #if 0 /* keep Emacsens' auto-indent happy */
  38. }
  39. #endif
  40. #endif
  41. /**
  42. * Constant for how many bytes the initial string regex should have.
  43. */
  44. #define GNUNET_REGEX_INITIAL_BYTES 24
  45. /**
  46. * Handle to store cached data about a regex announce.
  47. */
  48. struct GNUNET_REGEX_Announcement;
  49. /**
  50. * Handle to store data about a regex search.
  51. */
  52. struct GNUNET_REGEX_Search;
  53. /**
  54. * Announce this peer under the given regular expression. Does
  55. * not free resources, must call #GNUNET_REGEX_announce_cancel for
  56. * that.
  57. *
  58. * @param cfg configuration to use
  59. * @param regex Regular expression to announce.
  60. * @param refresh_delay after what delay should the announcement be repeated?
  61. * @param compression How many characters per edge can we squeeze?
  62. * @return Handle to reuse o free cached resources.
  63. * Must be freed by calling #GNUNET_REGEX_announce_cancel.
  64. */
  65. struct GNUNET_REGEX_Announcement *
  66. GNUNET_REGEX_announce (const struct GNUNET_CONFIGURATION_Handle *cfg,
  67. const char *regex,
  68. struct GNUNET_TIME_Relative refresh_delay,
  69. uint16_t compression);
  70. /**
  71. * Stop announcing the regex specified by the given handle.
  72. *
  73. * @param a handle returned by a previous #GNUNET_REGEX_announce call.
  74. */
  75. void
  76. GNUNET_REGEX_announce_cancel (struct GNUNET_REGEX_Announcement *a);
  77. /**
  78. * Search callback function, invoked for every result that was found.
  79. *
  80. * @param cls Closure provided in #GNUNET_REGEX_search.
  81. * @param id Peer providing a regex that matches the string.
  82. * @param get_path Path of the get request.
  83. * @param get_path_length Lenght of @a get_path.
  84. * @param put_path Path of the put request.
  85. * @param put_path_length Length of the @a put_path.
  86. */
  87. typedef void (*GNUNET_REGEX_Found)(void *cls,
  88. const struct GNUNET_PeerIdentity *id,
  89. const struct GNUNET_PeerIdentity *get_path,
  90. unsigned int get_path_length,
  91. const struct GNUNET_PeerIdentity *put_path,
  92. unsigned int put_path_length);
  93. /**
  94. * Search for a peer offering a regex matching certain string in the DHT.
  95. * The search runs until #GNUNET_REGEX_search_cancel is called, even if results
  96. * are returned.
  97. *
  98. * @param cfg configuration to use
  99. * @param string String to match against the regexes in the DHT.
  100. * @param callback Callback for found peers.
  101. * @param callback_cls Closure for @c callback.
  102. * @return Handle to stop search and free resources.
  103. * Must be freed by calling #GNUNET_REGEX_search_cancel.
  104. */
  105. struct GNUNET_REGEX_Search *
  106. GNUNET_REGEX_search (const struct GNUNET_CONFIGURATION_Handle *cfg,
  107. const char *string,
  108. GNUNET_REGEX_Found callback,
  109. void *callback_cls);
  110. /**
  111. * Stop search and free all data used by a #GNUNET_REGEX_search call.
  112. *
  113. * @param s Handle returned by a previous #GNUNET_REGEX_search call.
  114. */
  115. void
  116. GNUNET_REGEX_search_cancel (struct GNUNET_REGEX_Search *s);
  117. #if 0 /* keep Emacsens' auto-indent happy */
  118. {
  119. #endif
  120. #ifdef __cplusplus
  121. }
  122. #endif
  123. #endif
  124. /** @} */ /* end of group */