gnunet_dnsstub_lib.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2012, 2018 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 for helper library to send DNS requests to DNS resolver
  21. *
  22. * @defgroup dns-stub DNS Stub library
  23. * Helper library to send DNS requests to DNS resolver
  24. * @{
  25. */
  26. #ifndef GNUNET_DNSSTUB_LIB_H
  27. #define GNUNET_DNSSTUB_LIB_H
  28. #include "gnunet_util_lib.h"
  29. /**
  30. * Opaque handle to the stub resolver.
  31. */
  32. struct GNUNET_DNSSTUB_Context;
  33. /**
  34. * Opaque handle to a socket doing UDP requests.
  35. */
  36. struct GNUNET_DNSSTUB_RequestSocket;
  37. /**
  38. * Start a DNS stub resolver.
  39. *
  40. * @param num_sockets how many sockets should we open
  41. * in parallel for DNS queries for this stub?
  42. * @return NULL on error
  43. */
  44. struct GNUNET_DNSSTUB_Context *
  45. GNUNET_DNSSTUB_start (unsigned int num_sockets);
  46. /**
  47. * Add nameserver for use by the DNSSTUB. We will use
  48. * all provided nameservers for resolution (round-robin).
  49. *
  50. * @param ctx resolver context to modify
  51. * @param dns_ip target IP address to use (as string)
  52. * @return #GNUNET_OK on success
  53. */
  54. int
  55. GNUNET_DNSSTUB_add_dns_ip (struct GNUNET_DNSSTUB_Context *ctx,
  56. const char *dns_ip);
  57. /**
  58. * Add nameserver for use by the DNSSTUB. We will use
  59. * all provided nameservers for resolution (round-robin).
  60. *
  61. * @param ctx resolver context to modify
  62. * @param sa socket address of DNS resolver to use
  63. * @return #GNUNET_OK on success
  64. */
  65. int
  66. GNUNET_DNSSTUB_add_dns_sa (struct GNUNET_DNSSTUB_Context *ctx,
  67. const struct sockaddr *sa);
  68. /**
  69. * How long should we try requests before timing out?
  70. * Only effective for requests issued after this call.
  71. *
  72. * @param ctx resolver context to modify
  73. * @param retry_frequ how long to wait between retries
  74. */
  75. void
  76. GNUNET_DNSSTUB_set_retry (struct GNUNET_DNSSTUB_Context *ctx,
  77. struct GNUNET_TIME_Relative retry_freq);
  78. /**
  79. * Cleanup DNSSTUB resolver.
  80. *
  81. * @param ctx stub resolver to clean up
  82. */
  83. void
  84. GNUNET_DNSSTUB_stop (struct GNUNET_DNSSTUB_Context *ctx);
  85. /**
  86. * Function called with the result of a DNS resolution.
  87. * Once this function is called, the resolution request
  88. * is automatically cancelled / cleaned up. In particular,
  89. * the function will only be called once.
  90. *
  91. * @param cls closure
  92. * @param dns dns response, NULL on hard error (i.e. timeout)
  93. * @param dns_len number of bytes in @a dns
  94. */
  95. typedef void
  96. (*GNUNET_DNSSTUB_ResultCallback)(void *cls,
  97. const struct GNUNET_TUN_DnsHeader *dns,
  98. size_t dns_len);
  99. /**
  100. * Perform DNS resolution using our default IP from init.
  101. *
  102. * @param ctx stub resolver to use
  103. * @param request DNS request to transmit
  104. * @param request_len number of bytes in msg
  105. * @param rc function to call with result (once)
  106. * @param rc_cls closure for @a rc
  107. * @return socket used for the request, NULL on error
  108. */
  109. struct GNUNET_DNSSTUB_RequestSocket *
  110. GNUNET_DNSSTUB_resolve (struct GNUNET_DNSSTUB_Context *ctx,
  111. const void *request,
  112. size_t request_len,
  113. GNUNET_DNSSTUB_ResultCallback rc,
  114. void *rc_cls);
  115. /**
  116. * Cancel DNS resolution.
  117. *
  118. * @param rs resolution to cancel
  119. */
  120. void
  121. GNUNET_DNSSTUB_resolve_cancel (struct GNUNET_DNSSTUB_RequestSocket *rs);
  122. #endif
  123. /** @} */ /* end of group */