diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-01-02 20:13:38 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-01-02 20:13:38 +0100 |
commit | 60c6dfd1fe22a01a3f7723e7e2bb18d52895c527 (patch) | |
tree | f6ecf4f27ad1e91e4d49b061be0f4b05bda199f3 /src/nat/gnunet-service-nat_helper.c | |
parent | f28533eb5fbd2b8e00bb351eb9fd1da322c70505 (diff) | |
download | gnunet-60c6dfd1fe22a01a3f7723e7e2bb18d52895c527.tar.gz gnunet-60c6dfd1fe22a01a3f7723e7e2bb18d52895c527.zip |
fixes for starting and stopping gnunet-helper-nat-server
Diffstat (limited to 'src/nat/gnunet-service-nat_helper.c')
-rw-r--r-- | src/nat/gnunet-service-nat_helper.c | 65 |
1 files changed, 30 insertions, 35 deletions
diff --git a/src/nat/gnunet-service-nat_helper.c b/src/nat/gnunet-service-nat_helper.c index febc3c2dd..7e5051d65 100644 --- a/src/nat/gnunet-service-nat_helper.c +++ b/src/nat/gnunet-service-nat_helper.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet-service-nat_helper.h" | 29 | #include "gnunet-service-nat_helper.h" |
30 | 30 | ||
31 | #define LOG(kind,...) GNUNET_log_from (kind, "nat", __VA_ARGS__) | ||
32 | 31 | ||
33 | /** | 32 | /** |
34 | * Information we keep per NAT helper process. | 33 | * Information we keep per NAT helper process. |
@@ -133,11 +132,11 @@ nat_server_read (void *cls) | |||
133 | sizeof (mybuf)); | 132 | sizeof (mybuf)); |
134 | if (bytes < 1) | 133 | if (bytes < 1) |
135 | { | 134 | { |
136 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
137 | "Finished reading from server stdout with code: %d\n", | 136 | "Finished reading from server stdout with code: %d\n", |
138 | bytes); | 137 | bytes); |
139 | if (0 != GNUNET_OS_process_kill (h->server_proc, | 138 | if (0 != GNUNET_OS_process_kill (h->server_proc, |
140 | - GNUNET_TERM_SIG)) | 139 | GNUNET_TERM_SIG)) |
141 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, | 140 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, |
142 | "nat", | 141 | "nat", |
143 | "kill"); | 142 | "kill"); |
@@ -183,10 +182,9 @@ nat_server_read (void *cls) | |||
183 | &sin_addr.sin_addr))) | 182 | &sin_addr.sin_addr))) |
184 | { | 183 | { |
185 | /* should we restart gnunet-helper-nat-server? */ | 184 | /* should we restart gnunet-helper-nat-server? */ |
186 | LOG (GNUNET_ERROR_TYPE_WARNING, | 185 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
187 | "nat", | 186 | _("gnunet-helper-nat-server generated malformed address `%s'\n"), |
188 | _("gnunet-helper-nat-server generated malformed address `%s'\n"), | 187 | mybuf); |
189 | mybuf); | ||
190 | h->server_read_task | 188 | h->server_read_task |
191 | = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 189 | = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
192 | h->server_stdout_handle, | 190 | h->server_stdout_handle, |
@@ -195,10 +193,10 @@ nat_server_read (void *cls) | |||
195 | return; | 193 | return; |
196 | } | 194 | } |
197 | sin_addr.sin_port = htons ((uint16_t) port); | 195 | sin_addr.sin_port = htons ((uint16_t) port); |
198 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 196 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
199 | "gnunet-helper-nat-server read: %s:%d\n", | 197 | "gnunet-helper-nat-server read: %s:%d\n", |
200 | mybuf, | 198 | mybuf, |
201 | port); | 199 | port); |
202 | h->cb (h->cb_cls, | 200 | h->cb (h->cb_cls, |
203 | &sin_addr); | 201 | &sin_addr); |
204 | h->server_read_task | 202 | h->server_read_task |
@@ -238,10 +236,10 @@ restart_nat_server (void *cls) | |||
238 | &h->internal_address, | 236 | &h->internal_address, |
239 | ia, | 237 | ia, |
240 | sizeof (ia))); | 238 | sizeof (ia))); |
241 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 239 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
242 | "Starting `%s' at `%s'\n", | 240 | "Starting `%s' at `%s'\n", |
243 | "gnunet-helper-nat-server", | 241 | "gnunet-helper-nat-server", |
244 | ia); | 242 | ia); |
245 | /* Start the server process */ | 243 | /* Start the server process */ |
246 | binary | 244 | binary |
247 | = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-server"); | 245 | = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-server"); |
@@ -258,10 +256,9 @@ restart_nat_server (void *cls) | |||
258 | GNUNET_free (binary); | 256 | GNUNET_free (binary); |
259 | if (NULL == h->server_proc) | 257 | if (NULL == h->server_proc) |
260 | { | 258 | { |
261 | LOG (GNUNET_ERROR_TYPE_WARNING, | 259 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
262 | "nat", | 260 | _("Failed to start %s\n"), |
263 | _("Failed to start %s\n"), | 261 | "gnunet-helper-nat-server"); |
264 | "gnunet-helper-nat-server"); | ||
265 | GNUNET_DISK_pipe_close (h->server_stdout); | 262 | GNUNET_DISK_pipe_close (h->server_stdout); |
266 | h->server_stdout = NULL; | 263 | h->server_stdout = NULL; |
267 | try_again (h); | 264 | try_again (h); |
@@ -301,6 +298,7 @@ GN_start_gnunet_nat_server_ (const struct in_addr *internal_address, | |||
301 | h->cb = cb; | 298 | h->cb = cb; |
302 | h->cb_cls = cb_cls; | 299 | h->cb_cls = cb_cls; |
303 | h->internal_address = *internal_address; | 300 | h->internal_address = *internal_address; |
301 | restart_nat_server (h); | ||
304 | if (NULL == h->server_stdout) | 302 | if (NULL == h->server_stdout) |
305 | { | 303 | { |
306 | GN_stop_gnunet_nat_server_ (h); | 304 | GN_stop_gnunet_nat_server_ (h); |
@@ -328,9 +326,8 @@ GN_stop_gnunet_nat_server_ (struct HelperContext *h) | |||
328 | { | 326 | { |
329 | if (0 != GNUNET_OS_process_kill (h->server_proc, | 327 | if (0 != GNUNET_OS_process_kill (h->server_proc, |
330 | GNUNET_TERM_SIG)) | 328 | GNUNET_TERM_SIG)) |
331 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, | 329 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
332 | "nat", | 330 | "kill"); |
333 | "kill"); | ||
334 | GNUNET_OS_process_wait (h->server_proc); | 331 | GNUNET_OS_process_wait (h->server_proc); |
335 | GNUNET_OS_process_destroy (h->server_proc); | 332 | GNUNET_OS_process_destroy (h->server_proc); |
336 | h->server_proc = NULL; | 333 | h->server_proc = NULL; |
@@ -375,9 +372,8 @@ GN_request_connection_reversal (const struct in_addr *internal_address, | |||
375 | intv4, | 372 | intv4, |
376 | INET_ADDRSTRLEN)) | 373 | INET_ADDRSTRLEN)) |
377 | { | 374 | { |
378 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, | 375 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
379 | "nat", | 376 | "inet_ntop"); |
380 | "inet_ntop"); | ||
381 | return GNUNET_SYSERR; | 377 | return GNUNET_SYSERR; |
382 | } | 378 | } |
383 | if (NULL == inet_ntop (AF_INET, | 379 | if (NULL == inet_ntop (AF_INET, |
@@ -385,20 +381,19 @@ GN_request_connection_reversal (const struct in_addr *internal_address, | |||
385 | remv4, | 381 | remv4, |
386 | INET_ADDRSTRLEN)) | 382 | INET_ADDRSTRLEN)) |
387 | { | 383 | { |
388 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, | 384 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
389 | "nat", | 385 | "inet_ntop"); |
390 | "inet_ntop"); | ||
391 | return GNUNET_SYSERR; | 386 | return GNUNET_SYSERR; |
392 | } | 387 | } |
393 | GNUNET_snprintf (port_as_string, | 388 | GNUNET_snprintf (port_as_string, |
394 | sizeof (port_as_string), | 389 | sizeof (port_as_string), |
395 | "%d", | 390 | "%d", |
396 | internal_port); | 391 | internal_port); |
397 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 392 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
398 | _("Running gnunet-helper-nat-client %s %s %u\n"), | 393 | _("Running gnunet-helper-nat-client %s %s %u\n"), |
399 | intv4, | 394 | intv4, |
400 | remv4, | 395 | remv4, |
401 | internal_port); | 396 | internal_port); |
402 | binary | 397 | binary |
403 | = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client"); | 398 | = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client"); |
404 | proc | 399 | proc |