gnunet-service-nat_mini.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2011-2014, 2016 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. * @file nat/gnunet-service-nat_mini.c
  18. * @brief functions for interaction with miniupnp; tested with miniupnpc 1.5
  19. * @author Christian Grothoff
  20. */
  21. #ifndef GNUNET_SERVICE_NAT_MINI_H
  22. #define GNUNET_SERVICE_NAT_MINI_H
  23. /**
  24. * Signature of a callback that is given an IP address.
  25. *
  26. * @param cls closure
  27. * @param addr the address, NULL on errors
  28. * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
  29. */
  30. typedef void
  31. (*GNUNET_NAT_IPCallback) (void *cls,
  32. const struct in_addr *addr,
  33. enum GNUNET_NAT_StatusCode result);
  34. /**
  35. * Opaque handle to cancel #GNUNET_NAT_mini_get_external_ipv4() operation.
  36. */
  37. struct GNUNET_NAT_ExternalHandle;
  38. /**
  39. * Try to get the external IPv4 address of this peer.
  40. *
  41. * @param cb function to call with result
  42. * @param cb_cls closure for @a cb
  43. * @return handle for cancellation (can only be used until @a cb is called), NULL on error
  44. */
  45. struct GNUNET_NAT_ExternalHandle *
  46. GNUNET_NAT_mini_get_external_ipv4_ (GNUNET_NAT_IPCallback cb,
  47. void *cb_cls);
  48. /**
  49. * Cancel operation.
  50. *
  51. * @param eh operation to cancel
  52. */
  53. void
  54. GNUNET_NAT_mini_get_external_ipv4_cancel_ (struct GNUNET_NAT_ExternalHandle *eh);
  55. /**
  56. * Handle to a mapping created with upnpc.
  57. */
  58. struct GNUNET_NAT_MiniHandle;
  59. /**
  60. * Signature of the callback passed to #GNUNET_NAT_register() for
  61. * a function to call whenever our set of 'valid' addresses changes.
  62. *
  63. * @param cls closure
  64. * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
  65. * the previous (now invalid) one, #GNUNET_SYSERR indicates an error
  66. * @param addr either the previous or the new public IP address
  67. * @param addrlen actual length of the @a addr
  68. * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
  69. */
  70. typedef void
  71. (*GNUNET_NAT_MiniAddressCallback) (void *cls,
  72. int add_remove,
  73. const struct sockaddr *addr,
  74. socklen_t addrlen,
  75. enum GNUNET_NAT_StatusCode result);
  76. /**
  77. * Start mapping the given port using (mini)upnpc. This function
  78. * should typically not be used directly (it is used within the
  79. * general-purpose #GNUNET_NAT_register() code). However, it can be
  80. * used if specifically UPnP-based NAT traversal is to be used or
  81. * tested.
  82. *
  83. * @param port port to map
  84. * @param is_tcp #GNUNET_YES to map TCP, #GNUNET_NO for UDP
  85. * @param ac function to call with mapping result
  86. * @param ac_cls closure for @a ac
  87. * @return NULL on error
  88. */
  89. struct GNUNET_NAT_MiniHandle *
  90. GNUNET_NAT_mini_map_start (uint16_t port,
  91. int is_tcp,
  92. GNUNET_NAT_MiniAddressCallback ac,
  93. void *ac_cls);
  94. /**
  95. * Remove a mapping created with (mini)upnpc. Calling
  96. * this function will give 'upnpc' 1s to remove the mapping,
  97. * so while this function is non-blocking, a task will be
  98. * left with the scheduler for up to 1s past this call.
  99. *
  100. * @param mini the handle
  101. */
  102. void
  103. GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini);
  104. #endif