gnunet_nat_auto_service.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2007-2017 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. * @author Milan Bouchet-Valat
  19. *
  20. * @file
  21. * Service for testing and autoconfiguration of
  22. * NAT traversal functionality
  23. *
  24. * @defgroup nat NAT testing library
  25. *
  26. * @{
  27. */
  28. #ifndef GNUNET_NAT_AUTO_SERVICE_H
  29. #define GNUNET_NAT_AUTO_SERVICE_H
  30. #include "gnunet_util_lib.h"
  31. #include "gnunet_nat_service.h"
  32. /**
  33. * Handle to a NAT test.
  34. */
  35. struct GNUNET_NAT_AUTO_Test;
  36. /**
  37. * Start testing if NAT traversal works using the given configuration.
  38. * The transport adapters should be down while using this function.
  39. *
  40. * @param cfg configuration for the NAT traversal
  41. * @param proto protocol to test, i.e. IPPROTO_TCP or IPPROTO_UDP
  42. * @param section_name configuration section to use for configuration
  43. * @param report function to call with the result of the test
  44. * @param report_cls closure for @a report
  45. * @return handle to cancel NAT test
  46. */
  47. struct GNUNET_NAT_AUTO_Test *
  48. GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
  49. uint8_t proto,
  50. const char *section_name,
  51. GNUNET_NAT_TestCallback report,
  52. void *report_cls);
  53. /**
  54. * Stop an active NAT test.
  55. *
  56. * @param tst test to stop.
  57. */
  58. void
  59. GNUNET_NAT_AUTO_test_stop (struct GNUNET_NAT_AUTO_Test *tst);
  60. /**
  61. * Handle to auto-configuration in progress.
  62. */
  63. struct GNUNET_NAT_AUTO_AutoHandle;
  64. /**
  65. * Converts `enum GNUNET_NAT_StatusCode` to string
  66. *
  67. * @param err error code to resolve to a string
  68. * @return point to a static string containing the error code
  69. */
  70. const char *
  71. GNUNET_NAT_AUTO_status2string (enum GNUNET_NAT_StatusCode err);
  72. /**
  73. * Function called with the result from the autoconfiguration.
  74. *
  75. * @param cls closure
  76. * @param diff minimal suggested changes to the original configuration
  77. * to make it work (as best as we can)
  78. * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
  79. * @param type what the situation of the NAT
  80. */
  81. typedef void
  82. (*GNUNET_NAT_AUTO_AutoResultCallback)(void *cls,
  83. const struct GNUNET_CONFIGURATION_Handle *diff,
  84. enum GNUNET_NAT_StatusCode result,
  85. enum GNUNET_NAT_Type type);
  86. /**
  87. * Start auto-configuration routine. The transport adapters should
  88. * be stopped while this function is called.
  89. *
  90. * @param cfg initial configuration
  91. * @param cb function to call with autoconfiguration result
  92. * @param cb_cls closure for @a cb
  93. * @return handle to cancel operation
  94. */
  95. struct GNUNET_NAT_AUTO_AutoHandle *
  96. GNUNET_NAT_AUTO_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
  97. GNUNET_NAT_AUTO_AutoResultCallback cb,
  98. void *cb_cls);
  99. /**
  100. * Abort autoconfiguration.
  101. *
  102. * @param ah handle for operation to abort
  103. */
  104. void
  105. GNUNET_NAT_AUTO_autoconfig_cancel (struct GNUNET_NAT_AUTO_AutoHandle *ah);
  106. #endif
  107. /** @} */ /* end of group */
  108. /* end of gnunet_nat_auto_service.h */