summaryrefslogtreecommitdiff
path: root/src/nat/gnunet-service-nat_helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nat/gnunet-service-nat_helper.c')
-rw-r--r--src/nat/gnunet-service-nat_helper.c211
1 files changed, 86 insertions, 125 deletions
diff --git a/src/nat/gnunet-service-nat_helper.c b/src/nat/gnunet-service-nat_helper.c
index 43ac54adf..cf5038dd7 100644
--- a/src/nat/gnunet-service-nat_helper.c
+++ b/src/nat/gnunet-service-nat_helper.c
@@ -101,12 +101,10 @@ static void
try_again (struct HelperContext *h)
{
GNUNET_assert (NULL == h->server_read_task);
- h->server_retry_delay
- = GNUNET_TIME_STD_BACKOFF (h->server_retry_delay);
- h->server_read_task
- = GNUNET_SCHEDULER_add_delayed (h->server_retry_delay,
- &restart_nat_server,
- h);
+ h->server_retry_delay = GNUNET_TIME_STD_BACKOFF (h->server_retry_delay);
+ h->server_read_task = GNUNET_SCHEDULER_add_delayed (h->server_retry_delay,
+ &restart_nat_server,
+ h);
}
@@ -128,23 +126,16 @@ nat_server_read (void *cls)
struct sockaddr_in sin_addr;
h->server_read_task = NULL;
- memset (mybuf,
- 0,
- sizeof (mybuf));
- bytes
- = GNUNET_DISK_file_read (h->server_stdout_handle,
- mybuf,
- sizeof (mybuf));
+ memset (mybuf, 0, sizeof (mybuf));
+ bytes =
+ GNUNET_DISK_file_read (h->server_stdout_handle, mybuf, sizeof (mybuf));
if (bytes < 1)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Finished reading from server stdout with code: %d\n",
- (int) bytes);
- if (0 != GNUNET_OS_process_kill (h->server_proc,
- GNUNET_TERM_SIG))
- GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING,
- "nat",
- "kill");
+ "Finished reading from server stdout with code: %d\n",
+ (int) bytes);
+ if (0 != GNUNET_OS_process_kill (h->server_proc, GNUNET_TERM_SIG))
+ GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "nat", "kill");
GNUNET_OS_process_wait (h->server_proc);
GNUNET_OS_process_destroy (h->server_proc);
h->server_proc = NULL;
@@ -171,44 +162,37 @@ nat_server_read (void *cls)
}
/* construct socket address of sender */
- memset (&sin_addr,
- 0,
- sizeof (sin_addr));
+ memset (&sin_addr, 0, sizeof (sin_addr));
sin_addr.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
sin_addr.sin_len = sizeof (sin_addr);
#endif
- if ( (NULL == port_start) ||
- (1 != SSCANF (port_start,
- "%d",
- &port)) ||
- (-1 == inet_pton (AF_INET,
- mybuf,
- &sin_addr.sin_addr)))
+ if ((NULL == port_start) || (1 != sscanf (port_start, "%d", &port)) ||
+ (-1 == inet_pton (AF_INET, mybuf, &sin_addr.sin_addr)))
{
/* should we restart gnunet-helper-nat-server? */
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("gnunet-helper-nat-server generated malformed address `%s'\n"),
- mybuf);
- h->server_read_task
- = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->server_stdout_handle,
- &nat_server_read,
- h);
+ _ (
+ "gnunet-helper-nat-server generated malformed address `%s'\n"),
+ mybuf);
+ h->server_read_task =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ h->server_stdout_handle,
+ &nat_server_read,
+ h);
return;
}
sin_addr.sin_port = htons ((uint16_t) port);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "gnunet-helper-nat-server read: %s:%d\n",
- mybuf,
- port);
- h->cb (h->cb_cls,
- &sin_addr);
- h->server_read_task
- = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->server_stdout_handle,
- &nat_server_read,
- h);
+ "gnunet-helper-nat-server read: %s:%d\n",
+ mybuf,
+ port);
+ h->cb (h->cb_cls, &sin_addr);
+ h->server_read_task =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ h->server_stdout_handle,
+ &nat_server_read,
+ h);
}
@@ -227,71 +211,59 @@ restart_nat_server (void *cls)
h->server_read_task = NULL;
GNUNET_assert (NULL !=
- inet_ntop (AF_INET,
- &h->internal_address,
- ia,
- sizeof (ia)));
+ inet_ntop (AF_INET, &h->internal_address, ia, sizeof (ia)));
/* Start the server process */
binary = GNUNET_OS_get_suid_binary_path (h->cfg, "gnunet-helper-nat-server");
- if (GNUNET_YES !=
- GNUNET_OS_check_helper_binary (binary,
- GNUNET_YES,
- ia))
+ if (GNUNET_YES != GNUNET_OS_check_helper_binary (binary, GNUNET_YES, ia))
{
/* move instantly to max delay, as this is unlikely to be fixed */
- h->server_retry_delay
- = GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD;
+ h->server_retry_delay = GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD;
GNUNET_free (binary);
try_again (h);
return;
}
- h->server_stdout
- = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES,
- GNUNET_NO, GNUNET_YES);
+ h->server_stdout =
+ GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
if (NULL == h->server_stdout)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "pipe");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe");
GNUNET_free (binary);
try_again (h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting `%s' at `%s'\n",
- "gnunet-helper-nat-server",
- ia);
- h->server_proc
- = GNUNET_OS_start_process (GNUNET_NO,
- 0,
- NULL,
- h->server_stdout,
- NULL,
- binary,
- "gnunet-helper-nat-server",
- ia,
- NULL);
+ "Starting `%s' at `%s'\n",
+ "gnunet-helper-nat-server",
+ ia);
+ h->server_proc = GNUNET_OS_start_process (GNUNET_NO,
+ 0,
+ NULL,
+ h->server_stdout,
+ NULL,
+ binary,
+ "gnunet-helper-nat-server",
+ ia,
+ NULL);
GNUNET_free (binary);
if (NULL == h->server_proc)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to start %s\n"),
- "gnunet-helper-nat-server");
+ _ ("Failed to start %s\n"),
+ "gnunet-helper-nat-server");
GNUNET_DISK_pipe_close (h->server_stdout);
h->server_stdout = NULL;
try_again (h);
return;
}
/* Close the write end of the read pipe */
- GNUNET_DISK_pipe_close_end (h->server_stdout,
- GNUNET_DISK_PIPE_END_WRITE);
- h->server_stdout_handle
- = GNUNET_DISK_pipe_handle (h->server_stdout,
- GNUNET_DISK_PIPE_END_READ);
- h->server_read_task
- = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->server_stdout_handle,
- &nat_server_read,
- h);
+ GNUNET_DISK_pipe_close_end (h->server_stdout, GNUNET_DISK_PIPE_END_WRITE);
+ h->server_stdout_handle =
+ GNUNET_DISK_pipe_handle (h->server_stdout, GNUNET_DISK_PIPE_END_READ);
+ h->server_read_task =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ h->server_stdout_handle,
+ &nat_server_read,
+ h);
}
@@ -307,9 +279,9 @@ restart_nat_server (void *cls)
*/
struct HelperContext *
GN_start_gnunet_nat_server_ (const struct in_addr *internal_address,
- GN_ReversalCallback cb,
- void *cb_cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ GN_ReversalCallback cb,
+ void *cb_cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct HelperContext *h;
@@ -344,10 +316,8 @@ GN_stop_gnunet_nat_server_ (struct HelperContext *h)
}
if (NULL != h->server_proc)
{
- if (0 != GNUNET_OS_process_kill (h->server_proc,
- GNUNET_TERM_SIG))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "kill");
+ if (0 != GNUNET_OS_process_kill (h->server_proc, GNUNET_TERM_SIG))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
GNUNET_OS_process_wait (h->server_proc);
GNUNET_OS_process_destroy (h->server_proc);
h->server_proc = NULL;
@@ -379,9 +349,9 @@ GN_stop_gnunet_nat_server_ (struct HelperContext *h)
*/
int
GN_request_connection_reversal (const struct in_addr *internal_address,
- uint16_t internal_port,
- const struct in_addr *remote_v4,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ uint16_t internal_port,
+ const struct in_addr *remote_v4,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
char intv4[INET_ADDRSTRLEN];
char remv4[INET_ADDRSTRLEN];
@@ -389,22 +359,14 @@ GN_request_connection_reversal (const struct in_addr *internal_address,
struct GNUNET_OS_Process *proc;
char *binary;
- if (NULL == inet_ntop (AF_INET,
- internal_address,
- intv4,
- INET_ADDRSTRLEN))
+ if (NULL == inet_ntop (AF_INET, internal_address, intv4, INET_ADDRSTRLEN))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "inet_ntop");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
return GNUNET_SYSERR;
}
- if (NULL == inet_ntop (AF_INET,
- remote_v4,
- remv4,
- INET_ADDRSTRLEN))
+ if (NULL == inet_ntop (AF_INET, remote_v4, remv4, INET_ADDRSTRLEN))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "inet_ntop");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
return GNUNET_SYSERR;
}
GNUNET_snprintf (port_as_string,
@@ -412,23 +374,22 @@ GN_request_connection_reversal (const struct in_addr *internal_address,
"%d",
internal_port);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Running gnunet-helper-nat-client %s %s %u\n",
- intv4,
- remv4,
- internal_port);
+ "Running gnunet-helper-nat-client %s %s %u\n",
+ intv4,
+ remv4,
+ internal_port);
binary = GNUNET_OS_get_suid_binary_path (cfg, "gnunet-helper-nat-client");
- proc
- = GNUNET_OS_start_process (GNUNET_NO,
- 0,
- NULL,
- NULL,
- NULL,
- binary,
- "gnunet-helper-nat-client",
- intv4,
- remv4,
- port_as_string,
- NULL);
+ proc = GNUNET_OS_start_process (GNUNET_NO,
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ binary,
+ "gnunet-helper-nat-client",
+ intv4,
+ remv4,
+ port_as_string,
+ NULL);
GNUNET_free (binary);
if (NULL == proc)
return GNUNET_SYSERR;