glitch in the license text detected by hyazinthe, thank you!
[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
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
25 /**
26  * Signature of a callback that is given an IP address.
27  *
28  * @param cls closure
29  * @param addr the address, NULL on errors
30  * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
31  */
32 typedef void
33 (*GNUNET_NAT_IPCallback) (void *cls,
34                           const struct in_addr *addr,
35                           enum GNUNET_NAT_StatusCode result);
36
37
38 /**
39  * Opaque handle to cancel #GNUNET_NAT_mini_get_external_ipv4() operation.
40  */
41 struct GNUNET_NAT_ExternalHandle;
42
43
44 /**
45  * Try to get the external IPv4 address of this peer.
46  *
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
50  */
51 struct GNUNET_NAT_ExternalHandle *
52 GNUNET_NAT_mini_get_external_ipv4_ (GNUNET_NAT_IPCallback cb,
53                                     void *cb_cls);
54
55
56 /**
57  * Cancel operation.
58  *
59  * @param eh operation to cancel
60  */
61 void
62 GNUNET_NAT_mini_get_external_ipv4_cancel_ (struct GNUNET_NAT_ExternalHandle *eh);
63
64
65 /**
66  * Handle to a mapping created with upnpc.
67  */
68 struct GNUNET_NAT_MiniHandle;
69
70
71 /**
72  * Signature of the callback passed to #GNUNET_NAT_register() for
73  * a function to call whenever our set of 'valid' addresses changes.
74  *
75  * @param cls closure
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
81  */
82 typedef void
83 (*GNUNET_NAT_MiniAddressCallback) (void *cls,
84                                    int add_remove,
85                                    const struct sockaddr *addr,
86                                    socklen_t addrlen,
87                                    enum GNUNET_NAT_StatusCode result);
88
89
90 /**
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
95  * tested.
96  *
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
102  */
103 struct GNUNET_NAT_MiniHandle *
104 GNUNET_NAT_mini_map_start (uint16_t port,
105                            int is_tcp,
106                            GNUNET_NAT_MiniAddressCallback ac,
107                            void *ac_cls);
108
109
110 /**
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.
115  *
116  * @param mini the handle
117  */
118 void
119 GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini);
120
121
122 #endif