86930f39f2d7c17d5dc4744901bf4f28c3a01c71
[oweals/gnunet.git] / src / nat / gnunet-service-nat_mini.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2011-2014, 2016 GNUnet e.V.
4
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.
9
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.
14     
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/>.
17 */
18
19 /**
20  * @file nat/gnunet-service-nat_mini.c
21  * @brief functions for interaction with miniupnp; tested with miniupnpc 1.5
22  * @author Christian Grothoff
23  */
24 #ifndef GNUNET_SERVICE_NAT_MINI_H
25 #define GNUNET_SERVICE_NAT_MINI_H
26
27
28 /**
29  * Signature of a callback that is given an IP address.
30  *
31  * @param cls closure
32  * @param addr the address, NULL on errors
33  * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
34  */
35 typedef void
36 (*GNUNET_NAT_IPCallback) (void *cls,
37                           const struct in_addr *addr,
38                           enum GNUNET_NAT_StatusCode result);
39
40
41 /**
42  * Opaque handle to cancel #GNUNET_NAT_mini_get_external_ipv4() operation.
43  */
44 struct GNUNET_NAT_ExternalHandle;
45
46
47 /**
48  * Try to get the external IPv4 address of this peer.
49  *
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
53  */
54 struct GNUNET_NAT_ExternalHandle *
55 GNUNET_NAT_mini_get_external_ipv4_ (GNUNET_NAT_IPCallback cb,
56                                     void *cb_cls);
57
58
59 /**
60  * Cancel operation.
61  *
62  * @param eh operation to cancel
63  */
64 void
65 GNUNET_NAT_mini_get_external_ipv4_cancel_ (struct GNUNET_NAT_ExternalHandle *eh);
66
67
68 /**
69  * Handle to a mapping created with upnpc.
70  */
71 struct GNUNET_NAT_MiniHandle;
72
73
74 /**
75  * Signature of the callback passed to #GNUNET_NAT_register() for
76  * a function to call whenever our set of 'valid' addresses changes.
77  *
78  * @param cls closure
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
84  */
85 typedef void
86 (*GNUNET_NAT_MiniAddressCallback) (void *cls,
87                                    int add_remove,
88                                    const struct sockaddr *addr,
89                                    socklen_t addrlen,
90                                    enum GNUNET_NAT_StatusCode result);
91
92
93 /**
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
98  * tested.
99  *
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
105  */
106 struct GNUNET_NAT_MiniHandle *
107 GNUNET_NAT_mini_map_start (uint16_t port,
108                            int is_tcp,
109                            GNUNET_NAT_MiniAddressCallback ac,
110                            void *ac_cls);
111
112
113 /**
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.
118  *
119  * @param mini the handle
120  */
121 void
122 GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini);
123
124
125 #endif