gnunet_dns_service.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2012 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 to access the DNS service.
  21. *
  22. * @defgroup dns DNS service
  23. *
  24. * @see [Documentation](https://gnunet.org/gnunet-service-dns)
  25. *
  26. * @{
  27. */
  28. #ifndef GNUNET_DNS_SERVICE_H
  29. #define GNUNET_DNS_SERVICE_H
  30. #include "gnunet_util_lib.h"
  31. /**
  32. * Opaque DNS handle
  33. */
  34. struct GNUNET_DNS_Handle;
  35. /**
  36. * Handle to identify an individual DNS request.
  37. */
  38. struct GNUNET_DNS_RequestHandle;
  39. /**
  40. * Flags that specify when to call the client's handler.
  41. */
  42. enum GNUNET_DNS_Flags
  43. {
  44. /**
  45. * Useless option: never call the client.
  46. */
  47. GNUNET_DNS_FLAG_NEVER = 0,
  48. /**
  49. * Set this flag to see all requests first prior to resolution
  50. * (for monitoring). Clients that set this flag must then
  51. * call "GNUNET_DNS_request_forward" when they process a request
  52. * for the first time. Caling "GNUNET_DNS_request_answer" is
  53. * not allowed for MONITOR peers.
  54. */
  55. GNUNET_DNS_FLAG_REQUEST_MONITOR = 1,
  56. /**
  57. * This client should be called on requests that have not
  58. * yet been resolved as this client provides a resolution
  59. * service. Note that this does not guarantee that the
  60. * client will see all requests as another client might be
  61. * called first and that client might have already done the
  62. * resolution, in which case other pre-resolution clients
  63. * won't see the request anymore.
  64. */
  65. GNUNET_DNS_FLAG_PRE_RESOLUTION = 2,
  66. /**
  67. * This client wants to be called on the results of a DNS resolution
  68. * (either resolved by PRE-RESOLUTION clients or the global DNS).
  69. * The client then has a chance to modify the answer (or cause it to
  70. * be dropped). There is no guarantee that other POST-RESOLUTION
  71. * client's won't modify (or drop) the answer afterwards.
  72. */
  73. GNUNET_DNS_FLAG_POST_RESOLUTION = 4,
  74. /**
  75. * Set this flag to see all requests just before they are
  76. * returned to the network. Clients that set this flag must then
  77. * call "GNUNET_DNS_request_forward" when they process a request
  78. * for the last time. Caling "GNUNET_DNS_request_answer" is
  79. * not allowed for MONITOR peers.
  80. */
  81. GNUNET_DNS_FLAG_RESPONSE_MONITOR = 8
  82. };
  83. /**
  84. * Signature of a function that is called whenever the DNS service
  85. * encounters a DNS request and needs to do something with it. The
  86. * function has then the chance to generate or modify the response by
  87. * calling one of the three "GNUNET_DNS_request_*" continuations.
  88. *
  89. * When a request is intercepted, this function is called first to
  90. * give the client a chance to do the complete address resolution;
  91. * "rdata" will be NULL for this first call for a DNS request, unless
  92. * some other client has already filled in a response.
  93. *
  94. * If multiple clients exist, all of them are called before the global
  95. * DNS. The global DNS is only called if all of the clients'
  96. * functions call GNUNET_DNS_request_forward. Functions that call
  97. * GNUNET_DNS_request_forward will be called again before a final
  98. * response is returned to the application. If any of the clients'
  99. * functions call GNUNET_DNS_request_drop, the response is dropped.
  100. *
  101. * @param cls closure
  102. * @param rh request handle to user for reply
  103. * @param request_length number of bytes in request
  104. * @param request udp payload of the DNS request
  105. */
  106. typedef void
  107. (*GNUNET_DNS_RequestHandler)(void *cls,
  108. struct GNUNET_DNS_RequestHandle *rh,
  109. size_t request_length,
  110. const char *request);
  111. /**
  112. * If a GNUNET_DNS_RequestHandler calls this function, the client
  113. * has no desire to interfer with the request and it should
  114. * continue to be processed normally.
  115. *
  116. * @param rh request that should now be forwarded
  117. */
  118. void
  119. GNUNET_DNS_request_forward (struct GNUNET_DNS_RequestHandle *rh);
  120. /**
  121. * If a GNUNET_DNS_RequestHandler calls this function, the request is
  122. * to be dropped and no response should be generated.
  123. *
  124. * @param rh request that should now be dropped
  125. */
  126. void
  127. GNUNET_DNS_request_drop (struct GNUNET_DNS_RequestHandle *rh);
  128. /**
  129. * If a GNUNET_DNS_RequestHandler calls this function, the request is
  130. * supposed to be answered with the data provided to this call (with
  131. * the modifications the function might have made). The reply given
  132. * must always be a valid DNS reply and not a mutated DNS request.
  133. *
  134. * @param rh request that should now be answered
  135. * @param reply_length size of @a reply (uint16_t to force sane size)
  136. * @param reply reply data
  137. */
  138. void
  139. GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh,
  140. uint16_t reply_length,
  141. const char *reply);
  142. /**
  143. * Connect to the service-dns
  144. *
  145. * @param cfg configuration to use
  146. * @param flags when to call @a rh
  147. * @param rh function to call with DNS requests
  148. * @param rh_cls closure to pass to @a rh
  149. * @return DNS handle
  150. */
  151. struct GNUNET_DNS_Handle *
  152. GNUNET_DNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
  153. enum GNUNET_DNS_Flags flags,
  154. GNUNET_DNS_RequestHandler rh,
  155. void *rh_cls);
  156. /**
  157. * Disconnect from the DNS service.
  158. *
  159. * @param dh DNS handle
  160. */
  161. void
  162. GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *dh);
  163. #endif
  164. /** @} */ /* end of group */