diff options
Diffstat (limited to 'src/nat-auto/nat_auto_api.c')
-rw-r--r-- | src/nat-auto/nat_auto_api.c | 264 |
1 files changed, 140 insertions, 124 deletions
diff --git a/src/nat-auto/nat_auto_api.c b/src/nat-auto/nat_auto_api.c index d7c081e49..ae7bb6514 100644 --- a/src/nat-auto/nat_auto_api.c +++ b/src/nat-auto/nat_auto_api.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @author Christian Grothoff | 22 | * @author Christian Grothoff |
@@ -35,9 +35,7 @@ | |||
35 | /** | 35 | /** |
36 | * Handle to auto-configuration in progress. | 36 | * Handle to auto-configuration in progress. |
37 | */ | 37 | */ |
38 | struct GNUNET_NAT_AUTO_AutoHandle | 38 | struct GNUNET_NAT_AUTO_AutoHandle { |
39 | { | ||
40 | |||
41 | /** | 39 | /** |
42 | * Configuration we use. | 40 | * Configuration we use. |
43 | */ | 41 | */ |
@@ -57,7 +55,6 @@ struct GNUNET_NAT_AUTO_AutoHandle | |||
57 | * Closure for @e arc. | 55 | * Closure for @e arc. |
58 | */ | 56 | */ |
59 | void *arc_cls; | 57 | void *arc_cls; |
60 | |||
61 | }; | 58 | }; |
62 | 59 | ||
63 | 60 | ||
@@ -68,51 +65,70 @@ struct GNUNET_NAT_AUTO_AutoHandle | |||
68 | * @return point to a static string containing the error code | 65 | * @return point to a static string containing the error code |
69 | */ | 66 | */ |
70 | const char * | 67 | const char * |
71 | GNUNET_NAT_AUTO_status2string (enum GNUNET_NAT_StatusCode err) | 68 | GNUNET_NAT_AUTO_status2string(enum GNUNET_NAT_StatusCode err) |
72 | { | 69 | { |
73 | switch (err) | 70 | switch (err) |
74 | { | 71 | { |
75 | case GNUNET_NAT_ERROR_SUCCESS: | 72 | case GNUNET_NAT_ERROR_SUCCESS: |
76 | return _ ("Operation Successful"); | 73 | return _("Operation Successful"); |
77 | case GNUNET_NAT_ERROR_IPC_FAILURE: | 74 | |
78 | return _ ("IPC failure"); | 75 | case GNUNET_NAT_ERROR_IPC_FAILURE: |
79 | case GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR: | 76 | return _("IPC failure"); |
80 | return _ ("Failure in network subsystem, check permissions."); | 77 | |
81 | case GNUNET_NAT_ERROR_TIMEOUT: | 78 | case GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR: |
82 | return _ ("Encountered timeout while performing operation"); | 79 | return _("Failure in network subsystem, check permissions."); |
83 | case GNUNET_NAT_ERROR_NOT_ONLINE: | 80 | |
84 | return _ ("detected that we are offline"); | 81 | case GNUNET_NAT_ERROR_TIMEOUT: |
85 | case GNUNET_NAT_ERROR_UPNPC_NOT_FOUND: | 82 | return _("Encountered timeout while performing operation"); |
86 | return _ ("`upnpc` command not found"); | 83 | |
87 | case GNUNET_NAT_ERROR_UPNPC_FAILED: | 84 | case GNUNET_NAT_ERROR_NOT_ONLINE: |
88 | return _ ("Failed to run `upnpc` command"); | 85 | return _("detected that we are offline"); |
89 | case GNUNET_NAT_ERROR_UPNPC_TIMEOUT: | 86 | |
90 | return _ ("`upnpc' command took too long, process killed"); | 87 | case GNUNET_NAT_ERROR_UPNPC_NOT_FOUND: |
91 | case GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED: | 88 | return _("`upnpc` command not found"); |
92 | return _ ("`upnpc' command failed to establish port mapping"); | 89 | |
93 | case GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND: | 90 | case GNUNET_NAT_ERROR_UPNPC_FAILED: |
94 | return _ ("`external-ip' command not found"); | 91 | return _("Failed to run `upnpc` command"); |
95 | case GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED: | 92 | |
96 | return _ ("Failed to run `external-ip` command"); | 93 | case GNUNET_NAT_ERROR_UPNPC_TIMEOUT: |
97 | case GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID: | 94 | return _("`upnpc' command took too long, process killed"); |
98 | return _ ("`external-ip' command output invalid"); | 95 | |
99 | case GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID: | 96 | case GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED: |
100 | return _ ("no valid address was returned by `external-ip'"); | 97 | return _("`upnpc' command failed to establish port mapping"); |
101 | case GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO: | 98 | |
102 | return _ ("Could not determine interface with internal/local network address"); | 99 | case GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND: |
103 | case GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND: | 100 | return _("`external-ip' command not found"); |
104 | return _ ("No functioning gnunet-helper-nat-server installation found"); | 101 | |
105 | case GNUNET_NAT_ERROR_NAT_TEST_START_FAILED: | 102 | case GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED: |
106 | return _ ("NAT test could not be initialized"); | 103 | return _("Failed to run `external-ip` command"); |
107 | case GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT: | 104 | |
108 | return _ ("NAT test timeout reached"); | 105 | case GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID: |
109 | case GNUNET_NAT_ERROR_NAT_REGISTER_FAILED: | 106 | return _("`external-ip' command output invalid"); |
110 | return _ ("could not register NAT"); | 107 | |
111 | case GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND: | 108 | case GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID: |
112 | return _ ("No working gnunet-helper-nat-client installation found"); | 109 | return _("no valid address was returned by `external-ip'"); |
113 | default: | 110 | |
114 | return "unknown status code"; | 111 | case GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO: |
115 | } | 112 | return _("Could not determine interface with internal/local network address"); |
113 | |||
114 | case GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND: | ||
115 | return _("No functioning gnunet-helper-nat-server installation found"); | ||
116 | |||
117 | case GNUNET_NAT_ERROR_NAT_TEST_START_FAILED: | ||
118 | return _("NAT test could not be initialized"); | ||
119 | |||
120 | case GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT: | ||
121 | return _("NAT test timeout reached"); | ||
122 | |||
123 | case GNUNET_NAT_ERROR_NAT_REGISTER_FAILED: | ||
124 | return _("could not register NAT"); | ||
125 | |||
126 | case GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND: | ||
127 | return _("No working gnunet-helper-nat-client installation found"); | ||
128 | |||
129 | default: | ||
130 | return "unknown status code"; | ||
131 | } | ||
116 | } | 132 | } |
117 | 133 | ||
118 | 134 | ||
@@ -124,8 +140,8 @@ GNUNET_NAT_AUTO_status2string (enum GNUNET_NAT_StatusCode err) | |||
124 | * @return #GNUNET_OK if @a res is well-formed (always for now) | 140 | * @return #GNUNET_OK if @a res is well-formed (always for now) |
125 | */ | 141 | */ |
126 | static int | 142 | static int |
127 | check_auto_result (void *cls, | 143 | check_auto_result(void *cls, |
128 | const struct GNUNET_NAT_AUTO_AutoconfigResultMessage *res) | 144 | const struct GNUNET_NAT_AUTO_AutoconfigResultMessage *res) |
129 | { | 145 | { |
130 | return GNUNET_OK; | 146 | return GNUNET_OK; |
131 | } | 147 | } |
@@ -138,40 +154,40 @@ check_auto_result (void *cls, | |||
138 | * @param res the result | 154 | * @param res the result |
139 | */ | 155 | */ |
140 | static void | 156 | static void |
141 | handle_auto_result (void *cls, | 157 | handle_auto_result(void *cls, |
142 | const struct GNUNET_NAT_AUTO_AutoconfigResultMessage *res) | 158 | const struct GNUNET_NAT_AUTO_AutoconfigResultMessage *res) |
143 | { | 159 | { |
144 | struct GNUNET_NAT_AUTO_AutoHandle *ah = cls; | 160 | struct GNUNET_NAT_AUTO_AutoHandle *ah = cls; |
145 | size_t left; | 161 | size_t left; |
146 | struct GNUNET_CONFIGURATION_Handle *cfg; | 162 | struct GNUNET_CONFIGURATION_Handle *cfg; |
147 | enum GNUNET_NAT_Type type | 163 | enum GNUNET_NAT_Type type |
148 | = (enum GNUNET_NAT_Type) ntohl (res->type); | 164 | = (enum GNUNET_NAT_Type)ntohl(res->type); |
149 | enum GNUNET_NAT_StatusCode status | 165 | enum GNUNET_NAT_StatusCode status |
150 | = (enum GNUNET_NAT_StatusCode) ntohl (res->status_code); | 166 | = (enum GNUNET_NAT_StatusCode)ntohl(res->status_code); |
151 | 167 | ||
152 | left = ntohs (res->header.size) - sizeof (*res); | 168 | left = ntohs(res->header.size) - sizeof(*res); |
153 | cfg = GNUNET_CONFIGURATION_create (); | 169 | cfg = GNUNET_CONFIGURATION_create(); |
154 | if (GNUNET_OK != | 170 | if (GNUNET_OK != |
155 | GNUNET_CONFIGURATION_deserialize (cfg, | 171 | GNUNET_CONFIGURATION_deserialize(cfg, |
156 | (const char *) &res[1], | 172 | (const char *)&res[1], |
157 | left, | 173 | left, |
158 | NULL)) | 174 | NULL)) |
159 | { | 175 | { |
160 | GNUNET_break (0); | 176 | GNUNET_break(0); |
161 | ah->arc (ah->arc_cls, | 177 | ah->arc(ah->arc_cls, |
162 | NULL, | 178 | NULL, |
163 | GNUNET_NAT_ERROR_IPC_FAILURE, | 179 | GNUNET_NAT_ERROR_IPC_FAILURE, |
164 | type); | 180 | type); |
165 | } | 181 | } |
166 | else | 182 | else |
167 | { | 183 | { |
168 | ah->arc (ah->arc_cls, | 184 | ah->arc(ah->arc_cls, |
169 | cfg, | 185 | cfg, |
170 | status, | 186 | status, |
171 | type); | 187 | type); |
172 | } | 188 | } |
173 | GNUNET_CONFIGURATION_destroy (cfg); | 189 | GNUNET_CONFIGURATION_destroy(cfg); |
174 | GNUNET_NAT_AUTO_autoconfig_cancel (ah); | 190 | GNUNET_NAT_AUTO_autoconfig_cancel(ah); |
175 | } | 191 | } |
176 | 192 | ||
177 | 193 | ||
@@ -182,16 +198,16 @@ handle_auto_result (void *cls, | |||
182 | * @param error details about the error | 198 | * @param error details about the error |
183 | */ | 199 | */ |
184 | static void | 200 | static void |
185 | ah_error_handler (void *cls, | 201 | ah_error_handler(void *cls, |
186 | enum GNUNET_MQ_Error error) | 202 | enum GNUNET_MQ_Error error) |
187 | { | 203 | { |
188 | struct GNUNET_NAT_AUTO_AutoHandle *ah = cls; | 204 | struct GNUNET_NAT_AUTO_AutoHandle *ah = cls; |
189 | 205 | ||
190 | ah->arc (ah->arc_cls, | 206 | ah->arc(ah->arc_cls, |
191 | NULL, | 207 | NULL, |
192 | GNUNET_NAT_ERROR_IPC_FAILURE, | 208 | GNUNET_NAT_ERROR_IPC_FAILURE, |
193 | GNUNET_NAT_TYPE_UNKNOWN); | 209 | GNUNET_NAT_TYPE_UNKNOWN); |
194 | GNUNET_NAT_AUTO_autoconfig_cancel (ah); | 210 | GNUNET_NAT_AUTO_autoconfig_cancel(ah); |
195 | } | 211 | } |
196 | 212 | ||
197 | 213 | ||
@@ -205,55 +221,55 @@ ah_error_handler (void *cls, | |||
205 | * @return handle to cancel operation | 221 | * @return handle to cancel operation |
206 | */ | 222 | */ |
207 | struct GNUNET_NAT_AUTO_AutoHandle * | 223 | struct GNUNET_NAT_AUTO_AutoHandle * |
208 | GNUNET_NAT_AUTO_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 224 | GNUNET_NAT_AUTO_autoconfig_start(const struct GNUNET_CONFIGURATION_Handle *cfg, |
209 | GNUNET_NAT_AUTO_AutoResultCallback cb, | 225 | GNUNET_NAT_AUTO_AutoResultCallback cb, |
210 | void *cb_cls) | 226 | void *cb_cls) |
211 | { | 227 | { |
212 | struct GNUNET_NAT_AUTO_AutoHandle *ah = GNUNET_new (struct GNUNET_NAT_AUTO_AutoHandle); | 228 | struct GNUNET_NAT_AUTO_AutoHandle *ah = GNUNET_new(struct GNUNET_NAT_AUTO_AutoHandle); |
213 | struct GNUNET_MQ_MessageHandler handlers[] = { | 229 | struct GNUNET_MQ_MessageHandler handlers[] = { |
214 | GNUNET_MQ_hd_var_size (auto_result, | 230 | GNUNET_MQ_hd_var_size(auto_result, |
215 | GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT, | 231 | GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT, |
216 | struct GNUNET_NAT_AUTO_AutoconfigResultMessage, | 232 | struct GNUNET_NAT_AUTO_AutoconfigResultMessage, |
217 | ah), | 233 | ah), |
218 | GNUNET_MQ_handler_end () | 234 | GNUNET_MQ_handler_end() |
219 | }; | 235 | }; |
220 | struct GNUNET_MQ_Envelope *env; | 236 | struct GNUNET_MQ_Envelope *env; |
221 | struct GNUNET_NAT_AUTO_AutoconfigRequestMessage *req; | 237 | struct GNUNET_NAT_AUTO_AutoconfigRequestMessage *req; |
222 | char *buf; | 238 | char *buf; |
223 | size_t size; | 239 | size_t size; |
224 | 240 | ||
225 | buf = GNUNET_CONFIGURATION_serialize (cfg, | 241 | buf = GNUNET_CONFIGURATION_serialize(cfg, |
226 | &size); | 242 | &size); |
227 | if (size > GNUNET_MAX_MESSAGE_SIZE - sizeof (*req)) | 243 | if (size > GNUNET_MAX_MESSAGE_SIZE - sizeof(*req)) |
228 | { | 244 | { |
229 | GNUNET_break (0); | 245 | GNUNET_break(0); |
230 | GNUNET_free (buf); | 246 | GNUNET_free(buf); |
231 | GNUNET_free (ah); | 247 | GNUNET_free(ah); |
232 | return NULL; | 248 | return NULL; |
233 | } | 249 | } |
234 | ah->arc = cb; | 250 | ah->arc = cb; |
235 | ah->arc_cls = cb_cls; | 251 | ah->arc_cls = cb_cls; |
236 | ah->mq = GNUNET_CLIENT_connect (cfg, | 252 | ah->mq = GNUNET_CLIENT_connect(cfg, |
237 | "nat", | 253 | "nat", |
238 | handlers, | 254 | handlers, |
239 | &ah_error_handler, | 255 | &ah_error_handler, |
240 | ah); | 256 | ah); |
241 | if (NULL == ah->mq) | 257 | if (NULL == ah->mq) |
242 | { | 258 | { |
243 | GNUNET_break (0); | 259 | GNUNET_break(0); |
244 | GNUNET_free (buf); | 260 | GNUNET_free(buf); |
245 | GNUNET_free (ah); | 261 | GNUNET_free(ah); |
246 | return NULL; | 262 | return NULL; |
247 | } | 263 | } |
248 | env = GNUNET_MQ_msg_extra (req, | 264 | env = GNUNET_MQ_msg_extra(req, |
249 | size, | 265 | size, |
250 | GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG); | 266 | GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG); |
251 | GNUNET_memcpy (&req[1], | 267 | GNUNET_memcpy(&req[1], |
252 | buf, | 268 | buf, |
253 | size); | 269 | size); |
254 | GNUNET_free (buf); | 270 | GNUNET_free(buf); |
255 | GNUNET_MQ_send (ah->mq, | 271 | GNUNET_MQ_send(ah->mq, |
256 | env); | 272 | env); |
257 | return ah; | 273 | return ah; |
258 | } | 274 | } |
259 | 275 | ||
@@ -264,10 +280,10 @@ GNUNET_NAT_AUTO_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
264 | * @param ah handle for operation to abort | 280 | * @param ah handle for operation to abort |
265 | */ | 281 | */ |
266 | void | 282 | void |
267 | GNUNET_NAT_AUTO_autoconfig_cancel (struct GNUNET_NAT_AUTO_AutoHandle *ah) | 283 | GNUNET_NAT_AUTO_autoconfig_cancel(struct GNUNET_NAT_AUTO_AutoHandle *ah) |
268 | { | 284 | { |
269 | GNUNET_MQ_destroy (ah->mq); | 285 | GNUNET_MQ_destroy(ah->mq); |
270 | GNUNET_free (ah); | 286 | GNUNET_free(ah); |
271 | } | 287 | } |
272 | 288 | ||
273 | /* end of nat_api_auto.c */ | 289 | /* end of nat_api_auto.c */ |