gnunet_regex_service.h 4.4 KB

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