2 This file is part of GNUnet.
3 Copyright (C) 2011-2014, 2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file nat/gnunet-service-nat_mini.c
23 * @brief functions for interaction with miniupnp; tested with miniupnpc 1.5
24 * @author Christian Grothoff
26 #ifndef GNUNET_SERVICE_NAT_MINI_H
27 #define GNUNET_SERVICE_NAT_MINI_H
31 * Signature of a callback that is given an IP address.
34 * @param addr the address, NULL on errors
35 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
38 (*GNUNET_NAT_IPCallback) (void *cls,
39 const struct in_addr *addr,
40 enum GNUNET_NAT_StatusCode result);
44 * Opaque handle to cancel #GNUNET_NAT_mini_get_external_ipv4() operation.
46 struct GNUNET_NAT_ExternalHandle;
50 * Try to get the external IPv4 address of this peer.
52 * @param cb function to call with result
53 * @param cb_cls closure for @a cb
54 * @return handle for cancellation (can only be used until @a cb is called), NULL on error
56 struct GNUNET_NAT_ExternalHandle *
57 GNUNET_NAT_mini_get_external_ipv4_ (GNUNET_NAT_IPCallback cb,
64 * @param eh operation to cancel
67 GNUNET_NAT_mini_get_external_ipv4_cancel_ (struct GNUNET_NAT_ExternalHandle *eh);
71 * Handle to a mapping created with upnpc.
73 struct GNUNET_NAT_MiniHandle;
77 * Signature of the callback passed to #GNUNET_NAT_register() for
78 * a function to call whenever our set of 'valid' addresses changes.
81 * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
82 * the previous (now invalid) one, #GNUNET_SYSERR indicates an error
83 * @param addr either the previous or the new public IP address
84 * @param addrlen actual length of the @a addr
85 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
88 (*GNUNET_NAT_MiniAddressCallback) (void *cls,
90 const struct sockaddr *addr,
92 enum GNUNET_NAT_StatusCode result);
96 * Start mapping the given port using (mini)upnpc. This function
97 * should typically not be used directly (it is used within the
98 * general-purpose #GNUNET_NAT_register() code). However, it can be
99 * used if specifically UPnP-based NAT traversal is to be used or
102 * @param port port to map
103 * @param is_tcp #GNUNET_YES to map TCP, #GNUNET_NO for UDP
104 * @param ac function to call with mapping result
105 * @param ac_cls closure for @a ac
106 * @return NULL on error
108 struct GNUNET_NAT_MiniHandle *
109 GNUNET_NAT_mini_map_start (uint16_t port,
111 GNUNET_NAT_MiniAddressCallback ac,
116 * Remove a mapping created with (mini)upnpc. Calling
117 * this function will give 'upnpc' 1s to remove the mapping,
118 * so while this function is non-blocking, a task will be
119 * left with the scheduler for up to 1s past this call.
121 * @param mini the handle
124 GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini);