diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-11-30 08:22:59 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-11-30 08:22:59 +0100 |
commit | 738cbe38dec2f275994c822631bf3aba02a6e6d0 (patch) | |
tree | db2c234c16aeda98615babac49f2af7636740b21 /src/nat | |
parent | e43df97dfdb10903dd53571ab07863d95740592c (diff) | |
download | gnunet-738cbe38dec2f275994c822631bf3aba02a6e6d0.tar.gz gnunet-738cbe38dec2f275994c822631bf3aba02a6e6d0.zip |
moving basic logic for launching nat-client helper to new NAT service
Diffstat (limited to 'src/nat')
-rw-r--r-- | src/nat/gnunet-service-nat_helper.c | 65 | ||||
-rw-r--r-- | src/nat/gnunet-service-nat_helper.h | 15 |
2 files changed, 80 insertions, 0 deletions
diff --git a/src/nat/gnunet-service-nat_helper.c b/src/nat/gnunet-service-nat_helper.c index 4867f5675..e476da12d 100644 --- a/src/nat/gnunet-service-nat_helper.c +++ b/src/nat/gnunet-service-nat_helper.c | |||
@@ -342,4 +342,69 @@ GN_stop_gnunet_nat_server_ (struct HelperContext *h) | |||
342 | GNUNET_free (h); | 342 | GNUNET_free (h); |
343 | } | 343 | } |
344 | 344 | ||
345 | |||
346 | /** | ||
347 | * We want to connect to a peer that is behind NAT. Run the | ||
348 | * gnunet-helper-nat-client to send dummy ICMP responses to cause | ||
349 | * that peer to connect to us (connection reversal). | ||
350 | * | ||
351 | * @param internal_address out internal address to use | ||
352 | * @param sa the address of the peer (IPv4-only) | ||
353 | * @return #GNUNET_SYSERR on error, | ||
354 | * #GNUNET_OK otherwise | ||
355 | */ | ||
356 | int | ||
357 | GN_request_connection_reversal (const char *internal_address, | ||
358 | const struct sockaddr_in *sa) | ||
359 | { | ||
360 | char inet4[INET_ADDRSTRLEN]; | ||
361 | char port_as_string[6]; | ||
362 | struct GNUNET_OS_Process *proc; | ||
363 | char *binary; | ||
364 | |||
365 | GNUNET_assert (sa->sin_family == AF_INET); | ||
366 | if (NULL == inet_ntop (AF_INET, | ||
367 | &sa->sin_addr, | ||
368 | inet4, | ||
369 | INET_ADDRSTRLEN)) | ||
370 | { | ||
371 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
372 | "nat", | ||
373 | "inet_ntop"); | ||
374 | return GNUNET_SYSERR; | ||
375 | } | ||
376 | GNUNET_snprintf (port_as_string, | ||
377 | sizeof (port_as_string), | ||
378 | "%d", | ||
379 | ntohs (sa->sin_port)); | ||
380 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
381 | _("Running gnunet-helper-nat-client %s %s %u\n"), | ||
382 | internal_address, | ||
383 | inet4, | ||
384 | ntohs (sa->sin_port)); | ||
385 | binary | ||
386 | = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client"); | ||
387 | proc | ||
388 | = GNUNET_OS_start_process (GNUNET_NO, | ||
389 | 0, | ||
390 | NULL, | ||
391 | NULL, | ||
392 | NULL, | ||
393 | binary, | ||
394 | "gnunet-helper-nat-client", | ||
395 | internal_address, | ||
396 | inet4, | ||
397 | port_as_string, | ||
398 | NULL); | ||
399 | GNUNET_free (binary); | ||
400 | if (NULL == proc) | ||
401 | return GNUNET_SYSERR; | ||
402 | /* we know that the gnunet-helper-nat-client will terminate virtually | ||
403 | * instantly */ | ||
404 | GNUNET_OS_process_wait (proc); | ||
405 | GNUNET_OS_process_destroy (proc); | ||
406 | return GNUNET_OK; | ||
407 | } | ||
408 | |||
409 | |||
345 | /* end of gnunet-service-nat_helper.c */ | 410 | /* end of gnunet-service-nat_helper.c */ |
diff --git a/src/nat/gnunet-service-nat_helper.h b/src/nat/gnunet-service-nat_helper.h index c3074d9ad..861d62c1d 100644 --- a/src/nat/gnunet-service-nat_helper.h +++ b/src/nat/gnunet-service-nat_helper.h | |||
@@ -71,4 +71,19 @@ void | |||
71 | GN_stop_gnunet_nat_server_ (struct HelperContext *h); | 71 | GN_stop_gnunet_nat_server_ (struct HelperContext *h); |
72 | 72 | ||
73 | 73 | ||
74 | /** | ||
75 | * We want to connect to a peer that is behind NAT. Run the | ||
76 | * gnunet-helper-nat-client to send dummy ICMP responses to cause | ||
77 | * that peer to connect to us (connection reversal). | ||
78 | * | ||
79 | * @param internal_address out internal address to use | ||
80 | * @param sa the address of the peer (IPv4-only) | ||
81 | * @return #GNUNET_SYSERR on error, | ||
82 | * #GNUNET_OK otherwise | ||
83 | */ | ||
84 | int | ||
85 | GN_request_connection_reversal (const char *internal_address, | ||
86 | const struct sockaddr_in *sa); | ||
87 | |||
88 | |||
74 | /* end of gnunet-service-nat_helper.h */ | 89 | /* end of gnunet-service-nat_helper.h */ |