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 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.
17 * @file nat/gnunet-service-nat_mini.c
18 * @brief functions for interaction with miniupnp; tested with miniupnpc 1.5
19 * @author Christian Grothoff
21 #ifndef GNUNET_SERVICE_NAT_MINI_H
22 #define GNUNET_SERVICE_NAT_MINI_H
26 * Signature of a callback that is given an IP address.
29 * @param addr the address, NULL on errors
30 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
33 (*GNUNET_NAT_IPCallback) (void *cls,
34 const struct in_addr *addr,
35 enum GNUNET_NAT_StatusCode result);
39 * Opaque handle to cancel #GNUNET_NAT_mini_get_external_ipv4() operation.
41 struct GNUNET_NAT_ExternalHandle;
45 * Try to get the external IPv4 address of this peer.
47 * @param cb function to call with result
48 * @param cb_cls closure for @a cb
49 * @return handle for cancellation (can only be used until @a cb is called), NULL on error
51 struct GNUNET_NAT_ExternalHandle *
52 GNUNET_NAT_mini_get_external_ipv4_ (GNUNET_NAT_IPCallback cb,
59 * @param eh operation to cancel
62 GNUNET_NAT_mini_get_external_ipv4_cancel_ (struct GNUNET_NAT_ExternalHandle *eh);
66 * Handle to a mapping created with upnpc.
68 struct GNUNET_NAT_MiniHandle;
72 * Signature of the callback passed to #GNUNET_NAT_register() for
73 * a function to call whenever our set of 'valid' addresses changes.
76 * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
77 * the previous (now invalid) one, #GNUNET_SYSERR indicates an error
78 * @param addr either the previous or the new public IP address
79 * @param addrlen actual length of the @a addr
80 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
83 (*GNUNET_NAT_MiniAddressCallback) (void *cls,
85 const struct sockaddr *addr,
87 enum GNUNET_NAT_StatusCode result);
91 * Start mapping the given port using (mini)upnpc. This function
92 * should typically not be used directly (it is used within the
93 * general-purpose #GNUNET_NAT_register() code). However, it can be
94 * used if specifically UPnP-based NAT traversal is to be used or
97 * @param port port to map
98 * @param is_tcp #GNUNET_YES to map TCP, #GNUNET_NO for UDP
99 * @param ac function to call with mapping result
100 * @param ac_cls closure for @a ac
101 * @return NULL on error
103 struct GNUNET_NAT_MiniHandle *
104 GNUNET_NAT_mini_map_start (uint16_t port,
106 GNUNET_NAT_MiniAddressCallback ac,
111 * Remove a mapping created with (mini)upnpc. Calling
112 * this function will give 'upnpc' 1s to remove the mapping,
113 * so while this function is non-blocking, a task will be
114 * left with the scheduler for up to 1s past this call.
116 * @param mini the handle
119 GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini);