a588343353b4d9c5068ea9d5d72bde3dc666cedc
[oweals/gnunet.git] / src / include / gnunet_nat_auto_service.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2007-2017 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  * @author Christian Grothoff
21  * @author Milan Bouchet-Valat
22  *
23  * @file
24  * Service for testing and autoconfiguration of
25  * NAT traversal functionality
26  *
27  * @defgroup nat  NAT testing library
28  *
29  * @{
30  */
31
32 #ifndef GNUNET_NAT_AUTO_SERVICE_H
33 #define GNUNET_NAT_AUTO_SERVICE_H
34
35 #include "gnunet_util_lib.h"
36 #include "gnunet_nat_service.h"
37
38
39 /**
40  * Handle to a NAT test.
41  */
42 struct GNUNET_NAT_AUTO_Test;
43
44
45 /**
46  * Start testing if NAT traversal works using the given configuration.
47  *  The transport adapters should be down while using this function.
48  *
49  * @param cfg configuration for the NAT traversal
50  * @param proto protocol to test, i.e. IPPROTO_TCP or IPPROTO_UDP
51  * @param section_name configuration section to use for configuration
52  * @param report function to call with the result of the test
53  * @param report_cls closure for @a report
54  * @return handle to cancel NAT test
55  */
56 struct GNUNET_NAT_AUTO_Test *
57 GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
58                             uint8_t proto,
59                             const char *section_name,
60                             GNUNET_NAT_TestCallback report,
61                             void *report_cls);
62
63
64 /**
65  * Stop an active NAT test.
66  *
67  * @param tst test to stop.
68  */
69 void
70 GNUNET_NAT_AUTO_test_stop (struct GNUNET_NAT_AUTO_Test *tst);
71
72
73 /**
74  * Handle to auto-configuration in progress.
75  */
76 struct GNUNET_NAT_AUTO_AutoHandle;
77
78
79 /**
80  * Converts `enum GNUNET_NAT_StatusCode` to string
81  *
82  * @param err error code to resolve to a string
83  * @return point to a static string containing the error code
84  */
85 const char *
86 GNUNET_NAT_AUTO_status2string (enum GNUNET_NAT_StatusCode err);
87
88
89 /**
90  * Function called with the result from the autoconfiguration.
91  *
92  * @param cls closure
93  * @param diff minimal suggested changes to the original configuration
94  *             to make it work (as best as we can)
95  * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
96  * @param type what the situation of the NAT
97  */
98 typedef void
99 (*GNUNET_NAT_AUTO_AutoResultCallback)(void *cls,
100                                       const struct GNUNET_CONFIGURATION_Handle *diff,
101                                       enum GNUNET_NAT_StatusCode result,
102                                       enum GNUNET_NAT_Type type);
103
104
105 /**
106  * Start auto-configuration routine.  The transport adapters should
107  * be stopped while this function is called.
108  *
109  * @param cfg initial configuration
110  * @param cb function to call with autoconfiguration result
111  * @param cb_cls closure for @a cb
112  * @return handle to cancel operation
113  */
114 struct GNUNET_NAT_AUTO_AutoHandle *
115 GNUNET_NAT_AUTO_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
116                                   GNUNET_NAT_AUTO_AutoResultCallback cb,
117                                   void *cb_cls);
118
119
120 /**
121  * Abort autoconfiguration.
122  *
123  * @param ah handle for operation to abort
124  */
125 void
126 GNUNET_NAT_AUTO_autoconfig_cancel (struct GNUNET_NAT_AUTO_AutoHandle *ah);
127
128
129 #endif
130
131 /** @} */  /* end of group */
132
133 /* end of gnunet_nat_auto_service.h */