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/>.
20 * @file nat/gnunet-service-nat_mini.c
21 * @brief functions for interaction with miniupnp; tested with miniupnpc 1.5
22 * @author Christian Grothoff
24 #ifndef GNUNET_SERVICE_NAT_MINI_H
25 #define GNUNET_SERVICE_NAT_MINI_H
29 * Signature of a callback that is given an IP address.
32 * @param addr the address, NULL on errors
33 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
36 (*GNUNET_NAT_IPCallback) (void *cls,
37 const struct in_addr *addr,
38 enum GNUNET_NAT_StatusCode result);
42 * Opaque handle to cancel #GNUNET_NAT_mini_get_external_ipv4() operation.
44 struct GNUNET_NAT_ExternalHandle;
48 * Try to get the external IPv4 address of this peer.
50 * @param cb function to call with result
51 * @param cb_cls closure for @a cb
52 * @return handle for cancellation (can only be used until @a cb is called), NULL on error
54 struct GNUNET_NAT_ExternalHandle *
55 GNUNET_NAT_mini_get_external_ipv4_ (GNUNET_NAT_IPCallback cb,
62 * @param eh operation to cancel
65 GNUNET_NAT_mini_get_external_ipv4_cancel_ (struct GNUNET_NAT_ExternalHandle *eh);
69 * Handle to a mapping created with upnpc.
71 struct GNUNET_NAT_MiniHandle;
75 * Signature of the callback passed to #GNUNET_NAT_register() for
76 * a function to call whenever our set of 'valid' addresses changes.
79 * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
80 * the previous (now invalid) one, #GNUNET_SYSERR indicates an error
81 * @param addr either the previous or the new public IP address
82 * @param addrlen actual length of the @a addr
83 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
86 (*GNUNET_NAT_MiniAddressCallback) (void *cls,
88 const struct sockaddr *addr,
90 enum GNUNET_NAT_StatusCode result);
94 * Start mapping the given port using (mini)upnpc. This function
95 * should typically not be used directly (it is used within the
96 * general-purpose #GNUNET_NAT_register() code). However, it can be
97 * used if specifically UPnP-based NAT traversal is to be used or
100 * @param port port to map
101 * @param is_tcp #GNUNET_YES to map TCP, #GNUNET_NO for UDP
102 * @param ac function to call with mapping result
103 * @param ac_cls closure for @a ac
104 * @return NULL on error
106 struct GNUNET_NAT_MiniHandle *
107 GNUNET_NAT_mini_map_start (uint16_t port,
109 GNUNET_NAT_MiniAddressCallback ac,
114 * Remove a mapping created with (mini)upnpc. Calling
115 * this function will give 'upnpc' 1s to remove the mapping,
116 * so while this function is non-blocking, a task will be
117 * left with the scheduler for up to 1s past this call.
119 * @param mini the handle
122 GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini);