124 const char *port_start;
125 struct sockaddr_in sin_addr;
127 h->server_read_task = NULL;
128 memset (mybuf, 0,
sizeof(mybuf));
134 "Finished reading from server stdout with code: %d\n",
140 h->server_proc = NULL;
142 h->server_stdout = NULL;
143 h->server_stdout_handle = NULL;
149 for (
size_t i = 0; i <
sizeof(mybuf); i++)
151 if (mybuf[i] ==
'\n')
156 if ((mybuf[i] ==
':') && (i + 1 <
sizeof(mybuf)))
159 port_start = &mybuf[i + 1];
164 memset (&sin_addr, 0,
sizeof(sin_addr));
165 sin_addr.sin_family = AF_INET;
166 #if HAVE_SOCKADDR_IN_SIN_LEN
167 sin_addr.sin_len =
sizeof(sin_addr);
169 if ((NULL == port_start) || (1 != sscanf (port_start,
"%d", &
port)) ||
170 (-1 == inet_pton (AF_INET, mybuf, &sin_addr.sin_addr)))
175 "gnunet-helper-nat-server generated malformed address `%s'\n"),
177 h->server_read_task =
179 h->server_stdout_handle,
184 sin_addr.sin_port = htons ((uint16_t)
port);
186 "gnunet-helper-nat-server read: %s:%d\n",
189 h->cb (
h->cb_cls, &sin_addr);
190 h->server_read_task =
192 h->server_stdout_handle,
209 char ia[INET_ADDRSTRLEN];
211 h->server_read_task = NULL;
213 inet_ntop (AF_INET, &
h->internal_address, ia,
sizeof(ia)));
226 if (NULL ==
h->server_stdout)
234 "Starting `%s' at `%s'\n",
235 "gnunet-helper-nat-server",
242 "gnunet-helper-nat-server",
246 if (NULL ==
h->server_proc)
249 _ (
"Failed to start %s\n"),
250 "gnunet-helper-nat-server");
252 h->server_stdout = NULL;
258 h->server_stdout_handle =
260 h->server_read_task =
262 h->server_stdout_handle,
282 if (NULL ==
h->server_stdout)
300 if (NULL !=
h->server_read_task)
303 h->server_read_task = NULL;
305 if (NULL !=
h->server_proc)
311 h->server_proc = NULL;
313 h->server_stdout = NULL;
314 h->server_stdout_handle = NULL;
316 if (NULL !=
h->server_stdout)
319 h->server_stdout = NULL;
320 h->server_stdout_handle = NULL;
340 uint16_t internal_port,
341 const struct in_addr *remote_v4,
344 char intv4[INET_ADDRSTRLEN];
345 char remv4[INET_ADDRSTRLEN];
346 char port_as_string[6];
350 if (NULL == inet_ntop (AF_INET, internal_address, intv4, INET_ADDRSTRLEN))
355 if (NULL == inet_ntop (AF_INET, remote_v4, remv4, INET_ADDRSTRLEN))
361 sizeof(port_as_string),
365 "Running gnunet-helper-nat-client %s %s %u\n",
375 "gnunet-helper-nat-client",
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static uint16_t port
Port number.
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)
We want to connect to a peer that is behind NAT.
static void nat_server_read(void *cls)
We have been notified that gnunet-helper-nat-server has written something to stdout.
void GN_stop_gnunet_nat_server_(struct HelperContext *h)
Start the gnunet-helper-nat-server and process incoming requests.
static void try_again(struct HelperContext *h)
Try again starting the helper later.
static void restart_nat_server(void *cls)
Task that restarts the gnunet-helper-nat-server process after a crash after a certain delay.
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)
Start the gnunet-helper-nat-server and process incoming requests.
runs the gnunet-helper-nat-server
void(* GN_ReversalCallback)(void *cls, const struct sockaddr_in *ra)
Function called whenever we get a connection reversal request from another peer.
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close_end(struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd end)
Closes one half of an interprocess channel.
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
@ GNUNET_DISK_PF_BLOCKING_RW
Configure both pipe ends for blocking operations if set.
@ GNUNET_DISK_PIPE_END_WRITE
The writing-end of a pipe.
@ GNUNET_DISK_PIPE_END_READ
The reading-end of a pipe.
#define GNUNET_log(kind,...)
#define GNUNET_log_from_strerror(level, component, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_OS_get_suid_binary_path(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *progname)
Given the name of a helper, service or daemon binary construct the full path to the binary using the ...
struct GNUNET_OS_Process * GNUNET_OS_start_process(enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename,...)
Start a process.
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
enum GNUNET_GenericReturnValue GNUNET_OS_check_helper_binary(const char *binary, bool check_suid, const char *params)
Check whether an executable exists and possibly if the suid bit is set on the file.
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
enum GNUNET_GenericReturnValue GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
@ GNUNET_OS_INHERIT_STD_NONE
No standard streams should be inherited.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD
Threshold after which exponential backoff should not increase (15 m).
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Handle used to access files (and pipes).
Handle used to manage a pipe.
Entry in list of pending tasks.
Time for relative time used by GNUnet, in microseconds.
Information we keep per NAT helper process.
struct GNUNET_DISK_PipeHandle * server_stdout
stdout pipe handle for the gnunet-helper-nat-server process
const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to the GNUnet configuration.
struct GNUNET_OS_Process * server_proc
The process id of the server process (if behind NAT)
struct GNUNET_TIME_Relative server_retry_delay
How long do we wait for restarting a crashed gnunet-helper-nat-server?
struct GNUNET_SCHEDULER_Task * server_read_task
ID of select gnunet-helper-nat-server stdout read task.
struct in_addr internal_address
IP address we pass to the NAT helper.
const struct GNUNET_DISK_FileHandle * server_stdout_handle
stdout file handle (for reading) for the gnunet-helper-nat-server process
GN_ReversalCallback cb
Function to call if we receive a reversal request.
void * cb_cls
Closure for cb.